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/types ConditionalVariableSet.java SysPropertySet.java
Date Mon, 15 Jul 2002 19:58:58 GMT
patrickl    2002/07/15 12:58:58

  Modified:    daemon/src/java LauncherBootstrap.java
               daemon/src/java/org/apache/commons/launcher LaunchTask.java
                        Launcher.java
               daemon/src/java/org/apache/commons/launcher/types
                        ConditionalVariableSet.java SysPropertySet.java
  Log:
  Replace all Vectors with ArrayLists and Hashtables with HashMaps since only Java 1.2 or
higher is supported
  
  Revision  Changes    Path
  1.5       +4 -10     jakarta-commons-sandbox/daemon/src/java/LauncherBootstrap.java
  
  Index: LauncherBootstrap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/LauncherBootstrap.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LauncherBootstrap.java	11 Jul 2002 23:41:57 -0000	1.4
  +++ LauncherBootstrap.java	15 Jul 2002 19:58:57 -0000	1.5
  @@ -63,10 +63,10 @@
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLClassLoader;
  +import java.util.ArrayList;
   import java.util.Enumeration;
   import java.util.Properties;
   import java.util.StringTokenizer;
  -import java.util.Vector;
   
   /**
    * This class is used as a wrapper for loading the
  @@ -264,19 +264,13 @@
               return new URL[0];
   
           // Parse the path string
  -        Vector list = new Vector();
  +        ArrayList list = new ArrayList();
           StringTokenizer tokenizer = new StringTokenizer(fileList, ":");
           URL bootstrapURL = LauncherBootstrap.class.getResource("/" + LauncherBootstrap.class.getName()
+ ".class");
           while (tokenizer.hasMoreTokens())
  -            list.addElement(new URL(bootstrapURL, tokenizer.nextToken()));
  +            list.add(new URL(bootstrapURL, tokenizer.nextToken()));
   
  -        URL[] urls = new URL[list.size()];
  -        Enumeration enum = list.elements();
  -        int currentElement = 0;
  -        while (enum.hasMoreElements())
  -             urls[currentElement++] = (URL)enum.nextElement();
  -
  -        return urls;
  +        return (URL[])list.toArray(new URL[list.size()]);
   
       }
   
  
  
  
  1.8       +43 -49    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- LaunchTask.java	15 Jul 2002 05:02:35 -0000	1.7
  +++ LaunchTask.java	15 Jul 2002 19:58:58 -0000	1.8
  @@ -62,9 +62,9 @@
   import java.io.IOException;
   import java.net.URL;
   import java.net.URLClassLoader;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import java.util.Vector;
  +import java.util.ArrayList;
  +import java.util.HashMap;
  +import java.util.Iterator;
   import org.apache.commons.launcher.types.ConditionalArgument;
   import org.apache.commons.launcher.types.ConditionalVariable;
   import org.apache.commons.launcher.types.SysPropertySet;
  @@ -116,7 +116,7 @@
       /**
        * Cached synchronous child processes for all instances of this class.
        */
  -    private static Vector childProcesses = new Vector();
  +    private static ArrayList childProcesses = new ArrayList();
   
       //------------------------------------------------------------------ Fields
   
  @@ -207,12 +207,12 @@
       /**
        * Cached arg elements
        */
  -    private Vector taskArguments = new Vector();
  +    private ArrayList taskArguments = new ArrayList();
   
       /**
        * Cached jvmarg elements
        */
  -    private Vector taskJVMArguments = new Vector();
  +    private ArrayList taskJVMArguments = new ArrayList();
   
       /**
        * Cached sysproperty elements
  @@ -236,9 +236,9 @@
        *
        * @return the instances of this class.
        */
  -    public static Vector getChildProcesses() {
  +    public static Process[] getChildProcesses() {
   
  -        return childProcesses;
  +        return (Process[])childProcesses.toArray(new Process[childProcesses.size()]);
   
       }
   
  @@ -254,7 +254,7 @@
        */
       public void addArg(ConditionalArgument arg) {
   
  -        taskArguments.addElement(arg);
  +        taskArguments.add(arg);
   
       }
   
  @@ -268,7 +268,7 @@
        */
       public void addJvmarg(ConditionalArgument jvmArg) {
   
  -        taskJVMArguments.addElement(jvmArg);
  +        taskJVMArguments.add(jvmArg);
   
       }
   
  @@ -462,33 +462,33 @@
       }
   
       /**
  -     * Get a Vector containing the nested arg elements.
  +     * Get the list of nested arg elements.
        *
  -     * @return a Vector of ConditionalArgument objects
  +     * @return a list of ConditionalArgument objects
        */
  -    public Vector getArgs() {
  +    public ArrayList getArgs() {
   
           return taskArguments;
   
       }
   
       /**
  -     * Get a Vector containing the nested jvmarg elements.
  +     * Get the list of nested jvmarg elements.
        *
  -     * @return a Vector of ConditionalArgument objects
  +     * @return a list of ConditionalArgument objects
        */
  -    public Vector getJvmargs() {
  +    public ArrayList getJvmargs() {
   
           return taskJVMArguments;
   
       }
   
       /**
  -     * Get the nested sysproperty elements.
  +     * Get the list of nested sysproperty elements.
        *
        * @return the {@link ConditionalVariable} objects
        */
  -    public Vector getSysproperties() {
  +    public ArrayList getSysproperties() {
   
           return taskSysPropertySet.getSysproperties();
   
  @@ -542,8 +542,6 @@
                    }
               }
   
  -            Enumeration enum = null;
  -
               if (mainClassName == null)
                   throw new BuildException(Launcher.getLocalizedString("classname.null",
this.getClass().getName()));
   
  @@ -559,21 +557,20 @@
               }
   
               // Copy all of the nested jvmarg elements into the jvmArgs object
  -            Vector jvmArgs = new Vector(taskJVMArguments.size());
  -            enum = taskJVMArguments.elements();
  -            while (enum.hasMoreElements()) {
  -                ConditionalArgument value = (ConditionalArgument)enum.nextElement();
  +            ArrayList jvmArgs = new ArrayList(taskJVMArguments.size());
  +            for (int i = 0; i < taskArguments.size(); i++) {
  +                ConditionalArgument value = (ConditionalArgument)taskJVMArguments.get(i);
                   // Test "if" and "unless" conditions
                   if (testIfCondition(value.getIf()) && testUnlessCondition(value.getUnless()))
  -                    jvmArgs.addElement(value.getValue());
  +                    jvmArgs.add(value.getValue());
               }
   
               // Copy all of the nested sysproperty elements into the sysProps
               // object
  -            Hashtable sysProps = new Hashtable(taskSysPropertySet.getSysproperties().size());
  -            enum = taskSysPropertySet.getSysproperties().elements();
  -            while (enum.hasMoreElements()) {
  -                ConditionalVariable variable = (ConditionalVariable)enum.nextElement();
  +            ArrayList taskSysProps = taskSysPropertySet.getSysproperties();
  +            HashMap sysProps = new HashMap(taskSysProps.size());
  +            for (int i = 0; i < taskSysProps.size(); i++) {
  +                ConditionalVariable variable = (ConditionalVariable)taskSysProps.get(i);
                   // Test "if" and "unless" conditions
                   if (testIfCondition(variable.getIf()) && testUnlessCondition(variable.getUnless()))
                       sysProps.put(variable.getKey(), variable.getValue());
  @@ -642,13 +639,12 @@
               }
   
               // Copy all of the nested arg elements into the appArgs object
  -            Vector appArgs = new Vector(taskArguments.size());
  -            enum = taskArguments.elements();
  -            while (enum.hasMoreElements()) {
  -                ConditionalArgument value = (ConditionalArgument)enum.nextElement();
  +            ArrayList appArgs = new ArrayList(taskArguments.size());
  +            for (int i = 0; i < taskArguments.size(); i++) {
  +                ConditionalArgument value = (ConditionalArgument)taskArguments.get(i);
                   // Test "if" and "unless" conditions
                   if (testIfCondition(value.getIf()) && testUnlessCondition(value.getUnless()))
  -                    appArgs.addElement(value.getValue());
  +                    appArgs.add(value.getValue());
               }
   
               // Add the Launcher's command line arguments to the appArgs object
  @@ -657,21 +653,20 @@
                   Project project = getProject();
                   String arg = null;
                   while ((arg = project.getUserProperty(LaunchTask.ARG_PROP_NAME + Integer.toString(currentArg++)))
!= null)
  -                    appArgs.addElement(arg);
  +                    appArgs.add(arg);
                }
   
               // Assemble child command
               String[] cmd = new String[5 + jvmArgs.size() + sysProps.size() + appArgs.size()];
               int nextCmdArg = 0;
               cmd[nextCmdArg++] = Launcher.getJavaCommand();
  -            // Add javaArgs to command
  -            enum = jvmArgs.elements();
  -            while (enum.hasMoreElements())
  -                cmd[nextCmdArg++] = (String)enum.nextElement();
  +            // Add jvmArgs to command
  +            for (int i = 0; i < jvmArgs.size(); i++)
  +                cmd[nextCmdArg++] = (String)jvmArgs.get(i);
               // Add properties to command
  -            enum = sysProps.keys();
  -            while (enum.hasMoreElements()) {
  -                String key = (String)enum.nextElement();
  +            Iterator sysPropsKeys = sysProps.keySet().iterator();
  +            while (sysPropsKeys.hasNext()) {
  +                String key = (String)sysPropsKeys.next();
                   if (key == null)
                       continue;
                   String value = (String)sysProps.get(key);
  @@ -688,20 +683,19 @@
               cmd[nextCmdArg++] = ChildMain.class.getName();
               cmd[nextCmdArg++] = mainClassName;
               // Add args to command
  -            enum = appArgs.elements();
  -            while (enum.hasMoreElements())
  -                cmd[nextCmdArg++] = (String)enum.nextElement();
  +            for (int i = 0; i < appArgs.size(); i++)
  +                cmd[nextCmdArg++] = (String)appArgs.get(i);
   
               // Create a child JVM
               if (Launcher.isStopped())
                   throw new BuildException();
               Process proc = null;
  -            synchronized (LaunchTask.class) {
  +            synchronized (LaunchTask.childProcesses) {
                   proc = Runtime.getRuntime().exec(cmd);
                   // Add the synchronous child process
                   if (waitForChild) {
                       childProc = proc;
  -                    LaunchTask.childProcesses.addElement(childProc);
  +                    LaunchTask.childProcesses.add(childProc);
                   }
               }
               if (waitForChild) {
  @@ -722,9 +716,9 @@
                   throw new BuildException(e);
           } finally {
               // Remove the synchronous child process
  -            synchronized (LaunchTask.class) {
  +            synchronized (LaunchTask.childProcesses) {
                   if (waitForChild && childProc != null) {
  -                    LaunchTask.childProcesses.removeElement(childProc);
  +                    LaunchTask.childProcesses.remove(childProc);
                       childProc = null;
                   }
               }
  
  
  
  1.9       +23 -21    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Launcher.java	15 Jul 2002 05:02:35 -0000	1.8
  +++ Launcher.java	15 Jul 2002 19:58:58 -0000	1.9
  @@ -62,10 +62,7 @@
   import java.io.PrintStream;
   import java.net.URL;
   import java.net.URLClassLoader;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
   import java.util.ResourceBundle;
  -import java.util.Vector;
   import org.apache.commons.launcher.types.SysPropertySet;
   import org.apache.tools.ant.Main;
   import org.apache.tools.ant.Project;
  @@ -314,9 +311,19 @@
           }
   
           // Cache the current class loader for this thread and set the class
  -        // loader before running Ant
  +        // loader before running Ant. Note that we only set the class loader
  +        // if we are running a Java version earlier than 1.4 as on 1.4 this
  +        // causes unnecessary loading of the XML parser classes.
           ClassLoader parentLoader = Thread.currentThread().getContextClassLoader();
  -        Thread.currentThread().setContextClassLoader(Launcher.class.getClassLoader());
  +        boolean lessThan14 = true;
  +        try {
  +            Class.forName("java.lang.CharSequence");
  +            lessThan14 = false;
  +        } catch (ClassNotFoundException cnfe) {
  +            // If this class does not exist, then we are not running Java 1.4
  +        }
  +        if (lessThan14)
  +            Thread.currentThread().setContextClassLoader(Launcher.class.getClassLoader());
   
           try {
   
  @@ -356,9 +363,9 @@
               int currentArg = 0;
   
               // Get target
  -            Vector targets = new Vector(args.length - currentArg);
  +            String target = null;
               if (currentArg < args.length)
  -                targets.addElement(args[currentArg++]);
  +                target = args[currentArg++];
               else
                   throw new IllegalArgumentException(Launcher.getLocalizedString("missing.target"));
   
  @@ -406,21 +413,16 @@
               // Set standard Ant user properties
               project.setUserProperty("ant.version", Main.getAntVersion());
               project.setUserProperty("ant.file", launchFile.getCanonicalPath());
  -            project.setUserProperty("ant.java.version", Project.getJavaVersion());
  +            project.setUserProperty("ant.java.version", System.getProperty("java.specification.version"));
   
               // Set the buildfile
               ProjectHelper.configureProject(project, launchFile);
   
  -            // Check that the targets exist
  -            Hashtable availableTargets = project.getTargets();
  -            Enumeration targetListKeys = targets.elements();
  -            while (targetListKeys.hasMoreElements()) {
  -                String currentTarget = (String)targetListKeys.nextElement();
  -                if (!availableTargets.containsKey(currentTarget))
  -                    throw new IllegalArgumentException(currentTarget + " " + Launcher.getLocalizedString("invalid.target"));
  -            }
  +            // Check that the target exists
  +            if (!project.getTargets().containsKey(target))
  +                throw new IllegalArgumentException(target + " " + Launcher.getLocalizedString("invalid.target"));
   
  -            // Execute the targets
  +            // Execute the target
               Thread shutdownHook = new Thread(new Launcher());
               Runtime runtime = Runtime.getRuntime();
               try {
  @@ -428,7 +430,7 @@
               } catch (NoSuchMethodError nsme) {
                   // Early JVMs do not support this method
               }
  -            project.executeTargets(targets);
  +            project.executeTarget(target);
               try {
                   runtime.removeShutdownHook(shutdownHook);
               } catch (NoSuchMethodError nsme) {
  @@ -942,9 +944,9 @@
        */
       public static void killChildProcesses() {
   
  -        Enumeration enum = LaunchTask.getChildProcesses().elements();
  -        while (enum.hasMoreElements())
  -            ((Process)enum.nextElement()).destroy();
  +        Process[] procs = LaunchTask.getChildProcesses();
  +        for (int i = 0; i < procs.length; i++)
  +            procs[i].destroy();
   
       }
   
  
  
  
  1.2       +10 -12    jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/ConditionalVariableSet.java
  
  Index: ConditionalVariableSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/ConditionalVariableSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConditionalVariableSet.java	13 Jul 2002 20:12:34 -0000	1.1
  +++ ConditionalVariableSet.java	15 Jul 2002 19:58:58 -0000	1.2
  @@ -57,9 +57,8 @@
   
   package org.apache.commons.launcher.types;
   
  -import java.util.Enumeration;
  +import java.util.ArrayList;
   import java.util.Stack;
  -import java.util.Vector;
   import org.apache.commons.launcher.Launcher;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.types.DataType;
  @@ -78,7 +77,7 @@
       /**
        * Cached variables and nested ConditionalVariableSet objects
        */
  -    private Vector list = new Vector();
  +    private ArrayList list = new ArrayList();
   
       //----------------------------------------------------------------- Methods
   
  @@ -92,7 +91,7 @@
   
           if (isReference())
               throw noChildrenAllowed();
  -        list.addElement(variable);
  +        list.add(variable);
   
       }
   
  @@ -105,7 +104,7 @@
   
           if (isReference())
               throw noChildrenAllowed();
  -        list.addElement(set);
  +        list.add(set);
   
       }
   
  @@ -114,7 +113,7 @@
        *
        * @return the {@link ConditionalVariable} instances
        */
  -    protected Vector getConditionalvariables() {
  +    protected ArrayList getConditionalvariables() {
   
           // Make sure we don't have a circular reference to this instance
           if (!checked) {
  @@ -125,10 +124,9 @@
   
           // Recursively work through the tree of ConditionalVariableSet objects
           // and accumulate the list of ConditionalVariable objects.
  -        Vector mergedList = new Vector(list.size());
  -        Enumeration enum = list.elements();
  -        while (enum.hasMoreElements()) {
  -            Object o = enum.nextElement();
  +        ArrayList mergedList = new ArrayList(list.size());
  +        for (int i = 0; i < list.size(); i++) {
  +            Object o = list.get(i);
               ConditionalVariableSet nestedSet = null;
               if (o instanceof Reference) {
                   o = ((Reference)o).getReferencedObject(project);
  @@ -139,7 +137,7 @@
               } else if (o.getClass().isInstance(this)) {
                   nestedSet = (ConditionalVariableSet)o;
               } else if (o instanceof ConditionalVariable) {
  -                mergedList.addElement(o);
  +                mergedList.add(o);
               } else {
                   throw new BuildException(Launcher.getLocalizedString("cannot.nest", this.getClass().getName()));
               }
  @@ -163,7 +161,7 @@
   
           if (!list.isEmpty())
               throw tooManyAttributes();
  -        list.addElement(r);
  +        list.add(r);
           super.setRefid(r);
   
       }
  
  
  
  1.4       +2 -2      jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/SysPropertySet.java
  
  Index: SysPropertySet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/SysPropertySet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SysPropertySet.java	14 Jul 2002 20:16:15 -0000	1.3
  +++ SysPropertySet.java	15 Jul 2002 19:58:58 -0000	1.4
  @@ -57,7 +57,7 @@
   
   package org.apache.commons.launcher.types;
   
  -import java.util.Vector;
  +import java.util.ArrayList;
   
   /**
    * A class that represents a set of nested <sysproperty> elements.
  @@ -103,7 +103,7 @@
        *
        * @return the {@link ConditionalVariable} instances
        */
  -    public Vector getSysproperties() {
  +    public ArrayList getSysproperties() {
   
           return getConditionalvariables();
   
  
  
  

--
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