You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:28:28 UTC
[sling-slingstart-maven-plugin] 09/13: SLING-6544 allow to block
until user presses Enter
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag slingstart-maven-plugin-1.7.2
in repository https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git
commit 819d01471957df7b26a5f7328421d11194409aad
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Feb 23 11:51:25 2017 +0000
SLING-6544 allow to block until user presses Enter
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/slingstart-maven-plugin@1784111 13f79535-47bb-0310-9956-ffa450edef68
---
.../slingstart/run/AbstractStartStopMojo.java | 82 ++++++++++++++++++++++
.../sling/maven/slingstart/run/StartMojo.java | 35 ++-------
.../sling/maven/slingstart/run/StopMojo.java | 11 ++-
3 files changed, 93 insertions(+), 35 deletions(-)
diff --git a/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java b/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java
new file mode 100644
index 0000000..ac7d231
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/slingstart/run/AbstractStartStopMojo.java
@@ -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);
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java b/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
index af15111..d9271c8 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
@@ -60,20 +60,7 @@ import org.apache.sling.maven.slingstart.BuildConstants;
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 AbstractMojo {
/**
* 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 AbstractMojo {
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 AbstractMojo {
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 AbstractMojo {
}
}
}
+ blockIfNecessary();
}
/**
diff --git a/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java b/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java
index 0c58f2a..daf3e49 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/run/StopMojo.java
@@ -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.annotations.Mojo;
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());
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.