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/10 07:03:19 UTC

[sling-feature-launcher-maven-plugin] branch feature/SLING-10364-wait-for-input created (now da2100b)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a change to branch feature/SLING-10364-wait-for-input
in repository https://gitbox.apache.org/repos/asf/sling-feature-launcher-maven-plugin.git.


      at da2100b  SLING-10374 optionally wait for user input before stopping the server

This branch includes the following new commits:

     new da2100b  SLING-10374 optionally wait for user input before stopping the server

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-feature-launcher-maven-plugin] 01/01: SLING-10374 optionally wait for user input before stopping the server

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/SLING-10364-wait-for-input
in repository https://gitbox.apache.org/repos/asf/sling-feature-launcher-maven-plugin.git

commit da2100b521847eb06a512cca03fa82b000a4286b
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon May 10 09:03:07 2021 +0200

    SLING-10374 optionally wait for user input before stopping the server
---
 pom.xml                                            |  5 +++++
 .../sling/maven/feature/launcher/StopMojo.java     | 23 +++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 973454f..b83ef51 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,11 @@
             <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</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..4d3ec92 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
@@ -27,6 +27,8 @@ 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.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 +39,20 @@ 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;
+
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
-        
+        if (waitForInput) {
+            waitForInput();
+        }
         try {
             for ( Launch launch : launches ) {
                 getLog().info("Stopping launch with id " + launch.getId());
@@ -50,4 +63,12 @@ public class StopMojo extends AbstractMojo {
         }
     }
 
+    protected void waitForInput() throws MojoFailureException {
+        // http://stackoverflow.com/a/21977269/5155923
+        try {
+            prompter.prompt("Press Enter to continue");
+        } catch (PrompterException e) {
+            throw new MojoFailureException("Could not prompt for user input. Maven is probably running in non-interactive mode! Do not use parameter 'shouldBlockUntilKeyIsPressed' in that case", e);
+        }
+    }
 }