sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1784111 - in /sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run: AbstractStartStopMojo.java StartMojo.java StopMojo.java
Date Thu, 23 Feb 2017 11:51:25 GMT
Author: kwin
Date: Thu Feb 23 11:51:25 2017
New Revision: 1784111

URL: http://svn.apache.org/viewvc?rev=1784111&view=rev
Log:
SLING-6544 allow to block until user presses Enter

Added:
    sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java
  (with props)
Modified:
    sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
    sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java

Added: sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java?rev=1784111&view=auto
==============================================================================
--- sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java
(added)
+++ sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java
Thu Feb 23 11:51:25 2017
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.maven.slingstart.run;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+
+public abstract class AbstractStartStopMojo extends AbstractMojo {
+
+    /**
+     * Set this to "true" to skip starting the launchpad
+     */
+    @Parameter(property = "maven.test.skip", defaultValue = "false")
+    protected boolean skipLaunchpad;
+
+    /**
+     * Parameter containing the list of server configurations
+     */
+    @Parameter
+    protected List<ServerConfiguration> servers;
+
+    /**
+     * The system properties file will contain all started instances with their ports etc.
+     */
+    @Parameter(defaultValue = "${project.build.directory}/launchpad-runner.properties")
+    protected File systemPropertiesFile;
+
+    /**
+     * If {@code true} this mojo blocks until you press the Enter key.
+     */
+    @Parameter
+    protected boolean shouldBlockUntilKeyIsPressed;
+
+    @Component
+    private Prompter prompter;
+    
+    protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;
+    
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        if (this.skipLaunchpad) {
+            this.getLog().info("Executing of this mojo is disabled by configuration.");
+            return;
+        }
+        
+        doExecute();
+    }
+
+    protected void blockIfNecessary() throws MojoFailureException {
+        if (shouldBlockUntilKeyIsPressed) {
+            // 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);
+            }
+        }
+
+    }
+}

Propchange: sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java?rev=1784111&r1=1784110&r2=1784111&view=diff
==============================================================================
--- sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
(original)
+++ sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
Thu Feb 23 11:51:25 2017
@@ -60,20 +60,7 @@ import org.apache.sling.maven.slingstart
         defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST,
         threadSafe = true
     )
-public class StartMojo extends AbstractMojo {
-
-    /**
-     * Set this to "true" to skip starting the launchpad
-     *
-     */
-    @Parameter(property = "maven.test.skip", defaultValue = "false")
-    protected boolean skipLaunchpad;
-
-    /**
-     * Parameter containing the list of server configurations
-     */
-    @Parameter
-    private List<ServerConfiguration> servers;
+public class StartMojo extends AbstractStartStopMojo {
 
     /**
      * Overwrites debug parameter of all server configurations (if set).
@@ -111,7 +98,9 @@ public class StartMojo extends AbstractM
 
     /**
      * Keep the launchpad running.
+     * @deprecated Use {@link AbstractStartStopMojo#blockUntilKeyIsPressed} instead.
      */
+    @Deprecated
     @Parameter(property = "launchpad.keep.running", defaultValue = "false")
     private boolean keepLaunchpadRunning;
 
@@ -122,12 +111,6 @@ public class StartMojo extends AbstractM
     private boolean parallelExecution;
 
     /**
-     * The system properties file will contain all started instances with their ports etc.
-     */
-    @Parameter(defaultValue = "${project.build.directory}/launchpad-runner.properties")
-    protected File systemPropertiesFile;
-
-    /**
      * The Maven project.
      */
     @Parameter(property = "project", readonly = true, required = true)
@@ -175,16 +158,9 @@ public class StartMojo extends AbstractM
         return prjArtifact;
     }
 
-    /**
-     * @see org.apache.maven.plugin.Mojo#execute()
-     */
+    
     @Override
-    public void execute() throws MojoExecutionException, MojoFailureException {
-        if (this.skipLaunchpad) {
-            this.getLog().info("Executing of the start launchpad mojo is disabled by configuration.");
-            return;
-        }
-
+    protected void doExecute() throws MojoExecutionException, MojoFailureException {
         // delete properties
         if ( systemPropertiesFile != null && systemPropertiesFile.exists() ) {
             FileUtils.deleteQuietly(this.systemPropertiesFile);
@@ -250,6 +226,7 @@ public class StartMojo extends AbstractM
                 }
             }
         }
+        blockIfNecessary();
     }
 
     /**

Modified: sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java?rev=1784111&r1=1784110&r2=1784111&view=diff
==============================================================================
--- sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java
(original)
+++ sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java
Thu Feb 23 11:51:25 2017
@@ -25,6 +25,7 @@ import java.util.Properties;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 
@@ -37,14 +38,11 @@ import org.apache.maven.plugins.annotati
     defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST,
     threadSafe = true
 )
-public class StopMojo extends StartMojo {
+public class StopMojo extends AbstractStartStopMojo {
 
     @Override
-    public void execute() throws MojoExecutionException {
-        if (this.skipLaunchpad) {
-            this.getLog().info("Executing of the stop-multiple launchpad mojo is disabled
by configuration.");
-            return;
-        }
+    protected void doExecute() throws MojoExecutionException, MojoFailureException {
+        
         // read configurations
         final Properties launchpadConfigProps = new Properties();
         Reader reader = null;
@@ -70,6 +68,7 @@ public class StopMojo extends StartMojo
             }
         }
 
+        blockIfNecessary();
         if (configurations.size() > 0) {
             getLog().info(new StringBuilder("Stopping ").append(configurations.size()).append("
Launchpad instances").toString());
 



Mime
View raw message