You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2021/05/25 17:05:22 UTC
[sling-feature-launcher-maven-plugin] branch master updated:
SLING-10420 - add support for feature launcher variables (+test the
SLING-9994 vmOptions)
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-feature-launcher-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new de17ee3 SLING-10420 - add support for feature launcher variables (+test the SLING-9994 vmOptions)
de17ee3 is described below
commit de17ee396f4b27ab2fc19fef7a1be023357e5f26
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue May 25 19:03:11 2021 +0200
SLING-10420 - add support for feature launcher variables (+test the SLING-9994 vmOptions)
---
README.md | 4 ++++
src/it/simple-it/pom.xml | 10 ++++-----
.../java/org/apache/sling/it/AppRunningIT.java | 26 ++++++++++++++++++++--
.../maven/feature/launcher/LauncherArguments.java | 9 ++++++++
.../sling/maven/feature/launcher/StartMojo.java | 7 +++++-
5 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 577f8ac..6123aee 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,10 @@ Configure the plugin as follows:
<frameworkProperties>
<org.osgi.service.http.port>8080</org.osgi.service.http.port>
</frameworkProperties>
+ <!-- Feature launcher variables can be set like this -->
+ <variables>
+ <TEST_VARIABLE>TEST_VALUE</TEST_VARIABLE>
+ </variables>
</launcherArguments>
<startTimeoutSeconds>180</startTimeoutSeconds>
</launch>
diff --git a/src/it/simple-it/pom.xml b/src/it/simple-it/pom.xml
index a1b0e07..a1c95b7 100644
--- a/src/it/simple-it/pom.xml
+++ b/src/it/simple-it/pom.xml
@@ -112,16 +112,15 @@
<type>slingosgifeature</type>
</feature>
<launcherArguments>
- <!-- optionally uncomment to pass any required extra vm options -->
- <!--
<vmOptions>
- <value>-Xmx512m</value>
- <value>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5000</value>
+ <value>-DTEST_VM_OPTION=TEST_VM_OPTION_VALUE</value>
</vmOptions>
- -->
<frameworkProperties>
<org.osgi.service.http.port>${http.port}</org.osgi.service.http.port>
</frameworkProperties>
+ <variables>
+ <TEST_VARIABLE>TEST_VALUE</TEST_VARIABLE>
+ </variables>
</launcherArguments>
<startTimeoutSeconds>180</startTimeoutSeconds>
</launch>
@@ -144,6 +143,7 @@
<configuration>
<systemPropertyVariables>
<HTTP_PORT>${http.port}</HTTP_PORT>
+ <build.log.file>${project.build.directory}/../build.log</build.log.file>
</systemPropertyVariables>
</configuration>
<executions>
diff --git a/src/it/simple-it/src/test/java/org/apache/sling/it/AppRunningIT.java b/src/it/simple-it/src/test/java/org/apache/sling/it/AppRunningIT.java
index 5aa6e34..14b0825 100644
--- a/src/it/simple-it/src/test/java/org/apache/sling/it/AppRunningIT.java
+++ b/src/it/simple-it/src/test/java/org/apache/sling/it/AppRunningIT.java
@@ -18,14 +18,23 @@ package org.apache.sling.it;
import static org.junit.jupiter.api.Assertions.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
import org.junit.jupiter.api.Test;
-import org.apache.http.impl.client.*;
+import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
+import org.junit.jupiter.api.TestMethodOrder;
+ import org.apache.http.impl.client.*;
import org.apache.http.client.methods.*;
+@TestMethodOrder(Alphanumeric.class)
public class AppRunningIT {
@Test
- public void slinappIsUp() throws Exception {
+ public void aaSlingAppIsUp() throws Exception {
int port = Integer.getInteger("HTTP_PORT", 8080);
@@ -46,4 +55,17 @@ public class AppRunningIT {
fail("App is not yet ready, failing");
}
}
+
+ @Test
+ public void bbCheckLauncherCommandLineInLogs() throws Exception {
+ final String logFilename = System.getProperty("build.log.file");
+
+ // This verifies the launcherArguments vmOptions and variables from our test pom
+ final Pattern expected = Pattern.compile(".*\\-DTEST_VM_OPTION=TEST_VM_OPTION_VALUE.*\\-V, TEST_VARIABLE=TEST_VALUE.*");
+
+ try (Stream<String> lines = Files.lines(Paths.get(logFilename))) {
+ final Optional<String> expectedLine = lines.filter(line -> expected.matcher(line).matches()).findFirst();
+ assertTrue(expectedLine.isPresent(), "Expected pattern " + expected + " to be found in log file " + logFilename);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/maven/feature/launcher/LauncherArguments.java b/src/main/java/org/apache/sling/maven/feature/launcher/LauncherArguments.java
index aaef214..07617fd 100644
--- a/src/main/java/org/apache/sling/maven/feature/launcher/LauncherArguments.java
+++ b/src/main/java/org/apache/sling/maven/feature/launcher/LauncherArguments.java
@@ -25,6 +25,7 @@ public class LauncherArguments {
private String[] vmOptions = null;
private Map<String, String> frameworkProperties = new HashMap<>();
+ private Map<String, String> variables = new HashMap<>();
public String[] getVmOptions() {
return vmOptions;
@@ -41,4 +42,12 @@ public class LauncherArguments {
public void setFrameworkProperties(Map<String, String> frameworkProperties) {
this.frameworkProperties = frameworkProperties;
}
+
+ public Map<String, String> getVariables() {
+ return variables;
+ }
+
+ public void setVariables(Map<String, String> variables) {
+ this.variables = variables;
+ }
}
diff --git a/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java b/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java
index b8730e3..8706735 100644
--- a/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java
+++ b/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java
@@ -144,13 +144,18 @@ public class StartMojo extends AbstractMojo {
args.add(frameworkProperty.getKey()+"="+frameworkProperty.getValue());
}
+ for ( Map.Entry<String, String> variable : launch.getLauncherArguments().getVariables().entrySet() ) {
+ args.add("-V");
+ args.add(variable.getKey()+"="+variable.getValue());
+ }
+
// TODO - add support for all arguments supported by the feature launcher
ProcessBuilder pb = new ProcessBuilder(args);
pb.redirectOutput(Redirect.INHERIT);
pb.redirectInput(Redirect.INHERIT);
pb.directory(workDir);
- getLog().info("Starting launch with id " + launch.getId());
+ getLog().info("Starting launch with id '" + launch.getId() + "', args=" + args);
CountDownLatch latch = new CountDownLatch(1);