You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by en...@apache.org on 2021/01/18 19:14:35 UTC
[sling-slingfeature-maven-plugin] branch master updated:
SLING-10060 Substitutions for the "replacePropertyVariables" values (#66)
should prefer the system property value
This is an automated email from the ASF dual-hosted git repository.
enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 0fa0106 SLING-10060 Substitutions for the "replacePropertyVariables" values (#66) should prefer the system property value
0fa0106 is described below
commit 0fa01064594c92801bd871882172227728ecda49
Author: Eric Norman <en...@apache.org>
AuthorDate: Mon Jan 18 11:13:57 2021 -0800
SLING-10060 Substitutions for the "replacePropertyVariables" values (#66) should prefer the system property value
---
.../apache/sling/feature/maven/Substitution.java | 11 ++++++++--
.../sling/feature/maven/SubstitutionTest.java | 25 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/maven/Substitution.java b/src/main/java/org/apache/sling/feature/maven/Substitution.java
index ae6eec2..41678bf 100644
--- a/src/main/java/org/apache/sling/feature/maven/Substitution.java
+++ b/src/main/java/org/apache/sling/feature/maven/Substitution.java
@@ -67,8 +67,15 @@ public class Substitution {
if ( additionalProperties != null ) {
for(String p : additionalProperties) {
p = p.trim();
- if ( project.getProperties().containsKey(p)) {
- props.setProperty(p, project.getProperties().getProperty(p));
+ // check for a system property that overwrites the project property
+ String value = System.getProperty(p);
+ if (value == null && project.getProperties().containsKey(p)) {
+ // no system property, so try the project property
+ value = project.getProperties().getProperty(p);
+ }
+ if (value != null) {
+ // found a value
+ props.setProperty(p, value);
}
}
}
diff --git a/src/test/java/org/apache/sling/feature/maven/SubstitutionTest.java b/src/test/java/org/apache/sling/feature/maven/SubstitutionTest.java
index 372ed97..f345b94 100644
--- a/src/test/java/org/apache/sling/feature/maven/SubstitutionTest.java
+++ b/src/test/java/org/apache/sling/feature/maven/SubstitutionTest.java
@@ -52,6 +52,31 @@ public class SubstitutionTest {
}
}
+ /**
+ * SLING-10060 Verify that the additional properties prefer the system property
+ * value (if available) over the project property value
+ */
+ @Test
+ public void testReplaceAdditionalPropertiesMavenVarsWithSystemProperties() {
+ Properties storedProps = new Properties();
+ storedProps.putAll(System.getProperties());
+
+ try {
+ MavenProject proj = new MavenProject();
+ Properties p = proj.getProperties();
+ p.put("test", "foo");
+ p.put("test2", "foo2");
+
+ // set system property to override the project property
+ System.setProperty("test", "bar");
+
+ assertEquals("hellobargoodbyefoo2", Substitution.replaceMavenVars(proj, false, false, new String[] {"test", "test2"}, "hello${test}goodbye${test2}"));
+ } finally {
+ // Restore the system properties
+ System.setProperties(storedProps);
+ }
+ }
+
@Test
public void testOSGiVersion() {
assertEquals("1.2.3", Substitution.getOSGiVersion("1.2.3"));