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

The following examples show how to use org.tmatesoft.svn.core.wc2.SvnTarget. 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: 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 #6
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));
  }
}