Skip to content
Permalink
Browse files
[FIXED JENKINS-14102] mark maven build with test failures as unstable
Originally-Committed-As: 5f4f68be0081cd9b9554c7d0ce8529c573764056
  • Loading branch information
imod committed Dec 21, 2012
1 parent cc2707f commit adf9fc658df6e18a0d0648fea011bbe752094558
@@ -24,6 +24,7 @@
package hudson.maven;

import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.maven.reporters.TestFailureDetector;
import hudson.maven.util.ExecutionEventLogger;
import hudson.model.BuildListener;
import hudson.model.Result;
@@ -53,6 +54,7 @@
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

import static hudson.Util.*;
@@ -120,7 +122,12 @@ public Result call() throws IOException {

PrintStream logger = listener.getLogger();

if(r==0 && mavenExecutionResult.getThrowables().isEmpty()) return Result.SUCCESS;
if(r==0 && mavenExecutionResult.getThrowables().isEmpty()) {
if(mavenExecutionListener.hasTestFailures()){
return Result.UNSTABLE;
}
return Result.SUCCESS;
}

if (!mavenExecutionResult.getThrowables().isEmpty()) {
logger.println( "mavenExecutionResult exceptions not empty");
@@ -137,6 +144,9 @@ public Result call() throws IOException {

if(markAsSuccess) {
listener.getLogger().println(Messages.MavenBuilder_Failed());
if(mavenExecutionListener.hasTestFailures()){
return Result.UNSTABLE;
}
return Result.SUCCESS;
}
return Result.FAILURE;
@@ -158,6 +168,8 @@ public Result call() throws IOException {
private static final long serialVersionUID = 4942789836756366116L;

private final Maven3Builder maven3Builder;

private AtomicBoolean hasTestFailures = new AtomicBoolean();

/**
* Number of total nanoseconds {@link Maven3Builder} spent.
@@ -185,6 +197,10 @@ public MavenExecutionListener(Maven3Builder maven3Builder) {
this.eventLogger = new ExecutionEventLogger( new PrintStreamLogger( maven3Builder.listener.getLogger() ) );
}

public boolean hasTestFailures(){
return hasTestFailures.get();
}

private MavenBuildProxy2 getMavenBuildProxy2(MavenProject mavenProject) {
for (Entry<ModuleName,FilterImpl> entry : proxies.entrySet()) {
if (entry.getKey().compareTo( new ModuleName( mavenProject ) ) == 0) {
@@ -419,6 +435,15 @@ private void recordMojoEnded(ExecutionEvent event, Exception problem) {
for (MavenReporter mavenReporter : fixNull(mavenReporters)) {
try {
mavenReporter.postExecute( mavenBuildProxy2, mavenProject, mojoInfo, maven3Builder.listener, problem);
if (mavenReporter instanceof TestFailureDetector) {
TestFailureDetector detector = (TestFailureDetector) mavenReporter;
if(detector.hasTestFailures()) {
System.out.println("+++++++>>>>"+mavenReporter.getClass());
hasTestFailures.compareAndSet(false, true);
}else{
System.out.println("------->>>>"+mavenReporter.getClass());
}
}
} catch ( InterruptedException e ) {
e.printStackTrace();
} catch ( IOException e ) {
@@ -398,6 +398,10 @@ public MavenModuleSet(ItemGroup parent, String name) {
return postbuilders;
}

void addPostBuilder(Builder builder) throws IOException{
postbuilders.add(builder);
}

/**
* {@link #postbuilders} are run if the result is better or equal to this threshold.
*
@@ -51,6 +51,7 @@
import java.util.ListIterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
@@ -64,15 +65,21 @@
* Records the surefire test result.
* @author Kohsuke Kawaguchi
*/
public class SurefireArchiver extends MavenReporter {
public class SurefireArchiver extends TestFailureDetector {
private transient TestResult result;
private final AtomicBoolean hasTestFailures = new AtomicBoolean();

/**
* Store the filesets here as we want to track ignores between multiple runs of this class<br/>
* Note: Because this class can be run with different mojo goals with different path settings,
* we track multiple {@link FileSet}s for each encountered <tt>reportsDir</tt>
*/
private transient ConcurrentMap<File, FileSet> fileSets = new ConcurrentHashMap<File,FileSet>();

@Override
public boolean hasTestFailures() {
return hasTestFailures.get();
}

public boolean preExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener) throws InterruptedException, IOException {
if (isTestMojo(mojo)) {
@@ -161,6 +168,7 @@ public Integer call(MavenBuild build) throws IOException, InterruptedException {
// intercept that (or otherwise build will be marked as failure)
if(failCount>0) {
markBuildAsSuccess(error,build.getMavenBuildInformation());
hasTestFailures.compareAndSet(false, true);
}
}
}
@@ -0,0 +1,21 @@
package hudson.maven.reporters;

import hudson.maven.MavenReporter;

/**
* A maven reporter expressing whether he found test failures and the build should be marked as UNSTABLE.
*
* @author Dominik Bartholdi (imod)
*/
public abstract class TestFailureDetector extends MavenReporter {

private static final long serialVersionUID = 1L;

/**
* Have any test failures been detected?
*
* @return <code>true</code> if there ar test failures
*/
public abstract boolean hasTestFailures();

}

0 comments on commit adf9fc6

Please sign in to comment.