private String update(SvnOperationFactory svnOperationFactory, String label) throws SVNException { logger.debug("Repo already checked out - updating instead."); try { final SvnUpdate update = svnOperationFactory.createUpdate(); update.setSingleTarget(SvnTarget.fromFile(getWorkingDirectory())); long[] ids = update.run(); StringBuilder version = new StringBuilder(); for (long id : ids) { if (version.length() > 0) { version.append(","); } version.append(id); } return version.toString(); } catch (Exception e) { String message = "Could not update remote for " + label + " (current local=" + getWorkingDirectory().getPath() + "), remote: " + this.getUri() + ")"; if (logger.isDebugEnabled()) { logger.debug(message, e); } else if (logger.isWarnEnabled()) { logger.warn(message); } } final SVNStatus status = SVNClientManager.newInstance().getStatusClient() .doStatus(getWorkingDirectory(), false); return status != null ? status.getRevision().toString() : null; }
/** * Collects status information on a single Working Copy item. * * @param path local item's path * @param remote <span class="javakeyword">true</span> to check up the status of the item in the repository, * that will tell if the local item is out-of-date (like <i>'-u'</i> option in the * SVN client's <code>'svn status'</code> command), * otherwise <span class="javakeyword">false</span> * @return an <b>SVNStatus</b> object representing status information * for the item * @throws SVNException */ public SVNStatus doStatus(final File path, boolean remote) throws SVNException { return doStatus(path, remote, false); }
/** * Collects status information on a single Working Copy item. * * @param path local item's path * @param remote <span class="javakeyword">true</span> to check up the status of the item in the repository, * that will tell if the local item is out-of-date (like <i>'-u'</i> option in the * SVN client's <code>'svn status'</code> command), * otherwise <span class="javakeyword">false</span> * @return an <b>SVNStatus</b> object representing status information * for the item * @throws SVNException */ public SVNStatus doStatus(final File path, boolean remote) throws SVNException { return doStatus(path, remote, false); }
/** * Collects status information on a single Working Copy item. * * @param path local item's path * @param remote <span class="javakeyword">true</span> to check up the status of the item in the repository, * that will tell if the local item is out-of-date (like <i>'-u'</i> option in the * SVN client's <code>'svn status'</code> command), * otherwise <span class="javakeyword">false</span> * @return an <b>SVNStatus</b> object representing status information * for the item * @throws SVNException */ public SVNStatus doStatus(final File path, boolean remote) throws SVNException { return doStatus(path, remote, false); }
/** * Collects status information on a single Working Copy item. * * @param path * local item's path * @param remote * <span class="javakeyword">true</span> to check up the status * of the item in the repository, that will tell if the local * item is out-of-date (like <i>'-u'</i> option in the SVN * client's <code>'svn status'</code> command), otherwise <span * class="javakeyword">false</span> * @return an <b>SVNStatus</b> object representing status information for * the item * @throws SVNException */ public SVNStatus doStatus(final File path, boolean remote) throws SVNException { return doStatus(path, remote, false); }
public static long getWorkingCopyRevisionNumber (String localpath) { SVNStatus status = getWorkingStatus (localpath); Long revNum = status.getCommittedRevision().getNumber(); return revNum; } public static SVNStatus getWorkingStatus (String localpath) { SVNStatusClient statusClient = SVNClientManager.newInstance().getStatusClient(); File f = new File(localpath); SVNStatus status = statusClient.doStatus( f, false); return status; }
public static void canDelete(File path, boolean skipIgnored, ISVNOptions options) throws SVNException { SVNStatusClient statusClient = new SVNStatusClient((ISVNAuthenticationManager) null, options); statusClient.doStatus(path, SVNRevision.UNDEFINED, true, false, false, !skipIgnored, false, new ISVNStatusHandler() { public void handleStatus(SVNStatus status) throws SVNException { if (status.getContentsStatus() == SVNStatusType.STATUS_OBSTRUCTED) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.NODE_UNEXPECTED_KIND, "''{0}'' is in the way of the resource actually under version control", status.getFile()); SVNErrorManager.error(err); } else if (status.getEntry() == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNVERSIONED_RESOURCE, "''{0}'' is not under version control", status.getFile()); SVNErrorManager.error(err); } else if ((status.getContentsStatus() != SVNStatusType.STATUS_NORMAL && status.getContentsStatus() != SVNStatusType.STATUS_DELETED && status.getContentsStatus() != SVNStatusType.STATUS_MISSING) || (status.getPropertiesStatus() != SVNStatusType.STATUS_NONE && status.getPropertiesStatus() != SVNStatusType.STATUS_NORMAL)) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.CLIENT_MODIFIED, "''{0}'' has local modifications", status.getFile()); SVNErrorManager.error(err); } } }); }
@Override protected void preUpdate(ModuleLocation module, File local) throws SVNException, IOException { listener.getLogger().println("Cleaning up " + local); manager.getStatusClient().doStatus(local, null, SVNDepth.INFINITY, false, false, true, false, new ISVNStatusHandler() { public void handleStatus(SVNStatus status) throws SVNException { SVNStatusType s = status.getContentsStatus(); if (s == SVNStatusType.STATUS_UNVERSIONED || s == SVNStatusType.STATUS_IGNORED || s == SVNStatusType.STATUS_MODIFIED) { listener.getLogger().println("Deleting "+status.getFile()); try { File f = status.getFile(); if (f.isDirectory()) FileUtils.deleteDirectory(f); else f.delete(); } catch (IOException e) { throw new SVNException(SVNErrorMessage.UNKNOWN_ERROR_MESSAGE,e); } } } }, null); } }
@Override protected void preUpdate(ModuleLocation module, File local) throws SVNException, IOException { listener.getLogger().println("Cleaning up " + local); clientManager.getStatusClient().doStatus(local, null, SVNDepth.INFINITY, false, false, true, false, new ISVNStatusHandler() { public void handleStatus(SVNStatus status) throws SVNException { SVNStatusType s = status.getCombinedNodeAndContentsStatus(); if (s == SVNStatusType.STATUS_UNVERSIONED || s == SVNStatusType.STATUS_IGNORED || s == SVNStatusType.STATUS_MODIFIED) { listener.getLogger().println("Deleting "+status.getFile()); try { File f = status.getFile(); if (f.isDirectory()) hudson.Util.deleteRecursive(f); else f.delete(); } catch (IOException e) { throw new SVNException(new RemotableSVNErrorMessage(SVNErrorCode.UNKNOWN, e)); } } } }, null); } }
public Status[] status(final String path, boolean descend, boolean onServer, boolean getAll, boolean noIgnore, boolean ignoreExternals) throws ClientException { if (path == null) { return null; } final Collection statuses = new ArrayList(); SVNStatusClient stClient = getSVNStatusClient(); boolean oldIgnoreExternals = stClient.isIgnoreExternals(); stClient.setIgnoreExternals(ignoreExternals); try { stClient.doStatus(new File(path).getAbsoluteFile(), descend, onServer, getAll, noIgnore, !ignoreExternals, new ISVNStatusHandler(){ public void handleStatus(SVNStatus status) { statuses.add(JavaHLObjectFactory.createStatus(status.getFile().getPath(), status)); } }); } catch (SVNException e) { throwException(e); } finally { stClient.setIgnoreExternals(oldIgnoreExternals); } return (Status[]) statuses.toArray(new Status[statuses.size()]); }
import org.tmatesoft.svn.core.wc.* buildscript { repositories { mavenCentral() } dependencies { classpath group: 'org.tmatesoft.svnkit', name: 'svnkit', version: '1.7.11' } } def getSvnRevision(){ ISVNOptions options = SVNWCUtil.createDefaultOptions(true); SVNClientManager clientManager = SVNClientManager.newInstance(options); SVNStatusClient statusClient = clientManager.getStatusClient(); SVNStatus status = statusClient.doStatus(projectDir, false); SVNRevision revision = status.getRevision(); return revision.getNumber(); } allprojects { version = '1.2.3.' + getSvnRevision() }
ISVNOptions options = SVNWCUtil.createDefaultOptions(true); SVNClientManager clientManager = SVNClientManager.newInstance(options); SVNStatusClient statusClient = clientManager.getStatusClient(); SVNStatus status = statusClient.doStatus(projectDir, false); SVNRevision revision = status.getRevision();
public Status singleStatus(final String path, boolean onServer) throws ClientException { if (path == null) { return null; } SVNStatusClient client = getSVNStatusClient(); SVNStatus status = null; try { status = client.doStatus(new File(path).getAbsoluteFile(), onServer); } catch (SVNException e) { if (e.getErrorMessage().getErrorCode() == SVNErrorCode.WC_NOT_DIRECTORY) { File file = new File(path).getAbsoluteFile(); SVNFileType ft = SVNFileType.getType(file); status = new SVNStatus(null, file, ft == SVNFileType.NONE ? SVNNodeKind.NONE : SVNNodeKind.UNKNOWN, null, null, null, null, SVNStatusType.STATUS_UNVERSIONED, SVNStatusType.STATUS_NONE, SVNStatusType.STATUS_NONE, SVNStatusType.STATUS_NONE, false, false, false, null, null, null, null, null, null, null, null, null); } else { throwException(e); } } return JavaHLObjectFactory.createStatus(path, status); }
@Override public Status getLocalStatus(File file) throws VCSException { Status resultStatus = Status.STATUS_NORMAL; try { SVNStatusClient statusClient = getSVNManager().getStatusClient(); SVNStatusType svnStatus = statusClient.doStatus(file, false).getNodeStatus(); if (svnStatus == SVNStatusType.STATUS_MODIFIED) { resultStatus = Status.STATUS_MODIFIED; } else if (svnStatus == SVNStatusType.STATUS_DELETED) { resultStatus = Status.STATUS_DELETED; } else if (svnStatus == SVNStatusType.STATUS_ADDED || svnStatus == SVNStatusType.STATUS_UNVERSIONED) { resultStatus = Status.STATUS_ADDED; } } catch (SVNException e) { throw new VCSException("Can't get local status", e); } return resultStatus; }
private void status(String path, int depth, boolean onServer, boolean getAll, boolean noIgnore, boolean ignoreExternals, String[] changelists, ISVNStatusHandler handler) throws ClientException { if (path == null) { return; } SVNStatusClient stClient = getSVNStatusClient(); boolean oldIgnoreExternals = stClient.isIgnoreExternals(); stClient.setIgnoreExternals(ignoreExternals); try { stClient.doStatus(new File(path).getAbsoluteFile(), SVNRevision.HEAD, JavaHLObjectFactory.getSVNDepth(depth), onServer, getAll, noIgnore, !ignoreExternals, handler, JavaHLObjectFactory.getChangeListsCollection(changelists)); } catch (SVNException e) { throwException(e); } finally { stClient.setIgnoreExternals(oldIgnoreExternals); resetLog(); } }
private void status(String path, int depth, boolean onServer, boolean getAll, boolean noIgnore, boolean ignoreExternals, String[] changelists, ISVNStatusHandler handler) throws ClientException { if (path == null) { return; } SVNStatusClient stClient = getSVNStatusClient(); boolean oldIgnoreExternals = stClient.isIgnoreExternals(); stClient.setIgnoreExternals(ignoreExternals); try { stClient.doStatus(new File(path).getAbsoluteFile(), SVNRevision.HEAD, JavaHLObjectFactory.getSVNDepth(depth), onServer, getAll, noIgnore, !ignoreExternals, handler, JavaHLObjectFactory.getChangeListsCollection(changelists)); } catch (SVNException e) { throwException(e); } finally { stClient.setIgnoreExternals(oldIgnoreExternals); resetLog(); } }
private void status(String path, int depth, boolean onServer, boolean getAll, boolean noIgnore, boolean ignoreExternals, String[] changelists, ISVNStatusHandler handler) throws ClientException { if (path == null) { return; } SVNStatusClient stClient = getSVNStatusClient(); boolean oldIgnoreExternals = stClient.isIgnoreExternals(); stClient.setIgnoreExternals(ignoreExternals); try { stClient.doStatus(new File(path).getAbsoluteFile(), SVNRevision.HEAD, JavaHLObjectFactory.getSVNDepth(depth), onServer, getAll, noIgnore, !ignoreExternals, handler, JavaHLObjectFactory.getChangeListsCollection(changelists)); } catch (SVNException e) { throwException(e); } finally { stClient.setIgnoreExternals(oldIgnoreExternals); resetLog(); } }
/** * Gets the repository revision just committed. */ public long revision() throws Exception { // .getLookClient().doGetYoungestRevision(repo) would show last committed revision but would not be sensitive to checked-out branch; which is clearer? return SVNClientManager.newInstance().getStatusClient().doStatus(wc, true).getRemoteRevision().getNumber(); // http://stackoverflow.com/a/2295674/12916 }
/** * Makes sure that Subversion doesn't check out workspace in 1.6 */ @Email("http://www.nabble.com/SVN-1.6-td24081571.html") @Test public void workspaceVersion() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); p.setScm(loadSvnRepo()); FreeStyleBuild b = p.scheduleBuild2(0).get(); SvnClientManager wc = SubversionSCM.createClientManager((AbstractProject)null); SVNStatus st = wc.getStatusClient().doStatus(new File(b.getWorkspace().getRemote()+"/a"), false); int wcf = st.getWorkingCopyFormat(); System.out.println(wcf); assertEquals(SVNAdminAreaFactory.WC_FORMAT_14,wcf); }
private int checkoutWithFormat(int format) throws Exception { super.configureSvnWorkspaceFormat(format); FreeStyleProject project = r.jenkins.createProject(FreeStyleProject.class, "svntest" + format); SubversionSCM subversionSCM = new SubversionSCM("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant"); project.setScm(subversionSCM); r.assertBuildStatusSuccess(project.scheduleBuild2(0)); // Create a status client and get the working copy format. SVNClientManager testWCVerseion = SVNClientManager.newInstance(null, "testWCVerseion", null); File path = new File(project.getWorkspace().getRemote()); return testWCVerseion.getStatusClient().doStatus(path, true).getWorkingCopyFormat(); } }