提交 112ad008 编写于 作者: A abayer

[FIXED HUDSON-4491] If Maven is called with non-recursive flags, submodules are no longer parsed.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21856 71c3de6d-444a-0410-be80-ed276b4c234a
上级 cfffeb86
......@@ -525,6 +525,14 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
this.goals = goals;
}
private boolean checkMavenOption(String shortForm, String longForm) {
for (String t : Util.tokenize(getGoals())) {
if(t.equals(shortForm) || t.equals(longForm))
return true;
}
return false;
}
private List<String> getMavenArgument(String shortForm, String longForm) {
List<String> args = new ArrayList<String>();
boolean switchFound=false;
......@@ -576,6 +584,13 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
return props;
}
/**
* Check for "-N" or "--non-recursive" in the Maven goals/options.
*/
public boolean isNonRecursive() {
return checkMavenOption("-N", "--non-recursive");
}
/**
* Possibly null, whitespace-separated (including TAB, NL, etc) VM options
* to be used to launch Maven process.
......
......@@ -793,7 +793,8 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
private final Properties properties;
private final String privateRepository;
private final String alternateSettings;
private final boolean nonRecursive;
public PomParser(BuildListener listener, MavenInstallation mavenHome, MavenModuleSet project) {
// project cannot be shipped to the remote JVM, so all the relevant properties need to be captured now.
this.listener = listener;
......@@ -801,7 +802,8 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
this.rootPOM = project.getRootPOM();
this.profiles = project.getProfiles();
this.properties = project.getMavenProperties();
if (project.usesPrivateRepository()) {
this.nonRecursive = project.isNonRecursive();
if (project.usesPrivateRepository()) {
this.privateRepository = project.getWorkspace().child(".repository").getRemote();
}
else {
......@@ -838,8 +840,10 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
throw new AbortException(Messages.MavenModuleSetBuild_NoSuchPOMFile(pom));
if(verbose)
logger.println("Parsing "+pom);
logger.println("Parsing "
+ (nonRecursive ? "non-recursively " : "recursively ")
+ pom);
File settingsLoc = (alternateSettings == null) ? null
: new File(ws, alternateSettings);
......@@ -853,7 +857,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);
MavenUtil.resolveModules(embedder,mp,getRootPath(),relPath,listener,nonRecursive);
if(verbose) {
for (Entry<MavenProject, String> e : relPath.entrySet())
......
......@@ -160,33 +160,38 @@ public class MavenUtil {
* @throws AbortException
* errors will be reported to the listener and the exception thrown.
*/
public static void resolveModules(MavenEmbedder embedder, MavenProject project, String rel, Map<MavenProject,String> relativePathInfo, BuildListener listener) throws ProjectBuildingException, AbortException {
public static void resolveModules(MavenEmbedder embedder, MavenProject project,
String rel, Map<MavenProject,String> relativePathInfo,
BuildListener listener, boolean nonRecursive) throws ProjectBuildingException,
AbortException {
File basedir = project.getFile().getParentFile();
relativePathInfo.put(project,rel);
List<MavenProject> modules = new ArrayList<MavenProject>();
for (String modulePath : (List<String>) project.getModules()) {
if (Util.fixEmptyAndTrim(modulePath)!=null) {
File moduleFile = new File(basedir, modulePath);
if (moduleFile.exists() && moduleFile.isDirectory()) {
moduleFile = new File(basedir, modulePath + "/pom.xml");
if (!nonRecursive) {
List<MavenProject> modules = new ArrayList<MavenProject>();
for (String modulePath : (List<String>) project.getModules()) {
if (Util.fixEmptyAndTrim(modulePath)!=null) {
File moduleFile = new File(basedir, modulePath);
if (moduleFile.exists() && moduleFile.isDirectory()) {
moduleFile = new File(basedir, modulePath + "/pom.xml");
}
if(!moduleFile.exists())
throw new AbortException(moduleFile+" is referenced from "+project.getFile()+" but it doesn't exist");
String relativePath = rel;
if(relativePath.length()>0) relativePath+='/';
relativePath+=modulePath;
MavenProject child = embedder.readProject(moduleFile);
resolveModules(embedder,child,relativePath,relativePathInfo,listener,nonRecursive);
modules.add(child);
}
if(!moduleFile.exists())
throw new AbortException(moduleFile+" is referenced from "+project.getFile()+" but it doesn't exist");
String relativePath = rel;
if(relativePath.length()>0) relativePath+='/';
relativePath+=modulePath;
MavenProject child = embedder.readProject(moduleFile);
resolveModules(embedder,child,relativePath,relativePathInfo,listener);
modules.add(child);
}
project.setCollectedProjects(modules);
}
project.setCollectedProjects(modules);
}
/**
......
......@@ -28,9 +28,10 @@ public class MavenMultiModuleTest extends HudsonTestCase {
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip")));
assertFalse("MavenModuleSet.isNonRecursive() should be false", m.isNonRecursive());
assertBuildStatusSuccess(m.scheduleBuild2(0).get());
}
public void testIncrementalMultiModMaven() throws Exception {
configureDefaultMaven("apache-maven-2.2.1");
MavenModuleSet m = createMavenProject();
......@@ -64,6 +65,39 @@ public class MavenMultiModuleTest extends HudsonTestCase {
}
/**
* When "-N' or "--non-recursive" show up in the goals, any child modules should be ignored.
*/
@Bug(4491)
public void testMultiModMavenNonRecursiveParsing() throws Exception {
configureDefaultMaven("apache-maven-2.2.1");
MavenModuleSet m = createMavenProject();
m.setGoals("clean install -N");
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip")));
assertBuildStatusSuccess(m.scheduleBuild2(0).get());
MavenModuleSetBuild pBuild = m.getLastBuild();
for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) {
if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:multimod-top")) {
assertEquals("moduleA should have Result.SUCCESS", modBuild.getResult(), Result.SUCCESS);
}
if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:moduleA")) {
assertEquals("moduleA should have Result.NOT_BUILT", modBuild.getResult(), Result.NOT_BUILT);
}
if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:moduleB")) {
assertEquals("moduleB should have Result.NOT_BUILT", modBuild.getResult(), Result.NOT_BUILT);
}
if (modBuild.getParent().getModuleName().toString().equals("org.jvnet.hudson.main.test.multimod:moduleC")) {
assertEquals("moduleC should have Result.NOT_BUILT", modBuild.getResult(), Result.NOT_BUILT);
}
}
}
/**
* Module failures in build X should lead to those modules being re-run in build X+1, even if
* incremental build is enabled and nothing changed in those modules.
......@@ -105,7 +139,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
}
}
/**
* Test failures in a child module should lead to the parent being marked as unstable.
*/
......@@ -139,7 +173,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
}
}
/*
public void testParallelMultiModMavenWsExists() throws Exception {
configureDefaultMaven();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册