Skip to content
Permalink
Browse files
[FIXED JENKINS-14102] fix also for maven2 and add test cases
  • Loading branch information
imod committed Dec 21, 2012
1 parent 5f4f68b commit 193173f5597ca02a5ce73a2e34343f77493025dc
@@ -25,6 +25,7 @@
package hudson.maven;

import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.maven.reporters.TestFailureDetector;
import hudson.model.BuildListener;
import hudson.model.Result;
import java.io.IOException;
@@ -36,6 +37,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.maven.BuildFailureException;
import org.apache.maven.execution.MavenSession;
@@ -56,7 +58,7 @@
private long mojoStartTime;

private MavenBuildProxy2 lastProxy;

private final AtomicBoolean hasTestFailures = new AtomicBoolean();


public Maven2Builder(BuildListener listener,Map<ModuleName,ProxyImpl2> proxies, Collection<MavenModule> modules, List<String> goals, Map<String,String> systemProps, MavenBuildInformation mavenBuildInformation) {
@@ -151,9 +153,15 @@ void postExecute(MavenProject project, MojoInfo mojoInfo, Exception exception) t
mojoList.add(new ExecutedMojo(mojoInfo,System.currentTimeMillis()-mojoStartTime));

MavenBuildProxy2 proxy = proxies.get(name);
for (MavenReporter r : reporters.get(name))
if(!r.postExecute(proxy,project,mojoInfo,listener,exception))
for (MavenReporter r : reporters.get(name)){
if(!r.postExecute(proxy,project,mojoInfo,listener,exception)) {
throw new hudson.maven.agent.AbortException(r+" failed");
} else if (r instanceof TestFailureDetector) {
if(((TestFailureDetector) r).hasTestFailures()) {
hasTestFailures.compareAndSet(false, true);
}
}
}
if(exception!=null)
proxy.setResult(Result.FAILURE);
}
@@ -166,7 +174,10 @@ void onReportGenerated(MavenProject project, MavenReportInfo report) throws IOEx
throw new hudson.maven.agent.AbortException(r+" failed");
}


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

private static final long serialVersionUID = 1L;
}
@@ -436,12 +436,8 @@ private void recordMojoEnded(ExecutionEvent event, Exception problem) {
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());
if(((TestFailureDetector) mavenReporter).hasTestFailures()) {
hasTestFailures.compareAndSet(false, true);
}else{
System.out.println("------->>>>"+mavenReporter.getClass());
}
}
} catch ( InterruptedException e ) {
@@ -27,6 +27,7 @@
import hudson.FilePath;
import hudson.maven.reporters.MavenArtifactRecord;
import hudson.maven.reporters.SurefireArchiver;
import hudson.maven.reporters.TestFailureDetector;
import hudson.slaves.WorkspaceList;
import hudson.slaves.WorkspaceList.Lease;
import hudson.maven.agent.AbortException;
@@ -71,6 +72,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

import jenkins.mvn.SettingsProvider;
@@ -296,6 +298,7 @@ protected void setBuiltOnStr(String builtOn) {
*/
private static final class Builder extends MavenBuilder {
private final MavenBuildProxy buildProxy;
private final AtomicBoolean hasTestFailures = new AtomicBoolean();

/**
* Records of what was executed.
@@ -350,9 +353,15 @@ void preExecute(MavenProject project, MojoInfo info) throws IOException, Interru
void postExecute(MavenProject project, MojoInfo info, Exception exception) throws IOException, InterruptedException, AbortException {
executedMojos.add(new ExecutedMojo(info,System.currentTimeMillis()-startTime));

for (MavenReporter r : reporters.get(moduleName))
if(!r.postExecute(buildProxy,project,info,listener,exception))
for (MavenReporter r : reporters.get(moduleName)){
if(!r.postExecute(buildProxy,project,info,listener,exception)) {
throw new AbortException(r+" failed");
} else if (r instanceof TestFailureDetector) {
if(((TestFailureDetector) r).hasTestFailures()) {
hasTestFailures.compareAndSet(false, true);
}
}
}
}

@Override
@@ -376,6 +385,11 @@ void postModule(MavenProject project) throws InterruptedException, IOException,
throw new AbortException(r+" failed");
}

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

private static final long serialVersionUID = 1L;
}

@@ -43,6 +43,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.maven.BuildFailureException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
@@ -169,10 +171,18 @@ public Result call() throws IOException {
logger.println("Resource loading "+format(n,ch.resourceLoadingTime.get())+"ms, "+ch.resourceLoadingCount+" times");
}

if(r==0) return Result.SUCCESS;
if(r==0){
if(a.hasBuildFailures()){
return Result.UNSTABLE;
}
return Result.SUCCESS;
}

if(markAsSuccess) {
listener.getLogger().println(Messages.MavenBuilder_Failed());
if(a.hasBuildFailures()){
return Result.UNSTABLE;
}
return Result.SUCCESS;
}
return Result.FAILURE;
@@ -264,6 +274,7 @@ private void callSetListenerWithReflectOnInterceptorsQuietly( PluginManagerListe
private MavenProject lastModule;

private final MavenBuilder listener;
private final AtomicBoolean hasTestFailures = new AtomicBoolean();

/**
* Number of total nanoseconds {@link MavenBuilder} spent.
@@ -308,6 +319,8 @@ public void preExecute(MavenProject project, MojoExecution exec, Mojo mojo, Plex
public void postExecute(MavenProject project, MojoExecution exec, Mojo mojo, PlexusConfiguration mergedConfig, ExpressionEvaluator eval, Exception exception) throws IOException, InterruptedException {
long startTime = System.nanoTime();
listener.postExecute(project, new MojoInfo(exec, mojo, mergedConfig, eval),exception);
if(listener.hasBuildFailures())
hasTestFailures.compareAndSet(false, true);
overheadTime += System.nanoTime()-startTime;
}

@@ -328,6 +341,10 @@ private void fireLeaveModule() throws InterruptedException, IOException {
lastModule = null;
}
}

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

/**
@@ -351,4 +368,6 @@ private void fireLeaveModule() throws InterruptedException, IOException {
public static boolean markAsSuccess;

private static final long serialVersionUID = 1L;

public abstract boolean hasBuildFailures();
}
@@ -14,7 +14,7 @@
/**
* Have any test failures been detected?
*
* @return <code>true</code> if there ar test failures
* @return <code>true</code> if there are test failures
*/
public abstract boolean hasTestFailures();

@@ -52,12 +52,23 @@ public void testMaven3Failed() throws Exception {
public void testMaven3SkipPostBuilder() throws Exception {
MavenModuleSet m = createMavenProject();
m.setMaven( configureMaven3().getName() );
m.setGoals( "test -Dmaven.test.failure.ignore=false" );
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
// run dummy command only if build state is SUCCESS
m.setRunPostStepsIfResult(Result.SUCCESS);
m.addPostBuilder(new Shell("no-command"));
m.addPostBuilder(new Shell("no-valid-command"));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}

@Bug(14102)
public void testMaven2SkipPostBuilder() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
// run dummy command only if build state is SUCCESS
m.setRunPostStepsIfResult(Result.SUCCESS);
m.addPostBuilder(new Shell("no-valid-command"));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}
}

0 comments on commit 193173f

Please sign in to comment.