@Override public String getKey() { StringBuilder b = new StringBuilder("svn"); for (ModuleLocation loc : getLocations()) { b.append(' ').append(loc.getURL()); } return b.toString(); }
/** * Sets the <tt>SVN_REVISION</tt> environment variable during the build. */ @Override public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) { super.buildEnvVars(build, env); ModuleLocation[] svnLocations = getLocations(build); try { Map<String, Long> revisions = parseRevisionFile(build); if (svnLocations.length == 1) { Long rev = revisions.get(svnLocations[0].remote); if (rev != null) { env.put("SVN_REVISION", rev.toString()); env.put("SVN_URL", svnLocations[0].getURL()); } } else if (svnLocations.length > 1) { for (int i = 0; i < svnLocations.length; i++) { Long rev = revisions.get(svnLocations[i].remote); if (rev != null) { env.put("SVN_REVISION_" + (i + 1), rev.toString()); env.put("SVN_URL_" + (i + 1), svnLocations[i].getURL()); } } } } catch (IOException e) { // ignore this error LOGGER.log(Level.FINEST, "Exception while building envVars. Error will be ignored.", e); } }
/** * Sets the <tt>SVN_REVISION</tt> environment variable during the build. */ @Override public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) { super.buildEnvVars(build, env); ModuleLocation[] svnLocations = getLocations(build); try { Map<String, Long> revisions = parseRevisionFile(build); if (svnLocations.length == 1) { Long rev = revisions.get(svnLocations[0].remote); if (rev != null) { env.put("SVN_REVISION", rev.toString()); env.put("SVN_URL", svnLocations[0].getURL()); } } else if (svnLocations.length > 1) { for (int i = 0; i < svnLocations.length; i++) { Long rev = revisions.get(svnLocations[i].remote); if (rev != null) { env.put("SVN_REVISION_" + (i + 1), rev.toString()); env.put("SVN_URL_" + (i + 1), svnLocations[i].getURL()); } } } } catch (IOException e) { // ignore this error LOGGER.log(Level.FINEST, "Exception while building envVars. Error will be ignored.", e); } }
SvnInfo svnInfo = new SvnInfo(svnkitInfo); String url = l.getURL(); if(!svnInfo.url.equals(url)) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url);
String url = l.getURL(); if(svnInfo.url.equals(url)) { listener.getLogger().println("Workspace is "+url+". Using 'svn switch' to perform update.");
public boolean run(Collection<SubversionSCM.External> externals, Result changeLog) throws IOException, InterruptedException { boolean changelogFileCreated = false; final SVNClientManager manager = SubversionSCM.createSvnClientManager(build.getProject()); try { SVNLogClient svnlc = manager.getLogClient(); TransformerHandler th = createTransformerHandler(); th.setResult(changeLog); SVNXMLLogHandler logHandler = new SVNXMLLogHandler(th); // work around for http://svnkit.com/tracker/view.php?id=175 th.setDocumentLocator(DUMMY_LOCATOR); logHandler.startDocument(); for (ModuleLocation l : scm.getLocations(build)) { changelogFileCreated |= buildModule(l.getURL(), svnlc, logHandler); } for(SubversionSCM.External ext : externals) { changelogFileCreated |= buildModule( getUrlForPath(build.getWorkspace().child(ext.path)), svnlc, logHandler); } if(changelogFileCreated) { logHandler.endDocument(); } return changelogFileCreated; } finally { manager.dispose(); } }
/** * If a subversion remote uses $VAR or ${VAR} as a parameterized build, * we expand the url. This will expand using the DEFAULT item. If there * is a choice parameter, it will expand with the FIRST item. */ public ModuleLocation getExpandedLocation(Job<?, ?> project) { String url = this.getURL(); String returnURL = url; for (JobProperty property : project.getProperties().values()) { if (property instanceof ParametersDefinitionProperty) { ParametersDefinitionProperty pdp = (ParametersDefinitionProperty) property; for (String propertyName : pdp.getParameterDefinitionNames()) { if (url.contains(propertyName)) { ParameterDefinition pd = pdp.getParameterDefinition(propertyName); ParameterValue pv = pd.getDefaultParameterValue(); String replacement = ""; if (pv != null) { replacement = String.valueOf(pv.createVariableResolver(null).resolve(propertyName)); } returnURL = returnURL.replace("${" + propertyName + "}", replacement); returnURL = returnURL.replace("$" + propertyName, replacement); } } } } return new ModuleLocation(returnURL, credentialsId, getLocalDir(), getDepthOption(), isIgnoreExternalsOption(), isCancelProcessOnExternalsFail()); }
SvnInfo svnInfo = new SvnInfo(svnkitInfo); String url = l.getURL(); if(!svnInfo.url.equals(url)) { listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url);
public boolean run(Collection<SubversionSCM.External> externals, Result changeLog) throws IOException, InterruptedException { boolean changelogFileCreated = false; final SVNClientManager manager = SubversionSCM.createSvnClientManager(build.getProject()); try { SVNLogClient svnlc = manager.getLogClient(); TransformerHandler th = createTransformerHandler(); th.setResult(changeLog); SVNXMLLogHandler logHandler = new SVNXMLLogHandler(th); // work around for http://svnkit.com/tracker/view.php?id=175 th.setDocumentLocator(DUMMY_LOCATOR); logHandler.startDocument(); for (ModuleLocation l : scm.getLocations(build)) { changelogFileCreated |= buildModule(l.getURL(), svnlc, logHandler); } for(SubversionSCM.External ext : externals) { changelogFileCreated |= buildModule( getUrlForPath(build.getWorkspace().child(ext.path)), svnlc, logHandler); } if(changelogFileCreated) { logHandler.endDocument(); } return changelogFileCreated; } finally { manager.dispose(); } }
/** * Test parsing of @revision information from the tail of the URL */ @Test public void moduleLocationRevisions() throws Exception { SubversionSCM.ModuleLocation m = new SubversionSCM.ModuleLocation("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant@13000", null); SVNRevision r = m.getRevision(null); assertTrue(r.isValid()); assertEquals(13000, r.getNumber()); assertEquals("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant", m.getURL()); m = new SubversionSCM.ModuleLocation("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant@HEAD", null); r = m.getRevision(null); assertTrue(r.isValid()); assertSame(r, SVNRevision.HEAD); assertEquals("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant", m.getURL()); m = new SubversionSCM.ModuleLocation("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant@FAKE", null); r = m.getRevision(null); assertFalse(r.isValid()); assertEquals("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant@FAKE", m.getURL()); }
/** * Checks whether build locations contain specified revision. * * @param url url to verify. * @param locations module locations. * @return true if build locations contain specified revision. */ boolean isRevisionSpecifiedInBuildLocation(String url, ModuleLocation[] locations) { if (null != locations) { for (ModuleLocation location : locations) { if (location.getURL() != null && location.getURL().contains(url)) { SVNRevision revision = getRevisionFromRemoteUrl(location.getOriginRemote()); if (isRevisionPresent(revision)) { return true; } } } } return false; }
/** * Determines the revision to check out for the given location. */ protected SVNRevision getRevision(ModuleLocation l) { // for the SVN revision, we will use the first off: // - a @NNN suffix of the SVN url // - a value found in a RevisionParameterAction // - the revision corresponding to the build timestamp SVNRevision r = null; if (revisions != null) { r = revisions.getRevision(l.getURL()); } if (r == null) { r = SVNRevision.create(timestamp); } r = l.getRevision(r); return r; }
@Override public boolean isBrowserReusable(SubversionSCM x, SubversionSCM y) { ModuleLocation[] xl = x.getLocations(), yl = y.getLocations(); if (xl.length != yl.length) { return false; } for (int i = 0; i < xl.length; i++) { if (!xl[i].getURL().equals(yl[i].getURL())) { return false; } } return true; }
/** * Local directory to place the file to. * Relative to the workspace root. */ public String getLocalDir() { if(local==null) return getLastPathComponent(getURL()); return local; }
/** * Gets {@link #remote} as {@link SVNURL}. */ public SVNURL getSVNURL() throws SVNException { return SVNURL.parseURIEncoded(getURL()); }
/** * Gets {@link #remote} as {@link SVNURL}. */ public SVNURL getSVNURL() throws SVNException { return SVNURL.parseURIEncoded(getURL()); }
@Override public boolean isBrowserReusable(SubversionSCM x, SubversionSCM y) { ModuleLocation[] xl = x.getLocations(), yl = y.getLocations(); if (xl.length != yl.length) { return false; } for (int i = 0; i < xl.length; i++) { if (!xl[i].getURL().equals(yl[i].getURL())) { return false; } } return true; }
/** * Gets {@link #remote} as {@link SVNURL}. */ public SVNURL getSVNURL() throws SVNException { return SVNURL.parseURIEncoded(getURL()); }