You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2013/12/20 21:34:35 UTC

[1/3] git commit: Add @{...} property evaluation for the argLine.

Updated Branches:
  refs/heads/master 88a05af56 -> 7be072ea8


Add @{...} property evaluation for the argLine.

Replaces expressions @{property-name} in the argLine with the
corresponding properties from the model. This allows late evaluation
of property values when the plugin is executed (as compared to
evaluation when the pom is parsed as is done with ${property-name}
expressions).

This allows other plugins to modify or set properties with the changes
getting picked up by surefire.


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/f0d7ea72
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/f0d7ea72
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/f0d7ea72

Branch: refs/heads/master
Commit: f0d7ea72f477e7bf1661747edc8163127680cbc4
Parents: 75f05d7
Author: Henning Schmiedehausen <he...@schmiedehausen.org>
Authored: Tue Dec 17 21:14:56 2013 -0800
Committer: Henning Schmiedehausen <he...@schmiedehausen.org>
Committed: Tue Dec 17 21:17:02 2013 -0800

----------------------------------------------------------------------
 .../plugin/surefire/AbstractSurefireMojo.java   |  1 +
 .../booterclient/ForkConfiguration.java         | 33 ++++++++++++++++++--
 .../booterclient/ForkConfigurationTest.java     |  3 +-
 maven-surefire-plugin/src/site/fml/faq.fml      | 14 +++++++++
 4 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f0d7ea72/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
----------------------------------------------------------------------
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 d436f83..d92077e 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
@@ -1738,6 +1738,7 @@ public abstract class AbstractSurefireMojo
         return new ForkConfiguration( bootClasspathConfiguration, tmpDir, getEffectiveDebugForkedProcess(),
                                       getEffectiveJvm(),
                                       getWorkingDirectory() != null ? getWorkingDirectory() : getBasedir(),
+                                      getProject().getModel().getProperties(),
                                       getArgLine(), getEnvironmentVariables(), getLog().isDebugEnabled(),
                                       getEffectiveForkCount(), reuseForks );
     }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f0d7ea72/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
index ba1aa27..079ee32 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
@@ -22,8 +22,10 @@ package org.apache.maven.plugin.surefire.booterclient;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
@@ -63,6 +65,8 @@ public class ForkConfiguration
 
     private final String jvmExecutable;
 
+    private Properties modelProperties;
+
     private final String argLine;
 
     private final Map<String, String> environmentVariables;
@@ -76,7 +80,7 @@ public class ForkConfiguration
     private final String debugLine;
 
     public ForkConfiguration( Classpath bootClasspathConfiguration, File tmpDir, String debugLine, String jvmExecutable,
-                              File workingDirectory, String argLine, Map<String, String> environmentVariables,
+                              File workingDirectory, Properties modelProperties, String argLine, Map<String, String> environmentVariables,
                               boolean debugEnabled, int forkCount, boolean reuseForks )
     {
         this.bootClasspathConfiguration = bootClasspathConfiguration;
@@ -84,6 +88,7 @@ public class ForkConfiguration
         this.debugLine = debugLine;
         this.jvmExecutable = jvmExecutable;
         this.workingDirectory = workingDirectory;
+        this.modelProperties = modelProperties;
         this.argLine = argLine;
         this.environmentVariables = environmentVariables;
         this.debug = debugEnabled;
@@ -146,7 +151,7 @@ public class ForkConfiguration
 
         if ( argLine != null )
         {
-            cli.createArg().setLine( replaceThreadNumberPlaceholder( stripNewLines( argLine ), threadNumber ) );
+            cli.createArg().setLine( replaceThreadNumberPlaceholder( stripNewLines( replacePropertyExpressions( argLine ) ), threadNumber ) );
         }
 
         if ( environmentVariables != null )
@@ -204,6 +209,30 @@ public class ForkConfiguration
     }
 
     /**
+     * Replaces expressions <pre>@{property-name}</pre> with the corresponding properties
+     * from the model. This allows late evaluation of property values when the plugin is exexcuted (as compared
+     * to evaluation when the pom is parsed as is done with <pre>${property-name}</pre> expressions).
+     *
+     * This allows other plugins to modify or set properties with the changes getting picked up by surefire.
+     */
+    private String replacePropertyExpressions( String argLine )
+    {
+        if ( argLine == null ) {
+            return null;
+        }
+
+        for ( Enumeration<?> e = modelProperties.propertyNames(); e.hasMoreElements(); ) {
+            String key = e.nextElement().toString();
+            String field = "@{" + key + "}";
+            if ( argLine.contains(field) ) {
+                argLine = argLine.replace(field, modelProperties.getProperty(key, ""));
+            }
+        }
+
+        return argLine;
+    }
+
+    /**
      * Create a jar with just a manifest containing a Main-Class entry for BooterConfiguration and a Class-Path entry
      * for all classpath elements.
      *

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f0d7ea72/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
index 9a310b2..5944ec8 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
@@ -22,6 +22,7 @@ package org.apache.maven.plugin.surefire.booterclient;
 import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
+import java.util.Properties;
 
 import org.apache.maven.shared.utils.StringUtils;
 import org.apache.maven.shared.utils.cli.Commandline;
@@ -71,7 +72,7 @@ public class ForkConfigurationTest
     public static ForkConfiguration getForkConfiguration( String argLine, String jvm )
         throws IOException
     {
-        return new ForkConfiguration( Classpath.emptyClasspath(), null, null, jvm, new File( "." ).getCanonicalFile(), argLine,
+        return new ForkConfiguration( Classpath.emptyClasspath(), null, null, jvm, new File( "." ).getCanonicalFile(), new Properties(), argLine,
                                       null, false, 1, false );
     }
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f0d7ea72/maven-surefire-plugin/src/site/fml/faq.fml
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/site/fml/faq.fml b/maven-surefire-plugin/src/site/fml/faq.fml
index 9c44fbc..a518c57 100644
--- a/maven-surefire-plugin/src/site/fml/faq.fml
+++ b/maven-surefire-plugin/src/site/fml/faq.fml
@@ -83,5 +83,19 @@ under the License.
         </p>
       </answer>
     </faq>
+    <faq id="late-property-evaluation">
+      <question>How do I use properties set by other plugins in argLine?</question>
+      <answer>
+        <p>
+          Maven does property replacement for <pre>${...}</pre> values in pom.xml before any
+          plugin is run. So surefire would never see the place-holders in its argLine property.
+        </p>
+        <p>
+          Using an alternate syntax for these properties, <pre>@{...}</pre> allows late replacement
+          of properties when the plugin is executed, so properties that have been modified by other
+          plugins will be picked up correctly.
+        </p>
+      </answer>
+    </faq>
   </part>
 </faqs>


[3/3] git commit: [SUREFIRE-1047] Add @{...} property evaluation for the argLine. Submitted by: Henning Schmiedehausen

Posted by ag...@apache.org.
[SUREFIRE-1047] Add @{...} property evaluation for the argLine.
Submitted by: Henning Schmiedehausen

o Applied without changes


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/7be072ea
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/7be072ea
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/7be072ea

Branch: refs/heads/master
Commit: 7be072ea88c3705800d68b159953d44305b6113c
Parents: 88a05af 4683d4d
Author: Andreas Gudian <ag...@apache.org>
Authored: Fri Dec 20 21:08:47 2013 +0100
Committer: Andreas Gudian <ag...@apache.org>
Committed: Fri Dec 20 21:32:49 2013 +0100

----------------------------------------------------------------------
 .../plugin/surefire/AbstractSurefireMojo.java   |  1 +
 .../booterclient/ForkConfiguration.java         | 33 +++++++-
 .../booterclient/ForkConfigurationTest.java     |  3 +-
 maven-surefire-plugin/src/site/fml/faq.fml      | 14 ++++
 .../maven/surefire/its/ArgLinePropertiesIT.java | 39 +++++++++
 .../test/resources/argLine-properties/pom.xml   | 84 ++++++++++++++++++++
 .../TestSurefireArgLineProperties.java          | 58 ++++++++++++++
 .../src/test/resources/it.properties            | 19 +++++
 8 files changed, 248 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7be072ea/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
----------------------------------------------------------------------


[2/3] git commit: Integration test for properties replacement.

Posted by ag...@apache.org.
Integration test for properties replacement.


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/4683d4d1
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/4683d4d1
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/4683d4d1

Branch: refs/heads/master
Commit: 4683d4d1a208a30ff3beb24c2da93d8b3674da7b
Parents: f0d7ea7
Author: Henning Schmiedehausen <he...@schmiedehausen.org>
Authored: Wed Dec 18 19:37:27 2013 -0800
Committer: Henning Schmiedehausen <he...@schmiedehausen.org>
Committed: Wed Dec 18 19:37:27 2013 -0800

----------------------------------------------------------------------
 .../maven/surefire/its/ArgLinePropertiesIT.java | 39 +++++++++
 .../test/resources/argLine-properties/pom.xml   | 84 ++++++++++++++++++++
 .../TestSurefireArgLineProperties.java          | 58 ++++++++++++++
 .../src/test/resources/it.properties            | 19 +++++
 4 files changed, 200 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4683d4d1/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ArgLinePropertiesIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ArgLinePropertiesIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ArgLinePropertiesIT.java
new file mode 100644
index 0000000..cf1074e
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ArgLinePropertiesIT.java
@@ -0,0 +1,39 @@
+package org.apache.maven.surefire.its;
+
+/*
+ * 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.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.junit.Test;
+
+/**
+ * Test passing an argLine parameter
+ *
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ * @author <a href="mailto:krosenvold@apache.org">Kristian Rosenvold</a>
+ */
+public class ArgLinePropertiesIT
+    extends SurefireJUnit4IntegrationTestCase
+{
+    @Test
+    public void argLine()
+    {
+        unpack( "/argLine-properties" ).executeTest().verifyErrorFree( 4 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4683d4d1/surefire-integration-tests/src/test/resources/argLine-properties/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/argLine-properties/pom.xml b/surefire-integration-tests/src/test/resources/argLine-properties/pom.xml
new file mode 100644
index 0000000..e679767
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/argLine-properties/pom.xml
@@ -0,0 +1,84 @@
+<?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>
+
+  <parent>
+    <groupId>org.apache.maven.surefire</groupId>
+    <artifactId>it-parent</artifactId>
+    <version>1.0</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>testArgProperties</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for late replacement argLine properties.</name>
+
+  <properties>
+    <from.prop>from-prop-value</from.prop>
+    <override.prop>not-override-prop-value</override.prop>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>properties-maven-plugin</artifactId>
+        <version>1.0-alpha-2</version>
+        <executions>
+          <execution>
+            <id>default</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>read-project-properties</goal>
+            </goals>
+            <configuration>
+              <files>
+                <file>${project.basedir}/src/test/resources/it.properties</file>
+              </files>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <forkMode>once</forkMode>
+          <argLine>-Dp1=@{from.prop} -Dp2=@{override.prop} -Dp3=@{undefined.prop} -Dp4=@{generated.prop}</argLine>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4683d4d1/surefire-integration-tests/src/test/resources/argLine-properties/src/test/java/argLine-properties/TestSurefireArgLineProperties.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/argLine-properties/src/test/java/argLine-properties/TestSurefireArgLineProperties.java b/surefire-integration-tests/src/test/resources/argLine-properties/src/test/java/argLine-properties/TestSurefireArgLineProperties.java
new file mode 100644
index 0000000..a16fceb
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/argLine-properties/src/test/java/argLine-properties/TestSurefireArgLineProperties.java
@@ -0,0 +1,58 @@
+package argLine;
+
+/*
+ * 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.junit.Assert;
+import org.junit.Test;
+
+public class TestSurefireArgLineProperties
+{
+    @Test
+    public void testFromProp()
+    {
+        String fromProp = System.getProperty("p1");
+        Assert.assertNotNull(fromProp, "incorrect arg line, no p1 present?");
+        Assert.assertEquals("from-prop-value", fromProp);
+    }
+
+    @Test
+    public void testOverrideProp()
+    {
+        String overrideProp = System.getProperty("p2");
+        Assert.assertNotNull(overrideProp, "incorrect arg line, no p2 present?");
+        Assert.assertEquals("override-prop-value", overrideProp);
+    }
+
+    @Test
+    public void testUndefinedProp()
+    {
+        String undefinedProp = System.getProperty("p3");
+        Assert.assertNotNull(undefinedProp, "incorrect arg line, no p3 present?");
+        Assert.assertEquals("@{undefined.prop}", undefinedProp);
+    }
+
+    @Test
+    public void testGeneratedProp()
+    {
+        String generatedProp = System.getProperty("p4");
+        Assert.assertNotNull(generatedProp, "incorrect arg line, no p4 present?");
+        Assert.assertEquals("generated-prop-value", generatedProp);
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4683d4d1/surefire-integration-tests/src/test/resources/argLine-properties/src/test/resources/it.properties
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/argLine-properties/src/test/resources/it.properties b/surefire-integration-tests/src/test/resources/argLine-properties/src/test/resources/it.properties
new file mode 100644
index 0000000..dd889a2
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/argLine-properties/src/test/resources/it.properties
@@ -0,0 +1,19 @@
+# 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.
+
+override.prop=override-prop-value
+generated.prop=generated-prop-value