Skip to content

Commit

Permalink
[SUREFIRE-2150] upgrade to parent pom 39
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy committed Feb 13, 2023
1 parent 1f0c261 commit 877f578
Show file tree
Hide file tree
Showing 871 changed files with 58,414 additions and 54,825 deletions.
520 changes: 260 additions & 260 deletions maven-failsafe-plugin/pom.xml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugin.failsafe.util;

/*
Expand All @@ -19,13 +37,9 @@
* under the License.
*/

import org.apache.maven.surefire.shared.io.IOUtils;
import org.apache.maven.surefire.api.suite.RunResult;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand All @@ -34,6 +48,11 @@
import java.io.Reader;
import java.util.Locale;

import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.shared.io.IOUtils;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;

import static java.lang.Boolean.parseBoolean;
import static java.lang.Integer.parseInt;
import static java.lang.String.format;
Expand All @@ -47,92 +66,85 @@
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
* @since 2.20
*/
public final class FailsafeSummaryXmlUtils
{
public final class FailsafeSummaryXmlUtils {
private static final String FAILSAFE_SUMMARY_XML_SCHEMA_LOCATION =
"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/failsafe-summary.xsd";

private static final String MESSAGE_NIL_ELEMENT =
"<failureMessage xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>";

private static final String MESSAGE_ELEMENT =
"<failureMessage>%s</failureMessage>";

private static final String FAILSAFE_SUMMARY_XML_TEMPLATE =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<failsafe-summary xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xsi:noNamespaceSchemaLocation=\"" + FAILSAFE_SUMMARY_XML_SCHEMA_LOCATION + "\""
+ " result=\"%s\" timeout=\"%s\">\n"
+ " <completed>%d</completed>\n"
+ " <errors>%d</errors>\n"
+ " <failures>%d</failures>\n"
+ " <skipped>%d</skipped>\n"
+ " %s\n"
+ "</failsafe-summary>";

private FailsafeSummaryXmlUtils()
{
throw new IllegalStateException( "No instantiable constructor." );
private static final String MESSAGE_ELEMENT = "<failureMessage>%s</failureMessage>";

private static final String FAILSAFE_SUMMARY_XML_TEMPLATE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<failsafe-summary xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xsi:noNamespaceSchemaLocation=\"" + FAILSAFE_SUMMARY_XML_SCHEMA_LOCATION + "\""
+ " result=\"%s\" timeout=\"%s\">\n"
+ " <completed>%d</completed>\n"
+ " <errors>%d</errors>\n"
+ " <failures>%d</failures>\n"
+ " <skipped>%d</skipped>\n"
+ " %s\n"
+ "</failsafe-summary>";

private FailsafeSummaryXmlUtils() {
throw new IllegalStateException("No instantiable constructor.");
}

public static RunResult toRunResult( File failsafeSummaryXml ) throws Exception
{
public static RunResult toRunResult(File failsafeSummaryXml) throws Exception {
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();

try ( Reader reader = new InputStreamReader( new FileInputStream( failsafeSummaryXml ), UTF_8 ) )
{
Node root = ( Node ) xpath.evaluate( "/", new InputSource( reader ), NODE );

String completed = xpath.evaluate( "/failsafe-summary/completed", root );
String errors = xpath.evaluate( "/failsafe-summary/errors", root );
String failures = xpath.evaluate( "/failsafe-summary/failures", root );
String skipped = xpath.evaluate( "/failsafe-summary/skipped", root );
String failureMessage = xpath.evaluate( "/failsafe-summary/failureMessage", root );
String timeout = xpath.evaluate( "/failsafe-summary/@timeout", root );

return new RunResult( parseInt( completed ), parseInt( errors ), parseInt( failures ), parseInt( skipped ),
isBlank( failureMessage ) ? null : unescapeXml( failureMessage ),
parseBoolean( timeout )
);
try (Reader reader = new InputStreamReader(new FileInputStream(failsafeSummaryXml), UTF_8)) {
Node root = (Node) xpath.evaluate("/", new InputSource(reader), NODE);

String completed = xpath.evaluate("/failsafe-summary/completed", root);
String errors = xpath.evaluate("/failsafe-summary/errors", root);
String failures = xpath.evaluate("/failsafe-summary/failures", root);
String skipped = xpath.evaluate("/failsafe-summary/skipped", root);
String failureMessage = xpath.evaluate("/failsafe-summary/failureMessage", root);
String timeout = xpath.evaluate("/failsafe-summary/@timeout", root);

return new RunResult(
parseInt(completed),
parseInt(errors),
parseInt(failures),
parseInt(skipped),
isBlank(failureMessage) ? null : unescapeXml(failureMessage),
parseBoolean(timeout));
}
}

public static void fromRunResultToFile( RunResult fromRunResult, File toFailsafeSummaryXml )
throws IOException
{
public static void fromRunResultToFile(RunResult fromRunResult, File toFailsafeSummaryXml) throws IOException {
String failure = fromRunResult.getFailure();
String msg = isBlank( failure ) ? MESSAGE_NIL_ELEMENT : format( MESSAGE_ELEMENT, escapeXml10( failure ) );
String xml = format( Locale.ROOT, FAILSAFE_SUMMARY_XML_TEMPLATE,
String msg = isBlank(failure) ? MESSAGE_NIL_ELEMENT : format(MESSAGE_ELEMENT, escapeXml10(failure));
String xml = format(
Locale.ROOT,
FAILSAFE_SUMMARY_XML_TEMPLATE,
fromRunResult.getFailsafeCode(),
String.valueOf( fromRunResult.isTimeout() ),
String.valueOf(fromRunResult.isTimeout()),
fromRunResult.getCompletedCount(),
fromRunResult.getErrors(),
fromRunResult.getFailures(),
fromRunResult.getSkipped(),
msg );
msg);

try ( FileOutputStream os = new FileOutputStream( toFailsafeSummaryXml ) )
{
IOUtils.write( xml, os, UTF_8 );
try (FileOutputStream os = new FileOutputStream(toFailsafeSummaryXml)) {
IOUtils.write(xml, os, UTF_8);
}
}

public static void writeSummary( RunResult mergedSummary, File mergedSummaryFile, boolean inProgress )
throws Exception
{
if ( !mergedSummaryFile.getParentFile().isDirectory() )
{
public static void writeSummary(RunResult mergedSummary, File mergedSummaryFile, boolean inProgress)
throws Exception {
if (!mergedSummaryFile.getParentFile().isDirectory()) {
//noinspection ResultOfMethodCallIgnored
mergedSummaryFile.getParentFile().mkdirs();
}

if ( mergedSummaryFile.exists() && inProgress )
{
RunResult runResult = toRunResult( mergedSummaryFile );
mergedSummary = mergedSummary.aggregate( runResult );
if (mergedSummaryFile.exists() && inProgress) {
RunResult runResult = toRunResult(mergedSummaryFile);
mergedSummary = mergedSummary.aggregate(runResult);
}

fromRunResultToFile( mergedSummary, mergedSummaryFile );
fromRunResultToFile(mergedSummary, mergedSummaryFile);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugin.failsafe;

/*
Expand All @@ -19,16 +37,16 @@
* under the License.
*/

import java.io.File;
import java.io.IOException;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
Expand All @@ -37,80 +55,67 @@
/**
* @since 2.20
*/
public class IntegrationTestMojoTest
{
public class IntegrationTestMojoTest {
private IntegrationTestMojo mojo;

@Before
public void init() throws InvalidVersionSpecificationException, IOException
{
Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
new File( "./target/tmp" ).mkdir();
public void init() throws InvalidVersionSpecificationException, IOException {
Artifact artifact = new DefaultArtifact("g", "a", createFromVersionSpec("1.0"), "compile", "jar", "", null);
artifact.setFile(new File("./target/tmp/a-1.0.jar"));
new File("./target/tmp").mkdir();
artifact.getFile().createNewFile();
mojo = new IntegrationTestMojo();
MavenProject project = mock( MavenProject.class );
when( project.getArtifact() ).thenReturn( artifact );
mojo.setProject( project );
MavenProject project = mock(MavenProject.class);
when(project.getArtifact()).thenReturn(artifact);
mojo.setProject(project);
}

@Test
public void shouldBeJar()
{
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
public void shouldBeJar() {
mojo.setDefaultClassesDirectory(new File("./target/classes"));
File binaries = mojo.getMainBuildPath();
assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
assertThat(binaries.getName()).isEqualTo("a-1.0.jar");
}

@Test
public void shouldBeAnotherJar()
{
mojo.setMainBuildPath( new File( "./target/another-1.0.jar" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
public void shouldBeAnotherJar() {
mojo.setMainBuildPath(new File("./target/another-1.0.jar"));
mojo.setDefaultClassesDirectory(new File("./target/classes"));
File binaries = mojo.getMainBuildPath();
assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
assertThat(binaries.getName()).isEqualTo("another-1.0.jar");
}

@Test
public void shouldBeClasses()
{
mojo.setMainBuildPath( new File( "./target/classes" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
public void shouldBeClasses() {
mojo.setMainBuildPath(new File("./target/classes"));
mojo.setDefaultClassesDirectory(new File("./target/classes"));
File binaries = mojo.getMainBuildPath();
assertThat( binaries.getName() ).isEqualTo( "classes" );
assertThat(binaries.getName()).isEqualTo("classes");
}

@Test
public void shouldGetNullEnv()
{
assertThat( mojo.getExcludedEnvironmentVariables() )
.hasSize( 0 );
public void shouldGetNullEnv() {
assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(0);
}

@Test
public void shouldGetEnv()
{
mojo.setExcludedEnvironmentVariables( new String[] { "ABC", "KLM" } );
assertThat( mojo.getExcludedEnvironmentVariables() )
.hasSize( 2 )
.contains( "ABC", "KLM" );
public void shouldGetEnv() {
mojo.setExcludedEnvironmentVariables(new String[] {"ABC", "KLM"});
assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(2).contains("ABC", "KLM");
}

@Test
public void testShouldGetPropertyFile()
{
mojo.setSystemPropertiesFile( new File( "testShouldGetPropertyFile" ) );
assertThat( mojo.getSystemPropertiesFile() )
.isEqualTo( new File( "testShouldGetPropertyFile" ) );
public void testShouldGetPropertyFile() {
mojo.setSystemPropertiesFile(new File("testShouldGetPropertyFile"));
assertThat(mojo.getSystemPropertiesFile()).isEqualTo(new File("testShouldGetPropertyFile"));
}

@Test
public void shouldHaveJUnit5EnginesFilter()
{
mojo.setIncludeJUnit5Engines( new String[] { "e1", "e2" } );
assertThat( mojo.getIncludeJUnit5Engines() ).isEqualTo( new String[] { "e1", "e2" } );
public void shouldHaveJUnit5EnginesFilter() {
mojo.setIncludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(mojo.getIncludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});

mojo.setExcludeJUnit5Engines( new String[] { "e1", "e2" } );
assertThat( mojo.getExcludeJUnit5Engines() ).isEqualTo( new String[] { "e1", "e2" } );
mojo.setExcludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(mojo.getExcludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugin.failsafe;

/*
Expand Down Expand Up @@ -31,17 +49,15 @@
* @author Tibor Digana (tibor17)
* @since 2.21.0
*/
@SuiteClasses( {
IntegrationTestMojoTest.class,
MarshallerUnmarshallerTest.class,
RunResultTest.class,
VerifyMojoTest.class
} )
@RunWith( Suite.class )
public class JUnit4SuiteTest
{
public static Test suite()
{
return new JUnit4TestAdapter( JUnit4SuiteTest.class );
@SuiteClasses({
IntegrationTestMojoTest.class,
MarshallerUnmarshallerTest.class,
RunResultTest.class,
VerifyMojoTest.class
})
@RunWith(Suite.class)
public class JUnit4SuiteTest {
public static Test suite() {
return new JUnit4TestAdapter(JUnit4SuiteTest.class);
}
}

0 comments on commit 877f578

Please sign in to comment.