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/15 07:02:36 UTC

cvs commit: jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher LaunchTask.java Launcher.java

patrickl    2002/07/14 22:02:35

  Modified:    daemon/src/java/org/apache/commons/launcher LaunchTask.java
                        Launcher.java
  Log:
  Load supported Ant tasks directly instead of using the Project.init() method. This reduces the number of classes load and cuts down the time it takes the Launcher to execute the launch-ant.sh script by about 0.5 - 1.0 seconds depending on the verson of Ant.
  
  Revision  Changes    Path
  1.7       +4 -40     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LaunchTask.java	14 Jul 2002 20:16:15 -0000	1.6
  +++ LaunchTask.java	15 Jul 2002 05:02:35 -0000	1.7
  @@ -202,7 +202,7 @@
       /**
        * Cached systemIn flag.
        */
  -    private boolean systemIn = false;
  +    private boolean systemIn = true;
   
       /**
        * Cached arg elements
  @@ -462,17 +462,6 @@
       }
   
       /**
  -     * Get the systemIn flag.
  -     *
  -     * @return the systemIn flag
  -     */
  -    public boolean getSystemin() {
  -
  -        return systemIn;
  -
  -    }
  -
  -    /**
        * Get a Vector containing the nested arg elements.
        *
        * @return a Vector of ConditionalArgument objects
  @@ -716,17 +705,9 @@
                   }
               }
               if (waitForChild) {
  -                StreamConnector stdout =
  -                    new StreamConnector(proc.getInputStream(), System.out);
  -                StreamConnector stderr =
  -                    new StreamConnector(proc.getErrorStream(), System.err);
  -                stdout.start();
  -                stderr.start();
  -                if (systemIn) {
  -                    StreamConnector stdin =
  -                        new StreamConnector(System.in, proc.getOutputStream());
  -                    stdin.start();
  -                }
  +                new StreamConnector(proc.getInputStream(), System.out).start();
  +                new StreamConnector(proc.getErrorStream(), System.err).start();
  +                new StreamConnector(System.in, proc.getOutputStream()).start();
                   proc.waitFor();
               }
               // Need to check if the launching process has stopped because
  @@ -958,23 +939,6 @@
       public void setRequiretools(boolean requireTools) {
   
           this.requireTools = requireTools;
  -
  -    }
  -
  -    /**
  -     * Set the systemIn flag. Setting this flag to true will make the System.in
  -     * stream available to the child JVM created by this task. Setting this
  -     * flag to false will make the System.in have no input. Note that
  -     * setting this true has a noticable performance impact and should
  -     * only be set to true if the process to be launched requires
  -     * input from the user via System.in to run correctly.
  -     *
  -     * @param systemIn true if the System.in stream should be accessible to
  -     *  the child JVM
  -     */
  -    public void setSystemin(boolean systemIn) {
  -
  -        this.systemIn = systemIn;
   
       }
   
  
  
  
  1.8       +59 -37    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Launcher.java	14 Jul 2002 20:16:15 -0000	1.7
  +++ Launcher.java	15 Jul 2002 05:02:35 -0000	1.8
  @@ -72,6 +72,17 @@
   import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.Target;
   import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.taskdefs.Ant;
  +import org.apache.tools.ant.taskdefs.Available;
  +import org.apache.tools.ant.taskdefs.CallTarget;
  +import org.apache.tools.ant.taskdefs.ConditionTask;
  +import org.apache.tools.ant.taskdefs.Exit;
  +import org.apache.tools.ant.taskdefs.Property;
  +import org.apache.tools.ant.types.Description;
  +import org.apache.tools.ant.types.FileList;
  +import org.apache.tools.ant.types.FileSet;
  +import org.apache.tools.ant.types.Path;
  +import org.apache.tools.ant.types.PatternSet;
   
   /**
    * A class that is used to launch a Java process. The primary purpose of this
  @@ -189,13 +200,26 @@
       private static boolean stopped = false;
   
       /**
  -     * List of supported tasks
  +     * List of supported Ant tasks.
        */
  -    public final static String[] SUPPORTED_TASKS = new String[] {
  -            "fail",
  -            "property",
  -            "available",
  -            "condition"
  +    public final static Object[] SUPPORTED_ANT_TASKS = new Object[] {
  +            "ant", Ant.class,
  +            "antcall", CallTarget.class,
  +            "available", Available.class,
  +            "condition", ConditionTask.class,
  +            "fail", Exit.class,
  +            "property", Property.class
  +        };
  +
  +    /**
  +     * List of supported Ant types.
  +     */
  +    public final static Object[] SUPPORTED_ANT_TYPES = new Object[] {
  +            "description", Description.class,
  +            "fileset", FileSet.class,
  +            "filelist", FileList.class,
  +            "path", Path.class,
  +            "patternset", PatternSet.class
           };
   
       /**
  @@ -301,8 +325,32 @@
               // Set the project's class loader
               project.setCoreLoader(Launcher.class.getClassLoader());
   
  -            // Initialize the project
  -            project.init();
  +            // Initialize the project. Note that we don't invoke the
  +            // Project.init() method directly as this will cause all of
  +            // the myriad of Task subclasses to load which is a big
  +            // performance hit. Instead, we load only the
  +            // Launcher.SUPPORTED_ANT_TASKS and Launcher.SUPPORTED_ANT_TYPES
  +            // into the project that the Launcher supports.
  +            for (int i = 0; i < Launcher.SUPPORTED_ANT_TASKS.length; i++) {
  +                // The even numbered elements should be the task name
  +                String taskName = (String)Launcher.SUPPORTED_ANT_TASKS[i];
  +                // The odd numbered elements should be the task class
  +                Class taskClass = (Class)Launcher.SUPPORTED_ANT_TASKS[++i];
  +                project.addTaskDefinition(taskName, taskClass);
  +            }
  +            for (int i = 0; i < Launcher.SUPPORTED_ANT_TYPES.length; i++) {
  +                // The even numbered elements should be the type name
  +                String typeName = (String)Launcher.SUPPORTED_ANT_TYPES[i];
  +                // The odd numbered elements should be the type class
  +                Class typeClass = (Class)Launcher.SUPPORTED_ANT_TYPES[++i];
  +                project.addDataTypeDefinition(typeName, typeClass);
  +            }
  +
  +            // Define the LaunchTask.TASK_NAME task
  +            project.addTaskDefinition(LaunchTask.TASK_NAME, LaunchTask.class);
  +
  +            // Define the SysPropertySet.TYPE_NAME data type 
  +            project.addDataTypeDefinition(SysPropertySet.TYPE_NAME, SysPropertySet.class);
   
               // Parse the arguments
               int currentArg = 0;
  @@ -355,36 +403,10 @@
                   project.setUserProperty(LaunchTask.ARG_PROP_NAME + Integer.toString(i), appArgs[i]);
               }
   
  -            // Get Ant version
  -            String antVersion = Main.getAntVersion();
  -
  -            project.setUserProperty("ant.version", antVersion);
  +            // Set standard Ant user properties
  +            project.setUserProperty("ant.version", Main.getAntVersion());
               project.setUserProperty("ant.file", launchFile.getCanonicalPath());
  -
  -            // Reduce the set of supported tasks to only the ones that we
  -            // want to support. The reason for this is that we may be running
  -            // Ant in a custom class loader and we cannot be sure that all
  -            // of Ant's built-in and optional tasks will work.
  -            Hashtable taskList = project.getTaskDefinitions();
  -            Enumeration taskListKeys = taskList.keys();
  -            while (taskListKeys.hasMoreElements()) {
  -                String key = (String)taskListKeys.nextElement();
  -                boolean keepKey = false;
  -                for (int i = 0; i < Launcher.SUPPORTED_TASKS.length; i++) {
  -                    if (Launcher.SUPPORTED_TASKS[i].equals(key)) {
  -                        keepKey = true;
  -                        break;
  -                    }
  -                }
  -                if (!keepKey)
  -                    taskList.remove(key);
  -            }
  -
  -            // Define the LaunchTask.TASK_NAME task
  -            project.addTaskDefinition(LaunchTask.TASK_NAME, LaunchTask.class);
  -
  -            // Define the SysPropertySet.TYPE_NAME data type 
  -            project.addDataTypeDefinition(SysPropertySet.TYPE_NAME, SysPropertySet.class);
  +            project.setUserProperty("ant.java.version", Project.getJavaVersion());
   
               // Set the buildfile
               ProjectHelper.configureProject(project, launchFile);
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>