SLING-6545 allow to redirect stdout/stderr to dedicated file
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1783981 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java b/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java
index b1c132e..33f4429 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java
@@ -32,6 +32,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.shared.utils.StringUtils;
import org.apache.sling.maven.slingstart.launcher.Main;
/**
@@ -179,10 +180,18 @@
builder.command(args.toArray(new String[args.size()]));
builder.directory(this.configuration.getFolder());
builder.redirectErrorStream(true);
- builder.redirectOutput(Redirect.INHERIT);
- builder.redirectError(Redirect.INHERIT);
-
logger.info("Starting Launchpad " + this.configuration.getId() + "...");
+ String stdOutFile = this.configuration.getStdOutFile();
+ if (StringUtils.isNotBlank(stdOutFile)) {
+ File absoluteStdOutFile = new File(builder.directory(), stdOutFile);
+ // make sure to create the parent directories (if they do not exist yet)
+ absoluteStdOutFile.getParentFile().mkdirs();
+ builder.redirectOutput(absoluteStdOutFile);
+ logger.info("Redirecting stdout and stderr to " + absoluteStdOutFile);
+ } else {
+ builder.redirectOutput(Redirect.INHERIT);
+ }
+
logger.debug("Launchpad cmd: " + builder.command());
logger.debug("Launchpad dir: " + builder.directory());
diff --git a/src/main/java/org/apache/sling/maven/slingstart/run/ServerConfiguration.java b/src/main/java/org/apache/sling/maven/slingstart/run/ServerConfiguration.java
index 8aa00fc..2d0502a 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/run/ServerConfiguration.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/run/ServerConfiguration.java
@@ -64,6 +64,13 @@
/** The folder to use. */
private File folder;
+
+ /**
+ * The relative filename of the file which receives both the standard output (stdout) and standard error (stderr) of the server processes.
+ * If null or empty string the server process inherits stdout from the parent process (i.e. the Maven process).
+ * The given filename must be relative to the working directory of the according server.
+ */
+ private String stdOutFile;
/**
* Get the instance id
@@ -168,6 +175,14 @@
this.controlPort = controlPort;
}
+ public String getStdOutFile() {
+ return stdOutFile;
+ }
+
+ public void setStdOutFile(String stdOutFile) {
+ this.stdOutFile = stdOutFile;
+ }
+
/**
* Get the server
* @return The server
@@ -189,7 +204,7 @@
copy.setInstances(1);
copy.setFolder(this.getFolder());
copy.setControlPort(this.getControlPort());
-
+ copy.setStdOutFile(this.stdOutFile);
return copy;
}
@@ -199,6 +214,6 @@
+ ", port=" + port + ", controlPort=" + controlPort
+ ", contextPath=" + contextPath
+ ", vmOpts=" + vmOpts + ", vmDebugOpts=" + getVmDebugOpts(null) + ", opts=" + opts + ", instances="
- + instances + ", folder=" + folder + "]";
+ + instances + ", folder=" + folder + ", stdout=" + stdOutFile + "]";
}
}