Skip to content

Commit

Permalink
fixed tests in surefire-booter and ITs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor17 committed Jan 16, 2022
1 parent 9f28e74 commit aae9471
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion maven-failsafe-plugin/pom.xml
Expand Up @@ -266,12 +266,12 @@
<postBuildHookScript>verify</postBuildHookScript>
<settingsFile>src/it/settings.xml</settingsFile>
<skipInvocation>${skipTests}</skipInvocation>
<streamLogs>true</streamLogs>
<showErrors>true</showErrors>
<properties>
<integration-test-port>${failsafe-integration-test-port}</integration-test-port>
<integration-test-stop-port>${failsafe-integration-test-stop-port}</integration-test-stop-port>
</properties>
<debug>true</debug>
</configuration>
</execution>
</executions>
Expand Down
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Objects;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -61,20 +62,21 @@ final class SurefireDependencyResolver
{
static final String PROVIDER_GROUP_ID = "org.apache.maven.surefire";

private static final String[] PROVIDER_CLASSPATH_ORDER = {
"surefire-junit3",
"surefire-junit4",
"surefire-junit47",
"surefire-testng",
"surefire-junit-platform",
"surefire-api",
"surefire-logger-api",
"surefire-shared-utils",
"common-java5",
"common-junit3",
"common-junit4",
"common-junit48",
"common-testng-utils"
private static final String[][] PROVIDER_CLASSPATH_ORDER = {
// groupId, artifactId [, classifier]
{"org.apache.maven.surefire", "surefire-junit3"},
{"org.apache.maven.surefire", "surefire-junit4"},
{"org.apache.maven.surefire", "surefire-junit47"},
{"org.apache.maven.surefire", "surefire-testng"},
{"org.apache.maven.surefire", "surefire-junit-platform"},
{"org.apache.maven.surefire", "surefire-api"},
{"org.apache.maven.surefire", "surefire-logger-api"},
{"org.apache.maven.surefire", "surefire-shared-utils", "shaded"},
{"org.apache.maven.surefire", "common-java5"},
{"org.apache.maven.surefire", "common-junit3"},
{"org.apache.maven.surefire", "common-junit4"},
{"org.apache.maven.surefire", "common-junit48"},
{"org.apache.maven.surefire", "common-testng-utils"}
};

private final RepositorySystem repositorySystem;
Expand Down Expand Up @@ -221,13 +223,18 @@ Map<String, Artifact> getProviderClasspathAsMap( String providerArtifactId, Stri
private static Set<Artifact> orderProviderArtifacts( Set<Artifact> providerArtifacts )
{
Set<Artifact> orderedProviderArtifacts = new LinkedHashSet<>();
for ( String order : PROVIDER_CLASSPATH_ORDER )
for ( String[] coordinates : PROVIDER_CLASSPATH_ORDER )
{
Iterator<Artifact> providerArtifactsIt = providerArtifacts.iterator();
while ( providerArtifactsIt.hasNext() )
{
String groupId = coordinates[0];
String artifactId = coordinates[1];
String classifier = coordinates.length == 3 ? coordinates[2] : null;
Artifact providerArtifact = providerArtifactsIt.next();
if ( providerArtifact.getArtifactId().equals( order ) )
if ( providerArtifact.getGroupId().equals( groupId )
&& providerArtifact.getArtifactId().equals( artifactId )
&& Objects.equals( providerArtifact.getClassifier(), classifier ) )
{
orderedProviderArtifacts.add( providerArtifact );
providerArtifactsIt.remove();
Expand Down
Expand Up @@ -196,8 +196,8 @@ public void shouldHaveStartupConfigForModularClasspath()
booter.setFile( mockFile( "surefire-booter.jar" ) );

Artifact utils = new DefaultArtifact( "org.apache.maven.surefire", "surefire-shared-utils",
createFromVersion( "1" ), "runtime", "jar", "", handler );
utils.setFile( mockFile( "surefire-shared-utils.jar" ) );
createFromVersion( "1" ), "runtime", "jar", "shaded", handler );
utils.setFile( mockFile( "surefire-shared-utils-1-shaded.jar" ) );

Map<String, Artifact> artifacts = new HashMap<>();
artifacts.put( "org.apache.maven.surefire:maven-surefire-common", common );
Expand Down Expand Up @@ -244,8 +244,8 @@ public void shouldHaveStartupConfigForModularClasspath()
"test(compact) classpath: non-modular.jar junit.jar hamcrest.jar",
"test(compact) modulepath: modular.jar classes",
"provider(compact) classpath: surefire-provider.jar",
"in-process classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar",
"in-process(compact) classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar"
"in-process classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils-1-shaded.jar",
"in-process(compact) classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils-1-shaded.jar"
);

assertThat( conf ).isNotNull();
Expand Down Expand Up @@ -356,8 +356,8 @@ public void shouldHaveStartupConfigForModularClasspathAndTestDescriptor()
booter.setFile( mockFile( "surefire-booter.jar" ) );

Artifact utils = new DefaultArtifact( "org.apache.maven.surefire", "surefire-shared-utils",
createFromVersion( "1" ), "runtime", "jar", "", handler );
utils.setFile( mockFile( "surefire-shared-utils.jar" ) );
createFromVersion( "1" ), "runtime", "jar", "shaded", handler );
utils.setFile( mockFile( "surefire-shared-utils-1-shaded.jar" ) );

Map<String, Artifact> artifacts = new HashMap<>();
artifacts.put( "org.apache.maven.surefire:maven-surefire-common", common );
Expand Down Expand Up @@ -390,8 +390,8 @@ public void shouldHaveStartupConfigForModularClasspathAndTestDescriptor()
"test(compact) classpath:",
"test(compact) modulepath: test-classes classes modular.jar non-modular.jar junit.jar hamcrest.jar",
"provider(compact) classpath: surefire-provider.jar",
"in-process classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar",
"in-process(compact) classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar"
"in-process classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils-1-shaded.jar",
"in-process(compact) classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils-1-shaded.jar"
);

assertThat( conf ).isNotNull();
Expand Down
Expand Up @@ -478,8 +478,8 @@ public void shouldHaveStartupConfigForNonModularClasspath()
booter.setFile( mockFile( "surefire-booter.jar" ) );

Artifact utils = new DefaultArtifact( "org.apache.maven.surefire", "surefire-shared-utils",
createFromVersion( "1" ), "runtime", "jar", "", handler );
utils.setFile( mockFile( "surefire-shared-utils.jar" ) );
createFromVersion( "1" ), "runtime", "jar", "shaded", handler );
utils.setFile( mockFile( "surefire-shared-utils-1-shaded.jar" ) );

Map<String, Artifact> providerArtifactsMap = new HashMap<>();
providerArtifactsMap.put( "org.apache.maven.surefire:maven-surefire-common", common );
Expand Down Expand Up @@ -541,8 +541,8 @@ public void shouldHaveStartupConfigForNonModularClasspath()
"provider classpath: surefire-provider.jar",
"test(compact) classpath: test-classes classes junit.jar hamcrest.jar",
"provider(compact) classpath: surefire-provider.jar",
"in-process classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar",
"in-process(compact) classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar"
"in-process classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils-1-shaded.jar",
"in-process(compact) classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils-1-shaded.jar"
);

assertThat( conf.getClassLoaderConfiguration() )
Expand Down Expand Up @@ -632,8 +632,8 @@ private StartupConfiguration startupConfigurationForProvider( ProviderInfo provi
booter.setFile( mockFile( "surefire-booter.jar" ) );

Artifact utils = new DefaultArtifact( "org.apache.maven.surefire", "surefire-shared-utils",
createFromVersion( "1" ), "runtime", "jar", "", handler );
utils.setFile( mockFile( "surefire-shared-utils.jar" ) );
createFromVersion( "1" ), "runtime", "jar", "shaded", handler );
utils.setFile( mockFile( "surefire-shared-utils-1-shaded.jar" ) );

Map<String, Artifact> providerArtifactsMap = new HashMap<>();
providerArtifactsMap.put( "org.apache.maven.surefire:maven-surefire-common", common );
Expand Down
3 changes: 2 additions & 1 deletion surefire-booter/pom.xml
Expand Up @@ -115,11 +115,12 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.0.0-M4</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
<version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
<configuration>
Expand Down
Expand Up @@ -56,6 +56,8 @@
public class NewClassLoaderRunner
extends BlockJUnit4ClassRunner
{
private static final String PROJECT_DIR = System.getProperty( "java.dir" );

private Class<?> cls;

public NewClassLoaderRunner( Class<?> clazz )
Expand Down Expand Up @@ -235,16 +237,14 @@ private static Collection<URL> toPathList()
Collection<URL> classPath = new HashSet<>();
try
{
String[] files = FileUtils.fileRead( new File( "target/test-classpath/cp.txt" ), "UTF-8" )
.split( pathSeparator );
File classPathFile = new File( PROJECT_DIR, "target/test-classpath/cp.txt" );
String[] files = FileUtils.fileRead( classPathFile, "UTF-8" ).split( pathSeparator );
for ( String file : files )
{
File f = new File( file );
File dir = f.getParentFile();
classPath.add( ( dir.getName().equals( "target" ) ? new File( dir, "classes" ) : f ).toURL() );
classPath.add( new File( file ).toURL() );
}
classPath.add( new File( "target/classes" ).toURL() );
classPath.add( new File( "target/test-classes" ).toURL() );
classPath.add( new File( PROJECT_DIR, "target/classes" ).toURL() );
classPath.add( new File( PROJECT_DIR, "target/test-classes" ).toURL() );
}
catch ( IOException e )
{
Expand Down

0 comments on commit aae9471

Please sign in to comment.