commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From patri...@apache.org
Subject cvs commit: jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher ChildMain.java LaunchTask.java LaunchTask_en.properties Launcher.java
Date Mon, 22 Jul 2002 04:59:06 GMT
patrickl    2002/07/21 21:59:06

  Modified:    daemon/src/java/org/apache/commons/launcher ChildMain.java
                        LaunchTask.java LaunchTask_en.properties
                        Launcher.java
  Log:
  Move static fields from Launcher class to ChildMain class so that ChildMain does not need
to load the Launcher class. This eliminates the need for Ant to be in the child JVM's classpath
since ChildMain now has no required imports of Ant classes.
  
  Revision  Changes    Path
  1.7       +66 -10    jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/ChildMain.java
  
  Index: ChildMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/ChildMain.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ChildMain.java	20 Jul 2002 18:16:27 -0000	1.6
  +++ ChildMain.java	22 Jul 2002 04:59:06 -0000	1.7
  @@ -82,6 +82,62 @@
    */
   public class ChildMain extends Thread {
   
  +    //----------------------------------------------------------- Static Fields
  +
  +    /**
  +     * The appendOutput system property name.
  +     */
  +    public final static String APPEND_OUTPUT_PROP_NAME =
  +        "org.apache.commons.launcher.appendOutput";
  +
  +    /**
  +     * The displayMiminizedWindow system property name.
  +     */
  +    public final static String DISPLAY_MINIMIZED_WINDOW_PROP_NAME =
  +        "org.apache.commons.launcher.displayMinimizedWindow";
  +
  +    /**
  +     * The disposeMiminizedWindow system property name.
  +     */
  +    public final static String DISPOSE_MINIMIZED_WINDOW_PROP_NAME =
  +        "org.apache.commons.launcher.disposeMinimizedWindow";
  +
  +    /**
  +     * The executableName system property name.
  +     */
  +    public final static String EXECUTABLE_PROP_NAME =
  +        "org.apache.commons.launcher.executableName";
  +
  +    /**
  +     * The heartbeatFile system property name.
  +     */
  +    public final static String HEARTBEAT_FILE_PROP_NAME =
  +        "org.apache.commons.launcher.heartbeatFile";
  +
  +    /**
  +     * The miminizedWindowTitle system property name.
  +     */
  +    public final static String MINIMIZED_WINDOW_TITLE_PROP_NAME =
  +        "org.apache.commons.launcher.minimizedWindowTitle";
  +
  +    /**
  +     * The miminizedWindowIcon system property name.
  +     */
  +    public final static String MINIMIZED_WINDOW_ICON_PROP_NAME=
  +        "org.apache.commons.launcher.minimizedWindowIcon";
  +
  +    /**
  +     * The outputFile system property name.
  +     */
  +    public final static String OUTPUT_FILE_PROP_NAME =
  +        "org.apache.commons.launcher.outputFile";
  +
  +    /**
  +     * The waitForChild system property name.
  +     */
  +    public final static String WAIT_FOR_CHILD_PROP_NAME =
  +        "org.apache.commons.launcher.waitForChild";
  +
       //------------------------------------------------------------------ Fields
   
       /**
  @@ -117,7 +173,6 @@
   
           // Invoke the target application in a separate thread so that we
           // caught any uncaught errors thrown by the target application
  -        Launcher.setVerbose(true);
           Thread mainThread = new ChildMain(new ExitOnErrorThreadGroup(ChildMain.class.getName()),
args);
           mainThread.start();
   
  @@ -141,9 +196,9 @@
   
               // Start the thread to check if the parent JVM exits.
               boolean waitForChild = false;
  -            if (System.getProperty(Launcher.WAIT_FOR_CHILD_PROP_NAME) != null) {
  +            if (System.getProperty(ChildMain.WAIT_FOR_CHILD_PROP_NAME) != null) {
                   waitForChild = true;
  -                String heartbeatFile = System.getProperty(Launcher.HEARTBEAT_FILE_PROP_NAME);
  +                String heartbeatFile = System.getProperty(ChildMain.HEARTBEAT_FILE_PROP_NAME);
                   ParentListener heartbeat = new ParentListener(heartbeatFile);
                   // Make the thread a daemon thread so that it does not
                   // prevent this process from exiting when all of the
  @@ -153,10 +208,10 @@
               }
   
               // If applicable, redirect output and error streams
  -            String outputPath = System.getProperty(Launcher.OUTPUT_FILE_PROP_NAME);
  +            String outputPath = System.getProperty(ChildMain.OUTPUT_FILE_PROP_NAME);
               if (outputPath != null) {
                   boolean appendOutput = false;
  -                if (System.getProperty(Launcher.APPEND_OUTPUT_PROP_NAME) != null)
  +                if (System.getProperty(ChildMain.APPEND_OUTPUT_PROP_NAME) != null)
                       appendOutput = true;
                   PrintStream ps = new PrintStream(new FileOutputStream(outputPath, appendOutput),
true);
                   System.setOut(ps);
  @@ -179,17 +234,17 @@
               // Create the icon window if this is a waitForChild task
               Frame frame = null;
               boolean displayMinimizedWindow = false;
  -            if (System.getProperty(Launcher.DISPLAY_MINIMIZED_WINDOW_PROP_NAME) != null)
  +            if (System.getProperty(ChildMain.DISPLAY_MINIMIZED_WINDOW_PROP_NAME) != null)
                   displayMinimizedWindow = true;
               String osname = System.getProperty("os.name").toLowerCase();
               if (displayMinimizedWindow && osname.indexOf("windows") >= 0) {
                   try {
                       frame = new Frame();
  -                    String title = System.getProperty(Launcher.MINIMIZED_WINDOW_TITLE_PROP_NAME);
  +                    String title = System.getProperty(ChildMain.MINIMIZED_WINDOW_TITLE_PROP_NAME);
                       if (title != null)
                           frame.setTitle(title);
                       frame.setState(Frame.ICONIFIED);
  -                    String icon = System.getProperty(Launcher.MINIMIZED_WINDOW_TITLE_PROP_NAME);
  +                    String icon = System.getProperty(ChildMain.MINIMIZED_WINDOW_TITLE_PROP_NAME);
                       if (icon != null) {
                           Image iconImage = Toolkit.getDefaultToolkit().createImage(icon);
                           if (iconImage != null)
  @@ -214,14 +269,15 @@
               mainMethod.invoke(null, paramValues);
   
               // Close the frame if it exists
  -            if (frame != null && System.getProperty(Launcher.DISPOSE_MINIMIZED_WINDOW_PROP_NAME)
!= null) {
  +            if (frame != null && System.getProperty(ChildMain.DISPOSE_MINIMIZED_WINDOW_PROP_NAME)
!= null) {
                   // Exit this process. Closing or disposing of the window is not
                   // enough to allow the process to exit.
                   System.exit(0);
               }
   
           } catch (Throwable t) {
  -            Launcher.error(t);
  +            String message = t.getMessage();
  +            t.printStackTrace();
               System.exit(1);
           }
   
  
  
  
  1.17      +38 -19    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- LaunchTask.java	20 Jul 2002 18:07:32 -0000	1.16
  +++ LaunchTask.java	22 Jul 2002 04:59:06 -0000	1.17
  @@ -146,6 +146,11 @@
       private boolean disposeMinimizedWindow = true;
   
       /**
  +     * Cached failOnError flag.
  +     */
  +    private boolean failOnError = true;
  +
  +    /**
        * Cached filter instance.
        */
       private LaunchFilter filter = null;
  @@ -502,31 +507,31 @@
                   fullClasspath.append(filteredClasspath);
               }
   
  -            // Set Launcher.WAIT_FOR_CHILD_PROP_NAME property for child JVM
  -            sysProps.remove(Launcher.WAIT_FOR_CHILD_PROP_NAME);
  +            // Set ChildMain.WAIT_FOR_CHILD_PROP_NAME property for child JVM
  +            sysProps.remove(ChildMain.WAIT_FOR_CHILD_PROP_NAME);
               if (filteredWaitForChild)
  -                sysProps.put(Launcher.WAIT_FOR_CHILD_PROP_NAME, "");
  +                sysProps.put(ChildMain.WAIT_FOR_CHILD_PROP_NAME, "");
   
               // Set minimized window properties for child JVM
  -            sysProps.remove(Launcher.DISPLAY_MINIMIZED_WINDOW_PROP_NAME);
  -            sysProps.remove(Launcher.MINIMIZED_WINDOW_TITLE_PROP_NAME);
  -            sysProps.remove(Launcher.MINIMIZED_WINDOW_ICON_PROP_NAME);
  -            sysProps.remove(Launcher.DISPOSE_MINIMIZED_WINDOW_PROP_NAME);
  +            sysProps.remove(ChildMain.DISPLAY_MINIMIZED_WINDOW_PROP_NAME);
  +            sysProps.remove(ChildMain.MINIMIZED_WINDOW_TITLE_PROP_NAME);
  +            sysProps.remove(ChildMain.MINIMIZED_WINDOW_ICON_PROP_NAME);
  +            sysProps.remove(ChildMain.DISPOSE_MINIMIZED_WINDOW_PROP_NAME);
               if (!filteredWaitForChild && filteredDisplayMinimizedWindow) {
  -                sysProps.put(Launcher.DISPLAY_MINIMIZED_WINDOW_PROP_NAME, "");
  +                sysProps.put(ChildMain.DISPLAY_MINIMIZED_WINDOW_PROP_NAME, "");
                   if (filteredMinimizedWindowTitle != null)
  -                    sysProps.put(Launcher.MINIMIZED_WINDOW_TITLE_PROP_NAME, filteredMinimizedWindowTitle);
  +                    sysProps.put(ChildMain.MINIMIZED_WINDOW_TITLE_PROP_NAME, filteredMinimizedWindowTitle);
                   else
  -                    sysProps.put(Launcher.MINIMIZED_WINDOW_TITLE_PROP_NAME, getOwningTarget().getName());
  +                    sysProps.put(ChildMain.MINIMIZED_WINDOW_TITLE_PROP_NAME, getOwningTarget().getName());
                   if (filteredMinimizedWindowIcon != null)
  -                    sysProps.put(Launcher.MINIMIZED_WINDOW_ICON_PROP_NAME, filteredMinimizedWindowIcon.getCanonicalPath());
  -                // Set Launcher.DISPOSE_MINIMIZED_WINDOW_PROP_NAME property
  +                    sysProps.put(ChildMain.MINIMIZED_WINDOW_ICON_PROP_NAME, filteredMinimizedWindowIcon.getCanonicalPath());
  +                // Set ChildMain.DISPOSE_MINIMIZED_WINDOW_PROP_NAME property
                   if (filteredDisposeMinimizedWindow)
  -                    sysProps.put(Launcher.DISPOSE_MINIMIZED_WINDOW_PROP_NAME, "");
  +                    sysProps.put(ChildMain.DISPOSE_MINIMIZED_WINDOW_PROP_NAME, "");
               }
   
  -            // Set Launcher.OUTPUT_FILE_PROP_NAME property for child JVM
  -            sysProps.remove(Launcher.OUTPUT_FILE_PROP_NAME);
  +            // Set ChildMain.OUTPUT_FILE_PROP_NAME property for child JVM
  +            sysProps.remove(ChildMain.OUTPUT_FILE_PROP_NAME);
               if (!filteredWaitForChild && filteredRedirect) {
                   if (filteredOutputFile != null) {
                       String outputFilePath = filteredOutputFile.getCanonicalPath();
  @@ -538,9 +543,9 @@
                       }
                       if (!filteredOutputFile.canWrite())
                           throw new BuildException(outputFilePath + " " + Launcher.getLocalizedString("output.file.not.writable",
this.getClass().getName()));
  -                    sysProps.put(Launcher.OUTPUT_FILE_PROP_NAME, outputFilePath);
  +                    sysProps.put(ChildMain.OUTPUT_FILE_PROP_NAME, outputFilePath);
                       if (filteredAppendOutput)
  -                        sysProps.put(Launcher.APPEND_OUTPUT_PROP_NAME, "");
  +                        sysProps.put(ChildMain.APPEND_OUTPUT_PROP_NAME, "");
                       Launcher.getLog().println(Launcher.getLocalizedString("redirect.notice",
this.getClass().getName()) + " " + outputFilePath);
                   } else {
                       throw new BuildException(Launcher.getLocalizedString("output.file.null",
this.getClass().getName()));
  @@ -556,12 +561,12 @@
                   String tmpDirName = (String)sysProps.get("java.io.tmpdir");
                   if (tmpDirName != null)
                       tmpDir = new File(tmpDirName);
  -                File heartbeatFile = File.createTempFile(Launcher.HEARTBEAT_FILE_PROP_NAME
+ ".", "", tmpDir);
  +                File heartbeatFile = File.createTempFile(ChildMain.HEARTBEAT_FILE_PROP_NAME
+ ".", "", tmpDir);
                   heartbeatFile.deleteOnExit();
                   // Open the heartbeat file for writing so that it the child JVM
                   // will not be able to delete it while this process is running
                   FileOutputStream fos = new FileOutputStream(heartbeatFile);
  -                sysProps.put(Launcher.HEARTBEAT_FILE_PROP_NAME, heartbeatFile.getCanonicalPath());
  +                sysProps.put(ChildMain.HEARTBEAT_FILE_PROP_NAME, heartbeatFile.getCanonicalPath());
               }
   
               // Assemble child command
  @@ -622,6 +627,9 @@
                   // Let threads flush any unflushed output
                   stdout.join();
                   stderr.join();
  +                int exitValue = proc.exitValue();
  +                if (failOnError && exitValue != 0)
  +                    throw new BuildException(Launcher.getLocalizedString("child.failed",
this.getClass().getName()) + " " + exitValue);
               }
               // Need to check if the launching process has stopped because
               // processes don't throw exceptions when they are terminated
  @@ -764,6 +772,17 @@
   
       }
   
  +    /**
  +     * Set the failOnError flag.
  +     *
  +     * @param failOnError true if the launch process should stop if the child
  +     *  JVM returns an exit value other than 0
  +     */
  +    public void setFailonerror(boolean failOnError) {
  +
  +        this.failOnError = failOnError;
  +
  +    }
       /**
        * Set the filter class name.
        *
  
  
  
  1.3       +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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LaunchTask_en.properties	19 Jul 2002 08:05:11 -0000	1.2
  +++ LaunchTask_en.properties	22 Jul 2002 04:59:06 -0000	1.3
  @@ -10,3 +10,4 @@
   no.run.standalone=This task can only be used within the Launcher application. It cannot
be used within a regular Ant buildfile.
   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
  
  
  
  1.12      +2 -60     jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/Launcher.java
  
  Index: Launcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/Launcher.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Launcher.java	17 Jul 2002 00:15:51 -0000	1.11
  +++ Launcher.java	22 Jul 2002 04:59:06 -0000	1.12
  @@ -111,11 +111,6 @@
   
       //----------------------------------------------------------- Static Fields
   
  -    /**
  -     * The appendOutput system property name.
  -     */
  -    public final static String APPEND_OUTPUT_PROP_NAME =
  -        "org.apache.commons.launcher.appendOutput";
   
       /**
        * Cached bootstrap file.
  @@ -123,40 +118,11 @@
       private static File bootstrapFile = null;
   
       /**
  -     * The displayMiminizedWindow system property name.
  -     */
  -    public final static String DISPLAY_MINIMIZED_WINDOW_PROP_NAME =
  -        "org.apache.commons.launcher.displayMinimizedWindow";
  -
  -    /**
  -     * The disposeMiminizedWindow system property name.
  -     */
  -    public final static String DISPOSE_MINIMIZED_WINDOW_PROP_NAME =
  -        "org.apache.commons.launcher.disposeMinimizedWindow";
  -
  -    /**
  -     * The executableName system property name.
  -     */
  -    public final static String EXECUTABLE_PROP_NAME =
  -        "org.apache.commons.launcher.executableName";
  -
  -    /**
  -     * The heartbeatFile system property name.
  -     */
  -    public final static String HEARTBEAT_FILE_PROP_NAME =
  -        "org.apache.commons.launcher.heartbeatFile";
  -
  -    /**
        * Cached java command
        */
       private static String javaCmd = null;
   
       /**
  -     * This platform's line separator
  -     */
  -    public final static String LINE_SEPARATOR = System.getProperty("line.separator");
  -
  -    /**
        * Shared lock.
        */
       private static Object lock = new Object();
  @@ -167,24 +133,6 @@
       private static PrintStream log = System.err;
   
       /**
  -     * The miminizedWindowTitle system property name.
  -     */
  -    public final static String MINIMIZED_WINDOW_TITLE_PROP_NAME =
  -        "org.apache.commons.launcher.minimizedWindowTitle";
  -
  -    /**
  -     * The miminizedWindowIcon system property name.
  -     */
  -    public final static String MINIMIZED_WINDOW_ICON_PROP_NAME=
  -        "org.apache.commons.launcher.minimizedWindowIcon";
  -
  -    /**
  -     * The outputFile system property name.
  -     */
  -    public final static String OUTPUT_FILE_PROP_NAME =
  -        "org.apache.commons.launcher.outputFile";
  -
  -    /**
        * Cached resourceBundle
        */
       private static ResourceBundle resourceBundle = null;
  @@ -237,12 +185,6 @@
        */
       private static boolean verbose = false;
   
  -    /**
  -     * The waitForChild system property name.
  -     */
  -    public final static String WAIT_FOR_CHILD_PROP_NAME =
  -        "org.apache.commons.launcher.waitForChild";
  -
       //---------------------------------------------------------- Static Methods
   
   
  @@ -358,7 +300,7 @@
                       throw new IllegalArgumentException();
                   } else if ("-executablename".equals(args[currentArg])) {
                       if (currentArg + 1 < args.length)
  -                        System.setProperty(Launcher.EXECUTABLE_PROP_NAME, args[++currentArg]);
  +                        System.setProperty(ChildMain.EXECUTABLE_PROP_NAME, args[++currentArg]);
                       else
                           throw new IllegalArgumentException(args[currentArg] + " " + Launcher.getLocalizedString("missing.arg"));
                   } else if ("-verbose".equals(args[currentArg])) {
  @@ -850,7 +792,7 @@
                       // Property found
                       String propName = unresolved.substring(tokenStart + 1, closeProp);
                       if ("launcher.executable.name".equals(propName)) {
  -                        prop = System.getProperty(Launcher.EXECUTABLE_PROP_NAME);
  +                        prop = System.getProperty(ChildMain.EXECUTABLE_PROP_NAME);
                           if (prop != null) {
                               // Quote the property
                               prop = "\"" + prop + "\"";
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message