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 LaunchTask$SysPropertySet_en.properties LaunchTask.java Launcher.java
Date Fri, 12 Jul 2002 22:56:45 GMT
patrickl    2002/07/12 15:56:45

  Modified:    daemon/src/bin launcher.xml
               daemon/src/java/org/apache/commons/launcher LaunchTask.java
                        Launcher.java
  Added:       daemon/src/java/org/apache/commons/launcher
                        LaunchTask$SysPropertySet_en.properties
  Log:
  Add support for sharing system properties among multiple targets using the <syspropertyset>
data type.
  
  Revision  Changes    Path
  1.2       +6 -1      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- launcher.xml	10 Jul 2002 05:27:52 -0000	1.1
  +++ launcher.xml	12 Jul 2002 22:56:45 -0000	1.2
  @@ -19,6 +19,11 @@
       <fileset dir="${app.home}/lib" includes="*.jar"/>
     </path>
   
  +  <!-- Build the sysproperties relative to the application home -->
  +  <syspropertyset id="base.sys.properties">
  +    <sysproperty key="ant.home" file="${app.home}"/>
  +  </syspropertyset>
  +
     <!-- Target that sets JPDA properties when the "debug" property is set -->
     <target name="setjpda" description="Set JPDA properties" if="debug">
   
  @@ -70,8 +75,8 @@
         minimizedWindowTitle="${window.title}">
           <jvmarg value="-Xdebug" if="jpda.settings"/>
           <jvmarg value="-Xrunjdwp:${jpda.settings}" if="jpda.settings"/>
  +        <syspropertyset refid="base.sys.properties"/>
           <classpath refid="base.class.path"/>
  -        <sysproperty key="ant.home" file="${app.home}"/>
       </launch>
   
     </target>
  
  
  
  1.4       +121 -7    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LaunchTask.java	11 Jul 2002 22:06:01 -0000	1.3
  +++ LaunchTask.java	12 Jul 2002 22:56:45 -0000	1.4
  @@ -64,11 +64,13 @@
   import java.net.URLClassLoader;
   import java.util.Enumeration;
   import java.util.Hashtable;
  +import java.util.Stack;
   import java.util.Vector;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.types.DataType;
   import org.apache.tools.ant.types.Environment;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
  @@ -199,7 +201,7 @@
       /**
        * Cached sysproperty elements
        */
  -    private Vector taskVariables = new Vector();
  +    private SysPropertySet taskSysPropertySet = new SysPropertySet();
   
       /**
        * Cached waitForChild flag.
  @@ -246,7 +248,18 @@
        */
       public void addSysproperty(ConditionalVariable var) {
   
  -        taskVariables.addElement(var);
  +        taskSysPropertySet.addSysproperty(var);
  +
  +    }
  +
  +    /**
  +     * Add a nested syspropertyset element.
  +     *
  +     * @param set the syspropertyset element
  +     */
  +    public void addSyspropertyset(SysPropertySet set) {
  +
  +        taskSysPropertySet.addSyspropertyset(set);
   
       }
   
  @@ -448,13 +461,13 @@
       }
   
       /**
  -     * Get a Vector containing the nested sysproperty elements.
  +     * Get the nested sysproperty elements.
        *
  -     * @return a Vector of ConditionalVariable objects
  +     * @return the {@link LaunchTask.ConditionalVariable} objects
        */
       public Vector getSysproperties() {
   
  -        return taskVariables;
  +        return taskSysPropertySet.getSysproperties();
   
       }
   
  @@ -534,8 +547,8 @@
   
               // Copy all of the nested sysproperty elements into the sysProps
               // object
  -            Hashtable sysProps = new Hashtable(taskVariables.size());
  -            enum = taskVariables.elements();
  +            Hashtable sysProps = new Hashtable(taskSysPropertySet.getSysproperties().size());
  +            enum = taskSysPropertySet.getSysproperties().elements();
               while (enum.hasMoreElements()) {
                   ConditionalVariable variable = (ConditionalVariable)enum.nextElement();
                   // Test "if" and "unless" conditions
  @@ -1161,6 +1174,107 @@
           public void setUnless(String property) {
    
               this.unlessCondition = property;
  +
  +        }
  +
  +    }
  +
  +    public static class SysPropertySet extends DataType {
  +
  +        //-------------------------------------------------------------- Fields
  +
  +        /**
  +         * Cached variables and nested SysPropertySet objects
  +         */
  +        private Vector list = new Vector();
  +
  +        /**
  +         * Add a {@link LaunchTask.ConditionalVariable}.
  +         *
  +         * @param variable the {@link LaunchTask.ConditionalVariable} to be
  +         *  added
  +         */
  +        public void addSysproperty(ConditionalVariable variable) {
  +
  +            if (isReference())
  +                throw noChildrenAllowed();
  +            list.addElement(variable);
  +
  +        }
  +
  +        /**
  +         * Add a {@link LaunchTask.SysPropertySet}.
  +         *
  +         * @param set the {@link LaunchTask.SysPropertySet} to be added
  +         */
  +        public void addSyspropertyset(SysPropertySet set) {
  +
  +            if (isReference())
  +                throw noChildrenAllowed();
  +            list.addElement(set);
  +
  +        }
  +
  +        /**
  +         * Get {@link LaunchTask.ConditionalVariable} instances.
  +         *
  +         * @return the {@link LaunchTask.ConditionalVariable} instances
  +         */
  +        public Vector getSysproperties() {
  +
  +            // Make sure we don't have a circular reference to this instance
  +            if (!checked) {
  +                Stack stk = new Stack();
  +                stk.push(this);
  +                dieOnCircularReference(stk, project);
  +            }
  +
  +            // Recursively work through the tree of SysPropertySet 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();
  +                SysPropertySet nestedSet = null;
  +                if (o instanceof Reference) {
  +                    o = ((Reference)o).getReferencedObject(project);
  +                    // Only references to this class are allowed
  +                    if (!(o instanceof LaunchTask.SysPropertySet))
  +                        throw new BuildException(Launcher.getLocalizedString("cannot.reference",
this.getClass().getName()));
  +                    nestedSet = (SysPropertySet)o;
  +                } else if (o instanceof SysPropertySet) {
  +                    nestedSet = (SysPropertySet)o;
  +                } else if (o instanceof ConditionalVariable) {
  +                    mergedList.addElement(o);
  +                } else {
  +                    throw new BuildException(Launcher.getLocalizedString("cannot.nest",
this.getClass().getName()));
  +                }
  +                if (nestedSet != null) {
  +                    Vector nestedList = nestedSet.getSysproperties();
  +                    Enumeration nestedEnum = nestedList.elements();
  +                    while (nestedEnum.hasMoreElements())
  +                        mergedList.addElement(nestedEnum.nextElement());
  +                }
  +            }
  +
  +            return mergedList;
  +
  +        }
  +
  +        /**
  +         * Makes this instance a reference to another instance. You must not
  +         * set another attribute or nest elements inside this element if you
  +         * make it a reference.
  +         *
  +         * @param r the reference to another {@link LaunchTask.SysPropertySet}
  +         *  instance
  +         */
  +        public void setRefid(Reference r) throws BuildException {
  +
  +            if (!list.isEmpty())
  +                throw tooManyAttributes();
  +            list.addElement(r);
  +            super.setRefid(r);
   
           }
   
  
  
  
  1.5       +3 -0      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Launcher.java	11 Jul 2002 23:41:57 -0000	1.4
  +++ Launcher.java	12 Jul 2002 22:56:45 -0000	1.5
  @@ -401,6 +401,9 @@
               // Define the "launch" task
               project.addTaskDefinition("launch", LaunchTask.class);
   
  +            // Define the "syspropertyset" data type 
  +            project.addDataTypeDefinition("syspropertyset", LaunchTask.SysPropertySet.class);
  +
               // Set the buildfile
               ProjectHelper.configureProject(project, launchFile);
   
  
  
  
  1.1                  jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/LaunchTask$SysPropertySet_en.properties
  
  Index: LaunchTask$SysPropertySet_en.properties
  ===================================================================
  #
  # Localized strings for LaunchTask.SysPropertySet class
  #
  cannot.nest=Only <sysproperty> and <syspropertyset> elements can be nested
  cannot.reference=Only <syspropertyset> elements can be referenced
  
  
  

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