org.tmatesoft.svn.core.io.SVNRepositoryFactory Java Examples

The following examples show how to use org.tmatesoft.svn.core.io.SVNRepositoryFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubversionRepositoryInitializer.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #2
Source File: TestCheckOut.java    From klask-io with GNU General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #3
Source File: MCRVersioningMetadataStore.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: SvnTesterExternalListener.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
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;
  }
}
 
Example #5
Source File: SvnTesterExternal.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@NotNull
private SVNRepository openSvnRepository(@NotNull SVNURL url) throws SVNException {
  final SVNRepository repo = SVNRepositoryFactory.create(url);
  if (authManager != null) {
    repo.setAuthenticationManager(authManager);
  }
  return repo;
}
 
Example #6
Source File: SvnTesterSvnKit.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
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));
  }
}
 
Example #7
Source File: SvnUtil.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public static SVNRepository createRepository(String url) throws SVNException{
	return  SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));	
}
 
Example #8
Source File: SvnTestServer.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@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;
}