Skip to content

Commit

Permalink
[HUDSON-8415] M2 and M3 builds behave differently when tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
olamy committed Jan 13, 2011
1 parent 32a344f commit 3f2ab68
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 9 deletions.
Expand Up @@ -23,8 +23,8 @@
*/
package hudson.maven.reporters;

import hudson.Util;
import hudson.Extension;
import hudson.Util;
import hudson.maven.Maven3Builder;
import hudson.maven.MavenBuild;
import hudson.maven.MavenBuildProxy;
Expand All @@ -40,12 +40,6 @@
import hudson.model.Result;
import hudson.tasks.junit.TestResult;
import hudson.tasks.test.TestResultProjectAction;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;

import java.io.File;
import java.io.IOException;
Expand All @@ -54,6 +48,16 @@
import java.util.List;
import java.util.ListIterator;

import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3Dom;

/**
* Records the surefire test result.
* @author Kohsuke Kawaguchi
Expand All @@ -68,8 +72,21 @@ public boolean preExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo
// so that we can record this as yellow.
// note that because of the way Maven works, just updating system property at this point is too late
XmlPlexusConfiguration c = (XmlPlexusConfiguration) mojo.configuration.getChild("testFailureIgnore");
if(c!=null && c.getValue().equals("${maven.test.failure.ignore}") && System.getProperty("maven.test.failure.ignore")==null)
c.setValue("true");
if(c!=null && c.getValue().equals("${maven.test.failure.ignore}") && System.getProperty("maven.test.failure.ignore")==null) {
if (maven3orLater( build.getMavenBuildInformation().getMavenVersion() )) {
String fieldName = "testFailureIgnore";
if (mojo.mojoExecution.getConfiguration().getChild( fieldName ) != null) {
mojo.mojoExecution.getConfiguration().getChild( fieldName ).setValue( Boolean.TRUE.toString() );
} else {
Xpp3Dom child = new Xpp3Dom( fieldName );
child.setValue( Boolean.TRUE.toString() );
mojo.mojoExecution.getConfiguration().addChild( child );
}

} else {
c.setValue(Boolean.TRUE.toString());
}
}
}
}
return true;
Expand Down Expand Up @@ -212,6 +229,14 @@ else if (mojo.is("org.sonatype.flexmojos", "flexmojos-maven-plugin", "test-run")

return true;
}

public boolean maven3orLater(String mavenVersion) {
// null or empty so false !
if (StringUtils.isBlank( mavenVersion )) {
return false;
}
return new ComparableVersion (mavenVersion).compareTo( new ComparableVersion ("3.0") ) >= 0;
}

@Extension
public static final class DescriptorImpl extends MavenReporterDescriptor {
Expand Down
52 changes: 52 additions & 0 deletions test/src/test/java/hudson/maven/MavenBuildSurefireFailedTest.java
@@ -0,0 +1,52 @@
package hudson.maven;

import hudson.model.Result;
import hudson.tasks.Maven.MavenInstallation;

import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;

/**
* @author Olivier Lamy
*/
public class MavenBuildSurefireFailedTest extends HudsonTestCase {

@Bug(8415)
public void testMaven2Unstable() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}

@Bug(8415)
public void testMaven2Failed() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setGoals( "test -Dmaven.test.failure.ignore=false" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.FAILURE, m.scheduleBuild2(0).get());
}

@Bug(8415)
public void testMaven3Unstable() throws Exception {
MavenModuleSet m = createMavenProject();
m.setMaven( configureMaven3().getName() );
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}

@Bug(8415)
public void testMaven3Failed() throws Exception {
MavenModuleSet m = createMavenProject();
m.setMaven( configureMaven3().getName() );
m.setGoals( "test -Dmaven.test.failure.ignore=false" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.FAILURE, m.scheduleBuild2(0).get());
}


}
Binary file not shown.

0 comments on commit 3f2ab68

Please sign in to comment.