You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2017/10/05 09:10:45 UTC
[1/2] maven-surefire git commit: [SUREFIRE-1262] Add modulepath
support [Forced Update!]
Repository: maven-surefire
Updated Branches:
refs/heads/SUREFIRE-1262_2 2487cb7b8 -> 135a1cfcb (forced update)
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java
new file mode 100644
index 0000000..2b47c03
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java
@@ -0,0 +1,230 @@
+package org.apache.maven.plugin.surefire.booterclient;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
+import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.surefire.booter.AbstractPathConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.ModularClasspath;
+import org.apache.maven.surefire.booter.ModularClasspathConfiguration;
+import org.apache.maven.surefire.booter.StartupConfiguration;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.ModuleVisitor;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import static java.io.File.createTempFile;
+import static java.io.File.pathSeparatorChar;
+import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPath;
+import static org.objectweb.asm.Opcodes.ASM6;
+
+/**
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+public class ModularClasspathForkConfiguration
+ extends DefaultForkConfiguration
+{
+ @SuppressWarnings( "checkstyle:parameternumber" )
+ public ModularClasspathForkConfiguration( @Nonnull Classpath bootClasspath,
+ @Nonnull File tempDirectory,
+ @Nullable String debugLine,
+ @Nonnull File workingDirectory,
+ @Nonnull Properties modelProperties,
+ @Nullable String argLine,
+ @Nonnull Map<String, String> environmentVariables,
+ boolean debug,
+ int forkCount,
+ boolean reuseForks,
+ @Nonnull Platform pluginPlatform,
+ @Nonnull ConsoleLogger log )
+ {
+ super( bootClasspath, tempDirectory, debugLine, workingDirectory, modelProperties, argLine,
+ environmentVariables, debug, forkCount, reuseForks, pluginPlatform, log );
+ }
+
+ @Override
+ protected void resolveClasspath( OutputStreamFlushableCommandline cli, String startClass,
+ StartupConfiguration config )
+ throws SurefireBooterForkException
+ {
+ try
+ {
+ AbstractPathConfiguration pathConfig = config.getClasspathConfiguration();
+
+ ModularClasspathConfiguration modularClasspathConfiguration =
+ pathConfig.toRealPath( ModularClasspathConfiguration.class );
+
+ ModularClasspath modularClasspath = modularClasspathConfiguration.getModularClasspath();
+
+ File descriptor = modularClasspath.getModuleDescriptor();
+ List<String> modulePath = modularClasspath.getModulePath();
+ Collection<String> packages = modularClasspath.getPackages();
+ File patchFile = modularClasspath.getPatchFile();
+ List<String> classpath = toCompleteClasspath( config );
+
+ File argsFile = createArgsFile( descriptor, modulePath, classpath, packages, patchFile, startClass );
+
+ //todo what if path have spaces
+ cli.createArg().setValue( "@" + escapeToPlatformPath( argsFile.getAbsolutePath() ) );
+ }
+ catch ( IOException e )
+ {
+ throw new SurefireBooterForkException( "Error creating args file", e );
+ }
+ }
+
+ File createArgsFile( File moduleDescriptor, List<String> modulePath, List<String> classPath,
+ Collection<String> packages, File patchFile, String startClassName )
+ throws IOException
+ {
+ File surefireArgs = createTempFile( "surefireargs", "", getTempDirectory() );
+ if ( !isDebug() )
+ {
+ surefireArgs.deleteOnExit();
+ }
+
+ BufferedWriter writer = null;
+ try
+ {
+ writer = new BufferedWriter( new FileWriter( surefireArgs ) );
+
+ if ( modulePath != null && !modulePath.isEmpty() )
+ {
+ writer.write( "--module-path" );
+ writer.newLine();
+
+ for ( Iterator<String> it = modulePath.iterator(); it.hasNext(); )
+ {
+ writer.append( it.next() );
+ if ( it.hasNext() )
+ {
+ writer.append( pathSeparatorChar );
+ }
+ }
+
+ writer.newLine();
+ }
+
+ if ( classPath != null && !classPath.isEmpty() )
+ {
+ writer.write( "--class-path" );
+ writer.newLine();
+ for ( Iterator<String> it = classPath.iterator(); it.hasNext(); )
+ {
+ writer.append( it.next() );
+ if ( it.hasNext() )
+ {
+ writer.append( pathSeparatorChar );
+ }
+ }
+
+ writer.newLine();
+ }
+
+ //todo may return null
+ final String moduleName = toModuleName( moduleDescriptor );
+
+ writer.write( "--patch-module" );
+ writer.newLine();
+ writer.append( moduleName )
+ .append( '=' )
+ .append( patchFile.getPath() );
+
+ writer.newLine();
+
+ for ( String pkg : packages )
+ {
+ writer.write( "--add-exports" );
+ writer.newLine();
+ writer.append( moduleName )
+ .append( '/' )
+ .append( pkg )
+ .append( '=' )
+ .append( "ALL-UNNAMED" );
+
+ writer.newLine();
+ }
+
+ writer.write( "--add-modules" );
+ writer.newLine();
+ writer.append( moduleName );
+
+ writer.newLine();
+
+ writer.write( "--add-reads" );
+ writer.newLine();
+ writer.append( moduleName )
+ .append( '=' )
+ .append( "ALL-UNNAMED" );
+
+ writer.newLine();
+
+ writer.write( startClassName );
+
+ writer.newLine();
+ }
+ finally
+ {
+ if ( writer != null )
+ {
+ writer.close();
+ }
+ }
+
+ return surefireArgs;
+ }
+
+ private static String toModuleName( File moduleDescriptor ) throws IOException
+ {
+ if ( moduleDescriptor == null || !moduleDescriptor.isFile() )
+ {
+ return null;
+ }
+
+ final StringBuilder sb = new StringBuilder();
+ new ClassReader( new FileInputStream( moduleDescriptor ) ).accept( new ClassVisitor( ASM6 )
+ {
+ @Override
+ public ModuleVisitor visitModule( String name, int access, String version )
+ {
+ sb.setLength( 0 );
+ sb.append( name );
+ return super.visitModule( name, access, version );
+ }
+ }, 0 );
+
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/Platform.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/Platform.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/Platform.java
index 10b16dc..4762453 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/Platform.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/Platform.java
@@ -19,6 +19,7 @@ package org.apache.maven.plugin.surefire.booterclient;
* under the License.
*/
+import org.apache.maven.plugin.surefire.JdkAttributes;
import org.apache.maven.surefire.booter.SystemUtils;
import java.util.concurrent.Callable;
@@ -35,20 +36,28 @@ import static org.apache.maven.surefire.util.internal.DaemonThreadFactory.newDae
*/
public final class Platform
{
- private final RunnableFuture<Long> pidJob;
+ private final RunnableFuture<Long> pluginPidJob;
+
+ private volatile JdkAttributes jdk;
public Platform()
{
// the job may take 50 or 80 ms
- pidJob = new FutureTask<Long>( pidJob() );
- newDaemonThread( pidJob ).start();
+ this( new FutureTask<Long>( pidJob() ), null );
+ newDaemonThread( pluginPidJob ).start();
}
- public Long getPid()
+ private Platform( RunnableFuture<Long> pluginPidJob, JdkAttributes jdk )
+ {
+ this.pluginPidJob = pluginPidJob;
+ this.jdk = jdk;
+ }
+
+ public Long getPluginPid()
{
try
{
- return pidJob.get();
+ return pluginPidJob.get();
}
catch ( Exception e )
{
@@ -56,6 +65,16 @@ public final class Platform
}
}
+ public JdkAttributes getJdkExecAttributesForTests()
+ {
+ return jdk;
+ }
+
+ public Platform withJdkExecAttributesForTests( JdkAttributes jdk )
+ {
+ return new Platform( pluginPidJob, jdk );
+ }
+
private static Callable<Long> pidJob()
{
return new Callable<Long>()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/Relocator.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/Relocator.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/Relocator.java
index 2237698..9d7706b 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/Relocator.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/Relocator.java
@@ -21,47 +21,38 @@ package org.apache.maven.plugin.surefire.util;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
/**
* Relocates class names when running with relocated provider
*
* @author Kristian Rosenvold
*/
-public class Relocator
+public final class Relocator
{
private static final String RELOCATION_BASE = "org.apache.maven.surefire.";
+ private static final String PACKAGE_DELIMITER = "shadefire";
- @Nullable
- private final String relocation;
-
- public Relocator( @Nullable String relocation )
- {
- this.relocation = relocation;
- }
-
- public Relocator()
+ private Relocator()
{
- relocation = "shadefire";
+ throw new IllegalStateException( "no instantiable constructor" );
}
- @Nullable private String getRelocation()
+ @Nonnull
+ public static String relocate( @Nonnull String className )
{
- return relocation;
- }
-
- @Nonnull public String relocate( @Nonnull String className )
- {
- if ( relocation == null )
+ if ( className.contains( PACKAGE_DELIMITER ) )
{
return className;
}
- if ( className.contains( relocation ) )
+ else
{
- return className;
+ if ( !className.startsWith( RELOCATION_BASE ) )
+ {
+ throw new IllegalArgumentException( "'" + className + "' should start with '" + RELOCATION_BASE + "'" );
+ }
+ String rest = className.substring( RELOCATION_BASE.length() );
+ final String s = RELOCATION_BASE + PACKAGE_DELIMITER + ".";
+ return s + rest;
}
- String rest = className.substring( RELOCATION_BASE.length() );
- final String s = RELOCATION_BASE + getRelocation() + ".";
- return s + rest;
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java
index 8753ff1..00b8b74 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java
@@ -43,7 +43,7 @@ import static org.apache.maven.surefire.util.ReflectionUtils.getConstructor;
*
* @since 2.20
*/
-public class ServiceLoader
+public final class ServiceLoader
{
@Nonnull
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
index 035add0..fc00bcd 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
@@ -60,12 +60,14 @@ public class BooterDeserializerStartupConfigurationTest
public void testClassPathConfiguration()
throws IOException
{
- ClasspathConfiguration reloadedClasspathConfiguration =
+ AbstractPathConfiguration reloadedClasspathConfiguration =
getReloadedStartupConfiguration().getClasspathConfiguration();
- assertEquals( classpathConfiguration, reloadedClasspathConfiguration );
+
+ assertTrue( reloadedClasspathConfiguration instanceof ClasspathConfiguration );
+ assertCpConfigEquals( classpathConfiguration, (ClasspathConfiguration) reloadedClasspathConfiguration );
}
- private void assertEquals( ClasspathConfiguration expectedConfiguration,
+ private void assertCpConfigEquals( ClasspathConfiguration expectedConfiguration,
ClasspathConfiguration actualConfiguration )
{
assertEquals( expectedConfiguration.getTestClasspath().getClassPath(),
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
index b49e164..bb9add3 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
@@ -23,23 +23,30 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.plugin.surefire.JdkAttributes;
+import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.cli.Commandline;
import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.ClasspathConfiguration;
+import org.apache.maven.surefire.booter.StartupConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
-import java.util.Collections;
+import java.util.List;
import java.util.Properties;
+import static java.util.Collections.singletonList;
+import static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class ForkConfigurationTest
{
+ private static final StartupConfiguration STARTUP_CONFIG = new StartupConfiguration( "", null, null, false, false );
+
@Test
public void testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
throws IOException, SurefireBooterForkException
@@ -47,8 +54,11 @@ public class ForkConfigurationTest
ForkConfiguration config = getForkConfiguration( (String) null );
File cpElement = getTempClasspathFile();
- Commandline cli =
- config.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), true, false, null, 1 );
+ List<String> cp = singletonList( cpElement.getAbsolutePath() );
+ ClasspathConfiguration cpConfig = new ClasspathConfiguration( new Classpath( cp ), null, null, true, true );
+ StartupConfiguration startup = new StartupConfiguration( "", cpConfig, null, false, false );
+
+ Commandline cli = config.createCommandLine( startup, 1 );
String line = StringUtils.join( cli.getCommandline(), " " );
assertTrue( line.contains( "-jar" ) );
@@ -59,12 +69,14 @@ public class ForkConfigurationTest
throws IOException, SurefireBooterForkException
{
// SUREFIRE-657
+ ForkConfiguration config = getForkConfiguration( "abc\ndef" );
File cpElement = getTempClasspathFile();
- ForkConfiguration forkConfiguration = getForkConfiguration( "abc\ndef" );
- final Commandline commandLine =
- forkConfiguration.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), false, false,
- null, 1 );
+ List<String> cp = singletonList( cpElement.getAbsolutePath() );
+ ClasspathConfiguration cpConfig = new ClasspathConfiguration( new Classpath( cp ), null, null, true, true );
+ StartupConfiguration startup = new StartupConfiguration( "", cpConfig, null, false, false );
+
+ Commandline commandLine = config.createCommandLine( startup, 1 );
assertTrue( commandLine.toString().contains( "abc def" ) );
}
@@ -80,13 +92,16 @@ public class ForkConfigurationTest
File cwd = new File( baseDir, "fork_${surefire.forkNumber}" );
+ ClasspathConfiguration cpConfig = new ClasspathConfiguration( emptyClasspath(), null, null, true, true );
+ StartupConfiguration startup = new StartupConfiguration( "", cpConfig, null, false, false );
ForkConfiguration config = getForkConfiguration( null, cwd.getCanonicalFile() );
- Commandline commandLine = config.createCommandLine( Collections.<String>emptyList(), true, false, null, 1 );
+ Commandline commandLine = config.createCommandLine( startup, 1 );
File forkDirectory = new File( baseDir, "fork_1" );
forkDirectory.deleteOnExit();
- assertTrue( forkDirectory.getCanonicalPath().equals(
- commandLine.getShell().getWorkingDirectory().getCanonicalPath() ) );
+
+ String shellWorkDir = commandLine.getShell().getWorkingDirectory().getCanonicalPath();
+ assertEquals( shellWorkDir, forkDirectory.getCanonicalPath() );
}
@Test
@@ -107,7 +122,7 @@ public class ForkConfigurationTest
try
{
- config.createCommandLine( Collections.<String>emptyList(), true, false, null, 1 );
+ config.createCommandLine( STARTUP_CONFIG, 1 );
}
catch ( SurefireBooterForkException sbfe )
{
@@ -137,7 +152,7 @@ public class ForkConfigurationTest
try
{
- config.createCommandLine( Collections.<String>emptyList(), true, false, null, 1 );
+ config.createCommandLine( STARTUP_CONFIG, 1 );
}
catch ( SurefireBooterForkException sbfe )
{
@@ -182,8 +197,14 @@ public class ForkConfigurationTest
private static ForkConfiguration getForkConfiguration( String argLine, String jvm, File cwd )
throws IOException
{
- return new ForkConfiguration( Classpath.emptyClasspath(), null, null, new JdkAttributes( jvm, false ),
- cwd, new Properties(), argLine, null, false, 1, false, new Platform() );
+ Platform platform = new Platform().withJdkExecAttributesForTests( new JdkAttributes( jvm, false ) );
+ return new JarManifestForkConfiguration( emptyClasspath(), null, null,
+ cwd, new Properties(), argLine, null, false, 1, false, platform, new NullConsoleLogger() );
+
+ /*
+ return new ClasspathForkConfiguration( emptyClasspath(), null, null,
+ cwd, new Properties(), argLine, null, false, 1, false, platform, new NullConsoleLogger() );
+ */
}
// based on http://stackoverflow.com/questions/2591083/getting-version-of-java-in-runtime
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
index 3cec846..4d5951a 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
@@ -32,15 +32,13 @@ public class RelocatorTest
public void testFoo()
{
- Relocator relocator = new Relocator( "shadefire" );
String cn = "org.apache.maven.surefire.report.ForkingConsoleReporter";
- assertEquals( "org.apache.maven.surefire.shadefire.report.ForkingConsoleReporter", relocator.relocate( cn ) );
+ assertEquals( "org.apache.maven.surefire.shadefire.report.ForkingConsoleReporter", Relocator.relocate( cn ) );
}
public void testRelocation()
{
- Relocator relocator = new Relocator( "shadefire" );
String org1 = "org.apache.maven.surefire.fooz.Baz";
- assertEquals( "org.apache.maven.surefire.shadefire.fooz.Baz", relocator.relocate( org1 ) );
+ assertEquals( "org.apache.maven.surefire.shadefire.fooz.Baz", Relocator.relocate( org1 ) );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
index 5fa6df0..4cbbf00 100644
--- a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
+++ b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
@@ -20,7 +20,6 @@ package org.apache.maven.plugin.surefire;
import java.lang.reflect.Field;
-import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
import org.apache.maven.toolchain.Toolchain;
import junit.framework.TestCase;
@@ -35,7 +34,7 @@ public class SurefirePluginTest
SurefirePlugin surefirePlugin = new SurefirePlugin();
setFieldValue( surefirePlugin, "toolchain", new MyToolChain() );
setFieldValue( surefirePlugin, "forkMode", "never" );
- assertEquals( ForkConfiguration.FORK_ONCE, surefirePlugin.getEffectiveForkMode() );
+ assertEquals( "once", surefirePlugin.getEffectiveForkMode() );
}
public void testForkCountComputation()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4f0bf58..79c459c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,7 +88,7 @@
<properties>
<mavenVersion>2.2.1</mavenVersion>
<!-- <shadedVersion>2.12.4</shadedVersion> commented out due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
- <mavenPluginPluginVersion>3.3</mavenPluginPluginVersion>
+ <mavenPluginPluginVersion>3.5</mavenPluginPluginVersion>
<commonsLang3Version>3.5</commonsLang3Version>
<commonsIoVersion>2.5</commonsIoVersion>
<mavenSharedUtilsVersion>0.9</mavenSharedUtilsVersion>
@@ -233,10 +233,31 @@
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-common-artifact-filters</artifactId>
+ <version>1.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.fusesource.jansi</groupId>
+ <artifactId>jansi</artifactId>
+ <version>1.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
<version>1.6</version>
</dependency>
<dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-java</artifactId>
+ <version>0.9.3</version>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
@@ -379,15 +400,23 @@
<goals>
<goal>check</goal>
</goals>
+ <configuration>
+ <signature>
+ <groupId>org.codehaus.mojo.signature</groupId>
+ <artifactId>java16</artifactId>
+ <version>1.1</version>
+ </signature>
+ <excludeDependencies>
+ <param>org.codehaus.plexus:plexus-java</param>
+ <param>org.ow2.asm:asm</param>
+ </excludeDependencies>
+ <ignores>
+ <param>org.objectweb.asm.*</param>
+ <param>org.codehaus.plexus.languages.java.jpms.*</param>
+ </ignores>
+ </configuration>
</execution>
</executions>
- <configuration>
- <signature>
- <groupId>org.codehaus.mojo.signature</groupId>
- <artifactId>java16</artifactId>
- <version>1.1</version>
- </signature>
- </configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
@@ -408,7 +437,7 @@
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
- <version>3.0.0</version>
+ <version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
@@ -475,6 +504,24 @@
</rules>
</configuration>
</execution>
+ <execution>
+ <id>enforce-bytecode-version</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <enforceBytecodeVersion>
+ <maxJdkVersion>${maven.compiler.target}</maxJdkVersion>
+ <excludes>
+ <exclude>org.codehaus.plexus:plexus-java</exclude>
+ <exclude>org.ow2.asm:asm</exclude>
+ </excludes>
+ </enforceBytecodeVersion>
+ </rules>
+ <fail>true</fail>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/AbstractPathConfiguration.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/AbstractPathConfiguration.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/AbstractPathConfiguration.java
new file mode 100644
index 0000000..5f0b67e
--- /dev/null
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/AbstractPathConfiguration.java
@@ -0,0 +1,115 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * 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.
+ */
+
+import static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
+import static org.apache.maven.surefire.booter.Classpath.join;
+
+/**
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+public abstract class AbstractPathConfiguration
+{
+ public static final String CHILD_DELEGATION = "childDelegation";
+
+ public static final String ENABLE_ASSERTIONS = "enableAssertions";
+
+ public static final String CLASSPATH = "classPathUrl.";
+
+ public static final String SUREFIRE_CLASSPATH = "surefireClassPathUrl.";
+
+ private final Classpath surefireClasspathUrls;
+
+ /**
+ * Whether to enable assertions or not
+ * (can be affected by the fork arguments, and the ability to do so based on the JVM).
+ */
+ private final boolean enableAssertions;
+
+ // todo: @deprecated because the IsolatedClassLoader is really isolated - no parent.
+ private final boolean childDelegation;
+
+ protected AbstractPathConfiguration( Classpath surefireClasspathUrls,
+ boolean enableAssertions, boolean childDelegation )
+ {
+ if ( !( isClassPathConfig() ^ isModularPathConfig() ) )
+ {
+ throw new IllegalStateException( "modular path and class path should be exclusive" );
+ }
+ this.surefireClasspathUrls = surefireClasspathUrls;
+ this.enableAssertions = enableAssertions;
+ this.childDelegation = childDelegation;
+ }
+
+ public abstract Classpath getTestClasspath();
+
+ /**
+ * Must be exclusive with {@link #isClassPathConfig()}.
+ *
+ * @return {@code true} if <tt>this</tt> is {@link ModularClasspathConfiguration}.
+ */
+ public abstract boolean isModularPathConfig();
+
+ /**
+ * Must be exclusive with {@link #isModularPathConfig()}.
+ *
+ * @return {@code true} if <tt>this</tt> is {@link ClasspathConfiguration}.
+ */
+ public abstract boolean isClassPathConfig();
+
+ protected Classpath getInprocClasspath()
+ {
+ return emptyClasspath();
+ }
+
+ public <T extends AbstractPathConfiguration> T toRealPath( Class<T> type )
+ {
+ if ( isClassPathConfig() && type == ClasspathConfiguration.class
+ || isModularPathConfig() && type == ModularClasspathConfiguration.class )
+ {
+ return type.cast( this );
+ }
+ throw new IllegalStateException( "no target matched " + type );
+ }
+
+ public ClassLoader createMergedClassLoader()
+ throws SurefireExecutionException
+ {
+ return join( getInprocClasspath(), getTestClasspath() )
+ .createClassLoader( isChildDelegation(), isEnableAssertions(), "test" );
+ }
+
+ public Classpath getProviderClasspath()
+ {
+ return surefireClasspathUrls;
+ }
+
+ public boolean isEnableAssertions()
+ {
+ return enableAssertions;
+ }
+
+ @Deprecated
+ public boolean isChildDelegation()
+ {
+ return childDelegation;
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
index 7b22712..bcbed4f 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
@@ -191,34 +191,25 @@ public class Classpath implements Iterable<String>
public String getLogMessage( String descriptor )
{
- StringBuilder result = new StringBuilder();
- result.append( descriptor ).append( " classpath:" );
+ StringBuilder result = new StringBuilder( descriptor );
for ( String element : unmodifiableElements )
{
- result.append( " " ).append( element );
+ result.append( " " )
+ .append( element );
}
return result.toString();
}
public String getCompactLogMessage( String descriptor )
{
- StringBuilder result = new StringBuilder();
- result.append( descriptor ).append( " classpath:" );
+ StringBuilder result = new StringBuilder( descriptor );
for ( String element : unmodifiableElements )
{
result.append( " " );
if ( element != null )
{
int pos = element.lastIndexOf( File.separatorChar );
- if ( pos >= 0 )
- {
- result.append( element.substring( pos + 1 ) );
- }
- else
- {
- result.append( element );
- }
-
+ result.append( pos == -1 ? element : element.substring( pos + 1 ) );
}
else
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
index 0e84315..a288f2a 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.booter;
* under the License.
*/
+import static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
+
/**
* Represents the classpaths for the BooterConfiguration.
* <br>
@@ -27,88 +29,61 @@ package org.apache.maven.surefire.booter;
* @author Emmanuel Venisse
* @author Kristian Rosenvold
*/
-public class ClasspathConfiguration
+public class ClasspathConfiguration extends AbstractPathConfiguration
{
- public static final String CHILD_DELEGATION = "childDelegation";
-
- public static final String ENABLE_ASSERTIONS = "enableAssertions";
-
- public static final String CLASSPATH = "classPathUrl.";
-
- public static final String SUREFIRE_CLASSPATH = "surefireClassPathUrl.";
-
- private final Classpath classpathUrls;
-
- private final Classpath surefireClasspathUrls;
+ private final Classpath testClasspathUrls;
/**
* The surefire classpath to use when invoking in-process with the plugin
*/
private final Classpath inprocClasspath;
- /**
- * Whether to enable assertions or not (can be affected by the fork arguments, and the ability to do so based on the
- * JVM).
- */
- private final boolean enableAssertions;
-
- // todo: @deprecated because the IsolatedClassLoader is really isolated - no parent.
- private final boolean childDelegation;
-
public ClasspathConfiguration( boolean enableAssertions, boolean childDelegation )
{
- this( Classpath.emptyClasspath(), Classpath.emptyClasspath(), Classpath.emptyClasspath(), enableAssertions,
- childDelegation );
+ this( emptyClasspath(), emptyClasspath(), emptyClasspath(), enableAssertions, childDelegation );
}
ClasspathConfiguration( PropertiesWrapper properties )
{
- this( properties.getClasspath( CLASSPATH ), properties.getClasspath( SUREFIRE_CLASSPATH ),
- Classpath.emptyClasspath(),
+ this( properties.getClasspath( CLASSPATH ), properties.getClasspath( SUREFIRE_CLASSPATH ), emptyClasspath(),
properties.getBooleanProperty( ENABLE_ASSERTIONS ), properties.getBooleanProperty( CHILD_DELEGATION ) );
}
- public ClasspathConfiguration( Classpath testClasspath, Classpath surefireClassPathUrls, Classpath inprocClasspath,
- boolean enableAssertions, boolean childDelegation )
+ public ClasspathConfiguration( Classpath testClasspathUrls, Classpath surefireClassPathUrls,
+ Classpath inprocClasspath, boolean enableAssertions, boolean childDelegation )
{
- this.enableAssertions = enableAssertions;
- this.childDelegation = childDelegation;
+ super( surefireClassPathUrls, enableAssertions, childDelegation );
+ this.testClasspathUrls = testClasspathUrls;
this.inprocClasspath = inprocClasspath;
- this.classpathUrls = testClasspath;
- this.surefireClasspathUrls = surefireClassPathUrls;
- }
-
- public ClassLoader createMergedClassLoader()
- throws SurefireExecutionException
- {
- return Classpath.join( inprocClasspath, classpathUrls )
- .createClassLoader( childDelegation, enableAssertions, "test" );
}
- public Classpath getProviderClasspath()
+ @Override
+ protected Classpath getInprocClasspath()
{
- return surefireClasspathUrls;
+ return inprocClasspath;
}
public Classpath getTestClasspath()
{
- return classpathUrls;
+ return testClasspathUrls;
}
- public void trickClassPathWhenManifestOnlyClasspath()
- throws SurefireExecutionException
+ @Override
+ public final boolean isModularPathConfig()
{
- System.setProperty( "surefire.real.class.path", System.getProperty( "java.class.path" ) );
- getTestClasspath().writeToSystemProperty( "java.class.path" );
+ return !isClassPathConfig();
}
- public boolean isEnableAssertions()
+ @Override
+ public final boolean isClassPathConfig()
{
- return enableAssertions;
+ return true;
}
- public boolean isChildDelegation()
+ public void trickClassPathWhenManifestOnlyClasspath()
+ throws SurefireExecutionException
{
- return childDelegation;
+ System.setProperty( "surefire.real.class.path", System.getProperty( "java.class.path" ) );
+ getTestClasspath().writeToSystemProperty( "java.class.path" );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
index d00abc5..81872a8 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
@@ -88,7 +88,7 @@ public final class ForkedBooter
{
BooterDeserializer booterDeserializer =
new BooterDeserializer( createSurefirePropertiesIfFileExists( tmpDir, surefirePropsFileName ) );
- // todo: print PID in debug console logger in version 2.20.2
+ // todo: print PID in debug console logger in version 2.21.2
pingScheduler = isDebugging() ? null : listenToShutdownCommands( booterDeserializer.getPluginPid() );
setSystemProperties( new File( tmpDir, effectiveSystemPropertiesFileName ) );
@@ -96,20 +96,24 @@ public final class ForkedBooter
DumpErrorSingleton.getSingleton().init( dumpFileName, providerConfiguration.getReporterConfiguration() );
startupConfiguration = booterDeserializer.getProviderConfiguration();
- systemExitTimeoutInSeconds =
- providerConfiguration.systemExitTimeout( DEFAULT_SYSTEM_EXIT_TIMEOUT_IN_SECONDS );
+ systemExitTimeoutInSeconds = providerConfiguration.systemExitTimeout( DEFAULT_SYSTEM_EXIT_TIMEOUT_IN_SECONDS );
- ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
- if ( startupConfiguration.isManifestOnlyJarRequestedAndUsable() )
+ AbstractPathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
+
+ if ( classpathConfiguration.isClassPathConfig() )
{
- classpathConfiguration.trickClassPathWhenManifestOnlyClasspath();
+ if ( startupConfiguration.isManifestOnlyJarRequestedAndUsable() )
+ {
+ classpathConfiguration.toRealPath( ClasspathConfiguration.class )
+ .trickClassPathWhenManifestOnlyClasspath();
+ }
+ startupConfiguration.writeSurefireTestClasspathProperty();
}
ClassLoader classLoader = currentThread().getContextClassLoader();
classLoader.setDefaultAssertionStatus( classpathConfiguration.isEnableAssertions() );
- startupConfiguration.writeSurefireTestClasspathProperty();
- testSet = createTestSet( providerConfiguration.getTestForFork(),
- providerConfiguration.isReadTestsFromInStream(), classLoader );
+ boolean readTestsFromCommandReader = providerConfiguration.isReadTestsFromInStream();
+ testSet = createTestSet( providerConfiguration.getTestForFork(), readTestsFromCommandReader, classLoader );
}
private void execute()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java
new file mode 100644
index 0000000..0d7b8eb
--- /dev/null
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java
@@ -0,0 +1,70 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableCollection;
+import static java.util.Collections.unmodifiableList;
+
+/**
+ * Jigsaw class-path and module-path.
+ *
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+public final class ModularClasspath
+{
+ private final File moduleDescriptor;
+ private final List<String> modulePath;
+ private final Collection<String> packages;
+ private final File patchFile;
+
+ public ModularClasspath( File moduleDescriptor, List<String> modulePath, Collection<String> packages,
+ File patchFile )
+ {
+ this.moduleDescriptor = moduleDescriptor;
+ this.modulePath = modulePath;
+ this.packages = packages;
+ this.patchFile = patchFile;
+ }
+
+ public File getModuleDescriptor()
+ {
+ return moduleDescriptor;
+ }
+
+ public List<String> getModulePath()
+ {
+ return unmodifiableList( modulePath );
+ }
+
+ public Collection<String> getPackages()
+ {
+ return unmodifiableCollection( packages );
+ }
+
+ public File getPatchFile()
+ {
+ return patchFile;
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspathConfiguration.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspathConfiguration.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspathConfiguration.java
new file mode 100644
index 0000000..655b864
--- /dev/null
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspathConfiguration.java
@@ -0,0 +1,62 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+public class ModularClasspathConfiguration extends AbstractPathConfiguration
+{
+ private final ModularClasspath modularClasspath;
+ private final Classpath testClasspathUrls;
+
+ public ModularClasspathConfiguration( ModularClasspath modularClasspath, Classpath testClasspathUrls,
+ Classpath surefireClasspathUrls, boolean enableAssertions,
+ boolean childDelegation )
+ {
+ super( surefireClasspathUrls, enableAssertions, childDelegation );
+ this.modularClasspath = modularClasspath;
+ this.testClasspathUrls = testClasspathUrls;
+ }
+
+ @Override
+ public Classpath getTestClasspath()
+ {
+ return testClasspathUrls;
+ }
+
+ @Override
+ public final boolean isModularPathConfig()
+ {
+ return true;
+ }
+
+ @Override
+ public final boolean isClassPathConfig()
+ {
+ return !isModularPathConfig();
+ }
+
+ public ModularClasspath getModularClasspath()
+ {
+ return modularClasspath;
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java
index 91530b7..7dd30ff 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java
@@ -26,20 +26,15 @@ package org.apache.maven.surefire.booter;
*/
public class StartupConfiguration
{
- private final String providerClassName;
-
- private final ClasspathConfiguration classpathConfiguration;
+ private static final String SUREFIRE_TEST_CLASSPATH = "surefire.test.class.path";
+ private final String providerClassName;
+ private final AbstractPathConfiguration classpathConfiguration;
private final ClassLoaderConfiguration classLoaderConfiguration;
-
private final boolean isForkRequested;
-
private final boolean isInForkedVm;
- private static final String SUREFIRE_TEST_CLASSPATH = "surefire.test.class.path";
-
-
- public StartupConfiguration( String providerClassName, ClasspathConfiguration classpathConfiguration,
+ public StartupConfiguration( String providerClassName, AbstractPathConfiguration classpathConfiguration,
ClassLoaderConfiguration classLoaderConfiguration, boolean isForkRequested,
boolean inForkedVm )
{
@@ -63,11 +58,12 @@ public class StartupConfiguration
true );
}
- public ClasspathConfiguration getClasspathConfiguration()
+ public AbstractPathConfiguration getClasspathConfiguration()
{
return classpathConfiguration;
}
+ @Deprecated
public boolean useSystemClassLoader()
{
// todo; I am not totally convinced this logic is as simple as it could be
@@ -86,11 +82,7 @@ public class StartupConfiguration
public String getActualClassName()
{
- if ( isProviderMainClass() )
- {
- return stripEnd( providerClassName, "#main" );
- }
- return providerClassName;
+ return isProviderMainClass() ? stripEnd( providerClassName, "#main" ) : providerClassName;
}
/**
@@ -120,7 +112,7 @@ public class StartupConfiguration
}
else
{
- while ( ( end != 0 ) && ( strip.indexOf( str.charAt( end - 1 ) ) != -1 ) )
+ while ( end != 0 && strip.indexOf( str.charAt( end - 1 ) ) != -1 )
{
end--;
}
@@ -140,8 +132,6 @@ public class StartupConfiguration
public void writeSurefireTestClasspathProperty()
{
- ClasspathConfiguration classpathConfiguration = getClasspathConfiguration();
- classpathConfiguration.getTestClasspath().writeToSystemProperty( SUREFIRE_TEST_CLASSPATH );
+ getClasspathConfiguration().getTestClasspath().writeToSystemProperty( SUREFIRE_TEST_CLASSPATH );
}
-
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/surefire-integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/pom.xml b/surefire-integration-tests/pom.xml
index 4187d5f..2f8592a 100644
--- a/surefire-integration-tests/pom.xml
+++ b/surefire-integration-tests/pom.xml
@@ -101,6 +101,9 @@
<includes>
<include>org/apache/**/*IT*.java</include>
</includes>
+ <excludes>
+ <exclude>org/apache/**/*Java9*IT.java</exclude>
+ </excludes>
<!-- Pass current surefire version to the main suite so that it -->
<!-- can forward to all integration test projects. SUREFIRE-513 -->
<systemPropertyVariables>
[2/2] maven-surefire git commit: [SUREFIRE-1262] Add modulepath
support
Posted by ti...@apache.org.
[SUREFIRE-1262] Add modulepath support
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/135a1cfc
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/135a1cfc
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/135a1cfc
Branch: refs/heads/SUREFIRE-1262_2
Commit: 135a1cfcb0e97e2597a6c2f52c7aeb43098d9981
Parents: 5aed843
Author: Tibor17 <ti...@apache.org>
Authored: Sat Sep 16 21:25:37 2017 +0200
Committer: Tibor17 <ti...@apache.org>
Committed: Thu Oct 5 11:01:45 2017 +0200
----------------------------------------------------------------------
maven-surefire-common/pom.xml | 12 +-
.../plugin/surefire/AbstractSurefireMojo.java | 240 +++++++++---
.../surefire/InPluginVMSurefireStarter.java | 5 +-
.../AbstractClasspathForkConfiguration.java | 72 ++++
.../surefire/booterclient/BooterSerializer.java | 94 +++--
.../ClasspathForkConfiguration.java | 59 +++
.../booterclient/DefaultForkConfiguration.java | 344 +++++++++++++++++
.../booterclient/ForkConfiguration.java | 367 ++-----------------
.../surefire/booterclient/ForkStarter.java | 27 +-
.../JarManifestForkConfiguration.java | 139 +++++++
.../ModularClasspathForkConfiguration.java | 230 ++++++++++++
.../plugin/surefire/booterclient/Platform.java | 29 +-
.../maven/plugin/surefire/util/Relocator.java | 39 +-
.../surefire/providerapi/ServiceLoader.java | 2 +-
...terDeserializerStartupConfigurationTest.java | 8 +-
.../booterclient/ForkConfigurationTest.java | 49 ++-
.../maven/surefire/util/RelocatorTest.java | 6 +-
.../plugin/surefire/SurefirePluginTest.java | 3 +-
pom.xml | 65 +++-
.../booter/AbstractPathConfiguration.java | 115 ++++++
.../apache/maven/surefire/booter/Classpath.java | 19 +-
.../surefire/booter/ClasspathConfiguration.java | 73 ++--
.../maven/surefire/booter/ForkedBooter.java | 22 +-
.../maven/surefire/booter/ModularClasspath.java | 70 ++++
.../booter/ModularClasspathConfiguration.java | 62 ++++
.../surefire/booter/StartupConfiguration.java | 28 +-
surefire-integration-tests/pom.xml | 3 +
27 files changed, 1572 insertions(+), 610 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/pom.xml
----------------------------------------------------------------------
diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml
index 1bcd7c5..99dadf1 100644
--- a/maven-surefire-common/pom.xml
+++ b/maven-surefire-common/pom.xml
@@ -97,21 +97,17 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
- <version>1.3</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-plugin-testing-harness</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
- <version>1.13</version>
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-java</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index 88b223a..4fe2e40 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -24,6 +24,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@@ -43,6 +44,9 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.surefire.booterclient.ChecksumCalculator;
import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.ForkStarter;
+import org.apache.maven.plugin.surefire.booterclient.ClasspathForkConfiguration;
+import org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration;
+import org.apache.maven.plugin.surefire.booterclient.ModularClasspathForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.Platform;
import org.apache.maven.plugin.surefire.booterclient.ProviderDetector;
import org.apache.maven.plugin.surefire.log.PluginConsoleLogger;
@@ -58,6 +62,8 @@ import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.KeyValueSource;
+import org.apache.maven.surefire.booter.ModularClasspath;
+import org.apache.maven.surefire.booter.ModularClasspathConfiguration;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.ProviderParameterNames;
import org.apache.maven.surefire.booter.Shutdown;
@@ -80,6 +86,9 @@ import org.apache.maven.surefire.util.SurefireReflectionException;
import org.apache.maven.toolchain.DefaultToolchain;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.languages.java.jpms.LocationManager;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
import javax.annotation.Nonnull;
import java.io.File;
@@ -98,6 +107,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import static java.lang.Thread.currentThread;
@@ -105,6 +116,7 @@ import static java.util.Collections.singletonMap;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_7;
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT;
+//import static org.apache.commons.lang3.StringUtils.substringBeforeLast;
import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
import static org.apache.maven.shared.utils.StringUtils.capitalizeFirstLetter;
@@ -132,12 +144,13 @@ public abstract class AbstractSurefireMojo
extends AbstractMojo
implements SurefireExecutionParameters
{
+ private static final String FORK_ONCE = "once";
+ private static final String FORK_ALWAYS = "always";
+ private static final String FORK_NEVER = "never";
+ private static final String FORK_PERTHREAD = "perthread";
private static final Map<String, String> JAVA_9_MATCHER_OLD_NOTATION = singletonMap( "version", "[1.9,)" );
-
private static final Map<String, String> JAVA_9_MATCHER = singletonMap( "version", "[9,)" );
-
private static final Platform PLATFORM = new Platform();
-
private static final File SYSTEM_TMP_DIR = new File( System.getProperty( "java.io.tmpdir" ) );
private final ProviderDetector providerDetector = new ProviderDetector();
@@ -631,6 +644,7 @@ public abstract class AbstractSurefireMojo
@Parameter( property = "threadCountMethods", defaultValue = "0" )
private int threadCountMethods;
+ // todo see SUREFIRE-1226 in version 3.0
/**
* Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace.
*
@@ -727,6 +741,9 @@ public abstract class AbstractSurefireMojo
@Component
private ToolchainManager toolchainManager;
+ @Component
+ private LocationManager locationManager;
+
private Artifact surefireBooterArtifact;
private Toolchain toolchain;
@@ -1195,6 +1212,16 @@ public abstract class AbstractSurefireMojo
return tc;
}
+ private boolean existsModuleDescriptor()
+ {
+ return getModuleDescriptor().isFile();
+ }
+
+ private File getModuleDescriptor()
+ {
+ return new File( getClassesDirectory(), "module-info.class" );
+ }
+
/**
* Converts old TestNG configuration parameters over to new properties based configuration
* method. (if any are defined the old way)
@@ -1507,7 +1534,7 @@ public abstract class AbstractSurefireMojo
static boolean isForkModeNever( String forkMode )
{
- return ForkConfiguration.FORK_NEVER.equals( forkMode );
+ return FORK_NEVER.equals( forkMode );
}
protected boolean isForking()
@@ -1521,10 +1548,10 @@ public abstract class AbstractSurefireMojo
if ( toolchain != null && isForkModeNever( forkMode1 ) )
{
- return ForkConfiguration.FORK_ONCE;
+ return FORK_ONCE;
}
- return ForkConfiguration.getEffectiveForkMode( forkMode1 );
+ return getEffectiveForkMode( forkMode1 );
}
private List<RunOrder> getRunOrders()
@@ -1645,8 +1672,8 @@ public abstract class AbstractSurefireMojo
return new File( getBasedir(), ".surefire-" + configurationHash );
}
- StartupConfiguration createStartupConfiguration( ProviderInfo provider,
- ClassLoaderConfiguration classLoaderConfiguration )
+ private StartupConfiguration createStartupConfiguration( ProviderInfo provider, boolean isInprocess,
+ ClassLoaderConfiguration classLoaderConfiguration )
throws MojoExecutionException, MojoFailureException
{
try
@@ -1665,35 +1692,94 @@ public abstract class AbstractSurefireMojo
providerClasspath.addClassPathElementUrl( surefireArtifact.getFile().getAbsolutePath() )
.addClassPathElementUrl( getApiArtifact().getFile().getAbsolutePath() );
- final Classpath testClasspath = generateTestClasspath();
-
- getConsoleLogger().debug( testClasspath.getLogMessage( "test" ) );
- getConsoleLogger().debug( providerClasspath.getLogMessage( "provider" ) );
+ File moduleDescriptor = getModuleDescriptor();
- getConsoleLogger().debug( testClasspath.getCompactLogMessage( "test(compact)" ) );
- getConsoleLogger().debug( providerClasspath.getCompactLogMessage( "provider(compact)" ) );
-
- final ClasspathConfiguration classpathConfiguration =
- new ClasspathConfiguration( testClasspath, providerClasspath, inprocClassPath,
- effectiveIsEnableAssertions(), isChildDelegation() );
-
- return new StartupConfiguration( providerName, classpathConfiguration, classLoaderConfiguration,
- isForking(), false );
+ if ( moduleDescriptor.exists() && !isInprocess )
+ {
+ return newStartupConfigForModularClasspath( classLoaderConfiguration, providerClasspath, providerName,
+ moduleDescriptor );
+ }
+ else
+ {
+ return newStartupConfigForNonModularClasspath( classLoaderConfiguration, providerClasspath,
+ inprocClassPath, providerName );
+ }
}
- catch ( ArtifactResolutionException e )
+ catch ( AbstractArtifactResolutionException e )
{
throw new MojoExecutionException( "Unable to generate classpath: " + e, e );
}
- catch ( ArtifactNotFoundException e )
+ catch ( InvalidVersionSpecificationException e )
{
throw new MojoExecutionException( "Unable to generate classpath: " + e, e );
}
- catch ( InvalidVersionSpecificationException e )
+ catch ( IOException e )
{
- throw new MojoExecutionException( "Unable to generate classpath: " + e, e );
+ throw new MojoExecutionException( e.getMessage(), e );
}
}
+ //todo mock unit test
+ StartupConfiguration newStartupConfigForNonModularClasspath( ClassLoaderConfiguration classLoaderConfiguration,
+ Classpath providerClasspath, Classpath inprocClasspath,
+ String providerName )
+ throws MojoExecutionException, MojoFailureException, InvalidVersionSpecificationException,
+ AbstractArtifactResolutionException
+ {
+ Classpath testClasspath = generateTestClasspath();
+
+ getConsoleLogger().debug( testClasspath.getLogMessage( "test classpath:" ) );
+ getConsoleLogger().debug( providerClasspath.getLogMessage( "provider classpath:" ) );
+ getConsoleLogger().debug( testClasspath.getCompactLogMessage( "test(compact) classpath:" ) );
+ getConsoleLogger().debug( providerClasspath.getCompactLogMessage( "provider(compact) classpath:" ) );
+
+ ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( testClasspath, providerClasspath,
+ inprocClasspath, effectiveIsEnableAssertions(), isChildDelegation() );
+
+ return new StartupConfiguration( providerName, classpathConfiguration, classLoaderConfiguration, isForking(),
+ false );
+ }
+
+ //todo mock unit test
+ StartupConfiguration newStartupConfigForModularClasspath( ClassLoaderConfiguration classLoaderConfiguration,
+ Classpath providerClasspath, String providerName,
+ File moduleDescriptor )
+ throws MojoExecutionException, MojoFailureException, InvalidVersionSpecificationException,
+ AbstractArtifactResolutionException, IOException
+ {
+ ResolvePathsRequest<String> req = ResolvePathsRequest.withStrings( generateTestClasspath().getClassPath() )
+ .setMainModuleDescriptor( moduleDescriptor.getAbsolutePath() );
+
+ ResolvePathsResult<String> result = locationManager.resolvePaths( req );
+
+ Classpath testClasspath = new Classpath( result.getClasspathElements() );
+ Classpath testModulepath = new Classpath( result.getModulepathElements().keySet() );
+
+ SortedSet<String> packages = new TreeSet<String>();
+
+ /*for ( Object file : scanResult.getFiles() )
+ {
+ String className = (String) file;
+ packages.add( substringBeforeLast( className, "." ) );
+ }*/
+
+ ModularClasspath modularClasspath = new ModularClasspath( moduleDescriptor, testModulepath.getClassPath(),
+ packages, getTestClassesDirectory() );
+
+ ModularClasspathConfiguration classpathConfiguration = new ModularClasspathConfiguration( modularClasspath,
+ testClasspath, providerClasspath, effectiveIsEnableAssertions(), isChildDelegation() );
+
+ getConsoleLogger().debug( testClasspath.getLogMessage( "test classpath:" ) );
+ getConsoleLogger().debug( testModulepath.getLogMessage( "test modulepath:" ) );
+ getConsoleLogger().debug( providerClasspath.getLogMessage( "provider classpath:" ) );
+ getConsoleLogger().debug( testClasspath.getCompactLogMessage( "test(compact) classpath:" ) );
+ getConsoleLogger().debug( testModulepath.getCompactLogMessage( "test(compact) modulepath:" ) );
+ getConsoleLogger().debug( providerClasspath.getCompactLogMessage( "provider(compact) classpath:" ) );
+
+ return new StartupConfiguration( providerName, classpathConfiguration, classLoaderConfiguration, isForking(),
+ false );
+ }
+
private Artifact getCommonArtifact()
{
return getPluginArtifactMap().get( "org.apache.maven.surefire:maven-surefire-common" );
@@ -1941,7 +2027,8 @@ public abstract class AbstractSurefireMojo
RunOrderParameters runOrderParameters, ConsoleLogger log )
throws MojoExecutionException, MojoFailureException
{
- StartupConfiguration startupConfiguration = createStartupConfiguration( provider, classLoaderConfiguration );
+ StartupConfiguration startupConfiguration =
+ createStartupConfiguration( provider, false, classLoaderConfiguration );
String configChecksum = getConfigChecksum();
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration( configChecksum );
ProviderConfiguration providerConfiguration = createProviderConfiguration( runOrderParameters );
@@ -1950,16 +2037,17 @@ public abstract class AbstractSurefireMojo
}
private InPluginVMSurefireStarter createInprocessStarter( ProviderInfo provider,
- ClassLoaderConfiguration classLoaderConfiguration,
- RunOrderParameters runOrderParameters )
+ ClassLoaderConfiguration classLoaderConfiguration,
+ RunOrderParameters runOrderParameters )
throws MojoExecutionException, MojoFailureException
{
- StartupConfiguration startupConfiguration = createStartupConfiguration( provider, classLoaderConfiguration );
+ StartupConfiguration startupConfiguration =
+ createStartupConfiguration( provider, true, classLoaderConfiguration );
String configChecksum = getConfigChecksum();
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration( configChecksum );
ProviderConfiguration providerConfiguration = createProviderConfiguration( runOrderParameters );
- return new InPluginVMSurefireStarter( startupConfiguration, providerConfiguration,
- startupReportConfiguration, consoleLogger );
+ return new InPluginVMSurefireStarter( startupConfiguration, providerConfiguration, startupReportConfiguration,
+ getConsoleLogger() );
}
private ForkConfiguration getForkConfiguration() throws MojoFailureException
@@ -1969,36 +2057,76 @@ public abstract class AbstractSurefireMojo
Artifact shadeFire = getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-shadefire" );
// todo: 150 milli seconds, try to fetch List<String> within classpath asynchronously
- final Classpath bootClasspathConfiguration =
- getArtifactClasspath( shadeFire != null ? shadeFire : surefireBooterArtifact );
-
- return new ForkConfiguration( bootClasspathConfiguration, tmpDir, getEffectiveDebugForkedProcess(),
- getEffectiveJvm(),
- getWorkingDirectory() != null ? getWorkingDirectory() : getBasedir(),
- getProject().getModel().getProperties(),
- getArgLine(), getEnvironmentVariables(), getConsoleLogger().isDebugEnabled(),
- getEffectiveForkCount(), reuseForks, PLATFORM );
+ Classpath bootClasspath = getArtifactClasspath( shadeFire != null ? shadeFire : surefireBooterArtifact );
+
+ Platform platform = PLATFORM.withJdkExecAttributesForTests( getEffectiveJvm() );
+
+ if ( platform.getJdkExecAttributesForTests().isJava9AtLeast() && existsModuleDescriptor() )
+ {
+ return new ModularClasspathForkConfiguration( bootClasspath,
+ tmpDir,
+ getEffectiveDebugForkedProcess(),
+ getWorkingDirectory() != null ? getWorkingDirectory() : getBasedir(),
+ getProject().getModel().getProperties(),
+ getArgLine(),
+ getEnvironmentVariables(),
+ getConsoleLogger().isDebugEnabled(),
+ getEffectiveForkCount(),
+ reuseForks,
+ platform,
+ getConsoleLogger() );
+ }
+ else if ( getClassLoaderConfiguration().isManifestOnlyJarRequestedAndUsable() )
+ {
+ return new JarManifestForkConfiguration( bootClasspath,
+ tmpDir,
+ getEffectiveDebugForkedProcess(),
+ getWorkingDirectory() != null ? getWorkingDirectory() : getBasedir(),
+ getProject().getModel().getProperties(),
+ getArgLine(),
+ getEnvironmentVariables(),
+ getConsoleLogger().isDebugEnabled(),
+ getEffectiveForkCount(),
+ reuseForks,
+ platform,
+ getConsoleLogger() );
+ }
+ else
+ {
+ return new ClasspathForkConfiguration( bootClasspath,
+ tmpDir,
+ getEffectiveDebugForkedProcess(),
+ getWorkingDirectory() != null ? getWorkingDirectory() : getBasedir(),
+ getProject().getModel().getProperties(),
+ getArgLine(),
+ getEnvironmentVariables(),
+ getConsoleLogger().isDebugEnabled(),
+ getEffectiveForkCount(),
+ reuseForks,
+ platform,
+ getConsoleLogger() );
+ }
}
private void convertDeprecatedForkMode()
{
String effectiveForkMode = getEffectiveForkMode();
// FORK_ONCE (default) is represented by the default values of forkCount and reuseForks
- if ( ForkConfiguration.FORK_PERTHREAD.equals( effectiveForkMode ) )
+ if ( FORK_PERTHREAD.equals( effectiveForkMode ) )
{
forkCount = String.valueOf( threadCount );
}
- else if ( ForkConfiguration.FORK_NEVER.equals( effectiveForkMode ) )
+ else if ( FORK_NEVER.equals( effectiveForkMode ) )
{
forkCount = "0";
}
- else if ( ForkConfiguration.FORK_ALWAYS.equals( effectiveForkMode ) )
+ else if ( FORK_ALWAYS.equals( effectiveForkMode ) )
{
forkCount = "1";
reuseForks = false;
}
- if ( !ForkConfiguration.FORK_ONCE.equals( getForkMode() ) )
+ if ( !FORK_ONCE.equals( getForkMode() ) )
{
getConsoleLogger().warning( "The parameter forkMode is deprecated since version 2.14. "
+ "Use forkCount and reuseForks instead." );
@@ -2244,6 +2372,7 @@ public abstract class AbstractSurefireMojo
* @throws ArtifactNotFoundException when it happens
* @throws ArtifactResolutionException when it happens
*/
+ //todo mock unit test
private Classpath generateTestClasspath()
throws InvalidVersionSpecificationException, MojoFailureException, ArtifactResolutionException,
ArtifactNotFoundException, MojoExecutionException
@@ -2482,7 +2611,7 @@ public abstract class AbstractSurefireMojo
private void ensureThreadCountWithPerThread()
throws MojoFailureException
{
- if ( ForkConfiguration.FORK_PERTHREAD.equals( getEffectiveForkMode() ) && getThreadCount() < 1 )
+ if ( FORK_PERTHREAD.equals( getEffectiveForkMode() ) && getThreadCount() < 1 )
{
throw new MojoFailureException( "Fork mode perthread requires a thread count" );
}
@@ -3506,4 +3635,25 @@ public abstract class AbstractSurefireMojo
{
this.tempDir = tempDir;
}
+
+ private static String getEffectiveForkMode( String forkMode )
+ {
+ if ( "pertest".equalsIgnoreCase( forkMode ) )
+ {
+ return FORK_ALWAYS;
+ }
+ else if ( "none".equalsIgnoreCase( forkMode ) )
+ {
+ return FORK_NEVER;
+ }
+ else if ( forkMode.equals( FORK_NEVER ) || forkMode.equals( FORK_ONCE )
+ || forkMode.equals( FORK_ALWAYS ) || forkMode.equals( FORK_PERTHREAD ) )
+ {
+ return forkMode;
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Fork mode " + forkMode + " is not a legal value" );
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java
index b97c192..1d85001 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java
@@ -20,6 +20,7 @@ package org.apache.maven.plugin.surefire;
*/
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
import org.apache.maven.surefire.booter.SurefireExecutionException;
@@ -73,7 +74,9 @@ public class InPluginVMSurefireStarter
scanResult.writeTo( providerProperties );
startupConfig.writeSurefireTestClasspathProperty();
- ClassLoader testClassLoader = startupConfig.getClasspathConfiguration().createMergedClassLoader();
+ ClassLoader testClassLoader = startupConfig.getClasspathConfiguration()
+ .toRealPath( ClasspathConfiguration.class )
+ .createMergedClassLoader();
CommonReflector surefireReflector = new CommonReflector( testClassLoader );
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/AbstractClasspathForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/AbstractClasspathForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/AbstractClasspathForkConfiguration.java
new file mode 100644
index 0000000..120ae88
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/AbstractClasspathForkConfiguration.java
@@ -0,0 +1,72 @@
+package org.apache.maven.plugin.surefire.booterclient;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.surefire.booter.Classpath;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.File;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+abstract class AbstractClasspathForkConfiguration
+ extends DefaultForkConfiguration
+{
+ private static final String ADD_MODULES = "--add-modules";
+ private static final String ALL_JAVA_API = ADD_MODULES + " java.se.ee";
+
+ @SuppressWarnings( "checkstyle:parameternumber" )
+ public AbstractClasspathForkConfiguration( @Nonnull Classpath bootClasspath,
+ @Nonnull File tempDirectory,
+ @Nullable String debugLine,
+ @Nonnull File workingDirectory,
+ @Nonnull Properties modelProperties,
+ @Nullable String argLine,
+ @Nonnull Map<String, String> environmentVariables,
+ boolean debug,
+ int forkCount,
+ boolean reuseForks,
+ @Nonnull Platform pluginPlatform,
+ @Nonnull ConsoleLogger log )
+ {
+ super( bootClasspath, tempDirectory, debugLine, workingDirectory, modelProperties, argLine,
+ environmentVariables, debug, forkCount, reuseForks, pluginPlatform, log );
+ }
+
+ @Override
+ @Nonnull
+ protected String extendJvmArgLine( @Nonnull String jvmArgLine )
+ {
+ if ( getJdkForTests().isJava9AtLeast() && !jvmArgLine.contains( ADD_MODULES ) )
+ {
+ return jvmArgLine.isEmpty() ? ALL_JAVA_API : ALL_JAVA_API + " " + jvmArgLine;
+ }
+ else
+ {
+ return jvmArgLine;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
index 591e89c..97140ef 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
@@ -19,17 +19,12 @@ package org.apache.maven.plugin.surefire.booterclient;
* under the License.
*/
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
import org.apache.maven.plugin.surefire.SurefireProperties;
+import org.apache.maven.surefire.booter.AbstractPathConfiguration;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
-import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.KeyValueSource;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
-import org.apache.maven.surefire.booter.SystemPropertyManager;
import org.apache.maven.surefire.cli.CommandLineOption;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.testset.DirectoryScannerParameters;
@@ -39,8 +34,40 @@ import org.apache.maven.surefire.testset.TestListResolver;
import org.apache.maven.surefire.testset.TestRequest;
import org.apache.maven.surefire.util.RunOrder;
-// CHECKSTYLE_OFF: imports
-import static org.apache.maven.surefire.booter.BooterConstants.*;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import static org.apache.maven.surefire.booter.AbstractPathConfiguration.CHILD_DELEGATION;
+import static org.apache.maven.surefire.booter.AbstractPathConfiguration.CLASSPATH;
+import static org.apache.maven.surefire.booter.AbstractPathConfiguration.ENABLE_ASSERTIONS;
+import static org.apache.maven.surefire.booter.AbstractPathConfiguration.SUREFIRE_CLASSPATH;
+import static org.apache.maven.surefire.booter.BooterConstants.EXCLUDES_PROPERTY_PREFIX;
+import static org.apache.maven.surefire.booter.BooterConstants.FAIL_FAST_COUNT;
+import static org.apache.maven.surefire.booter.BooterConstants.FAILIFNOTESTS;
+import static org.apache.maven.surefire.booter.BooterConstants.FORKTESTSET;
+import static org.apache.maven.surefire.booter.BooterConstants.FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM;
+import static org.apache.maven.surefire.booter.BooterConstants.INCLUDES_PROPERTY_PREFIX;
+import static org.apache.maven.surefire.booter.BooterConstants.ISTRIMSTACKTRACE;
+import static org.apache.maven.surefire.booter.BooterConstants.MAIN_CLI_OPTIONS;
+import static org.apache.maven.surefire.booter.BooterConstants.PLUGIN_PID;
+import static org.apache.maven.surefire.booter.BooterConstants.PROVIDER_CONFIGURATION;
+import static org.apache.maven.surefire.booter.BooterConstants.REPORTSDIRECTORY;
+import static org.apache.maven.surefire.booter.BooterConstants.REQUESTEDTEST;
+import static org.apache.maven.surefire.booter.BooterConstants.RERUN_FAILING_TESTS_COUNT;
+import static org.apache.maven.surefire.booter.BooterConstants.RUN_ORDER;
+import static org.apache.maven.surefire.booter.BooterConstants.RUN_STATISTICS_FILE;
+import static org.apache.maven.surefire.booter.BooterConstants.SHUTDOWN;
+import static org.apache.maven.surefire.booter.BooterConstants.SOURCE_DIRECTORY;
+import static org.apache.maven.surefire.booter.BooterConstants.SPECIFIC_TEST_PROPERTY_PREFIX;
+import static org.apache.maven.surefire.booter.BooterConstants.SYSTEM_EXIT_TIMEOUT;
+import static org.apache.maven.surefire.booter.BooterConstants.TEST_CLASSES_DIRECTORY;
+import static org.apache.maven.surefire.booter.BooterConstants.TEST_SUITE_XML_FILES;
+import static org.apache.maven.surefire.booter.BooterConstants.TESTARTIFACT_CLASSIFIER;
+import static org.apache.maven.surefire.booter.BooterConstants.TESTARTIFACT_VERSION;
+import static org.apache.maven.surefire.booter.BooterConstants.USEMANIFESTONLYJAR;
+import static org.apache.maven.surefire.booter.BooterConstants.USESYSTEMCLASSLOADER;
+import static org.apache.maven.surefire.booter.SystemPropertyManager.writePropertiesFile;
/**
* Knows how to serialize and deserialize the booter configuration.
@@ -78,11 +105,11 @@ class BooterSerializer
properties.setProperty( PLUGIN_PID, pid );
- ClasspathConfiguration cp = providerConfiguration.getClasspathConfiguration();
- properties.setClasspath( ClasspathConfiguration.CLASSPATH, cp.getTestClasspath() );
- properties.setClasspath( ClasspathConfiguration.SUREFIRE_CLASSPATH, cp.getProviderClasspath() );
- properties.setProperty( ClasspathConfiguration.ENABLE_ASSERTIONS, String.valueOf( cp.isEnableAssertions() ) );
- properties.setProperty( ClasspathConfiguration.CHILD_DELEGATION, String.valueOf( cp.isChildDelegation() ) );
+ AbstractPathConfiguration cp = providerConfiguration.getClasspathConfiguration();
+ properties.setClasspath( CLASSPATH, cp.getTestClasspath() );
+ properties.setClasspath( SUREFIRE_CLASSPATH, cp.getProviderClasspath() );
+ properties.setProperty( ENABLE_ASSERTIONS, toString( cp.isEnableAssertions() ) );
+ properties.setProperty( CHILD_DELEGATION, toString( cp.isChildDelegation() ) );
TestArtifactInfo testNg = booterConfiguration.getTestArtifact();
if ( testNg != null )
@@ -101,18 +128,17 @@ class BooterSerializer
properties.addList( testSuiteDefinition.getSuiteXmlFiles(), TEST_SUITE_XML_FILES );
TestListResolver testFilter = testSuiteDefinition.getTestListResolver();
properties.setProperty( REQUESTEDTEST, testFilter == null ? "" : testFilter.getPluginParameterTest() );
- properties.setNullableProperty( RERUN_FAILING_TESTS_COUNT,
- String.valueOf( testSuiteDefinition.getRerunFailingTestsCount() ) );
+ int rerunFailingTestsCount = testSuiteDefinition.getRerunFailingTestsCount();
+ properties.setNullableProperty( RERUN_FAILING_TESTS_COUNT, toString( rerunFailingTestsCount ) );
}
DirectoryScannerParameters directoryScannerParameters = booterConfiguration.getDirScannerParams();
if ( directoryScannerParameters != null )
{
- properties.setProperty( FAILIFNOTESTS, String.valueOf( directoryScannerParameters.isFailIfNoTests() ) );
+ properties.setProperty( FAILIFNOTESTS, toString( directoryScannerParameters.isFailIfNoTests() ) );
properties.addList( directoryScannerParameters.getIncludes(), INCLUDES_PROPERTY_PREFIX );
properties.addList( directoryScannerParameters.getExcludes(), EXCLUDES_PROPERTY_PREFIX );
properties.addList( directoryScannerParameters.getSpecificTests(), SPECIFIC_TEST_PROPERTY_PREFIX );
-
properties.setProperty( TEST_CLASSES_DIRECTORY, directoryScannerParameters.getTestClassesDirectory() );
}
@@ -124,46 +150,40 @@ class BooterSerializer
}
ReporterConfiguration reporterConfiguration = booterConfiguration.getReporterConfiguration();
-
boolean rep = reporterConfiguration.isTrimStackTrace();
properties.setProperty( ISTRIMSTACKTRACE, rep );
properties.setProperty( REPORTSDIRECTORY, reporterConfiguration.getReportsDirectory() );
ClassLoaderConfiguration classLoaderConfig = providerConfiguration.getClassLoaderConfiguration();
- properties.setProperty( USESYSTEMCLASSLOADER, String.valueOf( classLoaderConfig.isUseSystemClassLoader() ) );
- properties.setProperty( USEMANIFESTONLYJAR, String.valueOf( classLoaderConfig.isUseManifestOnlyJar() ) );
- properties.setProperty( FAILIFNOTESTS, String.valueOf( booterConfiguration.isFailIfNoTests() ) );
+ properties.setProperty( USESYSTEMCLASSLOADER, toString( classLoaderConfig.isUseSystemClassLoader() ) );
+ properties.setProperty( USEMANIFESTONLYJAR, toString( classLoaderConfig.isUseManifestOnlyJar() ) );
+ properties.setProperty( FAILIFNOTESTS, toString( booterConfiguration.isFailIfNoTests() ) );
properties.setProperty( PROVIDER_CONFIGURATION, providerConfiguration.getProviderClassName() );
- properties.setProperty( FAIL_FAST_COUNT, String.valueOf( booterConfiguration.getSkipAfterFailureCount() ) );
+ properties.setProperty( FAIL_FAST_COUNT, toString( booterConfiguration.getSkipAfterFailureCount() ) );
properties.setProperty( SHUTDOWN, booterConfiguration.getShutdown().name() );
List<CommandLineOption> mainCliOptions = booterConfiguration.getMainCliOptions();
if ( mainCliOptions != null )
{
properties.addList( mainCliOptions, MAIN_CLI_OPTIONS );
}
+ properties.setNullableProperty( SYSTEM_EXIT_TIMEOUT, toString( booterConfiguration.getSystemExitTimeout() ) );
- properties.setNullableProperty( SYSTEM_EXIT_TIMEOUT,
- String.valueOf( booterConfiguration.getSystemExitTimeout() ) );
-
- return SystemPropertyManager.writePropertiesFile( properties, forkConfiguration.getTempDirectory(),
- "surefire", forkConfiguration.isDebug() );
+ File surefireTmpDir = forkConfiguration.getTempDirectory();
+ boolean debug = forkConfiguration.isDebug();
+ return writePropertiesFile( properties, surefireTmpDir, "surefire", debug );
}
- private String getTypeEncoded( Object value )
+ private static String getTypeEncoded( Object value )
{
if ( value == null )
{
return null;
}
- String valueToUse;
- if ( value instanceof Class )
- {
- valueToUse = ( (Class<?>) value ).getName();
- }
- else
- {
- valueToUse = value.toString();
- }
+ String valueToUse = value instanceof Class ? ( (Class<?>) value ).getName() : value.toString();
return value.getClass().getName() + "|" + valueToUse;
}
+ private static String toString( Object o )
+ {
+ return String.valueOf( o );
+ }
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ClasspathForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ClasspathForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ClasspathForkConfiguration.java
new file mode 100644
index 0000000..28b966e
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ClasspathForkConfiguration.java
@@ -0,0 +1,59 @@
+package org.apache.maven.plugin.surefire.booterclient;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
+import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.StartupConfiguration;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.apache.maven.shared.utils.StringUtils.join;
+
+/**
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+public final class ClasspathForkConfiguration
+ extends AbstractClasspathForkConfiguration
+{
+ @SuppressWarnings( "checkstyle:parameternumber" )
+ public ClasspathForkConfiguration( Classpath bootClasspath, File tempDirectory, String debugLine,
+ File workingDirectory, Properties modelProperties, String argLine,
+ Map<String, String> environmentVariables, boolean debug, int forkCount,
+ boolean reuseForks, Platform pluginPlatform, ConsoleLogger log )
+ {
+ super( bootClasspath, tempDirectory, debugLine, workingDirectory, modelProperties, argLine,
+ environmentVariables, debug, forkCount, reuseForks, pluginPlatform, log );
+ }
+
+ @Override
+ protected void resolveClasspath( OutputStreamFlushableCommandline cli, String booterThatHasMainMethod,
+ StartupConfiguration config )
+ throws SurefireBooterForkException
+ {
+ cli.addEnvironment( "CLASSPATH", join( toCompleteClasspath( config ).iterator(), File.pathSeparator ) );
+ cli.createArg().setValue( booterThatHasMainMethod );
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java
new file mode 100644
index 0000000..d8dbd3e
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java
@@ -0,0 +1,344 @@
+package org.apache.maven.plugin.surefire.booterclient;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.surefire.JdkAttributes;
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
+import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.surefire.booter.AbstractPathConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.StartupConfiguration;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+import org.apache.maven.surefire.util.internal.ImmutableMap;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.FORK_NUMBER_PLACEHOLDER;
+import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.THREAD_NUMBER_PLACEHOLDER;
+import static org.apache.maven.plugin.surefire.util.Relocator.relocate;
+import static org.apache.maven.surefire.booter.Classpath.join;
+
+/**
+ * Basic framework which constructs CLI.
+ *
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+public abstract class DefaultForkConfiguration
+ extends ForkConfiguration
+{
+ @Nonnull private final Classpath booterClasspath;
+ @Nonnull private final File tempDirectory;
+ @Nullable
+ private final String debugLine;
+ @Nonnull private final File workingDirectory;
+ @Nonnull private final Properties modelProperties;
+ @Nullable private final String argLine;
+ @Nonnull private final Map<String, String> environmentVariables;
+ private final boolean debug;
+ private final int forkCount;
+ private final boolean reuseForks;
+ @Nonnull private final Platform pluginPlatform;
+ @Nonnull private final ConsoleLogger log;
+
+ @SuppressWarnings( "checkstyle:parameternumber" )
+ public DefaultForkConfiguration( @Nonnull Classpath booterClasspath,
+ @Nonnull File tempDirectory,
+ @Nullable String debugLine,
+ @Nonnull File workingDirectory,
+ @Nonnull Properties modelProperties,
+ @Nullable String argLine,
+ @Nonnull Map<String, String> environmentVariables,
+ boolean debug,
+ int forkCount,
+ boolean reuseForks,
+ @Nonnull Platform pluginPlatform,
+ @Nonnull ConsoleLogger log )
+ {
+ this.booterClasspath = booterClasspath;
+ this.tempDirectory = tempDirectory;
+ this.debugLine = debugLine;
+ this.workingDirectory = workingDirectory;
+ this.modelProperties = modelProperties;
+ this.argLine = argLine;
+ this.environmentVariables = toImmutable( environmentVariables );
+ this.debug = debug;
+ this.forkCount = forkCount;
+ this.reuseForks = reuseForks;
+ this.pluginPlatform = pluginPlatform;
+ this.log = log;
+ }
+
+ protected abstract void resolveClasspath( OutputStreamFlushableCommandline cli, String booterThatHasMainMethod,
+ StartupConfiguration config )
+ throws SurefireBooterForkException;
+
+ @Nonnull
+ protected String extendJvmArgLine( @Nonnull String jvmArgLine )
+ {
+ return jvmArgLine;
+ }
+
+ /**
+ * @param config The startup configuration
+ * @param forkNumber index of forked JVM, to be the replacement in the argLine
+ * @return CommandLine able to flush entire command going to be sent to forked JVM
+ * @throws org.apache.maven.surefire.booter.SurefireBooterForkException when unable to perform the fork
+ */
+ @Nonnull
+ @Override
+ public OutputStreamFlushableCommandline createCommandLine( @Nonnull StartupConfiguration config, int forkNumber )
+ throws SurefireBooterForkException
+ {
+ OutputStreamFlushableCommandline cli = new OutputStreamFlushableCommandline();
+
+ cli.setWorkingDirectory( getWorkingDirectory( forkNumber ).getAbsolutePath() );
+
+ for ( Entry<String, String> entry : getEnvironmentVariables().entrySet() )
+ {
+ String value = entry.getValue();
+ cli.addEnvironment( entry.getKey(), value == null ? "" : value );
+ }
+
+ cli.setExecutable( getJdkForTests().getJvmExecutable() );
+
+ String jvmArgLine = newJvmArgLine( forkNumber );
+ if ( !jvmArgLine.isEmpty() )
+ {
+ cli.createArg()
+ .setLine( jvmArgLine );
+ }
+
+ if ( getDebugLine() != null && !getDebugLine().isEmpty() )
+ {
+ cli.createArg()
+ .setLine( getDebugLine() );
+ }
+
+ resolveClasspath( cli, findStartClass( config ), config );
+
+ return cli;
+ }
+
+ protected List<String> toCompleteClasspath( StartupConfiguration conf ) throws SurefireBooterForkException
+ {
+ AbstractPathConfiguration pathConfig = conf.getClasspathConfiguration();
+ if ( !( pathConfig.isClassPathConfig() ^ pathConfig.isModularPathConfig() ) )
+ {
+ throw new SurefireBooterForkException( "Could not find class-path config nor modular class-path either." );
+ }
+
+ //todo this could probably be simplified further
+ Classpath bootClasspath = conf.isProviderMainClass() ? pathConfig.getProviderClasspath() : getBooterClasspath();
+ Classpath testClasspath = pathConfig.getTestClasspath();
+ Classpath providerClasspath = pathConfig.getProviderClasspath();
+
+ Classpath completeClasspath = join( join( bootClasspath, testClasspath ), providerClasspath );
+
+ log.debug( completeClasspath.getLogMessage( "boot classpath:" ) );
+ log.debug( completeClasspath.getCompactLogMessage( "boot(compact) classpath:" ) );
+
+ return completeClasspath.getClassPath();
+ }
+
+ @Nonnull
+ protected File getWorkingDirectory( int forkNumber )
+ throws SurefireBooterForkException
+ {
+ File cwd = new File( replaceThreadNumberPlaceholder( getWorkingDirectory().getAbsolutePath(), forkNumber ) );
+
+ if ( !cwd.exists() && !cwd.mkdirs() )
+ {
+ throw new SurefireBooterForkException( "Cannot create workingDirectory " + cwd.getAbsolutePath() );
+ }
+
+ if ( !cwd.isDirectory() )
+ {
+ throw new SurefireBooterForkException(
+ "WorkingDirectory " + cwd.getAbsolutePath() + " exists and is not a directory" );
+ }
+ return cwd;
+ }
+
+ @Nonnull
+ protected static String replaceThreadNumberPlaceholder( @Nonnull String argLine, int threadNumber )
+ {
+ String threadNumberAsString = String.valueOf( threadNumber );
+ return argLine.replace( THREAD_NUMBER_PLACEHOLDER, threadNumberAsString )
+ .replace( FORK_NUMBER_PLACEHOLDER, threadNumberAsString );
+ }
+
+ /**
+ * Replaces expressions <pre>@{property-name}</pre> with the corresponding properties
+ * from the model. This allows late evaluation of property values when the plugin is executed (as compared
+ * to evaluation when the pom is parsed as is done with <pre>${property-name}</pre> expressions).
+ *
+ * This allows other plugins to modify or set properties with the changes getting picked up by surefire.
+ */
+ @Nonnull
+ protected String interpolateArgLineWithPropertyExpressions()
+ {
+ if ( getArgLine() == null )
+ {
+ return "";
+ }
+
+ String resolvedArgLine = getArgLine().trim();
+
+ if ( resolvedArgLine.isEmpty() )
+ {
+ return "";
+ }
+
+ for ( final String key : getModelProperties().stringPropertyNames() )
+ {
+ String field = "@{" + key + "}";
+ if ( getArgLine().contains( field ) )
+ {
+ resolvedArgLine = resolvedArgLine.replace( field, getModelProperties().getProperty( key, "" ) );
+ }
+ }
+
+ return resolvedArgLine;
+ }
+
+ @Nonnull
+ protected static String stripNewLines( @Nonnull String argLine )
+ {
+ return argLine.replace( "\n", " " ).replace( "\r", " " );
+ }
+
+ /**
+ * Immutable map.
+ *
+ * @param map immutable map copies elements from <code>map</code>
+ * @param <K> key type
+ * @param <V> value type
+ * @return never returns null
+ */
+ @Nonnull
+ protected static <K, V> Map<K, V> toImmutable( @Nullable Map<K, V> map )
+ {
+ return map == null ? Collections.<K, V>emptyMap() : new ImmutableMap<K, V>( map );
+ }
+
+ @Override
+ @Nonnull
+ public File getTempDirectory()
+ {
+ return tempDirectory;
+ }
+
+ @Override
+ @Nullable
+ protected String getDebugLine()
+ {
+ return debugLine;
+ }
+
+ @Override
+ @Nonnull
+ protected File getWorkingDirectory()
+ {
+ return workingDirectory;
+ }
+
+ @Override
+ @Nonnull
+ protected Properties getModelProperties()
+ {
+ return modelProperties;
+ }
+
+ @Override
+ @Nullable
+ protected String getArgLine()
+ {
+ return argLine;
+ }
+
+ @Override
+ @Nonnull
+ protected Map<String, String> getEnvironmentVariables()
+ {
+ return environmentVariables;
+ }
+
+ @Override
+ protected boolean isDebug()
+ {
+ return debug;
+ }
+
+ @Override
+ protected int getForkCount()
+ {
+ return forkCount;
+ }
+
+ @Override
+ protected boolean isReuseForks()
+ {
+ return reuseForks;
+ }
+
+ @Override
+ @Nonnull
+ protected Platform getPluginPlatform()
+ {
+ return pluginPlatform;
+ }
+
+ @Override
+ @Nonnull
+ protected JdkAttributes getJdkForTests()
+ {
+ return getPluginPlatform().getJdkExecAttributesForTests();
+ }
+
+ @Override
+ @Nonnull
+ protected Classpath getBooterClasspath()
+ {
+ return booterClasspath;
+ }
+
+ //todo add mock unit tests
+ private String newJvmArgLine( int forks )
+ {
+ String interpolatedArgs = stripNewLines( interpolateArgLineWithPropertyExpressions() );
+ String argsWithReplacedForkNumbers = replaceThreadNumberPlaceholder( interpolatedArgs, forks );
+ return extendJvmArgLine( argsWithReplacedForkNumbers );
+ }
+
+ //todo add mock unit test
+ private static String findStartClass( StartupConfiguration config )
+ {
+ String startClass = config.isProviderMainClass() ? config.getActualClassName() : DEFAULT_PROVIDER_CLASS;
+ return config.isShadefire() ? relocate( startClass ) : startClass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
index c962424..1ec0fc3 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
@@ -19,371 +19,48 @@ package org.apache.maven.plugin.surefire.booterclient;
* under the License.
*/
-import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
import org.apache.maven.plugin.surefire.JdkAttributes;
import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
-import org.apache.maven.plugin.surefire.util.Relocator;
import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ForkedBooter;
import org.apache.maven.surefire.booter.StartupConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
-import org.apache.maven.surefire.util.internal.ImmutableMap;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
-import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPath;
-import static org.apache.maven.shared.utils.StringUtils.join;
/**
* Configuration for forking tests.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
- * @author <a href="mailto:krosenvold@apache.org">Kristian Rosenvold</a>
*/
-public class ForkConfiguration
+public abstract class ForkConfiguration
{
- public static final String FORK_ONCE = "once";
-
- public static final String FORK_ALWAYS = "always";
-
- public static final String FORK_NEVER = "never";
-
- public static final String FORK_PERTHREAD = "perthread";
-
- private final int forkCount;
-
- private final boolean reuseForks;
-
- private final Classpath bootClasspathConfiguration;
-
- private final JdkAttributes jdk;
-
- private final Properties modelProperties;
-
- private final String argLine;
-
- private final Map<String, String> environmentVariables;
-
- private final File workingDirectory;
-
- private final File tempDirectory;
-
- private final boolean debug;
-
- private final String debugLine;
-
- private final Platform pluginPlatform;
-
- @SuppressWarnings( "checkstyle:parameternumber" )
- public ForkConfiguration( Classpath bootClasspathConfiguration, File tmpDir, String debugLine,
- JdkAttributes jdk, File workingDirectory, Properties modelProperties, String argLine,
- Map<String, String> environmentVariables, boolean debugEnabled, int forkCount,
- boolean reuseForks, Platform pluginPlatform )
- {
- this.bootClasspathConfiguration = bootClasspathConfiguration;
- this.tempDirectory = tmpDir;
- this.debugLine = debugLine;
- this.jdk = jdk;
- this.workingDirectory = workingDirectory;
- this.modelProperties = modelProperties;
- this.argLine = argLine;
- this.environmentVariables = toImmutable( environmentVariables );
- this.debug = debugEnabled;
- this.forkCount = forkCount;
- this.reuseForks = reuseForks;
- this.pluginPlatform = pluginPlatform;
- }
-
- public Classpath getBootClasspath()
- {
- return bootClasspathConfiguration;
- }
-
- public static String getEffectiveForkMode( String forkMode )
- {
- if ( "pertest".equalsIgnoreCase( forkMode ) )
- {
- return FORK_ALWAYS;
- }
- else if ( "none".equalsIgnoreCase( forkMode ) )
- {
- return FORK_NEVER;
- }
- else if ( forkMode.equals( FORK_NEVER ) || forkMode.equals( FORK_ONCE )
- || forkMode.equals( FORK_ALWAYS ) || forkMode.equals( FORK_PERTHREAD ) )
- {
- return forkMode;
- }
- else
- {
- throw new IllegalArgumentException( "Fork mode " + forkMode + " is not a legal value" );
- }
- }
+ public static final String DEFAULT_PROVIDER_CLASS = ForkedBooter.class.getName();
+
+ @Nonnull public abstract File getTempDirectory();
+ @Nullable protected abstract String getDebugLine();
+ @Nonnull protected abstract File getWorkingDirectory();
+ @Nonnull protected abstract Properties getModelProperties();
+ @Nullable protected abstract String getArgLine();
+ @Nonnull protected abstract Map<String, String> getEnvironmentVariables();
+ protected abstract boolean isDebug();
+ protected abstract int getForkCount();
+ protected abstract boolean isReuseForks();
+ @Nonnull protected abstract Platform getPluginPlatform();
+ @Nonnull protected abstract JdkAttributes getJdkForTests();
+ @Nonnull protected abstract Classpath getBooterClasspath();
/**
- * @param classPath cli the classpath arguments
* @param config The startup configuration
- * @param threadNumber the thread number, to be the replacement in the argLine @return A commandline
+ * @param forkNumber index of forked JVM, to be the replacement in the argLine
* @return CommandLine able to flush entire command going to be sent to forked JVM
* @throws org.apache.maven.surefire.booter.SurefireBooterForkException
* when unable to perform the fork
*/
- public OutputStreamFlushableCommandline createCommandLine( List<String> classPath, StartupConfiguration config,
- int threadNumber )
- throws SurefireBooterForkException
- {
- boolean useJar = config.getClassLoaderConfiguration().isManifestOnlyJarRequestedAndUsable();
-
- boolean shadefire = config.isShadefire();
-
- String providerThatHasMainMethod =
- config.isProviderMainClass() ? config.getActualClassName() : ForkedBooter.class.getName();
-
- return createCommandLine( classPath, useJar, shadefire, providerThatHasMainMethod, threadNumber );
- }
-
- OutputStreamFlushableCommandline createCommandLine( List<String> classPath, boolean useJar, boolean shadefire,
- String providerThatHasMainMethod, int threadNumber )
- throws SurefireBooterForkException
- {
- OutputStreamFlushableCommandline cli = new OutputStreamFlushableCommandline();
-
- cli.setExecutable( jdk.getJvmExecutable() );
-
- String jvmArgLine =
- replaceThreadNumberPlaceholder( stripNewLines( replacePropertyExpressions() ), threadNumber );
-
- if ( jdk.isJava9AtLeast() && !jvmArgLine.contains( "--add-modules" ) )
- {
- if ( jvmArgLine.isEmpty() )
- {
- jvmArgLine = "--add-modules java.se.ee";
- }
- else
- {
- jvmArgLine = "--add-modules java.se.ee " + jvmArgLine;
- }
- }
-
- if ( !jvmArgLine.isEmpty() )
- {
- cli.createArg().setLine( jvmArgLine );
- }
-
- for ( Map.Entry<String, String> entry : environmentVariables.entrySet() )
- {
- String value = entry.getValue();
- cli.addEnvironment( entry.getKey(), value == null ? "" : value );
- }
-
- if ( getDebugLine() != null && !getDebugLine().isEmpty() )
- {
- cli.createArg().setLine( getDebugLine() );
- }
-
- if ( useJar )
- {
- try
- {
- File jarFile = createJar( classPath, providerThatHasMainMethod );
- cli.createArg().setValue( "-jar" );
- cli.createArg().setValue( escapeToPlatformPath( jarFile.getAbsolutePath() ) );
- }
- catch ( IOException e )
- {
- throw new SurefireBooterForkException( "Error creating archive file", e );
- }
- }
- else
- {
- cli.addEnvironment( "CLASSPATH", join( classPath.iterator(), File.pathSeparator ) );
-
- final String forkedBooter =
- providerThatHasMainMethod != null ? providerThatHasMainMethod : ForkedBooter.class.getName();
-
- cli.createArg().setValue( shadefire ? new Relocator().relocate( forkedBooter ) : forkedBooter );
- }
-
- cli.setWorkingDirectory( getWorkingDirectory( threadNumber ).getAbsolutePath() );
-
- return cli;
- }
-
- private File getWorkingDirectory( int threadNumber )
- throws SurefireBooterForkException
- {
- File cwd = new File( replaceThreadNumberPlaceholder( workingDirectory.getAbsolutePath(), threadNumber ) );
- if ( !cwd.exists() && !cwd.mkdirs() )
- {
- throw new SurefireBooterForkException( "Cannot create workingDirectory " + cwd.getAbsolutePath() );
- }
- if ( !cwd.isDirectory() )
- {
- throw new SurefireBooterForkException(
- "WorkingDirectory " + cwd.getAbsolutePath() + " exists and is not a directory" );
- }
- return cwd;
- }
-
- private String replaceThreadNumberPlaceholder( String argLine, int threadNumber )
- {
- return argLine.replace( AbstractSurefireMojo.THREAD_NUMBER_PLACEHOLDER,
- String.valueOf( threadNumber ) ).replace( AbstractSurefireMojo.FORK_NUMBER_PLACEHOLDER,
- String.valueOf( threadNumber ) );
- }
-
- /**
- * Replaces expressions <pre>@{property-name}</pre> with the corresponding properties
- * from the model. This allows late evaluation of property values when the plugin is executed (as compared
- * to evaluation when the pom is parsed as is done with <pre>${property-name}</pre> expressions).
- *
- * This allows other plugins to modify or set properties with the changes getting picked up by surefire.
- */
- private String replacePropertyExpressions()
- {
- if ( argLine == null )
- {
- return "";
- }
-
- String resolvedArgLine = argLine.trim();
-
- if ( resolvedArgLine.isEmpty() )
- {
- return "";
- }
-
- for ( final String key : modelProperties.stringPropertyNames() )
- {
- String field = "@{" + key + "}";
- if ( argLine.contains( field ) )
- {
- resolvedArgLine = resolvedArgLine.replace( field, modelProperties.getProperty( key, "" ) );
- }
- }
-
- return resolvedArgLine;
- }
-
- /**
- * Create a jar with just a manifest containing a Main-Class entry for BooterConfiguration and a Class-Path entry
- * for all classpath elements.
- *
- * @param classPath List<String> of all classpath elements.
- * @param startClassName The classname to start (main-class)
- * @return The file pointint to the jar
- * @throws java.io.IOException When a file operation fails.
- */
- private File createJar( List<String> classPath, String startClassName )
- throws IOException
- {
- File file = File.createTempFile( "surefirebooter", ".jar", tempDirectory );
- if ( !debug )
- {
- file.deleteOnExit();
- }
- FileOutputStream fos = new FileOutputStream( file );
- JarOutputStream jos = new JarOutputStream( fos );
- try
- {
- jos.setLevel( JarOutputStream.STORED );
- JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" );
- jos.putNextEntry( je );
-
- Manifest man = new Manifest();
-
- // we can't use StringUtils.join here since we need to add a '/' to
- // the end of directory entries - otherwise the jvm will ignore them.
- StringBuilder cp = new StringBuilder();
- for ( Iterator<String> it = classPath.iterator(); it.hasNext(); )
- {
- File file1 = new File( it.next() );
- String uri = file1.toURI().toASCIIString();
- cp.append( uri );
- if ( file1.isDirectory() && !uri.endsWith( "/" ) )
- {
- cp.append( '/' );
- }
-
- if ( it.hasNext() )
- {
- cp.append( ' ' );
- }
- }
-
- man.getMainAttributes().putValue( "Manifest-Version", "1.0" );
- man.getMainAttributes().putValue( "Class-Path", cp.toString().trim() );
- man.getMainAttributes().putValue( "Main-Class", startClassName );
-
- man.write( jos );
-
- jos.closeEntry();
- jos.flush();
-
- return file;
- }
- finally
- {
- jos.close();
- }
- }
-
- public boolean isDebug()
- {
- return debug;
- }
-
- public String getDebugLine()
- {
- return debugLine;
- }
-
- public File getTempDirectory()
- {
- return tempDirectory;
- }
-
- public int getForkCount()
- {
- return forkCount;
- }
-
- public boolean isReuseForks()
- {
- return reuseForks;
- }
-
- public Platform getPluginPlatform()
- {
- return pluginPlatform;
- }
-
- private static String stripNewLines( String argLine )
- {
- return argLine.replace( "\n", " " ).replace( "\r", " " );
- }
-
- /**
- * Immutable map.
- *
- * @param map immutable map copies elements from <code>map</code>
- * @param <K> key type
- * @param <V> value type
- * @return never returns null
- */
- private static <K, V> Map<K, V> toImmutable( Map<K, V> map )
- {
- return map == null ? Collections.<K, V>emptyMap() : new ImmutableMap<K, V>( map );
- }
+ @Nonnull
+ public abstract OutputStreamFlushableCommandline createCommandLine( @Nonnull StartupConfiguration config,
+ int forkNumber )
+ throws SurefireBooterForkException;
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
index 3efbd57..e0d5ece 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
@@ -35,8 +35,7 @@ import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
import org.apache.maven.shared.utils.cli.CommandLineCallable;
import org.apache.maven.shared.utils.cli.CommandLineException;
-import org.apache.maven.surefire.booter.Classpath;
-import org.apache.maven.surefire.booter.ClasspathConfiguration;
+import org.apache.maven.surefire.booter.AbstractPathConfiguration;
import org.apache.maven.surefire.booter.KeyValueSource;
import org.apache.maven.surefire.booter.PropertiesWrapper;
import org.apache.maven.surefire.booter.ProviderConfiguration;
@@ -88,7 +87,6 @@ import static org.apache.maven.plugin.surefire.booterclient.lazytestprovider.Tes
import static org.apache.maven.shared.utils.cli.CommandLineUtils.executeCommandLineAsCallable;
import static org.apache.maven.shared.utils.cli.ShutdownHookUtils.addShutDownHook;
import static org.apache.maven.shared.utils.cli.ShutdownHookUtils.removeShutdownHook;
-import static org.apache.maven.surefire.booter.Classpath.join;
import static org.apache.maven.surefire.booter.SystemPropertyManager.writePropertiesFile;
import static org.apache.maven.surefire.suite.RunResult.SUCCESS;
import static org.apache.maven.surefire.suite.RunResult.failure;
@@ -553,13 +551,11 @@ public class ForkStarter
{
tempDir = forkConfiguration.getTempDirectory().getCanonicalPath();
BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
-
+ Long pluginPid = forkConfiguration.getPluginPlatform().getPluginPid();
surefireProperties = booterSerializer.serialize( providerProperties, providerConfiguration,
- startupConfiguration, testSet,
- readTestsFromInStream,
- forkConfiguration.getPluginPlatform().getPid() );
+ startupConfiguration, testSet, readTestsFromInStream, pluginPid );
- log.debug( "Determined Maven Process ID " + forkConfiguration.getPluginPlatform().getPid() );
+ log.debug( "Determined Maven Process ID " + pluginPid );
if ( effectiveSystemProperties != null )
{
@@ -580,20 +576,9 @@ public class ForkStarter
throw new SurefireBooterForkException( "Error creating properties files for forking", e );
}
- // this could probably be simplified further
- final Classpath bootClasspathConfiguration = startupConfiguration.isProviderMainClass()
- ? startupConfiguration.getClasspathConfiguration().getProviderClasspath()
- : forkConfiguration.getBootClasspath();
-
- Classpath bootClasspath = join(
- join( bootClasspathConfiguration, startupConfiguration.getClasspathConfiguration().getTestClasspath() ),
- startupConfiguration.getClasspathConfiguration().getProviderClasspath() );
- log.debug( bootClasspath.getLogMessage( "boot" ) );
- log.debug( bootClasspath.getCompactLogMessage( "boot(compact)" ) );
- OutputStreamFlushableCommandline cli =
- forkConfiguration.createCommandLine( bootClasspath.getClassPath(), startupConfiguration, forkNumber );
+ OutputStreamFlushableCommandline cli = forkConfiguration.createCommandLine( startupConfiguration, forkNumber );
if ( testProvidingInputStream != null )
{
@@ -702,7 +687,7 @@ public class ForkStarter
{
try
{
- final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
+ AbstractPathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
ClassLoader unifiedClassLoader = classpathConfiguration.createMergedClassLoader();
CommonReflector commonReflector = new CommonReflector( unifiedClassLoader );
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/135a1cfc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
new file mode 100644
index 0000000..0c19cdf
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
@@ -0,0 +1,139 @@
+package org.apache.maven.plugin.surefire.booterclient;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
+import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.StartupConfiguration;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+
+import javax.annotation.Nonnull;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPath;
+
+/**
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.21.0.Jigsaw
+ */
+public final class JarManifestForkConfiguration
+ extends AbstractClasspathForkConfiguration
+{
+ @SuppressWarnings( "checkstyle:parameternumber" )
+ public JarManifestForkConfiguration( Classpath bootClasspath, File tempDirectory, String debugLine,
+ File workingDirectory, Properties modelProperties, String argLine,
+ Map<String, String> environmentVariables, boolean debug, int forkCount,
+ boolean reuseForks, Platform pluginPlatform, ConsoleLogger log )
+ {
+ super( bootClasspath, tempDirectory, debugLine, workingDirectory, modelProperties, argLine,
+ environmentVariables, debug, forkCount, reuseForks, pluginPlatform, log );
+ }
+
+ @Override
+ protected void resolveClasspath( OutputStreamFlushableCommandline cli, String booterThatHasMainMethod,
+ StartupConfiguration config )
+ throws SurefireBooterForkException
+ {
+ try
+ {
+ File jar = createJar( toCompleteClasspath( config ), booterThatHasMainMethod );
+ cli.createArg().setValue( "-jar" );
+ cli.createArg().setValue( escapeToPlatformPath( jar.getAbsolutePath() ) );
+ }
+ catch ( IOException e )
+ {
+ throw new SurefireBooterForkException( "Error creating archive file", e );
+ }
+ }
+
+ /**
+ * Create a jar with just a manifest containing a Main-Class entry for BooterConfiguration and a Class-Path entry
+ * for all classpath elements.
+ *
+ * @param classPath List<String> of all classpath elements.
+ * @param startClassName The class name to start (main-class)
+ * @return file of the jar
+ * @throws IOException When a file operation fails.
+ */
+ @Nonnull
+ private File createJar( @Nonnull List<String> classPath, @Nonnull String startClassName )
+ throws IOException
+ {
+ File file = File.createTempFile( "surefirebooter", ".jar", getTempDirectory() );
+ if ( !isDebug() )
+ {
+ file.deleteOnExit();
+ }
+ FileOutputStream fos = new FileOutputStream( file );
+ JarOutputStream jos = new JarOutputStream( fos );
+ try
+ {
+ jos.setLevel( JarOutputStream.STORED );
+ JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" );
+ jos.putNextEntry( je );
+
+ Manifest man = new Manifest();
+
+ // we can't use StringUtils.join here since we need to add a '/' to
+ // the end of directory entries - otherwise the jvm will ignore them.
+ StringBuilder cp = new StringBuilder();
+ for ( Iterator<String> it = classPath.iterator(); it.hasNext(); )
+ {
+ File file1 = new File( it.next() );
+ String uri = file1.toURI().toASCIIString();
+ cp.append( uri );
+ if ( file1.isDirectory() && !uri.endsWith( "/" ) )
+ {
+ cp.append( '/' );
+ }
+
+ if ( it.hasNext() )
+ {
+ cp.append( ' ' );
+ }
+ }
+
+ man.getMainAttributes().putValue( "Manifest-Version", "1.0" );
+ man.getMainAttributes().putValue( "Class-Path", cp.toString().trim() );
+ man.getMainAttributes().putValue( "Main-Class", startClassName );
+
+ man.write( jos );
+
+ jos.closeEntry();
+ jos.flush();
+
+ return file;
+ }
+ finally
+ {
+ jos.close();
+ }
+ }
+}