Skip to content

Commit

Permalink
[SUREFIRE-1654] Remove deprecated forkMode parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBaars authored and slawekjaranowski committed Dec 20, 2022
1 parent 7ab8264 commit 80adc4f
Show file tree
Hide file tree
Showing 117 changed files with 312 additions and 691 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ 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();
Expand Down Expand Up @@ -362,23 +358,6 @@ public abstract class AbstractSurefireMojo
@Parameter( property = "failIfNoTests", defaultValue = "false" )
private boolean failIfNoTests;

/**
* <strong>DEPRECATED</strong> since version 2.14. Use {@code forkCount} and {@code reuseForks} instead.
* <br>
* <br>
* Option to specify the forking mode. Can be {@code never}, {@code once}, {@code always}, {@code perthread}.<br>
* The {@code none} and {@code pertest} are also accepted for backwards compatibility.<br>
* The {@code always} forks for each test-class.<br>
* The {@code perthread} creates the number of parallel forks specified by {@code threadCount}, where each forked
* JVM is executing one test-class. See also the parameter {@code reuseForks} for the lifetime of JVM.
*
* @since 2.1
* @deprecated
*/
@Deprecated
@Parameter( property = "forkMode", defaultValue = "once" )
private String forkMode;

/**
* Relative path to <i>temporary-surefire-boot</i> directory containing internal Surefire temporary files.
* <br>
Expand Down Expand Up @@ -440,7 +419,7 @@ public abstract class AbstractSurefireMojo

/**
* When false it makes tests run using the standard classloader delegation instead of the default Maven isolated
* classloader. Only used when forking ({@code forkMode} is not {@code none}).<br>
* classloader. Only used when forking ({@code forkCount} is greater than zero).<br>
* Setting it to false helps with some problems caused by conflicts between xml parsers in the classpath and the
* Java 5 provider parser.
*
Expand Down Expand Up @@ -1123,10 +1102,8 @@ boolean verifyParameters()
else
{
ensureEnableProcessChecker();
convertDeprecatedForkMode();
ensureWorkingDirectoryExists();
ensureParallelRunningCompatibility();
ensureThreadCountWithPerThread();
warnIfUselessUseSystemClassLoaderParameter();
warnIfDefunctGroupsCombinations();
warnIfRerunClashes();
Expand Down Expand Up @@ -1796,28 +1773,11 @@ private boolean isAnyJunit4( Artifact artifact )
return isWithinVersionSpec( artifact, "[4.0,)" );
}

private static boolean isForkModeNever( String forkMode )
{
return FORK_NEVER.equals( forkMode );
}

protected boolean isForking()
{
return 0 < getEffectiveForkCount();
}

String getEffectiveForkMode()
{
String forkMode1 = getForkMode();

if ( toolchain != null && isForkModeNever( forkMode1 ) )
{
return FORK_ONCE;
}

return getEffectiveForkMode( forkMode1 );
}

private List<RunOrder> getRunOrders()
{
String runOrderString = getRunOrder();
Expand Down Expand Up @@ -2144,7 +2104,7 @@ private Artifact getShadefireArtifact()
return getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-shadefire" );
}

private StartupReportConfiguration getStartupReportConfiguration( String configChecksum, boolean isForkMode )
private StartupReportConfiguration getStartupReportConfiguration( String configChecksum, boolean isForking )
{
SurefireStatelessReporter xmlReporter =
statelessTestsetReporter == null
Expand All @@ -2165,7 +2125,7 @@ private StartupReportConfiguration getStartupReportConfiguration( String configC
getReportsDirectory(), isTrimStackTrace(), getReportNameSuffix(),
getStatisticsFile( configChecksum ), requiresRunHistory(),
getRerunFailingTestsCount(), getReportSchemaLocation(), getEncoding(),
isForkMode, xmlReporter, outReporter, testsetReporter );
isForking, xmlReporter, outReporter, testsetReporter );
}

private boolean isSpecificTestSpecified()
Expand Down Expand Up @@ -2557,31 +2517,6 @@ private void ensureEnableProcessChecker() throws MojoFailureException
}
}

private void convertDeprecatedForkMode()
{
String effectiveForkMode = getEffectiveForkMode();
// FORK_ONCE (default) is represented by the default values of forkCount and reuseForks
if ( FORK_PERTHREAD.equals( effectiveForkMode ) )
{
forkCount = String.valueOf( threadCount );
}
else if ( FORK_NEVER.equals( effectiveForkMode ) )
{
forkCount = "0";
}
else if ( FORK_ALWAYS.equals( effectiveForkMode ) )
{
forkCount = "1";
reuseForks = false;
}

if ( !FORK_ONCE.equals( getForkMode() ) )
{
getConsoleLogger().warning( "The parameter forkMode is deprecated since version 2.14. "
+ "Use forkCount and reuseForks instead." );
}
}

@SuppressWarnings( "checkstyle:emptyblock" )
protected int getEffectiveForkCount()
{
Expand Down Expand Up @@ -2764,7 +2699,6 @@ private String getConfigChecksum()
checksum.add( getReportNameSuffix() );
checksum.add( isUseFile() );
checksum.add( isRedirectTestOutputToFile() );
checksum.add( getForkMode() );
checksum.add( getForkCount() );
checksum.add( isReuseForks() );
checksum.add( getJvm() );
Expand Down Expand Up @@ -2973,15 +2907,6 @@ private void ensureParallelRunningCompatibility()
}
}

private void ensureThreadCountWithPerThread()
throws MojoFailureException
{
if ( FORK_PERTHREAD.equals( getEffectiveForkMode() ) && getThreadCount() < 1 )
{
throw new MojoFailureException( "Fork mode perthread requires a thread count" );
}
}

private void warnIfUselessUseSystemClassLoaderParameter()
{
if ( isUseSystemClassLoader() && isNotForking() )
Expand Down Expand Up @@ -3678,17 +3603,6 @@ public void setFailIfNoTests( boolean failIfNoTests )
this.failIfNoTests = failIfNoTests;
}

public String getForkMode()
{
return forkMode;
}

@SuppressWarnings( "UnusedDeclaration" )
public void setForkMode( String forkMode )
{
this.forkMode = forkMode;
}

public String getJvm()
{
return jvm;
Expand Down Expand Up @@ -4099,27 +4013,6 @@ public void setResolutionErrorHandler( ResolutionErrorHandler resolutionErrorHan
this.resolutionErrorHandler = resolutionErrorHandler;
}

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" );
}
}

private static final class ClasspathCache
{
private final Map<String, Classpath> classpaths = new HashMap<>( 4 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private Object createStartupReportConfiguration( @Nonnull StartupReportConfigura
reporterConfiguration.isTrimStackTrace(), reporterConfiguration.getReportNameSuffix(),
reporterConfiguration.getStatisticsFile(), reporterConfiguration.isRequiresRunHistory(),
reporterConfiguration.getRerunFailingTestsCount(), reporterConfiguration.getXsdSchemaLocation(),
reporterConfiguration.getEncoding().name(), reporterConfiguration.isForkMode(),
reporterConfiguration.getEncoding().name(), reporterConfiguration.isForking(),
reporterConfiguration.getXmlReporter().clone( surefireClassLoader ),
reporterConfiguration.getConsoleOutputReporter().clone( surefireClassLoader ),
reporterConfiguration.getTestsetReporter().clone( surefireClassLoader )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public final class StartupReportConfiguration

private final Charset encoding;

private final boolean isForkMode;
private final boolean isForking;

private final SurefireStatelessReporter xmlReporter;

Expand All @@ -99,7 +99,7 @@ public StartupReportConfiguration( boolean useFile, boolean printSummary, String
boolean redirectTestOutputToFile,
@Nonnull File reportsDirectory, boolean trimStackTrace, String reportNameSuffix,
File statisticsFile, boolean requiresRunHistory, int rerunFailingTestsCount,
String xsdSchemaLocation, String encoding, boolean isForkMode,
String xsdSchemaLocation, String encoding, boolean isForking,
SurefireStatelessReporter xmlReporter, SurefireConsoleOutputReporter consoleOutputReporter,
SurefireStatelessTestsetInfoReporter testsetReporter )
{
Expand All @@ -118,7 +118,7 @@ public StartupReportConfiguration( boolean useFile, boolean printSummary, String
this.xsdSchemaLocation = xsdSchemaLocation;
String charset = trimToNull( encoding );
this.encoding = charset == null ? UTF_8 : Charset.forName( charset );
this.isForkMode = isForkMode;
this.isForking = isForking;
this.xmlReporter = xmlReporter;
this.consoleOutputReporter = consoleOutputReporter;
this.testsetReporter = testsetReporter;
Expand Down Expand Up @@ -162,14 +162,14 @@ public int getRerunFailingTestsCount()
public StatelessReportEventListener<WrappedReportEntry, TestSetStats> instantiateStatelessXmlReporter(
Integer forkNumber )
{
assert ( forkNumber == null ) == !isForkMode;
assert ( forkNumber == null ) == !isForking;

// If forking TestNG the suites have same name 'TestSuite' and tend to override report statistics in stateful
// reporter, see Surefire1535TestNGParallelSuitesIT. The testClassMethodRunHistory should be isolated.
// In the in-plugin execution of parallel JUnit4.7 with rerun the map must be shared because reports and
// listeners are in ThreadLocal, see Surefire1122ParallelAndFlakyTestsIT.
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory
= isForkMode
= isForking
? new ConcurrentHashMap<String, Deque<WrappedReportEntry>>()
: this.testClassMethodRunHistory;

Expand Down Expand Up @@ -243,9 +243,9 @@ public Charset getEncoding()
return encoding;
}

public boolean isForkMode()
public boolean isForking()
{
return isForkMode;
return isForking;
}

private File resolveReportsDirectory( Integer forkNumber )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void createReportingReporterFactory()
assertThat( reportConfiguration.getRerunFailingTestsCount() ).isEqualTo( 1 );
assertThat( reportConfiguration.getXsdSchemaLocation() ).isNull();
assertThat( reportConfiguration.getEncoding() ).isEqualTo( UTF_8 );
assertThat( reportConfiguration.isForkMode() ).isFalse();
assertThat( reportConfiguration.isForking() ).isFalse();
assertThat( reportConfiguration.getXmlReporter().toString() )
.isEqualTo( xmlReporter.toString() );
assertThat( reportConfiguration.getTestsetReporter().toString() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.api.util.DefaultScanResult;
import org.apache.maven.surefire.api.util.SureFireFileManager;
import org.apache.maven.toolchain.Toolchain;
import org.codehaus.plexus.logging.Logger;
import org.junit.Test;

Expand Down Expand Up @@ -100,16 +99,6 @@ public void testGetStartupReportConfiguration2() throws Exception
.isSameAs( testsetInfoReporter );
}

@Test
public void testForkMode()
{
AbstractSurefireMojo surefirePlugin = new Mojo( null, null );
setInternalState( surefirePlugin, "toolchain", new MyToolChain() );
setInternalState( surefirePlugin, "forkMode", "never" );
assertThat( surefirePlugin.getEffectiveForkMode() )
.isEqualTo( "once" );
}

@Test
@SuppressWarnings( "checkstyle:magicnumber" )
public void testForkCountComputation()
Expand Down Expand Up @@ -151,21 +140,6 @@ private static void assertConversionFails( AbstractSurefireMojo surefirePlugin,
fail( "Expected NumberFormatException when converting " + value );
}

private static class MyToolChain implements Toolchain
{
@Override
public String getType()
{
return null;
}

@Override
public String findTool( String s )
{
return null;
}
}

@Test
public void scanDependenciesShouldReturnNull()
throws MojoFailureException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void testCreateReporterWithZeroStatistics()
assertEquals( 0, reportConfig.getRerunFailingTestsCount() );
assertNull( reportConfig.getXsdSchemaLocation() );
assertEquals( UTF_8, reportConfig.getEncoding() );
assertFalse( reportConfig.isForkMode() );
assertFalse( reportConfig.isForking() );
assertNotNull( reportConfig.getXmlReporter() );
assertNotNull( reportConfig.getConsoleOutputReporter() );
assertNotNull( reportConfig.getTestsetReporter() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ java -classpath booter.jar MyApp

* Run Maven with <<<--debug>>> (or equivalently, <<<-X>>>) to get more detailed output

* Check your <<<forkCount>>>. If <<<forkCount=0>>> (or <<<forkMode=never>>>, the deprecated version of that), it's impossible to use the system class loader or a plain old Java classpath; we have to use an isolated class loader.
* Check your <<<forkCount>>>. If <<<forkCount=0>>>, it's impossible to use the system class loader or a plain old Java classpath; we have to use an isolated class loader.

* If you're using the defaults, <<<useSystemClassLoader=true>>> and <<<useManifestOnlyJar=false>>>. In that case, look at the generated manifest-only Surefire booter JAR. Open it up (it's just a zip) and read its manifest.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,32 +404,6 @@ public class TestSuite {
properties, e.g. <<<baseDir>>>, which may lead to changing system properties
and unexpected runtime behaviour.

* Migrating the Deprecated forkMode Parameter to forkCount and reuseForks

${thisPlugin.toLowerCase()} versions prior 2.14 used the parameter <<<forkMode>>>
to configure forking. Although that parameter is still supported for backward
compatibility, users are strongly encouraged to migrate their configuration
and use <<<forkCount>>> and <<<reuseForks>>> instead.


The migration is quite simple, given the following mapping:

*--------------------------+-------------------------------------------+
<<Old Setting>> | <<New Setting>> |
*--------------------------+-------------------------------------------+
<<<forkMode=once>>> | <<<forkCount=1>>> (default), |
(default) | <<<reuseForks=true>>> (default) |
*--------------------------+-------------------------------------------+
<<<forkMode=always>>> | <<<forkCount=1>>> (default), |
| <<<reuseForks=false>>> |
*--------------------------+-------------------------------------------+
<<<forkMode=never>>> | <<<forkCount=0>>> |
*--------------------------+-------------------------------------------+
<<<forkMode=perthread>>>, | <<<forkCount=N>>>, |
<<<threadCount=N>>> | (<<<reuseForks=false>>>, if you did not |
| had that one set) |
*--------------------------+-------------------------------------------+

* Known issues and limitations

* <<<$\{surefire.forkNumber\}>>> propagation is not supported on Maven 2.x
Expand Down
1 change: 0 additions & 1 deletion surefire-its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@
<runOrder>alphabetical</runOrder>
<threadCount>1</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
<forkMode>once</forkMode>
<argLine>-server -Xmx64m -XX:+UseG1GC -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Djava.awt.headless=true -Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
<includes>
<include>org/apache/**/*IT*.java</include>
Expand Down

0 comments on commit 80adc4f

Please sign in to comment.