You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/05/12 08:41:12 UTC
[sling-feature-launcher-maven-plugin] branch master updated:
SLING-10364 optionally wait for user input before stopping the server (#1)
This is an automated email from the ASF dual-hosted git repository.
kwin 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 5a77e67 SLING-10364 optionally wait for user input before stopping the server (#1)
5a77e67 is described below
commit 5a77e67d7c83cc8eaf25fdae8ebd1296afe0ec4d
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed May 12 10:41:07 2021 +0200
SLING-10364 optionally wait for user input before stopping the server (#1)
---
pom.xml | 10 +++++++
.../sling/maven/feature/launcher/StopMojo.java | 34 +++++++++++++++++++++-
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 973454f..9aaa82e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,16 @@
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interactivity-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-utils</artifactId>
+ <version>3.3.3</version>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
diff --git a/src/main/java/org/apache/sling/maven/feature/launcher/StopMojo.java b/src/main/java/org/apache/sling/maven/feature/launcher/StopMojo.java
index d8665d8..7be70f9 100644
--- a/src/main/java/org/apache/sling/maven/feature/launcher/StopMojo.java
+++ b/src/main/java/org/apache/sling/maven/feature/launcher/StopMojo.java
@@ -20,6 +20,7 @@ package org.apache.sling.maven.feature.launcher;
import java.util.List;
+import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -27,6 +28,9 @@ import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.shared.utils.logging.MessageUtils;
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
@Mojo( name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
public class StopMojo extends AbstractMojo {
@@ -37,9 +41,27 @@ public class StopMojo extends AbstractMojo {
@Component
private ProcessTracker processes;
+ /**
+ * If {@code true} stopping the server is deferred until you press the Enter key.
+ */
+ @Parameter(property = "feature-launcher.waitForInput", required = false, defaultValue = "false")
+ protected boolean waitForInput;
+
+ @Component
+ private Prompter prompter;
+
+ @Parameter(defaultValue = "${session.request}", readonly = true)
+ private MavenExecutionRequest executionRequest;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
-
+ if (waitForInput) {
+ if (executionRequest.isInteractiveMode()) {
+ waitForUserInput();
+ } else {
+ getLog().warn("Don't wait for user input as Maven is not running in interactive mode");
+ }
+ }
try {
for ( Launch launch : launches ) {
getLog().info("Stopping launch with id " + launch.getId());
@@ -50,4 +72,14 @@ public class StopMojo extends AbstractMojo {
}
}
+ protected void waitForUserInput() throws MojoFailureException {
+ // http://stackoverflow.com/a/21977269/5155923
+ try {
+ String message = MessageUtils.buffer().warning("Waiting for user input before build continues...").toString();
+ getLog().warn(message);
+ prompter.prompt("Press Enter to continue");
+ } catch (PrompterException e) {
+ throw new MojoFailureException("Could not prompt for user input. Do not use parameter 'waitForInput' in that case", e);
+ }
+ }
}