org.tmatesoft.svn.core.wc2.SvnOperationFactory Java Examples

The following examples show how to use org.tmatesoft.svn.core.wc2.SvnOperationFactory. 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: SubversionCommit.java    From Getaviz with Apache License 2.0 6 votes vote down vote up
private String createDiffDescription(long revision, String cleanedFilePath) throws SVNException {
	String returnable = null;
	final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
	try {
		final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		final SvnDiffGenerator diffGenerator = new SvnDiffGenerator();
		final SvnDiff diff = svnOperationFactory.createDiff();
		SVNURL currentRepoFilePath = SVNURL.parseURIEncoded(repo.getLocation().toString() + "/" + cleanedFilePath);
		List<SVNFileRevision> revisions = new ArrayList<SVNFileRevision>();
		repo.getFileRevisions(cleanedFilePath, revisions, 0, entry.getRevision());
		diff.setSources(SvnTarget.fromURL(currentRepoFilePath, SVNRevision.create(getLastCommitWhenChanged(revision, revisions))),
				SvnTarget.fromURL(currentRepoFilePath, SVNRevision.create(revision)));
		diff.setUseGitDiffFormat(true);
		diff.setDiffGenerator(diffGenerator);
		diff.setOutput(byteArrayOutputStream);
		diff.setDepth(SVNDepth.EMPTY);
		diff.run();
		returnable = new String(byteArrayOutputStream.toByteArray());
	} finally {
		svnOperationFactory.dispose();
	}
	return returnable;
}
 
Example #2
Source File: SvnWorkingCopyManager.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
public void checkoutBroken(File workingDirectory, VcsRepository repository, String revision)
    throws WorkingCopyCheckoutException {
  try {
    SvnUtil.setupLibrary();
    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    try {
        final SvnCheckout checkout = svnOperationFactory.createCheckout();
        checkout.setSingleTarget(SvnTarget.fromFile(workingDirectory));
        checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(repository.getUrl()), SVNRevision.create(Long.parseLong(revision))));
        checkout.run();
    } finally {
        svnOperationFactory.dispose();
    }
  } catch (NumberFormatException | SVNException e) {
    throw new WorkingCopyCheckoutException(repository, revision, e);
  }
}
 
Example #3
Source File: PackageDownloader.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * This method downloads an entire github repository or only a sub-directory within a repository.<br>
 * It can also download and extract an archive version of a github repository.
 * It relies on svn export command.<br>
 *
 * @param githubURL
 * @return
 */
private String downloadPackageFromGithub(String githubURL) throws SVNException {
    // Convert the githubRL to an svn format
    String svnURL = transformGithubURLToSvnURL(githubURL);

    // Save files in a system temporary directory
    String tDir = System.getProperty("java.io.tmpdir");
    String packagePath = tDir + "pkg_tmp" + System.nanoTime();
    File outputDir = new File(packagePath);

    // Perform an "svn export" command to download an entire repository or a subdirectory
    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    try {
        final SvnExport export = svnOperationFactory.createExport();
        export.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(svnURL)));
        export.setSingleTarget(SvnTarget.fromFile(outputDir));
        //overwrite an existing file
        export.setForce(true);
        export.run();
    } finally {
        //close connection pool associted with this object
        svnOperationFactory.dispose();
    }
    return packagePath;
}
 
Example #4
Source File: SVNKitEnvironmentRepositoryIntegrationTests.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
private void updateRepoForUpdate(String uri)
		throws SVNException, FileNotFoundException, IOException {
	SvnOperationFactory svnFactory = new SvnOperationFactory();
	final SvnCheckout checkout = svnFactory.createCheckout();
	checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(uri)));
	checkout.setSingleTarget(SvnTarget.fromFile(this.workingDir));
	checkout.run();

	// update bar.properties
	File barProps = new File(this.workingDir, "trunk/bar.properties");
	StreamUtils.copy("foo: foo", Charset.defaultCharset(),
			new FileOutputStream(barProps));
	// commit to repo
	SvnCommit svnCommit = svnFactory.createCommit();
	svnCommit.setCommitMessage("update bar.properties");
	svnCommit.setSingleTarget(SvnTarget.fromFile(barProps));
	svnCommit.run();
}
 
Example #5
Source File: SvnTestServer.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void close() throws Exception {
  shutdown(0);
  if (safeBranch) {
    new Git(repository)
        .branchDelete()
        .setBranchNames(testBranch)
        .setForce(true)
        .call();
  }
  for (SvnOperationFactory factory : svnFactories) {
    factory.dispose();
  }
  svnFactories.clear();
  repository.close();
  TestHelper.deleteDirectory(tempDirectory);
}
 
Example #6
Source File: StatusCmdTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void simple() throws Exception {
  try (SvnTestServer server = SvnTestServer.createMasterRepository()) {
    final SvnOperationFactory factory = server.createOperationFactory();

    final SvnCheckout checkout = factory.createCheckout();
    checkout.setSource(SvnTarget.fromURL(server.getUrl()));
    checkout.setSingleTarget(SvnTarget.fromFile(server.getTempDirectory().toFile()));
    checkout.setRevision(SVNRevision.create(1));
    checkout.run();

    final SvnGetStatus status = factory.createGetStatus();
    status.setSingleTarget(SvnTarget.fromFile(server.getTempDirectory().toFile()));
    status.setRevision(SVNRevision.create(2));
    status.run();
  }
}
 
Example #7
Source File: SvnClient.java    From steady with Apache License 2.0 5 votes vote down vote up
public File checkoutFile(String _rev, String _rel_path) {
	final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
	File f = null;
	SVNURL url = null;
	try {
		// Create subdir for given rev
		final String rel_dir = _rel_path.substring(0, _rel_path.lastIndexOf('/'));
		final Path rev_dir = Paths.get(this.workDir.toString(), _rev, rel_dir);
		Path p = Files.createDirectories(rev_dir);

		// Create SVNURL for specific file
		url = SVNURL.parseURIEncoded(this.rootRepo.getRepositoryRoot(false) + "/" + rel_dir);

		// Perform checkout
		SVNRevision revision = SVNRevision.create(Long.valueOf(_rev));

		SVNUpdateClient clnt = new SVNUpdateClient((ISVNAuthenticationManager)this.authManager, null);
		clnt.doCheckout(url, p.toFile(), revision, revision, SVNDepth.FILES, false); //IMMEDIATES, FILES, INFINITY

		//
		//			final SvnCheckout checkout = svnOperationFactory.createCheckout();
		//			checkout.setSingleTarget(SvnTarget.fromFile(p.toFile()));
		//			checkout.setSource(SvnTarget.fromURL(url));
		//			checkout.setDepth(SVNDepth.IMMEDIATES); //INFINITY
		//			checkout.setRevision(revision);
		//
		//			// Checkout and get file
		//			checkout.run();
		f = Paths.get(this.workDir.toString(), _rev, _rel_path).toFile();
	} catch (Exception e) {
		SvnClient.log.error("Error while checking out URL '" + url + "', revision "+ _rev + ": " + e.getMessage());
	} finally {
		svnOperationFactory.dispose();
	}
	return f;
}
 
Example #8
Source File: SvnKitEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized Locations getLocations(String application, String profile,
		String label) {
	if (label == null) {
		label = this.defaultLabel;
	}
	SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
	if (hasText(getUsername())) {
		svnOperationFactory
				.setAuthenticationManager(new DefaultSVNAuthenticationManager(null,
						false, getUsername(), getPassword()));
	}
	try {
		String version;
		if (new File(getWorkingDirectory(), ".svn").exists()) {
			version = update(svnOperationFactory, label);
		}
		else {
			version = checkout(svnOperationFactory);
		}
		return new Locations(application, profile, label, version,
				getPaths(application, profile, label));
	}
	catch (SVNException e) {
		throw new IllegalStateException("Cannot checkout repository", e);
	}
	finally {
		svnOperationFactory.dispose();
	}
}
 
Example #9
Source File: SvnTestServer.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@NotNull
private SvnOperationFactory createOperationFactory(@NotNull String username, @NotNull String password) {
  final SVNWCContext wcContext = new SVNWCContext(new DefaultSVNOptions(getTempDirectory().toFile(), true), null);
  wcContext.setSqliteTemporaryDbInMemory(true);
  wcContext.setSqliteJournalMode(SqlJetPagerJournalMode.MEMORY);

  final SvnOperationFactory factory = new SvnOperationFactory(wcContext);
  factory.setAuthenticationManager(BasicAuthenticationManager.newInstance(username, password.toCharArray()));
  svnFactories.add(factory);
  return factory;
}
 
Example #10
Source File: SvnUpdateTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Bug: svn up doesnt remove file #18
 * <pre>
 * bozaro@landfill:/tmp/test/git-as-svn$ echo > test.txt
 * bozaro@landfill:/tmp/test/git-as-svn$ svn add test.txt
 * A         test.txt
 * bozaro@landfill:/tmp/test/git-as-svn$ svn commit -m "Add new file"
 * Добавляю          test.txt
 * Передаю данные .
 * Committed revision 58.
 * bozaro@landfill:/tmp/test/git-as-svn$ svn up -r 57
 * Updating '.':
 * В редакции 57.
 * bozaro@landfill:/tmp/test/git-as-svn$ ls -l test.txt
 * -rw-rw-r-- 1 bozaro bozaro 1 авг.  15 00:50 test.txt
 * bozaro@landfill:/tmp/test/git-as-svn$
 * </pre>
 */
@Test
public void addAndUpdate() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SvnOperationFactory factory = server.createOperationFactory();
    final SVNClientManager client = SVNClientManager.newInstance(factory);
    // checkout
    final SvnCheckout checkout = factory.createCheckout();
    checkout.setSource(SvnTarget.fromURL(server.getUrl()));
    checkout.setSingleTarget(SvnTarget.fromFile(server.getTempDirectory().toFile()));
    checkout.setRevision(SVNRevision.HEAD);
    final long revision = checkout.run();
    // create file
    Path newFile = server.getTempDirectory().resolve("somefile.txt");
    TestHelper.saveFile(newFile, "Bla Bla Bla");
    // add file
    client.getWCClient().doAdd(newFile.toFile(), false, false, false, SVNDepth.INFINITY, false, true);
    // set eof property
    client.getWCClient().doSetProperty(newFile.toFile(), SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE), false, SVNDepth.INFINITY, null, null);
    // commit new file
    client.getCommitClient().doCommit(new File[]{newFile.toFile()}, false, "Add file commit", null, null, false, false, SVNDepth.INFINITY);
    // update for checkout revision
    client.getUpdateClient().doUpdate(server.getTempDirectory().toFile(), SVNRevision.create(revision), SVNDepth.INFINITY, false, false);
    // file must be remove
    Assert.assertFalse(Files.exists(newFile));
  }
}
 
Example #11
Source File: SvnTestServer.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@NotNull
public SvnOperationFactory createOperationFactory() {
  return createOperationFactory(USER_NAME, PASSWORD);
}