Java源码示例:org.tmatesoft.svn.core.io.SVNRepositoryFactory
示例1
public SVNRepository initRepository(boolean cached) throws SVNException, MalformedURLException {
SVNRepository repo = null;
SVNURL svnUrl = SVNURL.parseURIEncoded(url);
if (url.startsWith(HTTP_SCHEME + SCHEME_SEPARATOR) || url.startsWith(HTTPS_SCHEME + SCHEME_SEPARATOR)) {
DAVRepositoryFactory.setup();
repo = DAVRepositoryFactory.create(svnUrl);
repo.testConnection();
if(cached) {
TmpDirCreator tmpDirCreator = new TmpDirCreator(url);
File tempDir = tmpDirCreator.getLocalTempDir();
SVNURL cachedRepoPath = SVNURL.parseURIEncoded(FILE_SCHEME + SCHEME_SEPARATOR + tempDir);
if(!tempDir.exists()){
messageOutputStream.println("Caching subversion repository " + svnUrl + " This can take a while...");
tempDir.mkdirs();
cachedRepoPath = SVNRepositoryFactory.createLocalRepository(tempDir, true, true);
tmpDirCreator.writeIdFileToTempDir();
SVNRepository targetRepo = SVNRepositoryFactory.create(cachedRepoPath);
SVNRepositoryReplicator replicator = SVNRepositoryReplicator.newInstance();
replicator.setReplicationHandler(new ProgressBarReplicationHandler(repo.getLatestRevision()));
replicator.replicateRepository(repo, targetRepo, -1, -1);
messageOutputStream.println("\nCaching finished succesfully...");
}
svnUrl = cachedRepoPath;
FSRepositoryFactory.setup();
repo = FSRepositoryFactory.create(svnUrl);
}
} else if (url.startsWith(SVN_SCHEME + SCHEME_SEPARATOR)) {
SVNRepositoryFactoryImpl.setup();
repo = SVNRepositoryFactoryImpl.create(svnUrl);
} else if (url.startsWith(FILE_SCHEME + SCHEME_SEPARATOR)) {
FSRepositoryFactory.setup();
repo = FSRepositoryFactory.create(svnUrl);
} else
throw new MalformedURLException(String.format("URL %s is not an supported SVN url!", url));
repo.testConnection();
return repo;
}
示例2
public void checkoutTest() throws SVNException {
String checkoutPath = "svn://localhost";
String username = "integration";
String password = "integration";
String checkoutRootPath = new File("/home/jeremie/Developpement/checkoutsvn").getAbsolutePath();
DAVRepositoryFactory.setup();
final SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(checkoutPath));
repository.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager(username, password));
final SVNClientManager clientManager = SVNClientManager.newInstance(null, repository.getAuthenticationManager());
final SVNUpdateClient updateClient = clientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
final SVNNodeKind nodeKind = repository.checkPath("", -1);
if (nodeKind == SVNNodeKind.NONE) {
System.err.println("There is no entry at '" + checkoutPath + "'.");
System.exit(1);
} else if (nodeKind == SVNNodeKind.FILE) {
System.err.println("The entry at '" + checkoutPath + "' is a file while a directory was expected.");
System.exit(1);
}
System.out.println("*** CHECKOUT SVN Trunk/Branches ***");
System.out.println("Checkout source: " + checkoutPath);
System.out.println("Checkout destination: " + checkoutRootPath);
System.out.println("...");
try {
traverse(updateClient, repository, checkoutPath, checkoutRootPath, "", true);
} catch (final Exception e) {
System.err.println("ERROR : " + e.getMessage());
e.printStackTrace(System.err);
System.exit(-1);
}
System.out.println("");
System.out.println("Repository latest revision: " + repository.getLatestRevision());
}
示例3
/**
* Returns the SVN repository used to manage metadata versions in this
* store.
*
* @return the SVN repository used to manage metadata versions in this
* store.
*/
SVNRepository getRepository() throws SVNException {
SVNRepository repository = SVNRepositoryFactory.create(repURL);
String user = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID();
SVNAuthentication[] auth = {
SVNUserNameAuthentication.newInstance(user, false, repURL, false) };
BasicAuthenticationManager authManager = new BasicAuthenticationManager(auth);
repository.setAuthenticationManager(authManager);
return repository;
}
示例4
NativeDaemon(@NotNull String svnserve, @NotNull String svnadmin) throws IOException, InterruptedException, SVNException {
int port = detectPort();
url = SVNURL.create("svn", null, HOST, port, null, true);
repo = TestHelper.createTempDir("git-as-svn-repo");
log.info("Starting native svn daemon at: {}, url: {}", repo, url);
Runtime.getRuntime().exec(new String[]{
svnadmin,
"create",
repo.toString()
}).waitFor();
Path config = createConfigs(repo);
daemon = Runtime.getRuntime().exec(new String[]{
svnserve,
"--daemon",
"--root", repo.toString(),
"--config-file", config.toString(),
"--listen-host", HOST,
"--listen-port", Integer.toString(port)
});
long serverStartupTimeout = System.currentTimeMillis() + SERVER_STARTUP_TIMEOUT;
while (true) {
try {
SVNRepositoryFactory.create(url).getRevisionPropertyValue(0, "example");
} catch (SVNAuthenticationException ignored) {
break;
} catch (SVNException e) {
if ((e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_SVN_IO_ERROR) && (System.currentTimeMillis() < serverStartupTimeout)) {
Thread.sleep(SERVER_STARTUP_DELAY);
continue;
}
throw e;
}
break;
}
}
示例5
@NotNull
private SVNRepository openSvnRepository(@NotNull SVNURL url) throws SVNException {
final SVNRepository repo = SVNRepositoryFactory.create(url);
if (authManager != null) {
repo.setAuthenticationManager(authManager);
}
return repo;
}
示例6
public SvnTesterSvnKit() throws SVNException {
try {
repoDir = TestHelper.createTempDir("git-as-svn");
url = SVNRepositoryFactory.createLocalRepository(repoDir.toFile(), true, true);
} catch (IOException e) {
throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e));
}
}
示例7
public static SVNRepository createRepository(String url) throws SVNException{
return SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
}
示例8
@NotNull
public static SVNRepository openSvnRepository(@NotNull SVNURL url, @NotNull String username, @NotNull String password) throws SVNException {
final SVNRepository repo = SVNRepositoryFactory.create(url);
repo.setAuthenticationManager(BasicAuthenticationManager.newInstance(username, password.toCharArray()));
return repo;
}