Java源码示例:org.tmatesoft.svn.core.wc2.SvnOperationFactory
示例1
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;
}
示例2
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);
}
}
示例3
/**
* 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;
}
示例4
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();
}
示例5
@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);
}
示例6
@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();
}
}
示例7
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;
}
示例8
@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();
}
}
示例9
@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;
}
示例10
/**
* Bug: svn up doesnt remove file #18
* <pre>
* [email protected]:/tmp/test/git-as-svn$ echo > test.txt
* [email protected]:/tmp/test/git-as-svn$ svn add test.txt
* A test.txt
* [email protected]:/tmp/test/git-as-svn$ svn commit -m "Add new file"
* Добавляю test.txt
* Передаю данные .
* Committed revision 58.
* [email protected]:/tmp/test/git-as-svn$ svn up -r 57
* Updating '.':
* В редакции 57.
* [email protected]:/tmp/test/git-as-svn$ ls -l test.txt
* -rw-rw-r-- 1 bozaro bozaro 1 авг. 15 00:50 test.txt
* [email protected]:/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));
}
}
示例11
@NotNull
public SvnOperationFactory createOperationFactory() {
return createOperationFactory(USER_NAME, PASSWORD);
}