提交 28594298 编写于 作者: O Olivier Lamy

fix junit failures regarding incremental builds

上级 0a9d2826
...@@ -33,10 +33,10 @@ THE SOFTWARE. ...@@ -33,10 +33,10 @@ THE SOFTWARE.
<artifactId>maven-agent</artifactId> <artifactId>maven-agent</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Hudson Maven CLI agent</name> <name>Hudson Maven2 CLI agent</name>
<description> <description>
Code that boots up Maven2 with Hudson's remoting support in place. Code that boots up Maven2 with Hudson's remoting support in place.
Used for the native m2 support. Used for the native maven support.
</description> </description>
<build> <build>
......
...@@ -33,7 +33,7 @@ THE SOFTWARE. ...@@ -33,7 +33,7 @@ THE SOFTWARE.
<artifactId>maven-interceptor</artifactId> <artifactId>maven-interceptor</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Hudson Maven PluginManager interceptor</name> <name>Hudson Maven 2 PluginManager interceptor</name>
<description> <description>
Plexus module that intercepts invocations of key Maven components Plexus module that intercepts invocations of key Maven components
so that Hudson can monitor what's going on in Maven. so that Hudson can monitor what's going on in Maven.
......
...@@ -59,6 +59,7 @@ import hudson.util.MaskingClassLoader; ...@@ -59,6 +59,7 @@ import hudson.util.MaskingClassLoader;
import hudson.util.StreamTaskListener; import hudson.util.StreamTaskListener;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.io.PrintStream; import java.io.PrintStream;
...@@ -476,7 +477,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -476,7 +477,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
listener.getLogger().println("Found mavenVersion " + mavenVersion + " from file " + mavenInformation.getVersionResourcePath()); listener.getLogger().println("Found mavenVersion " + mavenVersion + " from file " + mavenInformation.getVersionResourcePath());
if(!project.isAggregatorStyleBuild()) { if(!project.isAggregatorStyleBuild()) {
parsePoms(listener, logger, envVars, mvn); parsePoms(listener, logger, envVars, mvn, getModuleRoot().getRemote());
// start module builds // start module builds
logger.println("Triggering "+project.getRootModule().getModuleName()); logger.println("Triggering "+project.getRootModule().getModuleName());
project.getRootModule().scheduleBuild(new UpstreamCause((Run<?,?>)MavenModuleSetBuild.this)); project.getRootModule().scheduleBuild(new UpstreamCause((Run<?,?>)MavenModuleSetBuild.this));
...@@ -501,7 +502,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -501,7 +502,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
if(!preBuild(listener, project.getPublishers())) if(!preBuild(listener, project.getPublishers()))
return Result.FAILURE; return Result.FAILURE;
parsePoms(listener, logger, envVars, mvn); // #5428 : do pre-build *before* parsing pom parsePoms(listener, logger, envVars, mvn,getModuleRoot().getRemote()); // #5428 : do pre-build *before* parsing pom
SplittableBuildListener slistener = new SplittableBuildListener(listener); SplittableBuildListener slistener = new SplittableBuildListener(listener);
proxies = new HashMap<ModuleName, ProxyImpl2>(); proxies = new HashMap<ModuleName, ProxyImpl2>();
List<String> changedModules = new ArrayList<String>(); List<String> changedModules = new ArrayList<String>();
...@@ -565,7 +566,8 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -565,7 +566,8 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
// If incrementalBuild is set, and we're on Maven 2.1 or later, *and* there's at least one module // If incrementalBuild is set, and we're on Maven 2.1 or later, *and* there's at least one module
// listed in changedModules, do the Maven incremental build commands - if there are no changed modules, // listed in changedModules, do the Maven incremental build commands - if there are no changed modules,
// We're building everything anyway. // We're building everything anyway.
if (project.isIncrementalBuild() && mvn.isMaven2_1(launcher) && !changedModules.isEmpty()) { boolean maven2_1orLater = new ComparableVersion (mavenVersion).compareTo( new ComparableVersion ("2.1") ) >= 0;
if (project.isIncrementalBuild() && maven2_1orLater && !changedModules.isEmpty()) {
margs.add("-amd"); margs.add("-amd");
margs.add("-pl", Util.join(changedModules, ",")); margs.add("-pl", Util.join(changedModules, ","));
} }
...@@ -659,12 +661,12 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -659,12 +661,12 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
} }
} }
private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVars, MavenInstallation mvn) throws IOException, InterruptedException { private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVars, MavenInstallation mvn, String workspacePath) throws IOException, InterruptedException {
logger.println("Parsing POMs"); logger.println("Parsing POMs");
List<PomInfo> poms; List<PomInfo> poms;
try { try {
poms = getModuleRoot().act(new PomParser(listener, mvn, project)); poms = getModuleRoot().act(new PomParser(listener, mvn, project, workspacePath));
} catch (IOException e) { } catch (IOException e) {
if (e.getCause() instanceof AbortException) if (e.getCause() instanceof AbortException)
throw (AbortException) e.getCause(); throw (AbortException) e.getCause();
...@@ -964,8 +966,8 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -964,8 +966,8 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
private final boolean nonRecursive; private final boolean nonRecursive;
// We're called against the module root, not the workspace, which can cause a lot of confusion. // We're called against the module root, not the workspace, which can cause a lot of confusion.
private final String workspaceProper; private final String workspaceProper;
private String workspacePath;
public PomParser(BuildListener listener, MavenInstallation mavenHome, MavenModuleSet project) { public PomParser(BuildListener listener, MavenInstallation mavenHome, MavenModuleSet project, String workspacePath) {
// project cannot be shipped to the remote JVM, so all the relevant properties need to be captured now. // project cannot be shipped to the remote JVM, so all the relevant properties need to be captured now.
this.listener = listener; this.listener = listener;
this.mavenHome = mavenHome; this.mavenHome = mavenHome;
...@@ -980,6 +982,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -980,6 +982,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
this.privateRepository = null; this.privateRepository = null;
} }
this.alternateSettings = project.getAlternateSettings(); this.alternateSettings = project.getAlternateSettings();
this.workspacePath = FilenameUtils.normalize( workspacePath );
} }
...@@ -1101,11 +1104,19 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -1101,11 +1104,19 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
} }
private void toPomInfo(MavenProject mp, PomInfo parent, Map<String,MavenProject> abslPath, Set<PomInfo> infos) throws IOException { private void toPomInfo(MavenProject mp, PomInfo parent, Map<String,MavenProject> abslPath, Set<PomInfo> infos) throws IOException {
PomInfo pi = new PomInfo(mp, parent, mp.getBasedir().getAbsolutePath()); String absolutePath = FilenameUtils.normalize( mp.getBasedir().getAbsolutePath());
String relPath = StringUtils.removeStart( absolutePath, this.workspacePath );
// root must be marked with only /
if (StringUtils.isBlank( relPath )) {
relPath = "/";
}
PomInfo pi = new PomInfo(mp, parent, relPath);
infos.add(pi); infos.add(pi);
for (String modulePath : mp.getModules()) for (String modulePath : mp.getModules())
{ {
if (StringUtils.isBlank( modulePath )) continue; if (StringUtils.isBlank( modulePath )) {
continue;
}
File path = new File(mp.getBasedir(), modulePath); File path = new File(mp.getBasedir(), modulePath);
MavenProject child = abslPath.get( path.getCanonicalPath()); MavenProject child = abslPath.get( path.getCanonicalPath());
toPomInfo(child,pi,abslPath,infos); toPomInfo(child,pi,abslPath,infos);
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
<version>1.389-SNAPSHOT</version> <version>1.389-SNAPSHOT</version>
</parent> </parent>
<artifactId>maven3-agent</artifactId> <artifactId>maven3-agent</artifactId>
<name>Hudson Maven3 Agent</name> <name>Hudson Maven3 CLI Agent</name>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jvnet.hudson.main</groupId> <groupId>org.jvnet.hudson.main</groupId>
......
...@@ -40,6 +40,7 @@ THE SOFTWARE. ...@@ -40,6 +40,7 @@ THE SOFTWARE.
<properties> <properties>
<concurrency>1</concurrency> <!-- -1 means # of processors in the system --> <concurrency>1</concurrency> <!-- -1 means # of processors in the system -->
<mavenDebug>false</mavenDebug>
</properties> </properties>
<build> <build>
...@@ -70,6 +71,10 @@ THE SOFTWARE. ...@@ -70,6 +71,10 @@ THE SOFTWARE.
<name>hudson.ClassicPluginStrategy.useAntClassLoader</name> <name>hudson.ClassicPluginStrategy.useAntClassLoader</name>
<value>true</value> <value>true</value>
</property> </property>
<property>
<name>hudson.maven.debug</name>
<value>${mavenDebug}</value>
</property>
</systemProperties> </systemProperties>
</configuration> </configuration>
</execution> </execution>
......
...@@ -34,32 +34,32 @@ public class MavenMultiModuleTest extends HudsonTestCase { ...@@ -34,32 +34,32 @@ public class MavenMultiModuleTest extends HudsonTestCase {
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21); configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject(); MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter()); m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod.zip"), m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod.zip"),
getClass().getResource("maven-multimod-changes.zip"))); getClass().getResource("maven-multimod-changes.zip")));
buildAndAssertSuccess(m); buildAndAssertSuccess(m);
// Now run a second build with the changes. // Now run a second build with the changes.
m.setIncrementalBuild(true); m.setIncrementalBuild(true);
buildAndAssertSuccess(m); buildAndAssertSuccess(m);
MavenModuleSetBuild pBuild = m.getLastBuild(); MavenModuleSetBuild pBuild = m.getLastBuild();
ExtractChangeLogSet changeSet = (ExtractChangeLogSet) pBuild.getChangeSet(); ExtractChangeLogSet changeSet = (ExtractChangeLogSet) pBuild.getChangeSet();
assertFalse("ExtractChangeLogSet should not be empty.", changeSet.isEmptySet()); assertFalse("ExtractChangeLogSet should not be empty.", changeSet.isEmptySet());
for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) { for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) {
String parentModuleName = modBuild.getParent().getModuleName().toString(); String parentModuleName = modBuild.getParent().getModuleName().toString();
if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleA")) { if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleA")) {
assertEquals("moduleA should have Result.NOT_BUILT", Result.NOT_BUILT, modBuild.getResult()); assertEquals("moduleA should have Result.NOT_BUILT", Result.NOT_BUILT, modBuild.getResult());
} }
else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleB")) { else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleB")) {
assertEquals("moduleB should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult()); assertEquals("moduleB should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult());
} }
else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleC")) { else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleC")) {
assertEquals("moduleC should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult()); assertEquals("moduleC should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult());
} }
} }
long summedModuleDuration = 0; long summedModuleDuration = 0;
for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) { for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册