org.tmatesoft.svn.core.wc.SVNClientManager Java Examples
The following examples show how to use
org.tmatesoft.svn.core.wc.SVNClientManager.
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: SvnKitProcessor.java From StatSVN with GNU Lesser General Public License v3.0 | 6 votes |
public SVNClientManager getManager() { if (manager==null) { // initialize DAVRepositoryFactory.setup(); SVNRepositoryFactoryImpl.setup(); FSRepositoryFactory.setup(); //readonly - configuration options are available only for reading DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true); options.setAuthStorageEnabled(false); // Creates an instance of SVNClientManager providing an options driver & username & password if (SvnConfigurationOptions.getSvnUsername()!=null && SvnConfigurationOptions.getSvnPassword()!=null) manager = SVNClientManager.newInstance(options, SvnConfigurationOptions.getSvnUsername(), SvnConfigurationOptions.getSvnPassword()); else manager = SVNClientManager.newInstance(options); } return manager; }
Example #2
Source File: SvnPersisterCoreImpl.java From proctor with Apache License 2.0 | 6 votes |
/** * Returns the most recent log entry startRevision. * startRevision should not be HEAD because the path @HEAD could be deleted. * * @param path * @param startRevision * @return * @throws SVNException */ private SVNLogEntry getMostRecentLogEntry(final SVNClientManager clientManager, final String path, final SVNRevision startRevision) throws SVNException { final String[] targetPaths = {path}; final SVNLogClient logClient = clientManager.getLogClient(); final FilterableSVNLogEntryHandler handler = new FilterableSVNLogEntryHandler(); final int limit = 1; // In order to get history is "descending" order, the startRevision should be the one closer to HEAD // The path@head could be deleted - must use 'pegRevision' to get history at a deleted path logClient.doLog(svnUrl, targetPaths, /* pegRevision */ startRevision, /* startRevision */ startRevision, /* endRevision */ SVNRevision.create(1), /* stopOnCopy */ false, /* discoverChangedPaths */ false, /* includeMergedRevisions */ false, limit, new String[]{SVNRevisionProperty.AUTHOR}, handler); if (handler.getLogEntries().isEmpty()) { return null; } else { return handler.getLogEntries().get(0); } }
Example #3
Source File: SvnProctor.java From proctor with Apache License 2.0 | 6 votes |
@Override public void verifySetup() throws StoreException { final Long latestRevision = getSvnCore().doWithClientAndRepository(new SvnPersisterCore.SvnOperation<Long>() { @Override public Long execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { return repo.getLatestRevision(); } @Override public StoreException handleException(final Exception e) throws StoreException { throw new StoreException("Failed to get latest revision for svn-path: " + svnUrl, e); } }); if (latestRevision <= 0) { throw new StoreException("Found non-positive revision (" + latestRevision + ") for svn-path: " + svnUrl); } }
Example #4
Source File: SvnProctor.java From proctor with Apache License 2.0 | 6 votes |
@Nonnull @Override public List<Revision> getMatrixHistory(final int start, final int limit) throws StoreException { final String[] targetPaths = {}; return getSvnCore().doWithClientAndRepository(new SvnPersisterCore.SvnOperation<List<Revision>>() { @Override public List<Revision> execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { return getSVNLogs(clientManager, targetPaths, SVNRevision.HEAD, start, limit); } @Override public StoreException handleException(final Exception e) throws StoreException { throw new StoreException.ReadException("Unable to get matrix history", e); } }); }
Example #5
Source File: SvnProctor.java From proctor with Apache License 2.0 | 6 votes |
@Nonnull @Override public String getLatestVersion() throws StoreException { return getSvnCore().doWithClientAndRepository(new SvnPersisterCore.SvnOperation<String>() { @Override public String execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { final String[] targetPaths = {}; final SVNRevision svnRevision = SVNRevision.HEAD; final SVNLogClient logClient = clientManager.getLogClient(); final FilterableSVNLogEntryHandler handler = new FilterableSVNLogEntryHandler(); // In order to get history is "descending" order, the startRevision should be the one closer to HEAD logClient.doLog(svnUrl, targetPaths, /* pegRevision */ SVNRevision.HEAD, svnRevision, SVNRevision.create(1), /* stopOnCopy */ false, /* discoverChangedPaths */ false, /* includeMergedRevisions */ false, /* limit */ 1, new String[]{SVNRevisionProperty.LOG}, handler); final SVNLogEntry entry = handler.getLogEntries().size() > 0 ? handler.getLogEntries().get(0) : null; return entry == null ? "-1" : String.valueOf(entry.getRevision()); } @Override public StoreException handleException(final Exception e) throws StoreException { throw new StoreException.ReadException("Unable to get latest revision", e); } }); }
Example #6
Source File: SvnProctor.java From proctor with Apache License 2.0 | 6 votes |
@Nonnull @Override public List<Revision> getHistory(final String test, final int start, final int limit) throws StoreException { return getSvnCore().doWithClientAndRepository(new SvnPersisterCore.SvnOperation<List<Revision>>() { @Override public List<Revision> execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { final long latestRevision = repo.getLatestRevision(); return getHistory(test, String.valueOf(latestRevision), start, limit); } @Override public StoreException handleException(final Exception e) throws StoreException { throw new StoreException.ReadException("Unable to get older revisions for " + test, e); } }); }
Example #7
Source File: SvnDirectoryRefresher.java From proctor with Apache License 2.0 | 5 votes |
@Override public void run() { try { if (!shutdown.get()) { svnPersisterCore.doWithClientAndRepository(new SvnPersisterCore.SvnOperation<Void>() { @Override public Void execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { LOGGER.info("(svn) refresh of " + directory); final long startms = System.currentTimeMillis(); SvnProctorUtils.cleanUpWorkingDir(LOGGER, directory, svnUrl, clientManager); final long elapsedms = System.currentTimeMillis() - startms; LOGGER.info("(svn) refresh of " + directory + " in " + elapsedms + " ms"); return null; } @Override public StoreException handleException(final Exception e) throws StoreException { throw new StoreException("Unabled to svn refresh: " + directory, e); } }); } else { LOGGER.info("Skipping svn refresh, shutdown in progress"); } } catch (Exception exp) { LOGGER.warn("Exception during svn refresh of " + directory, exp); } }
Example #8
Source File: TestCheckOut.java From klask-io with GNU General Public License v3.0 | 5 votes |
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 #9
Source File: SvnUpdateTest.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
/** * 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 #10
Source File: SvnProctor.java From proctor with Apache License 2.0 | 5 votes |
private List<Revision> getSVNLogs(final SVNClientManager clientManager, final String[] paths, final SVNRevision startRevision, final int start, final int limit) throws StoreException.ReadException { try { final SVNLogClient logClient = clientManager.getLogClient(); final FilterableSVNLogEntryHandler handler = new FilterableSVNLogEntryHandler(); // In order to get history is "descending" order, the startRevision should be the one closer to HEAD logClient.doLog(svnUrl, paths, /* pegRevision */ SVNRevision.HEAD, startRevision, SVNRevision.create(1), /* stopOnCopy */ false, /* discoverChangedPaths */ false, /* includeMergedRevisions */ false, /* limit */ start + limit, new String[]{SVNRevisionProperty.LOG, SVNRevisionProperty.AUTHOR, SVNRevisionProperty.DATE}, handler); final List<SVNLogEntry> entries = handler.getLogEntries(); final List<Revision> revisions; if (entries.size() <= start) { revisions = Collections.emptyList(); } else { final int end = Math.min(start + limit, entries.size()); revisions = Lists.newArrayListWithCapacity(end - start); for (int i = 0; i < end - start; i++) { final SVNLogEntry entry = entries.get(start + i); revisions.add(new Revision(String.valueOf(entry.getRevision()), entry.getAuthor(), entry.getDate(), entry.getMessage())); } } return revisions; } catch (final SVNException e) { throw new StoreException.ReadException("Unable to get older revisions"); } }
Example #11
Source File: SvnObjectPools.java From proctor with Apache License 2.0 | 5 votes |
@Override public SVNClientManager create() throws Exception { if (requiresAuthentication) { final BasicAuthenticationManager authManager = new BasicAuthenticationManager(username, password); return SVNClientManager.newInstance(null, authManager); } else { return SVNClientManager.newInstance(); } }
Example #12
Source File: SvnProctor.java From proctor with Apache License 2.0 | 5 votes |
@Nonnull @Override public List<Revision> getHistory(final String test, final String version, final int start, final int limit) throws StoreException { final Long revision = SvnPersisterCoreImpl.parseRevisionOrDie(version); return getSvnCore().doWithClientAndRepository(new SvnPersisterCore.SvnOperation<List<Revision>>() { @Override public List<Revision> execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { // check path before executing svn log final String testPath = getTestDefinitionsDirectory() + "/" + test; final SVNNodeKind kind = repo.checkPath(testPath, revision); if (kind == SVNNodeKind.NONE) { return Collections.emptyList(); } final String[] targetPaths = {testPath}; final SVNRevision svnRevision = SVNRevision.create(revision); return getSVNLogs(clientManager, targetPaths, svnRevision, start, limit); } @Override public StoreException handleException(final Exception e) throws StoreException { throw new StoreException.ReadException("Unable to get older revisions for " + test + " r" + revision, e); } }); }
Example #13
Source File: SvnObjectPools.java From proctor with Apache License 2.0 | 4 votes |
@Override public void destroyObject(final PooledObject<SVNClientManager> p) throws Exception { final SVNClientManager m = p.getObject(); m.dispose(); }
Example #14
Source File: SvnPersisterCoreImpl.java From proctor with Apache License 2.0 | 4 votes |
@Override public TestVersionResult determineVersions(final String fetchRevision) throws StoreException.ReadException { checkShutdownState(); return doReadWithClientAndRepository(new SvnOperation<TestVersionResult>() { @Override public TestVersionResult execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { final String testDefPath = testDefinitionsDirectory; /* final SVNDirEntry info = repo.info(testDefPath, 2); if (info == null) { LOGGER.warn("No test matrix found in " + testDefPath + " under " + svnPath); return null; } */ final Long revision = fetchRevision.length() > 0 ? parseRevisionOrDie(fetchRevision) : Long.valueOf(-1); final SVNRevision svnRevision = revision.longValue() > 0 ? SVNRevision.create(revision.longValue()) : SVNRevision.HEAD; final SVNLogClient logClient = clientManager.getLogClient(); final FilterableSVNDirEntryHandler handler = new FilterableSVNDirEntryHandler(); final SVNURL url = SvnPersisterCoreImpl.this.svnUrl.appendPath(testDefPath, false); logClient.doList(url, svnRevision, svnRevision, /* fetchlocks */false, SVNDepth.IMMEDIATES, SVNDirEntry.DIRENT_KIND | SVNDirEntry.DIRENT_CREATED_REVISION, handler); final SVNDirEntry logEntry = handler.getParent(); final List<TestVersionResult.Test> tests = Lists.newArrayListWithExpectedSize(handler.getChildren().size()); for (final SVNDirEntry testDefFile : handler.getChildren()) { if (testDefFile.getKind() != SVNNodeKind.DIR) { LOGGER.warn(String.format("svn kind (%s) is not SVNNodeKind.DIR, skipping %s", testDefFile.getKind(), testDefFile.getURL())); continue; } final String testName = testDefFile.getName(); final long testRevision; /* When a svn directory gets copied using svn cp source-dir destination-dir, the revision returned by svn list --verbose directory is different from that of svn log directory/sub-dir The revision returned by svn list is the revision of the on the source-dir instead of the destination-dir The code below checks to see if the directory at the provided revision exists, if it does it will use this revision. If the directory does does not exist, try and identify the correct revision using svn log. */ final SVNLogEntry log = getMostRecentLogEntry(clientManager, testDefPath + "/" + testDefFile.getRelativePath(), svnRevision); if (log != null && log.getRevision() != testDefFile.getRevision()) { // The difference in the log.revision and the list.revision can occur during an ( svn cp ) if (LOGGER.isDebugEnabled()) { LOGGER.debug("svn log r" + log.getRevision() + " is different than svn list r" + testDefFile.getRevision() + " for " + testDefFile.getURL()); } testRevision = log.getRevision(); } else { testRevision = testDefFile.getRevision(); } tests.add(new TestVersionResult.Test(testName, String.valueOf(testRevision))); } final String matrixRevision = String.valueOf(logEntry.getRevision()); return new TestVersionResult( tests, logEntry.getDate(), logEntry.getAuthor(), matrixRevision, logEntry.getCommitMessage() ); } @Override public StoreException handleException(final Exception e) throws StoreException { throw new StoreException.ReadException("Unable to read from SVN", e); } }); }
Example #15
Source File: SvnObjectPools.java From proctor with Apache License 2.0 | 4 votes |
public static ObjectPool<SVNClientManager> clientManagerPoolWithAuth(final String username, final String password) { return createObjectPool(new SVNClientManagerFactory(username, password)); }
Example #16
Source File: SvnObjectPools.java From proctor with Apache License 2.0 | 4 votes |
public static ObjectPool<SVNClientManager> clientManagerPool() { return createObjectPool(new SVNClientManagerFactory()); }
Example #17
Source File: SvnObjectPools.java From proctor with Apache License 2.0 | 4 votes |
@Override public PooledObject<SVNClientManager> wrap(final SVNClientManager obj) { return new DefaultPooledObject<SVNClientManager>(obj); }
Example #18
Source File: SvnProctorUtils.java From proctor with Apache License 2.0 | 4 votes |
static void doInWorkingDirectory( final Logger logger, final File userDir, final String username, final String password, final SVNURL svnUrl, final FileBasedProctorStore.ProctorUpdater updater, final String comment) throws IOException, SVNException, Exception { final BasicAuthenticationManager authManager = new BasicAuthenticationManager(username, password); final SVNClientManager userClientManager = SVNClientManager.newInstance(null, authManager); final SVNWCClient wcClient = userClientManager.getWCClient(); try { // Clean up the UserDir SvnProctorUtils.cleanUpWorkingDir(logger, userDir, svnUrl, userClientManager); /* if (previousVersion != 0) { final Collection<?> changesSinceGivenVersion = repo.log(new String[] { "" }, null, previousVersion, -1, false, false); if (! changesSinceGivenVersion.isEmpty()) { // TODO: the baseline version is out of date, so need to go back to the user } } updateClient.doCheckout(checkoutUrl, workingDir, null, SVNRevision.HEAD, SVNDepth.INFINITY, false); */ final FileBasedProctorStore.RcsClient rcsClient = new SvnPersisterCoreImpl.SvnRcsClient(wcClient); final boolean thingsChanged = updater.doInWorkingDirectory(rcsClient, userDir); if (thingsChanged) { final SVNCommitClient commitClient = userClientManager.getCommitClient(); final SVNCommitPacket commit = commitClient.doCollectCommitItems(new File[]{userDir}, false, false, SVNDepth.INFINITY, new String[0]); long elapsed = -System.currentTimeMillis(); final SVNCommitInfo info = commitClient.doCommit(commit, /* keepLocks */ false, comment); elapsed += System.currentTimeMillis(); if (logger.isDebugEnabled()) { final StringBuilder changes = new StringBuilder("Committed " + commit.getCommitItems().length + " changes: "); for (final SVNCommitItem item : commit.getCommitItems()) { changes.append(item.getKind() + " - " + item.getPath() + ", "); } changes.append(String.format(" in %d ms new revision: r%d", elapsed, info.getNewRevision())); logger.debug(changes.toString()); } } } finally { userClientManager.dispose(); } }
Example #19
Source File: SvnCheckoutTest.java From git-as-svn with GNU General Public License v2.0 | 4 votes |
/** * <pre> * svn checkout * echo > test.txt * svn commit -m "create test.txt" * rev N * echo foo > test.txt * svn commit -m "modify test.txt" * svn up rev N * </pre> */ @Test public void checkoutAndUpdate() throws Exception { try (SvnTestServer server = SvnTestServer.createEmpty()) { final SVNRepository repo = server.openSvnRepository(); final ISVNEditor editor = repo.getCommitEditor("Initial state", null, false, null); editor.openRoot(-1); editor.addDir("/src", null, -1); editor.addDir("/src/main", null, -1); editor.addFile("/src/main/source.txt", null, -1); editor.changeFileProperty("/src/main/source.txt", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE)); sendDeltaAndClose(editor, "/src/main/source.txt", null, "Source content"); editor.closeDir(); editor.addDir("/src/test", null, -1); editor.addFile("/src/test/test.txt", null, -1); editor.changeFileProperty("/src/test/test.txt", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE)); sendDeltaAndClose(editor, "/src/test/test.txt", null, "Test content"); editor.closeDir(); editor.closeDir(); editor.closeDir(); editor.closeEdit(); // checkout 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.HEAD); checkout.run(); final Path file = server.getTempDirectory().resolve("src/main/someFile.txt"); final SVNClientManager client = SVNClientManager.newInstance(factory); // create file final SVNCommitInfo commit; { Assert.assertFalse(Files.exists(file)); TestHelper.saveFile(file, "New content"); client.getWCClient().doAdd(file.toFile(), false, false, false, SVNDepth.INFINITY, false, true); client.getWCClient().doSetProperty(file.toFile(), SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE), false, SVNDepth.INFINITY, null, null); commit = client.getCommitClient().doCommit(new File[]{file.toFile()}, false, "Commit new file", null, null, false, false, SVNDepth.INFINITY); } // modify file { Assert.assertTrue(Files.exists(file)); TestHelper.saveFile(file, "Modified content"); client.getCommitClient().doCommit(new File[]{file.toFile()}, false, "Modify up-to-date commit", null, null, false, false, SVNDepth.INFINITY); } // update to previous commit client.getUpdateClient().doUpdate(server.getTempDirectory().toFile(), SVNRevision.create(commit.getNewRevision()), SVNDepth.INFINITY, false, false); // check no tree conflist ArrayList<String> changeLists = new ArrayList<>(); client.getStatusClient().doStatus(server.getTempDirectory().toFile(), SVNRevision.WORKING, SVNDepth.INFINITY, false, false, true, false, status -> { Assert.assertNull(status.getTreeConflict(), status.getFile().toString()); Assert.assertNull(status.getConflictNewFile(), status.getFile().toString()); }, changeLists); Assert.assertTrue(changeLists.isEmpty()); } }
Example #20
Source File: SvnKitInfo.java From StatSVN with GNU Lesser General Public License v3.0 | 4 votes |
public SVNClientManager getManager() { return getSvnKitProcessor().getManager(); }
Example #21
Source File: SvnKitPropget.java From StatSVN with GNU Lesser General Public License v3.0 | 4 votes |
public SVNClientManager getManager() { return getSvnKitProcessor().getManager(); }
Example #22
Source File: SvnKitDiff.java From StatSVN with GNU Lesser General Public License v3.0 | 2 votes |
/** * Shorthand for the svnkit client manager. * * @return the svnkit client manager */ public SVNClientManager getManager() { return getSvnKitProcessor().getManager(); }
Example #23
Source File: SvnPersisterCore.java From proctor with Apache License 2.0 | votes |
T execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception;