Skip to content

Commit

Permalink
[SUREFIRE] Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor17 committed May 6, 2015
1 parent c02be38 commit 84fd723
Show file tree
Hide file tree
Showing 68 changed files with 860 additions and 947 deletions.
Expand Up @@ -20,8 +20,6 @@
*/

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

Expand All @@ -38,8 +36,6 @@
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.surefire.suite.RunResult;

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

/**
* Run integration tests using Surefire.
*
Expand Down Expand Up @@ -310,15 +306,9 @@ protected int getRerunFailingTestsCount()
return rerunFailingTestsCount;
}

@SuppressWarnings( "unchecked" )
protected void handleSummary( RunResult summary, Exception firstForkException )
throws MojoExecutionException, MojoFailureException
{
writeSummary( summary, firstForkException );
}

@SuppressWarnings( "unchecked" )
private void writeSummary( RunResult summary, Exception firstForkException )
throws MojoExecutionException
{
File summaryFile = getSummaryFile();
if ( !summaryFile.getParentFile().isDirectory() )
Expand All @@ -327,8 +317,6 @@ private void writeSummary( RunResult summary, Exception firstForkException )
summaryFile.getParentFile().mkdirs();
}

FileOutputStream fout = null;
FileInputStream fin = null;
try
{
Object token = getPluginContext().get( FAILSAFE_IN_PROGRESS_CONTEXT_KEY );
Expand All @@ -338,11 +326,6 @@ private void writeSummary( RunResult summary, Exception firstForkException )
{
throw new MojoExecutionException( e.getMessage(), e );
}
finally
{
close( fin );
close( fout );
}

getPluginContext().put( FAILSAFE_IN_PROGRESS_CONTEXT_KEY, FAILSAFE_IN_PROGRESS_CONTEXT_KEY );
}
Expand Down Expand Up @@ -606,7 +589,7 @@ public Boolean getFailIfNoSpecifiedTests()
return failIfNoSpecifiedTests;
}

public void setFailIfNoSpecifiedTests( Boolean failIfNoSpecifiedTests )
public void setFailIfNoSpecifiedTests( boolean failIfNoSpecifiedTests )
{
this.failIfNoSpecifiedTests = failIfNoSpecifiedTests;
}
Expand Down
Expand Up @@ -334,7 +334,7 @@ public Boolean getFailIfNoTests()
return failIfNoTests;
}

public void setFailIfNoTests( Boolean failIfNoTests )
public void setFailIfNoTests( boolean failIfNoTests )
{
this.failIfNoTests = failIfNoTests;
}
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
Expand All @@ -35,6 +36,7 @@
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
Expand Down Expand Up @@ -1442,7 +1444,7 @@ private ProviderConfiguration createProviderConfiguration( RunOrderParameters ru
specificTests, actualFailIfNoTests, getRunOrder() );
}

Properties providerProperties = getProperties();
Map<String, String> providerProperties = toStringProperties( getProperties() );

return new ProviderConfiguration( directoryScannerParameters, runOrderParameters, actualFailIfNoTests,
reporterConfiguration,
Expand All @@ -1451,6 +1453,21 @@ private ProviderConfiguration createProviderConfiguration( RunOrderParameters ru
false );
}

private static Map<String, String> toStringProperties( Properties properties )
{
Map<String, String> h = new ConcurrentHashMap<String, String>( properties.size() );
for ( Enumeration e = properties.keys() ; e.hasMoreElements() ; )
{
Object k = e.nextElement();
Object v = properties.get( k );
if ( k.getClass() == String.class && v.getClass() == String.class )
{
h.put( (String) k, (String) v );
}
}
return h;
}

public String getStatisticsFileName( String configurationHash )
{
return getReportsDirectory().getParentFile().getParentFile() + File.separator + ".surefire-"
Expand Down Expand Up @@ -2587,7 +2604,7 @@ public void setSystemPropertiesFile( File systemPropertiesFile )
this.systemPropertiesFile = systemPropertiesFile;
}

public Properties getProperties()
private Properties getProperties()
{
return properties;
}
Expand Down Expand Up @@ -2649,7 +2666,7 @@ public Boolean getFailIfNoTests()
return failIfNoTests;
}

public void setFailIfNoTests( Boolean failIfNoTests )
public void setFailIfNoTests( boolean failIfNoTests )
{
this.failIfNoTests = failIfNoTests;
}
Expand Down
Expand Up @@ -19,8 +19,6 @@
* under the License.
*/

import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.ProviderFactory;
import org.apache.maven.surefire.booter.StartupConfiguration;
Expand All @@ -30,6 +28,8 @@
import org.apache.maven.surefire.util.DefaultScanResult;

import javax.annotation.Nonnull;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
* Starts the provider in the same VM as the surefire plugin.
Expand Down Expand Up @@ -67,7 +67,7 @@ public RunResult runSuitesInProcess( @Nonnull DefaultScanResult scanResult )
// The test classloader must be constructed first to avoid issues with commons-logging until we properly
// separate the TestNG classloader

Properties providerProperties = providerConfiguration.getProviderProperties();
Map<String, String> providerProperties = providerConfiguration.getProviderProperties();
scanResult.writeTo( providerProperties );

startupConfiguration.writeSurefireTestClasspathProperty();
Expand Down
Expand Up @@ -51,7 +51,7 @@ public ProviderList( ConfigurableProviderInfo dynamicProviderInfo, ProviderInfo.
List<ProviderInfo> providersToRun = new ArrayList<ProviderInfo>();

Set<String> manuallyConfiguredProviders = getManuallyConfiguredProviders();
if ( manuallyConfiguredProviders.size() > 0 )
if ( !manuallyConfiguredProviders.isEmpty() )
{
for ( String name : manuallyConfiguredProviders )
{
Expand Down
Expand Up @@ -117,5 +117,5 @@ public interface SurefireExecutionParameters

Boolean getFailIfNoSpecifiedTests();

void setFailIfNoSpecifiedTests( Boolean failIfNoSpecifiedTests );
void setFailIfNoSpecifiedTests( boolean failIfNoSpecifiedTests );
}
Expand Up @@ -27,7 +27,6 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -108,7 +107,6 @@ public void copyPropertiesFrom( Properties source )

public Iterable<Object> getStringKeySet()
{

//noinspection unchecked
return keySet();
}
Expand Down Expand Up @@ -176,16 +174,9 @@ public static void copyProperties( Properties target, Map<String, String> source
}
}

public void copyTo( Map target )
public void copyTo( Map<Object, Object> target )
{
Iterator iter = keySet().iterator();
Object key;
while ( iter.hasNext() )
{
key = iter.next();
//noinspection unchecked
target.put( key, get( key ) );
}
target.putAll( this );
}

public void setProperty( String key, File file )
Expand All @@ -206,7 +197,7 @@ public void setProperty( String key, Boolean aBoolean )

public void addList( List items, String propertyPrefix )
{
if ( items == null || items.size() == 0 )
if ( items == null || items.isEmpty() )
{
return;
}
Expand Down
Expand Up @@ -59,5 +59,5 @@ public interface SurefireReportParameters

Boolean getFailIfNoTests();

void setFailIfNoTests( Boolean failIfNoTests );
void setFailIfNoTests( boolean failIfNoTests );
}
Expand Up @@ -125,7 +125,7 @@ public File serialize( KeyValueSource sourceProperties, ProviderConfiguration bo

ReporterConfiguration reporterConfiguration = booterConfiguration.getReporterConfiguration();

Boolean rep = reporterConfiguration.isTrimStackTrace();
boolean rep = reporterConfiguration.isTrimStackTrace();
properties.setProperty( BooterConstants.ISTRIMSTACKTRACE, rep );
properties.setProperty( BooterConstants.REPORTSDIRECTORY, reporterConfiguration.getReportsDirectory() );
ClassLoaderConfiguration classLoaderConfiguration = providerConfiguration.getClassLoaderConfiguration();
Expand Down
Expand Up @@ -45,7 +45,7 @@ private void appendObject( Object item )

public void add( boolean value )
{
checksumItems.add( value ? Boolean.TRUE : Boolean.FALSE );
checksumItems.add( value );
}

public void add( int value )
Expand Down
Expand Up @@ -19,27 +19,6 @@
* under the License.
*/

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
import org.apache.maven.plugin.surefire.CommonReflector;
Expand Down Expand Up @@ -71,6 +50,27 @@
import org.apache.maven.surefire.util.DefaultScanResult;
import org.apache.maven.surefire.util.internal.StringUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicReference;

import static org.apache.maven.surefire.booter.Classpath.join;

/**
Expand Down Expand Up @@ -157,7 +157,7 @@ public RunResult run( SurefireProperties effectiveSystemProperties, DefaultScanR
{
try
{
Properties providerProperties = providerConfiguration.getProviderProperties();
Map<String, String> providerProperties = providerConfiguration.getProviderProperties();
scanResult.writeTo( providerProperties );
return isForkOnce()
? run( effectiveSystemProperties, providerProperties )
Expand All @@ -170,7 +170,7 @@ public RunResult run( SurefireProperties effectiveSystemProperties, DefaultScanR
}
}

private RunResult run( SurefireProperties effectiveSystemProperties, Properties providerProperties )
private RunResult run( SurefireProperties effectiveSystemProperties, Map<String, String> providerProperties )
throws SurefireBooterForkException
{
DefaultReporterFactory forkedReporterFactory = new DefaultReporterFactory( startupReportConfiguration );
Expand Down Expand Up @@ -215,8 +215,7 @@ private RunResult runSuitesForkOnceMultiple( final SurefireProperties effectiveS
RunResult globalResult = new RunResult( 0, 0, 0, 0 );

List<Class<?>> suites = new ArrayList<Class<?>>();
Iterator<Class<?>> suitesIterator = getSuitesIterator();
while ( suitesIterator.hasNext() )
for ( Iterator<Class<?>> suitesIterator = getSuitesIterator(); suitesIterator.hasNext(); )
{
suites.add( suitesIterator.next() );
}
Expand Down Expand Up @@ -298,8 +297,8 @@ private RunResult runSuitesForkPerTestSet( final SurefireProperties effectiveSys
{
// Ask to the executorService to run all tasks
RunResult globalResult = new RunResult( 0, 0, 0, 0 );
final Iterator<Class<?>> suites = getSuitesIterator();
while ( suites.hasNext() )

for ( final Iterator<Class<?>> suites = getSuitesIterator(); suites.hasNext(); )
{
final Object testSet = suites.next();
Callable<RunResult> pf = new Callable<RunResult>()
Expand Down
Expand Up @@ -141,7 +141,7 @@ public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStat
{
throw new IllegalStateException( "Get null test method run history" );
}
if ( methodEntryList.size() == 0 )
if ( methodEntryList.isEmpty() )
{
continue;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ private int getRunTimeForAllTests( Map<String, List<WrappedReportEntry>> methodR
{
throw new IllegalStateException( "Get null test method run history" );
}
if ( methodEntryList.size() == 0 )
if ( methodEntryList.isEmpty() )
{
continue;
}
Expand Down

0 comments on commit 84fd723

Please sign in to comment.