提交 87741425 编写于 作者: A abayer

[HUDSON-7684] Attempting to fix - I think this works, but it needs more...

[HUDSON-7684] Attempting to fix - I think this works, but it needs more testing in other environments

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@36799 71c3de6d-444a-0410-be80-ed276b4c234a
上级 4a6f58d5
......@@ -888,6 +888,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
this.privateRepository = null;
}
this.alternateSettings = project.getAlternateSettings();
}
/**
......@@ -896,15 +897,16 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
* Returns "abc" if rootPOM="abc/pom.xml"
* If rootPOM="pom.xml", this method returns "".
*/
private String getRootPath() {
private String getRootPath(String prefix) {
int idx = Math.max(rootPOM.lastIndexOf('/'), rootPOM.lastIndexOf('\\'));
if(idx==-1) return "";
return rootPOM.substring(0,idx);
return prefix + rootPOM.substring(0,idx);
}
public List<PomInfo> invoke(File ws, VirtualChannel channel) throws IOException {
File pom;
String rootPOMRelPrefix;
PrintStream logger = listener.getLogger();
if (IOUtils.isAbsolute(rootPOM)) {
......@@ -922,6 +924,18 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
if(!pom.exists())
throw new AbortException(Messages.MavenModuleSetBuild_NoSuchPOMFile(pom));
if (rootPOM.startsWith("../") || rootPOM.startsWith("..\\")) {
File wsp = new File(workspaceProper);
if (!ws.equals(wsp)) {
rootPOMRelPrefix = ws.getCanonicalPath().substring(wsp.getCanonicalPath().length()+1)+"/";
} else {
rootPOMRelPrefix = wsp.getName() + "/";
}
} else {
rootPOMRelPrefix = "";
}
if(verbose)
logger.println("Parsing "
+ (nonRecursive ? "non-recursively " : "recursively ")
......@@ -953,7 +967,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
properties, privateRepository, settingsLoc);
MavenProject mp = embedder.readProject(pom);
Map<MavenProject,String> relPath = new HashMap<MavenProject,String>();
MavenUtil.resolveModules(embedder,mp,getRootPath(),relPath,listener,nonRecursive);
MavenUtil.resolveModules(embedder,mp,getRootPath(rootPOMRelPrefix),relPath,listener,nonRecursive);
if(verbose) {
for (Entry<MavenProject, String> e : relPath.entrySet())
......@@ -984,7 +998,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
private static final long serialVersionUID = 1L;
}
private static final Logger LOGGER = Logger.getLogger(MavenModuleSetBuild.class.getName());
/**
......
......@@ -48,14 +48,32 @@ import java.util.zip.ZipInputStream;
public class ExtractResourceWithChangesSCM extends NullSCM {
private final URL firstZip;
private final URL secondZip;
private final String moduleRoot;
public ExtractResourceWithChangesSCM(URL firstZip, URL secondZip) {
if ((firstZip == null) || (secondZip == null))
throw new IllegalArgumentException();
this.firstZip = firstZip;
this.secondZip = secondZip;
this.moduleRoot = null;
}
public ExtractResourceWithChangesSCM(URL firstZip, URL secondZip, String moduleRoot) {
if ((firstZip == null) || (secondZip == null))
throw new IllegalArgumentException();
this.firstZip = firstZip;
this.secondZip = secondZip;
this.moduleRoot = moduleRoot;
}
@Override
public FilePath getModuleRoot(FilePath workspace) {
if (moduleRoot!=null) {
return workspace.child(moduleRoot);
}
return workspace;
}
@Override
public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException {
if (workspace.exists()) {
......
......@@ -109,6 +109,49 @@ public class MavenMultiModuleTest extends HudsonTestCase {
assertTrue("duration of moduleset build should be greater-equal than sum of the module builds",
pBuild.getDuration() >= summedModuleDuration);
}
@Bug(7684)
public void testRelRootPom() 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"),
"moduleA"));
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);
}
@Bug(6544)
public void testEstimatedDurationForIncrementalMultiModMaven()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册