提交 119d8aa2 编写于 作者: A abayer

[FIXED HUDSON-5357] Properly handle relative paths in modules when determining...

[FIXED HUDSON-5357] Properly handle relative paths in modules when determining changesets in Maven projects

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34983 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b75a8021
......@@ -50,6 +50,7 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.apache.commons.io.FilenameUtils;
import java.io.*;
import java.util.*;
......@@ -164,7 +165,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
private boolean belongsToSubsidiary(List<MavenModule> subsidiaries, String path) {
for (MavenModule sub : subsidiaries)
if(path.startsWith(sub.getRelativePath()))
if(path.startsWith(FilenameUtils.normalize(sub.getRelativePath())))
return true;
return false;
}
......@@ -173,9 +174,10 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
* Does this change happen somewhere in the given module or its descendants?
*/
private boolean isDescendantOf(ChangeLogSet.Entry e, MavenModule mod) {
for (String path : e.getAffectedPaths())
if(path.startsWith(mod.getRelativePath()))
for (String path : e.getAffectedPaths()) {
if(path.startsWith(FilenameUtils.normalize(mod.getRelativePath())))
return true;
}
return false;
}
};
......
......@@ -10,6 +10,7 @@ import org.jvnet.hudson.test.ExtractChangeLogSet;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.scm.ChangeLogSet;
import hudson.tasks.Maven.MavenInstallation;
import java.io.IOException;
......@@ -25,7 +26,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
*/
@Bug(4192)
public void testMultiModMavenWsExists() throws Exception {
configureDefaultMaven();
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip")));
......@@ -72,6 +73,47 @@ public class MavenMultiModuleTest extends HudsonTestCase {
pBuild.getDuration() >= summedModuleDuration);
}
@Bug(5357
public void testIncrRelMultiModMaven() throws Exception {
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.setRootPOM("parent/pom.xml");
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod-rel-base.zip"),
getClass().getResource("maven-multimod-changes.zip")));
buildAndAssertSuccess(m);
// Now run a second build with the changes.
m.setIncrementalBuild(true);
buildAndAssertSuccess(m);
MavenModuleSetBuild pBuild = m.getLastBuild();
ExtractChangeLogSet changeSet = (ExtractChangeLogSet) pBuild.getChangeSet();
assertFalse("ExtractChangeLogSet should not be empty.", changeSet.isEmptySet());
for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) {
String parentModuleName = modBuild.getParent().getModuleName().toString();
if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleA")) {
assertEquals("moduleA should have Result.NOT_BUILT", Result.NOT_BUILT, modBuild.getResult());
}
else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleB")) {
assertEquals("moduleB should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult());
}
else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleC")) {
assertEquals("moduleC should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult());
}
}
long summedModuleDuration = 0;
for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) {
summedModuleDuration += modBuild.getDuration();
}
assertTrue("duration of moduleset build should be greater-equal than sum of the module builds",
pBuild.getDuration() >= summedModuleDuration);
}
/**
* NPE in {@code getChangeSetFor(m)} in {@link MavenModuleSetBuild} when incremental build is
* enabled and a new module is added.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册