You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2019/11/20 20:41:54 UTC

[maven-surefire] branch master updated: [SUREFIRE-1378] Nice to have systemPropertiesFile configurable by user property

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


View the commit online:
https://github.com/apache/maven-surefire/commit/970b708752ee00f0a43c19acc228949e2a1da103

The following commit(s) were added to refs/heads/master by this push:
     new 970b708  [SUREFIRE-1378] Nice to have systemPropertiesFile configurable by user property
970b708 is described below

commit 970b708752ee00f0a43c19acc228949e2a1da103
Author: michal <mi...@michal-desktop>
AuthorDate: Wed May 31 21:52:50 2017 +0200

    [SUREFIRE-1378] Nice to have systemPropertiesFile configurable by user
    property
---
 .../maven/plugin/failsafe/IntegrationTestMojo.java |  15 +++
 .../plugin/failsafe/IntegrationTestMojoTest.java   | 107 ++++++++++++++++++++-
 .../plugin/surefire/AbstractSurefireMojo.java      |  27 ++----
 .../AbstractSurefireMojoJava7PlusTest.java         |  12 +++
 .../plugin/surefire/AbstractSurefireMojoTest.java  |  13 +++
 .../maven/plugin/surefire/MojoMocklessTest.java    |  12 +++
 .../maven/plugin/surefire/SurefirePlugin.java      |  16 +++
 .../maven/plugin/surefire/SurefirePluginTest.java  |  10 ++
 8 files changed, 193 insertions(+), 19 deletions(-)

diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
index f4fe1c3..a5adc3c 100644
--- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
+++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
@@ -441,6 +441,9 @@ public class IntegrationTestMojo
     @Parameter( property = "failsafe.enableProcessChecker" )
     private String enableProcessChecker;
 
+    @Parameter( property = "failsafe.systemPropertiesFile" )
+    private File systemPropertiesFile;
+
     @Override
     protected int getRerunFailingTestsCount()
     {
@@ -799,6 +802,18 @@ public class IntegrationTestMojo
     }
 
     @Override
+    public File getSystemPropertiesFile()
+    {
+        return systemPropertiesFile;
+    }
+
+    @Override
+    public void setSystemPropertiesFile( File systemPropertiesFile )
+    {
+        this.systemPropertiesFile = systemPropertiesFile;
+    }
+
+    @Override
     public Boolean getFailIfNoSpecifiedTests()
     {
         return failIfNoSpecifiedTests;
diff --git a/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
index cbb0b0f..c605938 100644
--- a/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
+++ b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
@@ -1 +1,106 @@
-package org.apache.maven.plugin.failsafe;

/*
 * 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 org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.versioning.Invali
 dVersionSpecificationException;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 * @since 2.20
 */
public class IntegrationTestMojoTest
{
    private IntegrationTestMojo mojo;

    @Before
    public void init() throws InvalidVersionSpecificationException, IOException
    {
        Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
        artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
        new File( "./target/tmp" ).mkdir();
        artifact.getFile().createNewFile();
        mojo = new IntegrationTestMojo();
        MavenProject project = mock( MavenProject.class );
        when( projec
 t.getArtifact() ).thenReturn( artifact );
        mojo.setProject( project );
    }

    @Test
    public void shouldBeJar()
    {
        mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
        File binaries = mojo.getClassesDirectory();
        assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
    }

    @Test
    public void shouldBeAnotherJar()
    {
        mojo.setClassesDirectory( new File( "./target/another-1.0.jar" ) );
        mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
        File binaries = mojo.getClassesDirectory();
        assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
    }

    @Test
    public void shouldBeClasses()
    {
        mojo.setClassesDirectory( new File( "./target/classes" ) );
        mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
        File binaries = mojo.getClassesDirectory();
        assertThat( binaries.getName() ).isEqualTo( "classes" );
    }

    @Test
  
   public void shouldGetNullEnv()
    {
        assertThat( mojo.getExcludedEnvironmentVariables() )
                .hasSize( 0 );
    }

    @Test
    public void shouldGetEnv()
    {
        mojo.setExcludedEnvironmentVariables( new String[] { "ABC", "KLM" } );
        assertThat( mojo.getExcludedEnvironmentVariables() )
                .hasSize( 2 )
                .contains( "ABC", "KLM" );
    }
}
\ No newline at end of file
+package org.apache.maven.plugin.failsafe;
+
+/*
+ * 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 org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.project.MavenProject;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * @since 2.20
+ */
+public class IntegrationTestMojoTest
+{
+    private IntegrationTestMojo mojo;
+
+    @Before
+    public void init() throws InvalidVersionSpecificationException, IOException
+    {
+        Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
+        artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
+        new File( "./target/tmp" ).mkdir();
+        artifact.getFile().createNewFile();
+        mojo = new IntegrationTestMojo();
+        MavenProject project = mock( MavenProject.class );
+        when( project.getArtifact() ).thenReturn( artifact );
+        mojo.setProject( project );
+    }
+
+    @Test
+    public void shouldBeJar()
+    {
+        mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
+        File binaries = mojo.getClassesDirectory();
+        assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
+    }
+
+    @Test
+    public void shouldBeAnotherJar()
+    {
+        mojo.setClassesDirectory( new File( "./target/another-1.0.jar" ) );
+        mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
+        File binaries = mojo.getClassesDirectory();
+        assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
+    }
+
+    @Test
+    public void shouldBeClasses()
+    {
+        mojo.setClassesDirectory( new File( "./target/classes" ) );
+        mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
+        File binaries = mojo.getClassesDirectory();
+        assertThat( binaries.getName() ).isEqualTo( "classes" );
+    }
+
+    @Test
+    public void shouldGetNullEnv()
+    {
+        assertThat( mojo.getExcludedEnvironmentVariables() )
+                .hasSize( 0 );
+    }
+
+    @Test
+    public void shouldGetEnv()
+    {
+        mojo.setExcludedEnvironmentVariables( new String[] { "ABC", "KLM" } );
+        assertThat( mojo.getExcludedEnvironmentVariables() )
+                .hasSize( 2 )
+                .contains( "ABC", "KLM" );
+    }
+
+    @Test
+    public void testShouldGetPropertyFile()
+    {
+        mojo.setSystemPropertiesFile( new File( "testShouldGetPropertyFile" ) );
+        assertThat( mojo.getSystemPropertiesFile() )
+                .isEqualTo( new File( "testShouldGetPropertyFile" ) );
+    }
+}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index a53d75a..75f6241 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -327,14 +327,6 @@ public abstract class AbstractSurefireMojo
     private Map<String, String> systemPropertyVariables;
 
     /**
-     * List of System properties, loaded from a file, to pass to the JUnit tests.
-     *
-     * @since 2.8.2
-     */
-    @Parameter
-    private File systemPropertiesFile;
-
-    /**
      * List of properties for configuring all TestNG related configurations. This is the new preferred method of
      * configuring TestNG.
      *
@@ -1097,11 +1089,11 @@ public abstract class AbstractSurefireMojo
         SurefireProperties sysProps = null;
         try
         {
-            sysProps = SurefireProperties.loadProperties( systemPropertiesFile );
+            sysProps = SurefireProperties.loadProperties( getSystemPropertiesFile() );
         }
         catch ( IOException e )
         {
-            String msg = "The system property file '" + systemPropertiesFile.getAbsolutePath() + "' can't be read.";
+            String msg = "The file '" + getSystemPropertiesFile().getAbsolutePath() + "' can't be read.";
             if ( getConsoleLogger().isDebugEnabled() )
             {
                 getConsoleLogger().debug( msg, e );
@@ -3370,16 +3362,15 @@ public abstract class AbstractSurefireMojo
         this.systemPropertyVariables = systemPropertyVariables;
     }
 
-    public File getSystemPropertiesFile()
-    {
-        return systemPropertiesFile;
-    }
+    /**
+     * List of System properties, loaded from a file, to pass to the JUnit tests.
+     *
+     * @since 2.8.2
+     */
+    public abstract File getSystemPropertiesFile();
 
     @SuppressWarnings( "UnusedDeclaration" )
-    public void setSystemPropertiesFile( File systemPropertiesFile )
-    {
-        this.systemPropertiesFile = systemPropertiesFile;
-    }
+    public abstract void setSystemPropertiesFile( File systemPropertiesFile );
 
     private Properties getProperties()
     {
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
index 9d1fcf8..9faa4eb 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
@@ -636,5 +636,17 @@ public class AbstractSurefireMojoJava7PlusTest
         {
             return null;
         }
+
+        @Override
+        public File getSystemPropertiesFile()
+        {
+            return null;
+        }
+
+        @Override
+        public void setSystemPropertiesFile( File systemPropertiesFile )
+        {
+
+        }
     }
 }
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
index c768e49..dacadc0 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
@@ -2126,6 +2126,18 @@ public class AbstractSurefireMojoTest
             return new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-plugin", createFromVersion( "1" ),
                     null, "jar", null, mock( ArtifactHandler.class ) );
         }
+
+        @Override
+        public File getSystemPropertiesFile()
+        {
+            return null;
+        }
+
+        @Override
+        public void setSystemPropertiesFile( File systemPropertiesFile )
+        {
+
+        }
     }
 
     private static File mockFile( String absolutePath )
@@ -2167,5 +2179,6 @@ public class AbstractSurefireMojoTest
             }
         }
         return new AR();
+
     }
 }
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
index f7393ef..ccf63f7 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
@@ -767,5 +767,17 @@ public class MojoMocklessTest
         {
             return projectTestArtifacts;
         }
+
+        @Override
+        public File getSystemPropertiesFile()
+        {
+            return null;
+        }
+
+        @Override
+        public void setSystemPropertiesFile( File systemPropertiesFile )
+        {
+
+        }
     }
 }
diff --git a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
index 4bc3b6d..17e9032 100644
--- a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
+++ b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
@@ -422,6 +422,9 @@ public class SurefirePlugin
     @Parameter( property = "surefire.enableProcessChecker" )
     private String enableProcessChecker;
 
+    @Parameter( property = "surefire.systemPropertiesFile" )
+    private File systemPropertiesFile;
+
     @Override
     protected int getRerunFailingTestsCount()
     {
@@ -459,6 +462,19 @@ public class SurefirePlugin
         return "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd";
     }
     
+
+    public File getSystemPropertiesFile()
+    {
+        return systemPropertiesFile;
+    }
+
+
+    public void setSystemPropertiesFile( File systemPropertiesFile )
+    {
+        this.systemPropertiesFile = systemPropertiesFile;
+    }
+
+
     // now for the implementation of the field accessors
 
     @Override
diff --git a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
index 3c759b1..19a5f96 100644
--- a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
+++ b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
@@ -23,6 +23,8 @@ import junit.framework.TestCase;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.surefire.suite.RunResult;
 
+import java.io.File;
+
 import static org.fest.assertions.Assertions.assertThat;
 
 /**
@@ -104,4 +106,12 @@ public class SurefirePluginTest extends TestCase
                 .hasSize( 2 )
                 .contains( "ABC", "KLM" );
     }
+
+    public void testShouldGetPropertyFile()
+    {
+        SurefirePlugin plugin = new SurefirePlugin();
+        plugin.setSystemPropertiesFile( new File( "testShouldGetPropertyFile" ) );
+        assertThat( plugin.getSystemPropertiesFile() )
+                .isEqualTo( new File( "testShouldGetPropertyFile" ) );
+    }
 }