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

fix junit failures regarding incremental builds

上级 0a9d2826
......@@ -33,10 +33,10 @@ THE SOFTWARE.
<artifactId>maven-agent</artifactId>
<packaging>jar</packaging>
<name>Hudson Maven CLI agent</name>
<name>Hudson Maven2 CLI agent</name>
<description>
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>
<build>
......
......@@ -33,7 +33,7 @@ THE SOFTWARE.
<artifactId>maven-interceptor</artifactId>
<packaging>jar</packaging>
<name>Hudson Maven PluginManager interceptor</name>
<name>Hudson Maven 2 PluginManager interceptor</name>
<description>
Plexus module that intercepts invocations of key Maven components
so that Hudson can monitor what's going on in Maven.
......
......@@ -59,6 +59,7 @@ import hudson.util.MaskingClassLoader;
import hudson.util.StreamTaskListener;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.PrintStream;
......@@ -476,7 +477,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
listener.getLogger().println("Found mavenVersion " + mavenVersion + " from file " + mavenInformation.getVersionResourcePath());
if(!project.isAggregatorStyleBuild()) {
parsePoms(listener, logger, envVars, mvn);
parsePoms(listener, logger, envVars, mvn, getModuleRoot().getRemote());
// start module builds
logger.println("Triggering "+project.getRootModule().getModuleName());
project.getRootModule().scheduleBuild(new UpstreamCause((Run<?,?>)MavenModuleSetBuild.this));
......@@ -501,7 +502,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
if(!preBuild(listener, project.getPublishers()))
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);
proxies = new HashMap<ModuleName, ProxyImpl2>();
List<String> changedModules = new ArrayList<String>();
......@@ -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
// listed in changedModules, do the Maven incremental build commands - if there are no changed modules,
// 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("-pl", Util.join(changedModules, ","));
}
......@@ -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");
List<PomInfo> poms;
try {
poms = getModuleRoot().act(new PomParser(listener, mvn, project));
poms = getModuleRoot().act(new PomParser(listener, mvn, project, workspacePath));
} catch (IOException e) {
if (e.getCause() instanceof AbortException)
throw (AbortException) e.getCause();
......@@ -964,8 +966,8 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
private final boolean nonRecursive;
// We're called against the module root, not the workspace, which can cause a lot of confusion.
private final String workspaceProper;
public PomParser(BuildListener listener, MavenInstallation mavenHome, MavenModuleSet project) {
private String workspacePath;
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.
this.listener = listener;
this.mavenHome = mavenHome;
......@@ -980,6 +982,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
this.privateRepository = null;
}
this.alternateSettings = project.getAlternateSettings();
this.workspacePath = FilenameUtils.normalize( workspacePath );
}
......@@ -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 {
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);
for (String modulePath : mp.getModules())
{
if (StringUtils.isBlank( modulePath )) continue;
if (StringUtils.isBlank( modulePath )) {
continue;
}
File path = new File(mp.getBasedir(), modulePath);
MavenProject child = abslPath.get( path.getCanonicalPath());
toPomInfo(child,pi,abslPath,infos);
......
......@@ -8,7 +8,8 @@
<version>1.389-SNAPSHOT</version>
</parent>
<artifactId>maven3-agent</artifactId>
<name>Hudson Maven3 Agent</name>
<name>Hudson Maven3 CLI Agent</name>
<dependencies>
<dependency>
<groupId>org.jvnet.hudson.main</groupId>
......
......@@ -40,6 +40,7 @@ THE SOFTWARE.
<properties>
<concurrency>1</concurrency> <!-- -1 means # of processors in the system -->
<mavenDebug>false</mavenDebug>
</properties>
<build>
......@@ -70,6 +71,10 @@ THE SOFTWARE.
<name>hudson.ClassicPluginStrategy.useAntClassLoader</name>
<value>true</value>
</property>
<property>
<name>hudson.maven.debug</name>
<value>${mavenDebug}</value>
</property>
</systemProperties>
</configuration>
</execution>
......
......@@ -34,32 +34,32 @@ public class MavenMultiModuleTest extends HudsonTestCase {
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod.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());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod.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());
}
}
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()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册