You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/09/24 12:23:19 UTC
[sling-slingstart-maven-plugin] branch master updated: SLING-7949
Slingstart Maven Plugin should allow substitution of project properties in
feature model files
This is an automated email from the ASF dual-hosted git repository.
davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 107d4d3 SLING-7949 Slingstart Maven Plugin should allow substitution of project properties in feature model files
107d4d3 is described below
commit 107d4d3f0566bc78d949e00d37cfa164dd03e5bb
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Sep 24 13:21:17 2018 +0100
SLING-7949 Slingstart Maven Plugin should allow substitution of project properties in feature model files
Unit test included
---
.../maven/slingstart/FeatureModelConverter.java | 20 +++++++++++++++++---
.../maven/slingstart/FeatureModelConverterTest.java | 6 ++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/maven/slingstart/FeatureModelConverter.java b/src/main/java/org/apache/sling/maven/slingstart/FeatureModelConverter.java
index 622296e..aa81756 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/FeatureModelConverter.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/FeatureModelConverter.java
@@ -33,6 +33,7 @@ import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
public class FeatureModelConverter {
static final String BUILD_DIR = "provisioning/converted";
@@ -113,12 +114,25 @@ public class FeatureModelConverter {
static String replaceVars(MavenProject project, String s) {
// There must be a better way than enumerating all these?
- s = s.replaceAll("\\Q${project.groupId}\\E", project.getGroupId());
- s = s.replaceAll("\\Q${project.artifactId}\\E", project.getArtifactId());
- s = s.replaceAll("\\Q${project.version}\\E", project.getVersion());
+ s = replaceAll(s, "project.groupId", project.getGroupId());
+ s = replaceAll(s, "project.artifactId", project.getArtifactId());
+ s = replaceAll(s, "project.version", project.getVersion());
+
+
+ Properties props = project.getProperties();
+ if (props != null) {
+ for (String key : props.stringPropertyNames()) {
+ s = replaceAll(s, key, props.getProperty(key));
+ }
+ }
+
return s;
}
+ private static String replaceAll(String s, String key, String value) {
+ return s.replaceAll("\\Q${" + key + "}\\E", value);
+ }
+
private static ArtifactManager getArtifactManager(MavenProject project, MavenSession session)
throws IOException {
List<String> repos = new ArrayList<>();
diff --git a/src/test/java/org/apache/sling/maven/slingstart/FeatureModelConverterTest.java b/src/test/java/org/apache/sling/maven/slingstart/FeatureModelConverterTest.java
index 55590eb..b4deea8 100644
--- a/src/test/java/org/apache/sling/maven/slingstart/FeatureModelConverterTest.java
+++ b/src/test/java/org/apache/sling/maven/slingstart/FeatureModelConverterTest.java
@@ -32,6 +32,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
+import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -138,13 +139,18 @@ public class FeatureModelConverterTest {
public void testReplaceVars() {
MavenProject mp = Mockito.mock(MavenProject.class);
+ Properties props = new Properties();
+ props.put("foo", "bar");
+
Mockito.when(mp.getGroupId()).thenReturn("abc");
Mockito.when(mp.getArtifactId()).thenReturn("a.b.c");
Mockito.when(mp.getVersion()).thenReturn("1.2.3-SNAPSHOT");
+ Mockito.when(mp.getProperties()).thenReturn(props);
assertEquals("xxxabcyyy", FeatureModelConverter.replaceVars(mp,
"xxx${project.groupId}yyy"));
assertEquals("xxxabcyyya.b.c1.2.3-SNAPSHOT", FeatureModelConverter.replaceVars(mp,
"xxx${project.groupId}yyy${project.artifactId}${project.version}"));
+ assertEquals("xxxbaryyy", FeatureModelConverter.replaceVars(mp, "xxx${foo}yyy"));
}
}