ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/types CommandlineJavaTest.java
Date Mon, 12 May 2003 14:00:11 GMT
bodewig     2003/05/12 07:00:10

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs Java.java
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        JUnitTask.java
               src/main/org/apache/tools/ant/types CommandlineJava.java
                        PropertySet.java
               src/testcases/org/apache/tools/ant/types
                        CommandlineJavaTest.java
  Log:
  Add nested <propertyset>s to <java> and <junit>.
  
  Revision  Changes    Path
  1.414     +2 -1      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.413
  retrieving revision 1.414
  diff -u -r1.413 -r1.414
  --- WHATSNEW	9 May 2003 13:41:03 -0000	1.413
  +++ WHATSNEW	12 May 2003 14:00:08 -0000	1.414
  @@ -306,7 +306,8 @@
     defaultexcludes task.  Bugzilla Report 12700.
   
   * There is a new data type <propertyset> that can be used to collect
  -  properties.
  +  properties.  It is supported by <ant>, <antcall>, <subant>, <java>
  +  and <junit>.
   
   * <concat> can now control the encoding of the output as well and optionally
     add new-line characters at the end of files that get concatenated but
  
  
  
  1.59      +10 -0     ant/src/main/org/apache/tools/ant/taskdefs/Java.java
  
  Index: Java.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- Java.java	22 Apr 2003 22:12:53 -0000	1.58
  +++ Java.java	12 May 2003 14:00:09 -0000	1.59
  @@ -65,6 +65,7 @@
   import org.apache.tools.ant.types.CommandlineJava;
   import org.apache.tools.ant.types.Environment;
   import org.apache.tools.ant.types.Path;
  +import org.apache.tools.ant.types.PropertySet;
   import org.apache.tools.ant.types.Reference;
   
   /**
  @@ -301,6 +302,15 @@
        */
       public void addSysproperty(Environment.Variable sysp) {
           cmdl.addSysproperty(sysp);
  +    }
  +
  +    /**
  +     * Adds a set of properties as system properties.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void addSyspropertyset(PropertySet sysp) {
  +        cmdl.addSyspropertyset(sysp);
       }
   
       /**
  
  
  
  1.63      +15 -1     ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  
  Index: JUnitTask.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- JUnitTask.java	18 Apr 2003 23:40:26 -0000	1.62
  +++ JUnitTask.java	12 May 2003 14:00:09 -0000	1.63
  @@ -75,6 +75,7 @@
   import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.apache.tools.ant.types.Environment;
   import org.apache.tools.ant.types.Path;
  +import org.apache.tools.ant.types.PropertySet;
   import org.apache.tools.ant.util.FileUtils;
   import org.apache.tools.ant.util.LoaderUtils;
   import junit.framework.AssertionFailedError;
  @@ -400,6 +401,19 @@
        */
       public void addSysproperty(Environment.Variable sysp) {
           commandline.addSysproperty(sysp);
  +    }
  +
  +    /**
  +     * Adds a set of properties that will be used as system properties
  +     * that tests can access.
  +     *
  +     * This might be useful to tranfer Ant properties to the
  +     * testcases when JVM forking is not enabled.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void addSyspropertyset(PropertySet sysp) {
  +        commandline.addSyspropertyset(sysp);
       }
   
       /**
  
  
  
  1.38      +40 -6     ant/src/main/org/apache/tools/ant/types/CommandlineJava.java
  
  Index: CommandlineJava.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/CommandlineJava.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- CommandlineJava.java	10 Feb 2003 14:14:30 -0000	1.37
  +++ CommandlineJava.java	12 May 2003 14:00:10 -0000	1.38
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -99,22 +99,37 @@
        */
       public static class SysProperties extends Environment implements Cloneable {
           Properties sys = null;
  +        private Vector propertySets = new Vector();
   
           public String[] getVariables() throws BuildException {
               String[] props = super.getVariables();
  +            Properties p = mergePropertySets();
         
               if (props == null) {
  -              return null;
  +                if (p.size() == 0) {
  +                    return null;
  +                } else {
  +                    props = new String[0];
  +                }
               }
   
  -            for (int i = 0; i < props.length; i++) {
  -                props[i] = "-D" + props[i];
  +            String[] result = new String[props.length + p.size()];
  +            int i = 0;
  +            for (; i < props.length; i++) {
  +                result[i] = "-D" + props[i];
  +            }
  +            for (Enumeration enum = p.keys(); enum.hasMoreElements();) {
  +                String key = (String) enum.nextElement();
  +                String value = p.getProperty(key);
  +                result[i++] = "-D" + key + "=" + value;
               }
  -            return props;
  +            
  +            return result;
           }
   
           public int size() {
  -            return variables.size();
  +            Properties p = mergePropertySets();
  +            return variables.size() + p.size();
           }
   
           public void setSystem() throws BuildException {
  @@ -125,6 +140,7 @@
                       Object o = e.nextElement();
                       p.put(o, sys.get(o));
                   }
  +                p.putAll(mergePropertySets());
                   for (Enumeration e = variables.elements(); e.hasMoreElements();) {
                       Environment.Variable v = (Environment.Variable) e.nextElement();
                       p.put(v.getKey(), v.getValue());
  @@ -152,12 +168,26 @@
               try {
                   SysProperties c = (SysProperties) super.clone();
                   c.variables = (Vector) variables.clone();
  +                c.propertySets = (Vector) propertySets.clone();
                   return c;
               } catch (CloneNotSupportedException e) {
                   return null;
               }
           }
   
  +        public void addSyspropertyset(PropertySet ps) {
  +            propertySets.addElement(ps);
  +        }
  +
  +        private Properties mergePropertySets() {
  +            Properties p = new Properties();
  +            for (Enumeration e = propertySets.elements(); 
  +                 e.hasMoreElements();) {
  +                PropertySet ps = (PropertySet) e.nextElement();
  +                p.putAll(ps.getProperties());
  +            }
  +            return p;
  +        }
       }
   
       /**
  @@ -178,6 +208,10 @@
   
       public void addSysproperty(Environment.Variable sysp) {
           sysProperties.addVariable(sysp);
  +    }
  +
  +    public void addSyspropertyset(PropertySet sysp) {
  +        sysProperties.addSyspropertyset(sysp);
       }
   
       public void setVm(String vm) {
  
  
  
  1.3       +8 -3      ant/src/main/org/apache/tools/ant/types/PropertySet.java
  
  Index: PropertySet.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/PropertySet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PropertySet.java	12 May 2003 12:16:07 -0000	1.2
  +++ PropertySet.java	12 May 2003 14:00:10 -0000	1.3
  @@ -174,11 +174,11 @@
       }
   
       public boolean getDynamic() {
  -        return getRef().dynamic;
  +        return isReference() ? getRef().dynamic : dynamic;
       }
   
       public Mapper getMapper() {
  -        return getRef()._mapper;
  +        return isReference() ? getRef()._mapper : _mapper;
       }
   
       public Properties getProperties() {
  @@ -187,7 +187,12 @@
   
           if (getDynamic() || cachedNames == null) {
               names = new Vector(); // :TODO: should be a Set!
  -            getRef().addPropertyNames(names, prj.getProperties());
  +            if (isReference()) {
  +                getRef().addPropertyNames(names, prj.getProperties());    
  +            } else {
  +                addPropertyNames(names, prj.getProperties());
  +            }
  +
               if (!getDynamic()) {
                   cachedNames = names;
               }
  
  
  
  1.16      +11 -1     ant/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java
  
  Index: CommandlineJavaTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CommandlineJavaTest.java	7 Mar 2003 11:23:13 -0000	1.15
  +++ CommandlineJavaTest.java	12 May 2003 14:00:10 -0000	1.16
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -143,6 +143,13 @@
           v.setKey("key");
           v.setValue("value");
           c.addSysproperty(v);
  +
  +        project.setProperty("key2", "value2");
  +        PropertySet ps = new PropertySet();
  +        ps.setProject(project);
  +        ps.appendName("key2");
  +        c.addSyspropertyset(ps);
  +
           try {
               c.setSystemProperties();
               String newClasspath = System.getProperty("java.class.path");
  @@ -151,10 +158,13 @@
               assertNotNull(System.getProperty("key"));
               assertEquals("value", System.getProperty("key"));
               assertTrue(System.getProperties().containsKey("java.class.path"));
  +            assertNotNull(System.getProperty("key2"));
  +            assertEquals("value2", System.getProperty("key2"));
           } finally {
               c.restoreSystemProperties();
           }
           assertNull(System.getProperty("key"));
  +        assertNull(System.getProperty("key2"));
       }
   
   }
  
  
  

Mime
View raw message