maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dant...@apache.org
Subject svn commit: r686454 - in /maven/surefire/trunk: ./ maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/ maven-surefire-plugin/src/site/apt/examples/ surefire-integration-tests/ surefire-integration-tests/src/test/java/org/apache/maven/...
Date Sat, 16 Aug 2008 05:58:03 GMT
Author: dantran
Date: Fri Aug 15 22:58:02 2008
New Revision: 686454

URL: http://svn.apache.org/viewvc?rev=686454&view=rev
Log:
- SUREFIRE-511: Replacement of 'systemProperties' to use Map interface.
- Add partial fix for SUREFIRE-513 to support SUREFIRE-511 ITs
- ignore eclipse workspace folder

Added:
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractSurefireIT.java
Modified:
    maven/surefire/trunk/   (props changed)
    maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
    maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/system-properties.apt
    maven/surefire/trunk/surefire-integration-tests/pom.xml
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractTestCaseTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgSuiteXmlTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-suite-xml/pom.xml

Propchange: maven/surefire/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Aug 15 22:58:02 2008
@@ -4,3 +4,4 @@
 *.iws
 .classpath
 .project
+.metadata

Modified: maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Fri Aug 15 22:58:02 2008
@@ -222,12 +222,20 @@
 
     /**
      * List of System properties to pass to the JUnit tests.
-     * 
+     * @deprecated use systemPropertyVariables instead
      * @parameter
      */
     private Properties systemProperties;
 
     /**
+     * List of System properties to pass to the JUnit tests. 
+     * 
+     * @parameter
+     * @since 2.5
+     */
+    private Map systemPropertyVariables;
+    
+    /**
      * List of properties for configuring all TestNG related configurations. This is the
new
      * preferred method of configuring TestNG.
      *
@@ -472,6 +480,11 @@
     private Properties originalSystemProperties;
 
     /**
+     * systemPropertyVariables + systemProperties
+     */
+    private Properties internalSystemProperties = new Properties();
+
+    /**
      * Flag to disable the generation of report files in xml format.
      * 
      * @parameter expression="${disableXmlReport}" default-value="false"
@@ -520,7 +533,6 @@
      * @readonly
      */
     private MavenSession session;
-    
 
     public void execute()
         throws MojoExecutionException, MojoFailureException
@@ -873,7 +885,7 @@
 
         if ( getLog().isDebugEnabled() )
         {
-            showMap( systemProperties, "system property" );
+            showMap( internalSystemProperties, "system property" );
         }
 
         if ( fork.isForking() )
@@ -882,7 +894,7 @@
             fork.setUseSystemClassLoader( useSystemClassLoader.booleanValue() );
             fork.setUseManifestOnlyJar( useManifestOnlyJar );
 
-            fork.setSystemProperties( systemProperties );
+            fork.setSystemProperties( internalSystemProperties );
             
             if ( "true".equals( debugForkedProcess ) )
             {
@@ -1012,9 +1024,29 @@
 
     protected void processSystemProperties( boolean setInSystem )
     {
-        if ( systemProperties == null )
+        if ( this.systemProperties != null )
         {
-            systemProperties = new Properties();
+            for ( Iterator i = systemProperties.keySet().iterator(); i.hasNext(); )
+            {
+                String key = (String) i.next();
+                String value = (String) systemProperties.get( key );
+                internalSystemProperties.setProperty( key, value );
+            }
+        }
+        
+        if ( this.systemPropertyVariables != null )
+        {
+            for ( Iterator i = systemPropertyVariables.keySet().iterator(); i.hasNext();
)
+            {
+                String key = (String) i.next();
+                String value = (String) systemPropertyVariables.get( key );
+                if ( value == null )
+                {
+                    this.getLog().error( key + "'s value cannot be null." );
+                }
+                internalSystemProperties.setProperty( key, value );
+            }
+            
         }
 
         originalSystemProperties = (Properties) System.getProperties().clone();
@@ -1026,24 +1058,24 @@
         
         // Get the properties from the MavenSession instance to make embedded use work correctly
         Properties userSpecifiedProperties = (Properties) session.getExecutionProperties().clone();
-        userSpecifiedProperties.putAll( systemProperties );
+        userSpecifiedProperties.putAll( internalSystemProperties );
         //systemProperties = userSpecifiedProperties;
 
-        systemProperties.setProperty( "basedir", basedir.getAbsolutePath() );
-        systemProperties.setProperty( "user.dir", workingDirectory.getAbsolutePath() );
+        internalSystemProperties.setProperty( "basedir", basedir.getAbsolutePath() );
+        internalSystemProperties.setProperty( "user.dir", workingDirectory.getAbsolutePath()
);
 
-        systemProperties.setProperty( "localRepository", localRepository.getBasedir() );
+        internalSystemProperties.setProperty( "localRepository", localRepository.getBasedir()
);
 
         if ( setInSystem )
         {
             // Add all system properties configured by the user
-            Iterator iter = systemProperties.keySet().iterator();
+            Iterator iter = internalSystemProperties.keySet().iterator();
 
             while ( iter.hasNext() )
             {
                 String key = (String) iter.next();
 
-                String value = systemProperties.getProperty( key );
+                String value = internalSystemProperties.getProperty( key );
 
                 System.setProperty( key, value );
             }

Modified: maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/system-properties.apt
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/system-properties.apt?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/system-properties.apt
(original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/system-properties.apt
Fri Aug 15 22:58:02 2008
@@ -2,13 +2,45 @@
   Using System Properties
   ------
   Allan Ramirez
+  Dan Tran
   ------
   July 2006
   ------
 
 Using System Properties
 
-  To add a system property, use the following configuration:
+  There are two ways to add a list of system properties to Surefire:
+
+* systemProperyVariable
+
+  This configuration is the replacement of the deprecated <systemProperies>.  It can
accept any value
+  from Maven's properties that can be converted <<to String value>>
+
++---+
+<project>
+  [...]
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.4.2</version>
+        <configuration>
+          <systemPropertyVariables>
+            <propertyName>propertyValue</propertyName>
+            <buildDirectory>${project.build.directory}</buildDirectory>
+            [...]
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  [...]
+</project>
++---+
+
+
+* systemProperties ( deprecated ) 
 
 +---+
 <project>
@@ -25,6 +57,7 @@
               <name>propertyName</name>
               <value>propertyValue</value>
             </property>
+            [...]
           </systemProperties>
         </configuration>
       </plugin>

Modified: maven/surefire/trunk/surefire-integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/pom.xml?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/pom.xml (original)
+++ maven/surefire/trunk/surefire-integration-tests/pom.xml Fri Aug 15 22:58:02 2008
@@ -32,6 +32,7 @@
     <plugins>
       <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
+        <version>${project.version}</version>
         <configuration>
           <!-- DGF only include the "org" package; don't try to run the 
             tests of the projects under test directly -->
@@ -40,6 +41,13 @@
             <include>org/**/*Test.java</include>
             <include>org/**/*TestCase.java</include>
           </includes>
+          
+          <!-- Pass current surefire version to the main suite so that it -->
+          <!-- can forward to all integration test projects. SUREFIRE-513 -->
+          <systemPropertyVariables>
+            <surefire.version>${project.version}</surefire.version>
+          </systemPropertyVariables>
+          
         </configuration>
       </plugin>
     </plugins>

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractSurefireIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractSurefireIT.java?rev=686454&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractSurefireIT.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractSurefireIT.java
Fri Aug 15 22:58:02 2008
@@ -0,0 +1,26 @@
+package org.apache.maven.surefire.its;
+
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Base class of all integration test cases. Mainly used to pickup surefire version
+ * from system property
+ * @author Dan T. Tran
+ *
+ */
+public abstract class AbstractSurefireIT
+    extends TestCase
+{
+    private String surefireVersion = System.getProperty( "surefire.version" );
+
+    protected ArrayList getInitialGoals()
+    {
+        ArrayList goals = new ArrayList();
+        goals.add( "-Dsurefire.version=" + surefireVersion );
+        return goals;
+    }
+
+}

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractTestCaseTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractTestCaseTest.java?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractTestCaseTest.java
(original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractTestCaseTest.java
Fri Aug 15 22:58:02 2008
@@ -28,4 +28,5 @@
         
         HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, testDir );        
     }
+
 }

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTest.java?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTest.java
(original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SystemPropertiesTest.java
Fri Aug 15 22:58:02 2008
@@ -1,21 +1,20 @@
 package org.apache.maven.surefire.its;
 
 
-import junit.framework.TestCase;
-import org.apache.maven.it.Verifier;
-import org.apache.maven.it.util.ResourceExtractor;
-
 import java.io.File;
 import java.util.ArrayList;
 
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
 /**
  * Test system properties
- * 
+ *
  * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
- * 
+ *
  */
 public class SystemPropertiesTest
-    extends TestCase
+    extends AbstractSurefireIT
 {
     public void testSystemProperties ()
         throws Exception
@@ -23,24 +22,24 @@
         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/system-properties"
);
 
         Verifier verifier = new Verifier( testDir.getAbsolutePath() );
-        ArrayList goals = new ArrayList();
+        ArrayList goals = getInitialGoals();
         goals.add( "test" );
         // SUREFIRE-121... someday we should re-enable this
         // goals.add( "-DsetOnMavenCommandLine=baz" );
         verifier.executeGoals( goals );
         verifier.verifyErrorFreeLog();
         verifier.resetStreams();
-        
-        HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, testDir );        
+
+        HelperAssertions.assertTestSuiteResults( 4, 0, 0, 0, testDir );
     }
-    
+
     public void testSystemPropertiesNoFork()
         throws Exception
     {
         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/system-properties"
);
 
         Verifier verifier = new Verifier( testDir.getAbsolutePath() );
-        ArrayList goals = new ArrayList();
+        ArrayList goals = getInitialGoals();
         goals.add( "test" );
         goals.add( "-DforkMode=never" );
         // SUREFIRE-121... someday we should re-enable this
@@ -51,6 +50,6 @@
         verifier.verifyErrorFreeLog();
         verifier.resetStreams();
 
-        HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, testDir );
+        HelperAssertions.assertTestSuiteResults( 4, 0, 0, 0, testDir );
     }
 }

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgSuiteXmlTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgSuiteXmlTest.java?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgSuiteXmlTest.java
(original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgSuiteXmlTest.java
Fri Aug 15 22:58:02 2008
@@ -16,7 +16,7 @@
  * 
  */
 public class TestNgSuiteXmlTest
-    extends TestCase
+    extends AbstractSurefireIT
 {
     public void testTestNgSuiteXml ()
         throws Exception
@@ -24,7 +24,9 @@
         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/testng-suite-xml"
);
 
         Verifier verifier = new Verifier( testDir.getAbsolutePath() );
-        verifier.executeGoal( "test" );
+        List goals = getInitialGoals();
+        goals.add( "test" );
+        verifier.executeGoals( goals );
         verifier.verifyErrorFreeLog();
         verifier.resetStreams();
         
@@ -37,7 +39,8 @@
         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/testng-suite-xml"
);
 
         Verifier verifier = new Verifier( testDir.getAbsolutePath() );
-        List goals = Arrays.asList( new String[] {"test", "-DforkMode=always"} );
+        List goals = getInitialGoals();
+        goals.addAll( Arrays.asList( new String[] {"test", "-DforkMode=always" } ) );
         verifier.executeGoals( goals );
         verifier.verifyErrorFreeLog();
         verifier.resetStreams();

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml
(original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/pom.xml
Fri Aug 15 22:58:02 2008
@@ -31,8 +31,30 @@
   <build>
     <plugins>
       <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.2</version>
+        <executions>
+          <execution>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>reserve-network-port</goal>
+            </goals>
+            <configuration>
+              <portNames>
+                <portName>reservedPort1</portName>
+                <portName>reservedPort2</portName>
+                <portName>reservedPort3</portName>
+              </portNames>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+        
+      
+      <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
-        <version>2.4</version>
+        <version>${surefire.version}</version>
         <configuration>
           <systemProperties>
             <property>
@@ -40,18 +62,18 @@
               <value>foo</value>
             </property>
           </systemProperties>
+          <systemPropertyVariables>
+            <buildDirectory>${project.build.directory}</buildDirectory>
+            <reservedPort1>${reservedPort1}</reservedPort1>
+            <reservedPort2>${reservedPort2}</reservedPort2>
+            <reservedPort3>${reservedPort3}</reservedPort3>
+          </systemPropertyVariables>
           <argLine>-DsetOnArgLine=bar</argLine>
         </configuration>
       </plugin>
     </plugins>
     
   </build>
-  <pluginRepositories>
-        <pluginRepository>
-          <id>dfabulich</id>
-          <url>http://people.apache.org/~dfabulich/staging-repo/</url>
-        </pluginRepository>
-    </pluginRepositories>
 
   <dependencies>
     <dependency>
@@ -61,5 +83,9 @@
       <scope>test</scope>
     </dependency>
   </dependencies>
+  
+  <properties>
+    <reservedPort3>1</reservedPort3>
+  </properties>
 
 </project>

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java
(original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/system-properties/src/test/java/systemProperties/BasicTest.java
Fri Aug 15 22:58:02 2008
@@ -3,6 +3,7 @@
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import java.io.File;
 
 public class BasicTest
     extends TestCase
@@ -19,6 +20,34 @@
         assertEquals("setOnArgLine property not set", "bar", System.getProperty("setOnArgLine"));
     }
 
+    
+    public void testSystemPropertyUsingMavenProjectProperties()
+    {
+        String actualBuildDirectory = new File( System.getProperty( "basedir" ),"target"
).getAbsolutePath();
+        
+        String buildDirectoryFromPom = new File( System.getProperty( "buildDirectory") ).getAbsolutePath();
+        
+        assertEquals( "Pom property not set.", actualBuildDirectory, buildDirectoryFromPom
);
+    }
+    
+    public void testSystemPropertyGenerateByOtherPlugin()
+        throws Exception
+    {
+        int  reservedPort1 = Integer.parseInt( System.getProperty(  "reservedPort1" ) );
+        int  reservedPort2 = Integer.parseInt( System.getProperty(  "reservedPort2" ) );
+        int  reservedPort3 = Integer.parseInt( System.getProperty(  "reservedPort3" ) );
+        System.out.println( "reservedPort1: " + reservedPort1 );
+        System.out.println( "reservedPort2: " + reservedPort2 );
+        System.out.println( "reservedPort3: " + reservedPort3 );
+        
+        assertTrue( reservedPort1 != reservedPort2 );
+        
+        //plugin cannot overwrite the default value set in the pom, this is maven bug
+        assertEquals( 1, reservedPort3 );
+        
+    }
+    
+    
 // SUREFIRE-121; someday we should re-enable this    
 //    public void testSetOnMavenCommandLine()
 //    {

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-suite-xml/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-suite-xml/pom.xml?rev=686454&r1=686453&r2=686454&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-suite-xml/pom.xml
(original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-suite-xml/pom.xml
Fri Aug 15 22:58:02 2008
@@ -29,7 +29,7 @@
   <name>TestNG Suite XML File</name>
 
   <properties>
-     <testNgVersion>5.7</testNgVersion>
+    <testNgVersion>5.7</testNgVersion>
   </properties>
 
   <dependencies>
@@ -47,6 +47,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.version}</version>
         <configuration>
           <suiteXmlFiles>
             <file>src/test-data/testng.xml</file>
@@ -65,4 +66,5 @@
   </build>
 
 
+
 </project>



Mime
View raw message