You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by pa...@apache.org on 2002/07/24 18:57:28 UTC
cvs commit: jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher LaunchCommand.java LaunchTask.java LaunchTask_en.properties
patrickl 2002/07/24 09:57:27
Modified: daemon/src/bin launcher.xml
daemon/src/java/org/apache/commons/launcher
LaunchCommand.java LaunchTask.java
LaunchTask_en.properties
Log:
Add "print" attribute to the <launch> command so that the child JVM's command line can be printed to System.err.
Revision Changes Path
1.7 +3 -2 jakarta-commons-sandbox/daemon/src/bin/launcher.xml
Index: launcher.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/bin/launcher.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- launcher.xml 24 Jul 2002 14:52:03 -0000 1.6
+++ launcher.xml 24 Jul 2002 16:57:27 -0000 1.7
@@ -14,10 +14,10 @@
-->
-<project name="Ant Launcher" default="ant" basedir="..">
+<project name="Ant Launcher" default="ant" basedir=".">
<!-- Set the application home to the parent directory of this directory -->
- <property name="app.home" location="${basedir}"/>
+ <property name="app.home" location="${basedir}/.."/>
<!-- Build the classpath relative to the application home -->
<path id="base.class.path">
@@ -79,6 +79,7 @@
<launch classname="org.apache.tools.ant.Main"
waitforchild="${wait}"
debug="${jdb}"
+ print="${print}"
requiretools="true"
redirectoutput="true"
output="${app.home}/logs/ant.log"
1.5 +54 -0 jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/LaunchCommand.java
Index: LaunchCommand.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/LaunchCommand.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LaunchCommand.java 22 Jul 2002 05:41:39 -0000 1.4
+++ LaunchCommand.java 24 Jul 2002 16:57:27 -0000 1.5
@@ -123,6 +123,16 @@
private File outputFile = null;
/**
+ * Cached print flag.
+ */
+ private boolean print = false;
+
+ /**
+ * Cached requireTools flag.
+ */
+ private boolean requireTools = false;
+
+ /**
* Cached redirect flag.
*/
private boolean redirect = false;
@@ -303,6 +313,28 @@
}
/**
+ * Get the print flag.
+ *
+ * @return the print flag
+ */
+ public boolean getPrint() {
+
+ return print;
+
+ }
+
+ /**
+ * Get the requireTools flag.
+ *
+ * @return the requireTools flag
+ */
+ public boolean getRequiretools() {
+
+ return requireTools;
+
+ }
+
+ /**
* Get the list of nested sysproperty elements.
*
* @return the {@link String} objects
@@ -332,6 +364,28 @@
public boolean getWaitforchild() {
return waitForChild;
+
+ }
+
+ /**
+ * Set the print flag.
+ *
+ * @param print the print flag
+ */
+ public void setPrint(boolean print) {
+
+ this.print = print;
+
+ }
+
+ /**
+ * Set the requireTools flag.
+ *
+ * @param requireTools the requireTools flag
+ */
+ public void setRequiretools(boolean requireTools) {
+
+ this.requireTools = requireTools;
}
1.21 +70 -8 jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/LaunchTask.java
Index: LaunchTask.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/LaunchTask.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- LaunchTask.java 24 Jul 2002 15:44:36 -0000 1.20
+++ LaunchTask.java 24 Jul 2002 16:57:27 -0000 1.21
@@ -65,6 +65,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.StringTokenizer;
import org.apache.commons.launcher.types.ArgumentSet;
import org.apache.commons.launcher.types.ConditionalArgument;
import org.apache.commons.launcher.types.ConditionalVariable;
@@ -191,6 +192,11 @@
private File outputFile = null;
/**
+ * Cached print flag.
+ */
+ private boolean print = false;
+
+ /**
* Cached redirect flag.
*/
private boolean redirect = false;
@@ -367,13 +373,6 @@
if (Launcher.isStopped())
throw new BuildException();
- // Prepend standard paths to classpath
- StringBuffer fullClasspath = new StringBuffer(Launcher.getBootstrapFile().getPath());
- if (requireTools) {
- fullClasspath.append(File.pathSeparator);
- fullClasspath.append(Launcher.getToolsClasspath());
- }
-
if (mainClassName == null)
throw new BuildException(Launcher.getLocalizedString("classname.null", this.getClass().getName()));
@@ -437,6 +436,8 @@
boolean filteredFailOnError = failOnError;
String filteredMinimizedWindowTitle = minimizedWindowTitle;
File filteredMinimizedWindowIcon = minimizedWindowIcon;
+ boolean filteredPrint = print;
+ boolean filteredRequireTools = requireTools;
boolean filteredUseSystemIn = useSystemIn;
boolean filteredWaitForChild = waitForChild;
@@ -473,6 +474,8 @@
command.setFailonerror(filteredFailOnError);
command.setMinimizedwindowtitle(filteredMinimizedWindowTitle);
command.setMinimizedwindowicon(filteredMinimizedWindowIcon);
+ command.setPrint(filteredPrint);
+ command.setRequiretools(filteredRequireTools);
command.setUsesystemin(filteredUseSystemIn);
command.setWaitforchild(filteredWaitForChild);
filter.filter(command);
@@ -490,6 +493,8 @@
filteredFailOnError = command.getFailonerror();
filteredMinimizedWindowTitle = command.getMinimizedwindowtitle();
filteredMinimizedWindowIcon = command.getMinimizedwindowicon();
+ filteredPrint = command.getPrint();
+ filteredRequireTools = command.getRequiretools();
filteredUseSystemIn = command.getUsesystemin();
filteredWaitForChild = command.getWaitforchild();
// Check changes
@@ -517,7 +522,12 @@
filteredUseSystemIn = true;
}
- // Prepend this package's classpath
+ // Prepend standard paths to classpath
+ StringBuffer fullClasspath = new StringBuffer(Launcher.getBootstrapFile().getPath());
+ if (filteredRequireTools) {
+ fullClasspath.append(File.pathSeparator);
+ fullClasspath.append(Launcher.getToolsClasspath());
+ }
if (filteredClasspath != null) {
fullClasspath.append(File.pathSeparator);
fullClasspath.append(filteredClasspath);
@@ -612,12 +622,52 @@
cmd[nextCmdArg++] = "-classpath";
cmd[nextCmdArg++] = fullClasspath.toString();
// Add main class to command
+ int mainClassArg = nextCmdArg;
cmd[nextCmdArg++] = ChildMain.class.getName();
cmd[nextCmdArg++] = filteredMainClassName;
// Add args to command
for (int i = 0; i < appArgs.size(); i++)
cmd[nextCmdArg++] = (String)appArgs.get(i);
+ // Print command
+ if (filteredPrint) {
+ // Quote the command arguments
+ String osname = System.getProperty("os.name").toLowerCase();
+ StringBuffer buf = new StringBuffer(cmd.length * 100);
+ String quote = null;
+ String replaceQuote = null;
+ if (osname.indexOf("windows") >= 0) {
+ // Use double-quotes to quote on Windows
+ quote = "\"";
+ replaceQuote = quote + quote + quote;
+ } else {
+ // Use single-quotes to quote on Unix
+ quote = "'";
+ replaceQuote = quote + "\\" + quote + quote;
+ }
+ for (int i = 0; i < cmd.length; i++) {
+ // Pull ChildMain out of command as we want to print the
+ // real JVM command that can be executed by the user
+ if (i == mainClassArg)
+ continue;
+ if (i > 0)
+ buf.append(" ");
+ buf.append(quote);
+ StringTokenizer tokenizer = new StringTokenizer(cmd[i], quote, true);
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ if (quote.equals(token))
+ buf.append(replaceQuote);
+ else
+ buf.append(token);
+ }
+ buf.append(quote);
+ }
+ // Print the quoted command
+ System.err.println(Launcher.getLocalizedString("executing.child.command", this.getClass().getName()) + ":");
+ System.err.println(buf.toString());
+ }
+
// Create a child JVM
if (Launcher.isStopped())
throw new BuildException();
@@ -867,6 +917,18 @@
public void setOutput(File outputFile) {
this.outputFile = outputFile;
+
+ }
+
+ /**
+ * Set the print flag. Setting this flag to true will cause the full child
+ * JVM command to be printed to {@link System#out}.
+ *
+ * @param print the print flag
+ */
+ public void setPrint(boolean print) {
+
+ this.print = print;
}
1.4 +1 -0 jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/LaunchTask_en.properties
Index: LaunchTask_en.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/LaunchTask_en.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LaunchTask_en.properties 22 Jul 2002 04:59:06 -0000 1.3
+++ LaunchTask_en.properties 24 Jul 2002 16:57:27 -0000 1.4
@@ -11,3 +11,4 @@
filter.not.filter=class does not implement the LaunchFilter interface
filter.exception=filter class encountered a problem
child.failed=The launched process returned an exit value of
+executing.child.command=Executing the following command
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>