Skip to content

Commit

Permalink
maven install phase prevented if there are failures (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
iantmoore committed Sep 25, 2016
1 parent f4f2588 commit c76a7c0
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Requirements
1.0.4
-----
* Added a checkbox to the report to optionally hide skipped steps
* Substeps Mojos - Failures should prevent the Maven install phase from running; The runner mojo will throw a MojoFailureException only if the verify phase is not planned. The Report Builder will throw any such exception if one is encountered in the maven session.


1.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import com.technophobia.substeps.runner.IExecutionListener;

import java.io.File;
import java.io.Serializable;

/**
* Created by ian on 24/05/16.
*/
public interface IExecutionResultsCollector extends IExecutionListener {
public interface IExecutionResultsCollector extends IExecutionListener, Serializable {
void initOutputDirectories(RootNode rootNode);

void setDataDir(File dataDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object ExecutionResultsCollector{


// TODO - remove the ctor params to allow injection from Maven via setter... eurgh builder instead ? when to init ?
class ExecutionResultsCollector extends IExecutionResultsCollector{
class ExecutionResultsCollector extends IExecutionResultsCollector {

private val log: Logger = LoggerFactory.getLogger(classOf[ExecutionResultsCollector])

Expand All @@ -49,8 +49,8 @@ class ExecutionResultsCollector extends IExecutionResultsCollector{
def setDataDir(dir : File) = this.dataDir = dir
def setPretty(pretty : Boolean) = this.pretty = pretty


val UTF8 = Charset.forName("UTF-8")
@transient
lazy val UTF8 = Charset.forName("UTF-8")

var featureToResultsDirMap: Map[FeatureNode, File] = Map()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ public void execute() throws MojoExecutionException, MojoFailureException {

reportBuilder.buildFromDirectory(this.executionResultsCollector.getDataDir());



List<Throwable> exceptions = this.session.getResult().getExceptions();

if (exceptions != null && !exceptions.isEmpty()){
getLog().info("got exceptions");
for (Throwable t : exceptions){
if (t instanceof MojoFailureException){
MojoFailureException failure = (MojoFailureException)t;
// remove the exception otherwise it will get logged twice
this.session.getResult().getExceptions().remove(t);

throw failure;

}
}
}
else {
getLog().info("All good, no failures");
}
// ensureValidConfiguration();
//
// this.runner = this.runTestsInForkedVM ? createForkedRunner() : createInProcessRunner();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {

this.runner = this.runTestsInForkedVM ? createForkedRunner() : createInProcessRunner();

executeConfigs();

processBuildData();
try {
executeConfigs();

this.runner.shutdown();
processBuildData();
}
finally {
this.runner.shutdown();
}
}


Expand Down Expand Up @@ -219,18 +222,40 @@ private void addToLegacyReport(final RootNode rootNode) {
private void processBuildData() throws MojoFailureException {

if (reportBuilder == null && this.executionReportBuilder != null) {

this.executionReportBuilder.buildReport();
}


StringBuilder buf = new StringBuilder();
for (String s : this.session.getGoals()){
buf.append(s);
buf.append(" ");
}

this.getLog().info("this.session.getGoals(): " + buf.toString());

List<String> goals = this.session.getGoals();

if (this.buildFailureManager.testSuiteFailed()) {

this.session.getResult().addException(new MojoFailureException("Substep Execution failed:\n"
+ this.buildFailureManager.getBuildFailureInfo()));
MojoFailureException e = new MojoFailureException("Substep Execution failed:\n"
+ this.buildFailureManager.getBuildFailureInfo());


// actually throwing an exception results in the build terminating immediately
// - not really desireable as it stops the report from being built in the verify phase

if (goals.contains("verify") || goals.contains("install") || goals.contains("deploy")){

// we don't want to throw the exception - it will be thrown in the reportbuildermojo
getLog().info("Not immediately failing the build, deferring..");
this.session.getResult().addException(e);
}
else {
throw e;
}

} else if (!this.buildFailureManager.testSuiteCompletelyPassed()) {
// print out the failure string (but won't include any failures)
getLog().info(this.buildFailureManager.getBuildFailureInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@
import com.technophobia.substeps.runner.ExecutionConfig;
import com.technophobia.substeps.runner.SubstepsReportBuilderMojo;
import com.technophobia.substeps.runner.SubstepsRunnerMojo;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.junit.Assert;
import org.junit.Ignore;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import static org.hamcrest.Matchers.*;

Expand All @@ -42,14 +52,14 @@ public void setUp() throws Exception {
}

private void actuallyRunTheTest() throws Exception{
File testPom = new File(getBasedir(),
"src/test/resources/sample-pom.xml");

File testPom = new File(getBasedir(), "src/test/resources/sample-pom.xml");

Assert.assertNotNull(testPom);
Assert.assertTrue(testPom.exists());

PlexusConfiguration pluginConfiguration = this.extractPluginConfiguration("substeps-maven-plugin", testPom);
final SubstepsRunnerMojo mojo = (SubstepsRunnerMojo)lookupMojo("org.substeps", "substeps-maven-plugin", "1.0.2-SNAPSHOT", "run-features", pluginConfiguration);
final SubstepsRunnerMojo mojo = (SubstepsRunnerMojo)lookupMojo("org.substeps", "substeps-maven-plugin", "1.0.4-SNAPSHOT", "run-features", pluginConfiguration);

Assert.assertNotNull("expecting a mojo", mojo);

Expand Down Expand Up @@ -103,9 +113,11 @@ private void actuallyRunTheTest() throws Exception{

}

public void testMojoGoal() throws Exception {
public void testMojoConfig() throws Exception {

// no op, can't get this test to work in release, when the version gets bumped

//actuallyRunTheTest();
}


}
8 changes: 5 additions & 3 deletions runner/Maven/src/test/resources/sample-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.substeps</groupId>
<artifactId>mojo-sample</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>

<packaging>jar</packaging>
<name>pom sample</name>
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>org.substeps</groupId>
<artifactId>substeps-core</artifactId>
<version>1.0.2-IM-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</dependency>

<dependency>
Expand All @@ -49,7 +49,9 @@
<plugin>
<groupId>org.substeps</groupId>
<artifactId>substeps-maven-plugin</artifactId>
<version>1.0.2-SNAPSHOT</version>
<!--
<version>1.0.4-SNAPSHOT</version>
-->

<executions>
<execution>
Expand Down

0 comments on commit c76a7c0

Please sign in to comment.