/** * @since 1.252 * @deprecated Use {@link #getLocations(EnvVars, Run)} for vars * expansion to be performed on all env vars rather than just * build parameters. */ public ModuleLocation[] getLocations(AbstractBuild<?,?> build) { return getLocations(null, build); }
public BuildRevisionMapTask(AbstractBuild<?, ?> build, SubversionSCM parent, TaskListener listener, List<External> externals) { this.authProvider = parent.getDescriptor().createAuthenticationProvider(build.getParent()); this.listener = listener; this.externals = externals; this.locations = parent.getLocations(build); }
@SuppressWarnings("unchecked") public static Map<String, Long> getRevisionsForBuild(SubversionSCM scm, AbstractBuild build) throws IOException, InterruptedException, IllegalArgumentException, IllegalAccessException { SCMRevisionState revisionInfo = scm.calcRevisionsFromBuild(build, null, null); for(Field field: revisionInfo.getClass().getDeclaredFields()) { field.setAccessible(true); if (field.getName().equals("revisions")) { return (Map<String, Long>) field.get(revisionInfo); } } throw new IllegalArgumentException("Something is broken in reflection or SVN plugin internals changed. So sad."); } }
public BuildRevisionMapTask(Run<?, ?> build, SubversionSCM parent, TaskListener listener, List<External> externals, EnvVars env) { this.listener = listener; this.externals = externals; this.locations = parent.getLocations(env, build); this.defaultAuthProvider = parent.createAuthenticationProvider(build.getParent(), null, listener); this.authProviders = new LinkedHashMap<String, ISVNAuthenticationProvider>(); for (ModuleLocation loc: locations) { authProviders.put(loc.remote, parent.createAuthenticationProvider(build.getParent(), loc, listener)); } }
public CheckOutTask(AbstractBuild<?, ?> build, SubversionSCM scm, Date queueTime, Date buildTime, TaskListener listener) { this.authProvider = scm.getDescriptor().createAuthenticationProvider(build.getParent()); this.queueTime = queueTime; this.buildTime = buildTime; this.listener = listener; this.locations = scm.getLocations(build); this.revisionParameterAction = build.getAction(RevisionParameterAction.class); this.task = scm.getWorkspaceUpdater().createTask(); this.revisionPolicy = (scm.getDescriptor() != null ? scm.getDescriptor().getRevisionPolicy() : null); }
private String getExcludedRevpropNormalized() { String s = Util.fixEmptyAndTrim(getExcludedRevprop()); if (s != null) { return s; } return getDescriptor().getGlobalExcludedRevprop(); }
baseline = (SVNRevisionState) _baseline; } else if (project.getLastBuild() != null) { baseline = (SVNRevisionState) calcRevisionsFromBuild(project.getLastBuild(), launcher, listener); } else { baseline = new SVNRevisionState(null); if (repositoryLocationsNoLongerExist(lastCompletedBuild, listener)) { for (ModuleLocation loc : getLocations(lastCompletedBuild)) { String locURL = loc.getURL().replace("\\", "/"); //This is required for windows based machines. file:///C:\\dev\\ should be file:///C:/dev/ if (!baseline.revisions.containsKey(locURL)) { final ISVNAuthenticationProvider authProvider = getDescriptor().createAuthenticationProvider(project); final ModuleLocation[] moduleLocations = getLocations(lastCompletedBuild);
baseline = (SVNRevisionState) _baseline; } else if (project.getLastBuild() != null) { baseline = (SVNRevisionState) calcRevisionsFromBuild(project.getLastBuild(), launcher != null ? workspace : null, launcher, listener); } else { if (workspace != null && !isPollFromMaster()) { channel = workspace.getChannel(); if (channel != null && channel instanceof Channel) { if (project instanceof AbstractProject && repositoryLocationsNoLongerExist(lastCompletedBuild, listener, env)) { disableProject((AbstractProject) project, listener); return NO_CHANGES; for (ModuleLocation loc : getLocations(env, lastCompletedBuild)) { final SVNLogHandler logHandler = new SVNLogHandler(createSVNLogFilter(), listener); for (ModuleLocation loc : getLocations(env, null)) { String url; try { return BUILD_NOW; authProviders.put(url, createAuthenticationProvider(project, loc, listener)); final ISVNAuthenticationProvider defaultAuthProvider = createAuthenticationProvider(project, null, listener);
private void verify(SubversionSCM lhs, SubversionSCM rhs) { ModuleLocation[] ll = lhs.getLocations(); ModuleLocation[] rl = rhs.getLocations(); assertEquals(ll.length, rl.length); for(int i=0; i<ll.length; i++) { assertEquals(ll[i].local, rl[i].local); assertEquals(ll[i].remote, rl[i].remote); } assertNullEquals(lhs.getExcludedRegions(), rhs.getExcludedRegions()); assertNullEquals(lhs.getExcludedUsers(), rhs.getExcludedUsers()); assertNullEquals(lhs.getExcludedRevprop(), rhs.getExcludedRevprop()); assertNullEquals(lhs.getExcludedCommitMessages(), rhs.getExcludedCommitMessages()); assertNullEquals(lhs.getIncludedRegions(), rhs.getIncludedRegions()); assertEquals(lhs.getWorkspaceUpdater().getClass(), rhs.getWorkspaceUpdater().getClass()); }
@Override public FilePath[] getModuleRoots(FilePath workspace) { final ModuleLocation[] moduleLocations = getLocations(); if (moduleLocations.length > 0) { FilePath[] moduleRoots = new FilePath[moduleLocations.length]; for (int i = 0; i < moduleLocations.length; i++) { moduleRoots[i] = workspace.child(moduleLocations[i].getLocalDir()); } return moduleRoots; } return new FilePath[]{getModuleRoot(workspace)}; }
public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, final BuildListener listener, File changelogFile) throws IOException, InterruptedException { List<External> externals = checkout(build, workspace, listener); if (externals == null) { return false; } // write out the revision file PrintWriter w = new PrintWriter(new FileOutputStream(getRevisionFile(build))); try { Map<String, SvnInfo> revMap = workspace.act(new BuildRevisionMapTask(build, this, listener, externals)); for (Entry<String, SvnInfo> e : revMap.entrySet()) { w.println(e.getKey() + '/' + e.getValue().revision); } build.addAction(new SubversionTagAction(build, revMap.values())); } finally { w.close(); } // write out the externals info new XmlFile(External.XSTREAM, getExternalsFile(build.getProject())).write(externals); return calcChangeLog(build, changelogFile, listener, externals); }
@Override public FilePath[] getModuleRoots(FilePath workspace, AbstractBuild build) { if (build == null) { return getModuleRoots(workspace); } // TODO: can't I get the build listener here? TaskListener listener = new LogTaskListener(LOGGER, WARNING); final EnvVars env; try { env = build.getEnvironment(listener); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } final ModuleLocation[] moduleLocations = getLocations(); if (moduleLocations.length > 0) { FilePath[] moduleRoots = new FilePath[moduleLocations.length]; for (int i = 0; i < moduleLocations.length; i++) { moduleRoots[i] = _getModuleRoot(workspace, moduleLocations[i].getLocalDir(), env); } return moduleRoots; } return new FilePath[] { getModuleRoot(workspace, build) }; }
/** * * @deprecated as of 1.40 * Use {@link #createClientManager(ISVNAuthenticationProvider)} */ public static SVNClientManager createSvnClientManager(ISVNAuthenticationProvider authProvider) { return createClientManager(authProvider).getCore(); }
public List<External> invoke(File ws, VirtualChannel channel) throws IOException { manager = createSvnClientManager(authProvider); this.ws = ws; try { List<External> externals = perform(); checkClockOutOfSync(); return externals; } catch (InterruptedException e) { throw (InterruptedIOException) new InterruptedIOException().initCause(e); } finally { manager.dispose(); } }
@Override public FilePath getModuleRoot(FilePath workspace, AbstractBuild build) { if (build == null) { return getModuleRoot(workspace); } // TODO: can't I get the build listener here? TaskListener listener = new LogTaskListener(LOGGER, WARNING); final EnvVars env; try { env = build.getEnvironment(listener); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } if (getLocations().length > 0) return _getModuleRoot(workspace, getLocations()[0].getLocalDir(), env); return workspace; }
/** * @since 1.34 */ public boolean repositoryLocationsNoLongerExist(Run<?,?> build, TaskListener listener, EnvVars env) { PrintStream out = listener.getLogger(); for (ModuleLocation l : getLocations(env, build)) try { if (getDescriptor().checkRepositoryPath(build.getParent(), l.getSVNURL(), lookupCredentials(build.getParent(), l.credentialsId, l.getSVNURL())) == SVNNodeKind.NONE) { out.println("Location '" + l.remote + "' does not exist"); ParametersAction params = build.getAction(ParametersAction.class); if (params != null) { // since this is used to disable projects, be conservative LOGGER.fine("Location could be expanded on build '" + build + "' parameters values:"); return false; } return true; } } catch (SVNException e) { // be conservative, since we are just trying to be helpful in detecting // non existent locations. If we can't detect that, we'll do nothing LOGGER.log(FINE, "Location check failed",e); } return false; }
SVNLogFilter logFilter = scm.isFilterChangelog() ? scm.createSVNLogFilter() : new NullSVNLogFilter(); DirAwareSVNXMLLogHandler logHandler = new DirAwareSVNXMLLogHandler(th, logFilter); logHandler.startDocument(); for (ModuleLocation l : scm.getLocations(env, build)) { ISVNAuthenticationProvider authProvider = CredentialsSVNAuthenticationProviderImpl .createAuthenticationProvider(build.getParent(), scm, l, listener); final SVNClientManager manager = SubversionSCM.createClientManager(authProvider).getCore(); try { SVNLogClient svnlc = manager.getLogClient();
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(); } }
@SuppressWarnings("deprecation") @Test public void shouldSetEnvironmentVariablesWithSingleSvnModule() throws IOException { // GIVEN an scm with a single module location SubversionSCM scm = mockSCMForBuildEnvVars(); ModuleLocation[] singleLocation = new ModuleLocation[] {new ModuleLocation("/remotepath", "")}; when(scm.getLocations(any(EnvVars.class), any(AbstractBuild.class))).thenReturn(singleLocation); Map<String, Long> revisions = new HashMap<>(); revisions.put("/remotepath", 4711L); when(scm.parseSvnRevisionFile(any(AbstractBuild.class))).thenReturn(revisions); // WHEN envVars are build AbstractBuild<?,?> build = mock(AbstractBuild.class); Map<String, String> envVars = new HashMap<>(); scm.buildEnvVars(build, envVars); // THEN: we have the (legacy) SVN_URL and SVN_REVISION vars assertThat(envVars.get("SVN_URL"), is("/remotepath")); assertThat(envVars.get("SVN_REVISION"), is("4711")); // AND: also the index-based vars assertThat(envVars.get("SVN_URL_1"), is("/remotepath")); assertThat(envVars.get("SVN_REVISION_1"), is("4711")); }
/** * 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); } }