mbenson     2005/05/18 09:52:06

  Modified:    .        Tag: ANT_16_BRANCH WHATSNEW
               src/main/org/apache/tools/ant/types Tag: ANT_16_BRANCH
                        PropertySet.java
               src/etc/testcases/types Tag: ANT_16_BRANCH propertyset.xml
               src/testcases/org/apache/tools/ant/types Tag: ANT_16_BRANCH
                        PropertySetTest.java
  Log:
  Merge nested mapped propertyset fix
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.503.2.227 +2 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.503.2.226
  retrieving revision 1.503.2.227
  diff -u -r1.503.2.226 -r1.503.2.227
  --- WHATSNEW  13 May 2005 08:09:35 -0000      1.503.2.226
  +++ WHATSNEW  18 May 2005 16:52:05 -0000      1.503.2.227
  @@ -24,6 +24,8 @@
   * <unzip> and <untar> could leave file handles open on invalid
     archives.  Bugzilla report 34893.
   
  +* propertyset threw NPE with nested, mapped propertysets.
  +
   Other changes:
   --------------
   
  
  
  
  No                   revision
  No                   revision
  1.8.2.11  +15 -21    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.8.2.10
  retrieving revision 1.8.2.11
  diff -u -r1.8.2.10 -r1.8.2.11
  --- PropertySet.java  19 Jan 2005 18:34:48 -0000      1.8.2.10
  +++ PropertySet.java  18 May 2005 16:52:05 -0000      1.8.2.11
  @@ -166,11 +166,11 @@
        * @param to output pattern.
        */
       public void setMapper(String type, String from, String to) {
  -        Mapper mapper = createMapper();
  +        Mapper m = createMapper();
           Mapper.MapperType mapperType = new Mapper.MapperType();
           mapperType.setValue(type);
  -        mapper.setFrom(from);
  -        mapper.setTo(to);
  +        m.setFrom(from);
  +        m.setTo(to);
       }
   
       /**
  @@ -282,6 +282,12 @@
           Hashtable props =
               prj == null ? getAllSystemProperties() : prj.getProperties();
   
  +        //quick & dirty, to make nested mapped p-sets work:
  +        for (Enumeration e = setRefs.elements(); e.hasMoreElements();) {
  +            PropertySet set = (PropertySet) e.nextElement();
  +            props.putAll(set.getProperties());
  +        }
  +
           if (getDynamic() || cachedNames == null) {
               names = new HashSet();
               addPropertyNames(names, props);
  @@ -302,19 +308,19 @@
           } else {
               names = cachedNames;
           }
  -        FileNameMapper mapper = null;
  +        FileNameMapper m = null;
           Mapper myMapper = getMapper();
           if (myMapper != null) {
  -            mapper = myMapper.getImplementation();
  +            m = myMapper.getImplementation();
           }
           Properties properties = new Properties();
           //iterate through the names, get the matching values
           for (Iterator iter = names.iterator(); iter.hasNext();) {
               String name = (String) iter.next();
               String value = (String) props.get(name);
  -            if (mapper != null) {
  +            if (m != null) {
                   //map the names
  -                String[] newname = mapper.mapFileName(name);
  +                String[] newname = m.mapFileName(name);
                   if (newname != null) {
                       name = newname[0];
                   }
  @@ -382,20 +388,7 @@
        * @return the referenced PropertySet.
        */
       protected PropertySet getRef() {
  -        if (!isChecked()) {
  -            Stack stk = new Stack();
  -            stk.push(this);
  -            dieOnCircularReference(stk, getProject());
  -        }
  -
  -        Object o = getRefid().getReferencedObject(getProject());
  -        if (!(o instanceof PropertySet)) {
  -            String msg = getRefid().getRefId()
  -                + " doesn\'t denote a propertyset";
  -            throw new BuildException(msg);
  -        } else {
  -            return (PropertySet) o;
  -        }
  +        return (PropertySet) getCheckedRef(PropertySet.class, "propertyset");
       }
   
       /**
  @@ -469,4 +462,5 @@
           }
           return b.toString();
       }
  +
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +39 -0     ant/src/etc/testcases/types/propertyset.xml
  
  Index: propertyset.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/types/propertyset.xml,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- propertyset.xml   7 Feb 2005 11:13:57 -0000       1.1.2.1
  +++ propertyset.xml   18 May 2005 16:52:05 -0000      1.1.2.2
  @@ -52,4 +52,43 @@
         exp="barB=BarB, fooA=FooA"
         got="${toString:my-set}"/>
     </target>
  +
  +  <target name="nested-mapped">
  +    <propertyset id="nested-mapped">
  +      <propertyset>
  +        <propertyset refid="properties-starting-with-foo"/>
  +        <globmapper from="foo*" to="boo*" />
  +      </propertyset>
  +      <propertyset>
  +        <propertyset refid="properties-starting-with-bar"/>
  +        <globmapper from="bar*" to="far*" />
  +      </propertyset>
  +    </propertyset>
  +    <expect.equals
  +      test="nested mapped propertysets"
  +      exp="booA=FooA, farB=BarB"
  +      got="${toString:nested-mapped}"/>
  +  </target>
  +
  +  <target name="nested-mapped-mapped">
  +    <propertyset id="nested-mapped-mapped">
  +      <propertyset>
  +        <propertyset refid="properties-starting-with-foo"/>
  +        <globmapper from="foo*" to="boo*" />
  +      </propertyset>
  +      <propertyset>
  +        <propertyset refid="properties-starting-with-bar"/>
  +        <globmapper from="bar*" to="far*" />
  +      </propertyset>
  +      <mapper>
  +        <globmapper from="boo*" to="hoo*" />
  +        <globmapper from="far*" to="near*" />
  +      </mapper>
  +    </propertyset>
  +    <expect.equals
  +      test="nested mapped propertysets"
  +      exp="hooA=FooA, nearB=BarB"
  +      got="${toString:nested-mapped-mapped}"/>
  +  </target>
  +
   </project>
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +8 -0      
ant/src/testcases/org/apache/tools/ant/types/PropertySetTest.java
  
  Index: PropertySetTest.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/ant/types/PropertySetTest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- PropertySetTest.java      7 Feb 2005 11:13:57 -0000       1.1.2.1
  +++ PropertySetTest.java      18 May 2005 16:52:05 -0000      1.1.2.2
  @@ -36,4 +36,12 @@
       public void testReferenceToTwoReferences() {
           executeTarget("reference-to-two-references");
       }
  +
  +    public void testNestedMapped() {
  +        executeTarget("nested-mapped");
  +    }
  +
  +    public void testNestedMappedMapped() {
  +        executeTarget("nested-mapped-mapped");
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to