You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by df...@apache.org on 2007/12/25 21:38:18 UTC

svn commit: r606809 - in /maven/surefire/trunk: maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/ surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ surefire-integration-tests/src/test/resources/working-director...

Author: dfabulich
Date: Tue Dec 25 12:38:17 2007
New Revision: 606809

URL: http://svn.apache.org/viewvc?rev=606809&view=rev
Log:
[SUREFIRE-419] Ensuring consistent working directory when forking/non-forking and in reactor/non-reactor

Added:
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/WorkingDirectoryTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/pom.xml
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/java/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/java/workingDir/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/java/workingDir/BasicTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/pom.xml
Modified:
    maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java

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=606809&r1=606808&r2=606809&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 Tue Dec 25 12:38:17 2007
@@ -320,7 +320,7 @@
     /**
      * Command line working directory.
      * 
-     * @parameter
+     * @parameter expression="${basedir}"
      */
     private File workingDirectory;
 
@@ -941,6 +941,7 @@
         systemProperties = userSpecifiedProperties;
 
         systemProperties.setProperty( "basedir", basedir.getAbsolutePath() );
+        systemProperties.setProperty( "user.dir", workingDirectory.getAbsolutePath() );
 
         systemProperties.setProperty( "localRepository", localRepository.getBasedir() );
 

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/WorkingDirectoryTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/WorkingDirectoryTest.java?rev=606809&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/WorkingDirectoryTest.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/WorkingDirectoryTest.java Tue Dec 25 12:38:17 2007
@@ -0,0 +1,107 @@
+package org.apache.maven.surefire.its;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * Test working directory configuration, SUREFIRE-416
+ * 
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ * 
+ */
+public class WorkingDirectoryTest
+    extends TestCase
+{
+    
+    private File testDir;
+    private File childTestDir;
+    private File targetDir;
+    private File outFile;
+
+    public void setUp() throws IOException {
+        testDir = ResourceExtractor.simpleExtractResources( getClass(), "/working-directory" );
+        childTestDir = new File( testDir, "child" );
+        targetDir = new File( childTestDir, "target" );
+        outFile = new File( targetDir, "out.txt" );
+        outFile.delete();
+    }
+    
+    public void testWorkingDirectory ()
+        throws Exception
+    {
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.executeGoal( "test" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+        
+        HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
+        verifyOutputDirectory( childTestDir );
+    }
+    
+    public void verifyOutputDirectory( File childTestDir )
+        throws IOException
+    {
+        assertTrue( "out.txt doesn't exist: " + outFile.getAbsolutePath(), outFile.exists() );
+        Properties p = new Properties();
+        FileInputStream is = new FileInputStream( outFile );
+        p.load( is );
+        String userDirPath = p.getProperty( "user.dir" );
+        assertNotNull( "user.dir was null in property file", userDirPath );
+        File userDir = new File( userDirPath );
+        assertEquals( "wrong user.dir", childTestDir.getAbsolutePath(), userDir.getAbsolutePath() );
+    }
+    
+    public void testWorkingDirectoryNoFork()
+        throws Exception
+    {
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        ArrayList goals = new ArrayList();
+        goals.add( "test");
+        goals.add( "-DforkMode=never" );
+        verifier.executeGoals( goals );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
+        verifyOutputDirectory( childTestDir );
+    }
+    
+    public void testWorkingDirectoryChildOnly()
+        throws Exception
+    {   
+        Verifier verifier = new Verifier( childTestDir.getAbsolutePath() );
+        verifier.executeGoal( "test" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
+        verifyOutputDirectory( childTestDir );
+    }
+
+    
+    
+    public void testWorkingDirectoryChildOnlyNoFork()
+        throws Exception
+    {
+        
+        Verifier verifier = new Verifier( childTestDir.getAbsolutePath() );
+        ArrayList goals = new ArrayList();
+        goals.add( "test");
+        goals.add( "-DforkMode=never" );
+        verifier.executeGoals( goals );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
+        verifyOutputDirectory( childTestDir );
+    }
+}

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/pom.xml?rev=606809&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/pom.xml (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/pom.xml Tue Dec 25 12:38:17 2007
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>working-directory-child</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for working directory configuration</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/java/workingDir/BasicTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/java/workingDir/BasicTest.java?rev=606809&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/java/workingDir/BasicTest.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/child/src/test/java/workingDir/BasicTest.java Tue Dec 25 12:38:17 2007
@@ -0,0 +1,23 @@
+package workingDir;
+
+import junit.framework.TestCase;
+import java.io.*;
+import java.util.Properties;
+
+public class BasicTest
+    extends TestCase
+{
+
+    public void testWorkingDir() throws Exception {
+        File target = new File( "target" ).getAbsoluteFile();
+        File outFile = new File( target, "out.txt" );
+        FileOutputStream os = new FileOutputStream(outFile);
+        String userDir = System.getProperty("user.dir");
+        Properties p = new Properties();
+        p.setProperty( "user.dir", userDir );
+        p.store( os, "" );
+        os.flush();
+        os.close();
+    }
+
+}

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/pom.xml?rev=606809&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/pom.xml (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/working-directory/pom.xml Tue Dec 25 12:38:17 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>working-directory</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for working directory configuration (parent)</name>
+  <packaging>pom</packaging>
+  <modules>
+    <module>child</module>
+  </modules>
+</project>
\ No newline at end of file