Skip to content

Commit

Permalink
[FIXED JENKINS-16217] Take into account the svn:externals of a projec…
Browse files Browse the repository at this point in the history
…t when looking for projects to trigger from a post-commit hook.
  • Loading branch information
Tom Palmer authored and ndeloof committed Jan 4, 2013
1 parent b20cf64 commit ee2d28e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/SubversionRepositoryStatus.java 100644 → 100755
Expand Up @@ -134,7 +134,7 @@ public void doNotifyCommit(StaplerRequest req, StaplerResponse rsp) throws Servl
List<SvnInfo> infos = new ArrayList<SvnInfo>();

boolean projectMatches = false;
for (ModuleLocation loc : sscm.getLocations()) {
for (ModuleLocation loc : sscm.getProjectLocations(p)) {
if (loc.getUUID(p).equals(uuid)) uuidFound = true; else continue;

String m = loc.getSVNURL().getPath();
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/hudson/scm/SubversionSCM.java
Expand Up @@ -46,6 +46,8 @@
import hudson.model.AbstractProject;
import hudson.model.Computer;
import hudson.model.Hudson;
import java.util.Arrays;
import java.util.WeakHashMap;
import jenkins.model.Jenkins.MasterComputer;
import hudson.model.Node;
import hudson.model.ParametersAction;
Expand Down Expand Up @@ -222,6 +224,11 @@ public class SubversionSCM extends SCM implements Serializable {
private boolean ignoreDirPropChanges;
private boolean filterChangelog;

/**
* A cache of the svn:externals (keyed by project).
*/
private transient Map<AbstractProject, List<External>> projectExternalsCache;

/**
* @deprecated as of 1.286
*/
Expand Down Expand Up @@ -439,6 +446,48 @@ public ModuleLocation[] getLocations(EnvVars env, AbstractBuild<?,?> build) {
return outLocations;
}

/**
* Get the list of every checked-out location. This differs from {@link #getLocations()}
* which returns only the configured locations whereas this method returns the configured
* locations + any svn:externals locations.
*/
public ModuleLocation[] getProjectLocations(AbstractProject project) throws IOException {
List<External> projectExternals = getExternals(project);

ModuleLocation[] configuredLocations = getLocations();
if (projectExternals.isEmpty()) {
return configuredLocations;
}

List<ModuleLocation> allLocations = new ArrayList<ModuleLocation>(configuredLocations.length + projectExternals.size());
allLocations.addAll(Arrays.asList(configuredLocations));

for (External external : projectExternals) {
allLocations.add(new ModuleLocation(external.url, external.path));
}

return allLocations.toArray(new ModuleLocation[allLocations.size()]);
}

private List<External> getExternals(AbstractProject context) throws IOException {
Map<AbstractProject, List<External>> projectExternalsCache = getProjectExternalsCache();
List<External> projectExternals;
synchronized (projectExternalsCache) {
projectExternals = projectExternalsCache.get(context);
}

if (projectExternals == null) {
projectExternals = parseExternalsFile(context);

synchronized (projectExternalsCache) {
if (!projectExternalsCache.containsKey(context)) {
projectExternalsCache.put(context, projectExternals);
}
}
}
return projectExternals;
}

@Override
@Exported
public SubversionRepositoryBrowser getBrowser() {
Expand Down Expand Up @@ -759,6 +808,10 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa

// write out the externals info
new XmlFile(External.XSTREAM,getExternalsFile(build.getProject())).write(externals);
Map<AbstractProject, List<External>> projectExternalsCache = getProjectExternalsCache();
synchronized (projectExternalsCache) {
projectExternalsCache.put(build.getProject(), externals);
}

return calcChangeLog(build, changelogFile, listener, externals, env);
}
Expand Down Expand Up @@ -806,6 +859,13 @@ private List<External> checkout(AbstractBuild build, FilePath workspace, TaskLis
return externals;
}

private synchronized Map<AbstractProject, List<External>> getProjectExternalsCache() {
if (projectExternalsCache == null) {
projectExternalsCache = new WeakHashMap<AbstractProject, List<External>>();
}

return projectExternalsCache;
}

/**
* Either run "svn co" or "svn up" equivalent.
Expand Down

0 comments on commit ee2d28e

Please sign in to comment.