Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A test pull request #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions maven-failsafe-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,6 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<!-- Generate the xpp3 reader code -->
<goal>xpp3-reader</goal>
<!-- Generate the xpp3 writer code -->
<goal>xpp3-writer</goal>
<!-- Generate the Java sources for the model itself -->
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<models>
<model>src/main/mdo/failsafe-summary.mdo</model>
</models>
<version>2.12</version>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@
* under the License.
*/

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
Expand All @@ -37,16 +27,16 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.failsafe.model.FailsafeSummary;
import org.apache.maven.surefire.failsafe.model.io.xpp3.FailsafeSummaryXpp3Reader;
import org.apache.maven.surefire.failsafe.model.io.xpp3.FailsafeSummaryXpp3Writer;
import org.apache.maven.shared.utils.ReaderFactory;

import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.util.NestedCheckedException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import static org.apache.maven.shared.utils.io.IOUtil.close;

Expand All @@ -55,7 +45,7 @@
*
* @author Jason van Zyl
* @author Stephen Connolly
* @noinspection JavaDoc, UnusedDeclaration
* @noinspection JavaDoc,
*/
@Mojo( name = "integration-test", requiresProject = true, requiresDependencyResolution = ResolutionScope.TEST,
defaultPhase = LifecyclePhase.INTEGRATION_TEST, threadSafe = true )
Expand Down Expand Up @@ -181,31 +171,11 @@ public class IntegrationTestMojo
protected void handleSummary(RunResult summary, NestedCheckedException firstForkException)
throws MojoExecutionException, MojoFailureException
{
FailsafeSummary failsafeSummary = createFailsafeSummaryFromSummary( summary, firstForkException );
writeSummary( failsafeSummary );
}

private FailsafeSummary createFailsafeSummaryFromSummary(RunResult summary, NestedCheckedException firstForkException)
{
FailsafeSummary failsafeSummary = new FailsafeSummary();
if ( firstForkException == null )
{
if ( summary != null )
{
failsafeSummary.setResult( summary.getForkedProcessCode() );
}
}
else
{
failsafeSummary.setResult( ProviderConfiguration.TESTS_FAILED_EXIT_CODE );
//noinspection ThrowableResultOfMethodCallIgnored
failsafeSummary.setException( firstForkException.getMessage() );
}
return failsafeSummary;
writeSummary( summary, firstForkException );
}

@SuppressWarnings( "unchecked" )
private void writeSummary( FailsafeSummary summary )
private void writeSummary( RunResult summary, NestedCheckedException firstForkException )
throws MojoExecutionException
{
File summaryFile = getSummaryFile();
Expand All @@ -219,34 +189,13 @@ private void writeSummary( FailsafeSummary summary )
FileInputStream fin = null;
try
{
FailsafeSummary mergedSummary = summary;
Object token = getPluginContext().get( FAILSAFE_IN_PROGRESS_CONTEXT_KEY );
if ( summaryFile.exists() && token != null )
{
fin = new FileInputStream( summaryFile );

mergedSummary = new FailsafeSummaryXpp3Reader().read(
new InputStreamReader( new BufferedInputStream( fin ), getEncodingOrDefault() ) );

mergedSummary.merge( summary );
}

fout = new FileOutputStream( summaryFile );
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( fout );
Writer writer = new OutputStreamWriter( bufferedOutputStream, getEncodingOrDefault() );
FailsafeSummaryXpp3Writer xpp3Writer = new FailsafeSummaryXpp3Writer();
xpp3Writer.write( writer, mergedSummary );
writer.close();
bufferedOutputStream.close();
summary.writeSummary(summaryFile, token != null, getEncodingOrDefault());
}
catch ( IOException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
catch ( XmlPullParserException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
finally
{
close( fin );
Expand All @@ -270,6 +219,7 @@ private String getEncodingOrDefault()
}
}

@SuppressWarnings("deprecation")
protected boolean isSkipExecution()
{
return isSkip() || isSkipTests() || isSkipITs() || isSkipExec();
Expand Down Expand Up @@ -305,12 +255,14 @@ public void setSkipITs( boolean skipITs )
this.skipITs = skipITs;
}

@SuppressWarnings("deprecation")
@Deprecated
public boolean isSkipExec()
{
return skipExec;
}

@SuppressWarnings("deprecation")
@Deprecated
public void setSkipExec( boolean skipExec )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
* under the License.
*/

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -33,13 +27,14 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.shared.utils.ReaderFactory;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.surefire.failsafe.model.FailsafeSummary;
import org.apache.maven.surefire.failsafe.model.io.xpp3.FailsafeSummaryXpp3Reader;
import org.apache.maven.shared.utils.io.IOUtil;
import org.apache.maven.shared.utils.ReaderFactory;
import org.apache.maven.surefire.suite.RunResult;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import java.io.*;

/**
* Verify integration tests ran using Surefire.
*
Expand Down Expand Up @@ -156,7 +151,7 @@ public void execute()
getLog().info(
StringUtils.capitalizeFirstLetter( getPluginName() ) + " report directory: " + getReportsDirectory() );

int result;
RunResult summary;
try
{
String encoding;
Expand All @@ -172,10 +167,9 @@ public void execute()
encoding = this.encoding;
}

final FailsafeSummary summary;
if ( !summaryFile.isFile() && summaryFiles != null )
{
summary = new FailsafeSummary();
summary = RunResult.noTestsRun();
}
else
{
Expand All @@ -185,10 +179,9 @@ public void execute()
{
for ( File file : summaryFiles )
{
summary.merge( readSummary( encoding, file ) );
summary = summary.aggregate( readSummary( encoding, file ) );
}
}
result = summary.getResult();
}
catch ( IOException e )
{
Expand All @@ -199,11 +192,11 @@ public void execute()
throw new MojoExecutionException( e.getMessage(), e );
}

SurefireHelper.reportExecution( this, result, getLog() );
SurefireHelper.reportExecution( this, summary, getLog() );
}
}

private FailsafeSummary readSummary( String encoding, File summaryFile )
private RunResult readSummary( String encoding, File summaryFile )
throws IOException, XmlPullParserException
{
FileInputStream fileInputStream = null;
Expand All @@ -214,8 +207,7 @@ private FailsafeSummary readSummary( String encoding, File summaryFile )
fileInputStream = new FileInputStream( summaryFile );
bufferedInputStream = new BufferedInputStream( fileInputStream );
reader = new InputStreamReader( bufferedInputStream, encoding );
FailsafeSummaryXpp3Reader xpp3Reader = new FailsafeSummaryXpp3Reader();
return xpp3Reader.read( reader );
return RunResult.fromInputStream(bufferedInputStream, encoding);
}
finally
{
Expand All @@ -236,7 +228,7 @@ protected boolean verifyParameters()

if ( !getTestClassesDirectory().exists() )
{
if ( getFailIfNoTests() != null && getFailIfNoTests().booleanValue() )
if ( getFailIfNoTests() != null && getFailIfNoTests())
{
throw new MojoFailureException( "No tests to run!" );
}
Expand Down
Loading