Skip to content

Commit

Permalink
[FIXED JENKINS-7684] NullPointerException when an incremental build i…
Browse files Browse the repository at this point in the history
…s triggered
  • Loading branch information
olamy committed Feb 22, 2011
1 parent c1739b8 commit a19afb1
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
Expand Up @@ -206,7 +206,7 @@ private boolean notInSubsidiary(List<MavenModule> subsidiaries, ChangeLogSet.Ent

private boolean belongsToSubsidiary(List<MavenModule> subsidiaries, String path) {
for (MavenModule sub : subsidiaries)
if (FilenameUtils.separatorsToUnix(path).startsWith(FilenameUtils.normalize(sub.getRelativePath())))
if (FilenameUtils.separatorsToUnix(path).startsWith(normalizePath(sub.getRelativePath())))
return true;
return false;
}
Expand All @@ -216,7 +216,7 @@ private boolean belongsToSubsidiary(List<MavenModule> subsidiaries, String path)
*/
private boolean isDescendantOf(ChangeLogSet.Entry e, MavenModule mod) {
for (String path : e.getAffectedPaths()) {
if (FilenameUtils.separatorsToUnix(path).startsWith(FilenameUtils.normalize(mod.getRelativePath())))
if (FilenameUtils.separatorsToUnix(path).startsWith(normalizePath(mod.getRelativePath())))
return true;
}
return false;
Expand Down Expand Up @@ -281,7 +281,7 @@ public long getEstimatedDuration() {

return result != 0 ? result : -1;
}

/**
* Estimates the duration overhead the {@link MavenModuleSetBuild} itself adds
* to the sum of duration of the module builds.
Expand Down Expand Up @@ -309,6 +309,18 @@ private long estimateModuleSetBuildDurationOverhead(int numberOfBuilds) {
return Math.round((double)overhead / moduleSetBuilds.size());
}

private static String normalizePath(String relPath) {
// JENKINS-8525 FilenameUtils.normalize for ../foo returns null
if (StringUtils.isEmpty(relPath) || StringUtils.startsWith( relPath, "../" )) {
LOGGER.config("No need to normalize " + (StringUtils.isEmpty(relPath) ? "an empty path" : relPath));
} else {
String tmp = FilenameUtils.normalize( relPath );
LOGGER.config("Normalized path " + relPath + " to "+tmp);
relPath = tmp;
}
return relPath;
}

/**
* Gets the version of Maven used for build.
*
Expand Down Expand Up @@ -492,7 +504,7 @@ protected Result doRun(final BuildListener listener) throws Exception {
"Either your server has no Maven installations defined, or the requested Maven version does not exist.");

mvn = mvn.forEnvironment(envVars).forNode(Computer.currentComputer().getNode(), listener);

MavenInformation mavenInformation = getModuleRoot().act( new MavenVersionCallable( mvn.getHome() ));

String mavenVersion = mavenInformation.getVersion();
Expand Down Expand Up @@ -1209,11 +1221,8 @@ public List<PomInfo> invoke(File ws, VirtualChannel channel) throws IOException
private void toPomInfo(MavenProject mp, PomInfo parent, Map<String,MavenProject> abslPath, Set<PomInfo> infos) throws IOException {

String relPath = PathTool.getRelativeFilePath( this.moduleRootPath, mp.getBasedir().getPath() );

// JENKINS-8525 FilenameUtils.normalize for ../foo returns null
if (!StringUtils.startsWith( relPath, "../" )) {
relPath = FilenameUtils.normalize( relPath );
}
relPath = normalizePath(relPath);

if (parent == null ) {
relPath = getRootPath(rootPOMRelPrefix);
}
Expand Down

0 comments on commit a19afb1

Please sign in to comment.