You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2012/08/20 18:54:42 UTC
svn commit: r1375103 - in /maven/surefire/trunk:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/
maven-surefire-common/src/test/java/org/apache/mav...
Author: krosenvold
Date: Mon Aug 20 16:54:41 2012
New Revision: 1375103
URL: http://svn.apache.org/viewvc?rev=1375103&view=rev
Log:
o Consolidated the properties implementations, introduced readonly KeyValueSource
Added:
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
- copied, changed from r1374642, maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/OrderedPropertiesTest.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/KeyValueSource.java
Removed:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/OrderedProperties.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/OrderedPropertiesTest.java
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=1375103&r1=1375102&r2=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java Mon Aug 20 16:54:41 2012
@@ -603,7 +603,7 @@ public abstract class AbstractSurefireMo
boolean verifyParameters()
throws MojoFailureException, MojoExecutionException
{
- setProperties( new OrderedProperties( getProperties() ) );
+ setProperties( new SurefireProperties( getProperties() ) );
if ( isSkipExecution() )
{
getLog().info( "Tests are skipped." );
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java?rev=1375103&r1=1375102&r2=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java Mon Aug 20 16:54:41 2012
@@ -1,5 +1,4 @@
package org.apache.maven.plugin.surefire;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,21 +18,119 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.surefire.booter.KeyValueSource;
/**
- * A wrapper around java.util.Properties providing surefire-specific helper stuff
+ * A properties implementation that preserves insertion order.
*/
public class SurefireProperties
- extends Properties
+ extends Properties implements KeyValueSource
{
+ private final LinkedHashSet<Object> items = new LinkedHashSet<Object>();
+
+ public SurefireProperties()
+ {
+ }
+
+ public SurefireProperties( Properties source )
+ {
+ if ( source != null )
+ {
+ this.putAll( source );
+ }
+ }
+
+ @Override
+ public synchronized Object put( Object key, Object value )
+ {
+ items.add( key );
+ return super.put( key, value );
+ }
+
+ @Override
+ public synchronized Object remove( Object key )
+ {
+ items.remove( key );
+ return super.remove( key );
+ }
+
+ @Override
+ public synchronized void clear()
+ {
+ items.clear();
+ super.clear();
+ }
+
+ public synchronized Enumeration<Object> keys()
+ {
+ return Collections.enumeration( items );
+ }
+
+ public void copyProperties( Properties source )
+ {
+ if ( source != null )
+ {
+ //noinspection unchecked
+ for ( Object key : source.keySet() )
+ {
+ Object value = source.get( key );
+ put( key, value );
+ }
+ }
+ }
+
+ private Iterable<Object> getStringKeySet()
+ {
+
+ //noinspection unchecked
+ return keySet();
+ }
+
+ public void showToLog( org.apache.maven.plugin.logging.Log log, String setting )
+ {
+ for ( Object key : getStringKeySet() )
+ {
+ String value = getProperty( (String) key );
+ log.debug( "Setting " + setting + " [" + key + "]=[" + value + "]" );
+ }
+ }
+
+ public void verifyLegalSystemProperties( org.apache.maven.plugin.logging.Log log )
+ {
+ for ( Object key : getStringKeySet() )
+ {
+ if ( "java.library.path".equals( key ) )
+ {
+ log.warn(
+ "java.library.path cannot be set as system property, use <argLine>-Djava.library.path=...<argLine> instead" );
+ }
+ }
+ }
+
+
+ public void copyToSystemProperties()
+ {
+
+ //noinspection unchecked
+ for ( Object o : items )
+ {
+ String key = (String) o;
+ String value = getProperty( key );
+
+ System.setProperty( key, value );
+ }
+ }
static SurefireProperties calculateEffectiveProperties( Properties systemProperties, File systemPropertiesFile,
Map<String, String> systemPropertyVariables,
@@ -44,7 +141,7 @@ public class SurefireProperties
if ( systemPropertiesFile != null )
{
- Properties props = new OrderedProperties();
+ Properties props = new SurefireProperties();
try
{
InputStream fis = new FileInputStream( systemPropertiesFile );
@@ -79,19 +176,6 @@ public class SurefireProperties
return result;
}
- public void copyProperties( Properties source )
- {
- if ( source != null )
- {
- //noinspection unchecked
- for ( Object key : source.keySet() )
- {
- Object value = source.get( key );
- put( key, value );
- }
- }
- }
-
public static void copyProperties( Properties target, Map<String, String> source )
{
if ( source != null )
@@ -108,44 +192,14 @@ public class SurefireProperties
}
}
- public void copyToSystemProperties()
+ public void copyTo( Map target )
{
-
- //noinspection unchecked
- for ( Object o : getStringKeySet() )
- {
- String key = (String) o;
- String value = getProperty( key );
-
- System.setProperty( key, value );
- }
- }
-
- public void showToLog( org.apache.maven.plugin.logging.Log log, String setting )
- {
- for ( Object key : getStringKeySet() )
- {
- String value = getProperty( (String) key );
- log.debug( "Setting " + setting + " [" + key + "]=[" + value + "]" );
- }
- }
-
- private Iterable<Object> getStringKeySet()
- {
-
- //noinspection unchecked
- return keySet();
- }
-
- public void verifyLegalSystemProperties( org.apache.maven.plugin.logging.Log log )
- {
- for ( Object key : getStringKeySet() )
- {
- if ( "java.library.path".equals( key ) )
- {
- log.warn(
- "java.library.path cannot be set as system property, use <argLine>-Djava.library.path=...<argLine> instead" );
- }
+ Iterator iter = keySet().iterator();
+ Object key;
+ while(iter.hasNext()){
+ key = iter.next();
+ //noinspection unchecked
+ target.put( key, get( key ));
}
}
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java?rev=1375103&r1=1375102&r2=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java Mon Aug 20 16:54:41 2012
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.util.Properties;
import org.apache.maven.surefire.booter.BooterConstants;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
+import org.apache.maven.surefire.booter.KeyValueSource;
import org.apache.maven.surefire.booter.PropertiesWrapper;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
@@ -64,13 +65,13 @@ class BooterSerializer
/*
DOes not modify sourceProperties
*/
- public File serialize(Properties sourceProperties, ProviderConfiguration booterConfiguration, StartupConfiguration providerConfiguration,
+ public File serialize(KeyValueSource sourceProperties, ProviderConfiguration booterConfiguration, StartupConfiguration providerConfiguration,
Object testSet)
throws IOException
{
PropertiesWrapper properties = new PropertiesWrapper(new Properties( ) );
- properties.getProperties().putAll( sourceProperties );
+ sourceProperties.copyTo( properties.getProperties() );
providerConfiguration.getClasspathConfiguration().addForkProperties( properties );
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1375103&r1=1375102&r2=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java Mon Aug 20 16:54:41 2012
@@ -32,13 +32,15 @@ import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.maven.plugin.surefire.CommonReflector;
-import org.apache.maven.plugin.surefire.StartupReportConfiguration;
import org.apache.maven.plugin.surefire.SurefireProperties;
+import org.apache.maven.plugin.surefire.StartupReportConfiguration;
import org.apache.maven.plugin.surefire.booterclient.output.ForkClient;
import org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer;
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
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.PropertiesWrapper;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.ProviderFactory;
import org.apache.maven.surefire.booter.StartupConfiguration;
@@ -111,7 +113,7 @@ public class ForkStarter
{
final ForkClient forkClient =
new ForkClient( fileReporterFactory, startupReportConfiguration.getTestVmSystemProperties() );
- result = fork( null, providerProperties, forkClient, fileReporterFactory.getGlobalRunStatistics(),
+ result = fork( null, new PropertiesWrapper( providerProperties), forkClient, fileReporterFactory.getGlobalRunStatistics(),
effectiveSystemProperties );
}
else if ( ForkConfiguration.FORK_ALWAYS.equals( requestedForkMode ) )
@@ -158,7 +160,7 @@ public class ForkStarter
public RunResult call()
throws Exception
{
- return fork( testSet, properties, forkClient,
+ return fork( testSet, new PropertiesWrapper( properties), forkClient,
fileReporterFactory.getGlobalRunStatistics(),
effectiveSystemProperties );
}
@@ -216,7 +218,7 @@ public class ForkStarter
}
- private RunResult fork( Object testSet, Properties providerProperties, ForkClient forkClient,
+ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkClient forkClient,
RunStatistics globalRunStatistics, SurefireProperties effectiveSystemProperties )
throws SurefireBooterForkException
{
Copied: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java (from r1374642, maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/OrderedPropertiesTest.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java?p2=maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java&p1=maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/OrderedPropertiesTest.java&r1=1374642&r2=1375103&rev=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/OrderedPropertiesTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java Mon Aug 20 16:54:41 2012
@@ -26,14 +26,14 @@ import junit.framework.TestCase;
/**
* Tests the insertion-order preserving properties collection
*/
-public class OrderedPropertiesTest
+public class SurefirePropertiesTest
extends TestCase
{
public void testKeys()
throws Exception
{
- OrderedProperties orderedProperties = new OrderedProperties( null );
+ SurefireProperties orderedProperties = new SurefireProperties( null );
orderedProperties.setProperty( "abc", "1" );
orderedProperties.setProperty( "xyz", "1" );
orderedProperties.setProperty( "efg", "1" );
@@ -48,7 +48,7 @@ public class OrderedPropertiesTest
public void testKeysReinsert()
throws Exception
{
- OrderedProperties orderedProperties = new OrderedProperties( null );
+ SurefireProperties orderedProperties = new SurefireProperties( null );
orderedProperties.setProperty( "abc", "1" );
orderedProperties.setProperty( "xyz", "1" );
orderedProperties.setProperty( "efg", "1" );
@@ -67,7 +67,7 @@ public class OrderedPropertiesTest
Properties src = new Properties();
src.setProperty( "a", "1" );
src.setProperty( "b", "2" );
- OrderedProperties orderedProperties = new OrderedProperties( src );
+ SurefireProperties orderedProperties = new SurefireProperties( src );
// Cannot make assumptions about insertion order
assertEquals( 2, orderedProperties.size() );
Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java?rev=1375103&r1=1375102&r2=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java Mon Aug 20 16:54:41 2012
@@ -30,6 +30,7 @@ import java.util.Properties;
import org.apache.maven.surefire.booter.BooterDeserializer;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
+import org.apache.maven.surefire.booter.PropertiesWrapper;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
import org.apache.maven.surefire.booter.SystemPropertyManager;
@@ -171,7 +172,7 @@ public class BooterDeserializerProviderC
throws IOException
{
final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( null, null );
- Properties props = new Properties();
+ PropertiesWrapper props = new PropertiesWrapper( new Properties());
BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
String aTest = "aTest";
final File propsTest = booterSerializer.serialize( props, booterConfiguration, testProviderConfiguration, aTest);
Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java?rev=1375103&r1=1375102&r2=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java Mon Aug 20 16:54:41 2012
@@ -127,7 +127,7 @@ public class BooterDeserializerStartupCo
throws IOException
{
final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( null, null );
- Properties props = new Properties();
+ PropertiesWrapper props = new PropertiesWrapper( new Properties());
BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
String aTest = "aTest";
final File propsTest = booterSerializer.serialize( props, getProviderConfiguration(), startupConfiguration, aTest);
Added: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/KeyValueSource.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/KeyValueSource.java?rev=1375103&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/KeyValueSource.java (added)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/KeyValueSource.java Mon Aug 20 16:54:41 2012
@@ -0,0 +1,29 @@
+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.util.Map;
+
+/**
+ * A key-value source obeying the geneal constrains of java.util.Properties
+ */
+public interface KeyValueSource
+{
+ void copyTo( Map target );
+}
Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java?rev=1375103&r1=1375102&r2=1375103&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java Mon Aug 20 16:54:41 2012
@@ -23,6 +23,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.apache.maven.surefire.util.internal.StringUtils;
@@ -30,6 +31,7 @@ import org.apache.maven.surefire.util.in
* @author Kristian Rosenvold
*/
public class PropertiesWrapper
+ implements KeyValueSource
{
private final Properties properties;
@@ -183,4 +185,14 @@ public class PropertiesWrapper
}
}
+ public void copyTo( Map target )
+ {
+ Iterator iter = properties.keySet().iterator();
+ Object key;
+ while ( iter.hasNext() )
+ {
+ key = iter.next();
+ target.put( key, properties.get( key ) );
+ }
+ }
}