Author: krosenvold Date: Wed Aug 1 20:20:19 2012 New Revision: 1368237 URL: http://svn.apache.org/viewvc?rev=1368237&view=rev Log: o Made the property files written by the fork logic obey insertion order, so they are human readable
This has been annoying me since the beginning of time Added: 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 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=1368237&r1=1368236&r2=1368237&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 Wed Aug 1 20:20:19 2012 @@ -573,6 +573,7 @@ public abstract class AbstractSurefireMo boolean verifyParameters() throws MojoFailureException { + setProperties( new OrderedProperties( getProperties() ) ); if ( isSkipExecution() ) { getLog().info( "Tests are skipped." ); @@ -593,7 +594,6 @@ public abstract class AbstractSurefireMo ensureParallelRunningCompatibility(); warnIfUselessUseSystemClassLoaderParameter(); } - return true; } @@ -642,6 +642,7 @@ public abstract class AbstractSurefireMo { List<ProviderInfo> providers = createProviders(); Summary summary = new Summary(); + for ( ProviderInfo provider : providers ) { executeProvider( provider, summary ); @@ -717,11 +718,6 @@ public abstract class AbstractSurefireMo */ private void convertTestNGParameters() { - if ( getProperties() == null ) // May be predefined from plugin paramaters - { - setProperties( new Properties() ); - } - if ( this.getParallel() != null ) { getProperties().setProperty( ProviderParameterNames.PARALLEL_PROP, this.getParallel() ); @@ -747,10 +743,6 @@ public abstract class AbstractSurefireMo private void convertGroupParameters() { - if ( getProperties() == null ) // May be predefined from plugin paramaters - { - setProperties( new Properties() ); - } if ( this.getExcludedGroups() != null ) { getProperties().setProperty( ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP, this.getExcludedGroups() ); @@ -777,11 +769,6 @@ public abstract class AbstractSurefireMo */ private void convertJunitCoreParameters() { - if ( getProperties() == null ) - { - setProperties( new Properties() ); - } - if ( this.getParallel() != null ) { getProperties().setProperty( ProviderParameterNames.PARALLEL_PROP, this.getParallel() ); @@ -889,10 +876,6 @@ public abstract class AbstractSurefireMo } Properties providerProperties = getProperties(); - if ( providerProperties == null ) - { - providerProperties = new Properties(); - } RunOrderParameters runOrderParameters = new RunOrderParameters( getRunOrder(), getStatisticsFileName( configurationHash ) ); @@ -1338,7 +1321,8 @@ public abstract class AbstractSurefireMo } - protected void addPluginSpecificChecksumItems( ChecksumCalculator checksum ){ + protected void addPluginSpecificChecksumItems( ChecksumCalculator checksum ) + { } @@ -1539,7 +1523,7 @@ public abstract class AbstractSurefireMo if ( this.getSystemPropertiesFile() != null ) { - Properties props = new Properties(); + Properties props = new OrderedProperties(); try { FileInputStream fis = new FileInputStream( getSystemPropertiesFile() ); Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/OrderedProperties.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/OrderedProperties.java?rev=1368237&view=auto ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/OrderedProperties.java (added) +++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/OrderedProperties.java Wed Aug 1 20:20:19 2012 @@ -0,0 +1,69 @@ +package org.apache.maven.plugin.surefire; +/* + * 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.*; + +/** + * A properties implementation that preserves insertion order. + */ +public class OrderedProperties + extends Properties +{ + private final LinkedHashSet<Object> items = new LinkedHashSet<Object>(); + + public OrderedProperties() + { + } + + public OrderedProperties( 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 ); + } + +} Added: 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/OrderedPropertiesTest.java?rev=1368237&view=auto ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/OrderedPropertiesTest.java (added) +++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/OrderedPropertiesTest.java Wed Aug 1 20:20:19 2012 @@ -0,0 +1,70 @@ +package org.apache.maven.plugin.surefire; +/* + * 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 junit.framework.TestCase; + +import java.util.Enumeration; +import java.util.Properties; + +/** + * Tests the insertion-order preserving properties collection + */ +public class OrderedPropertiesTest extends TestCase { + + public void testKeys() throws Exception { + OrderedProperties orderedProperties = new OrderedProperties(null); + orderedProperties.setProperty("abc", "1"); + orderedProperties.setProperty("xyz", "1"); + orderedProperties.setProperty("efg", "1"); + + Enumeration<Object> keys = orderedProperties.keys(); + assertEquals("abc", keys.nextElement()); + assertEquals("xyz", keys.nextElement()); + assertEquals( "efg", keys.nextElement() ); + + } + + public void testKeysReinsert() throws Exception { + OrderedProperties orderedProperties = new OrderedProperties(null); + orderedProperties.setProperty("abc", "1"); + orderedProperties.setProperty("xyz", "1"); + orderedProperties.setProperty("efg", "1"); + orderedProperties.setProperty("abc", "2"); + orderedProperties.remove( "xyz" ); + orderedProperties.setProperty( "xyz", "1" ); + + Enumeration<Object> keys = orderedProperties.keys(); + assertEquals("abc", keys.nextElement()); + assertEquals("efg", keys.nextElement()); + assertEquals("xyz", keys.nextElement()); + } + + public void testConstructWithOther(){ + Properties src = new Properties( ); + src.setProperty( "a" , "1"); + src.setProperty( "b" , "2"); + OrderedProperties orderedProperties = new OrderedProperties(src); + // Cannot make assumptions about insertion order + assertEquals( 2, orderedProperties.size() ); + + + } + +}