ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs PathConvertTest.java
Date Tue, 22 Feb 2005 18:32:40 GMT
mbenson     2005/02/22 10:32:40

  Modified:    .        Tag: ANT_16_BRANCH WHATSNEW
               src/etc/testcases/taskdefs Tag: ANT_16_BRANCH
                        pathconvert.xml
               docs/manual/CoreTasks Tag: ANT_16_BRANCH pathconvert.html
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        PathConvert.java
               src/testcases/org/apache/tools/ant/taskdefs Tag:
                        ANT_16_BRANCH PathConvertTest.java
  Log:
  Merge pathconvert doesn't require targetos|dirsep|pathsep.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.503.2.182 +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.503.2.181
  retrieving revision 1.503.2.182
  diff -u -r1.503.2.181 -r1.503.2.182
  --- WHATSNEW	22 Feb 2005 15:30:40 -0000	1.503.2.181
  +++ WHATSNEW	22 Feb 2005 18:32:40 -0000	1.503.2.182
  @@ -99,6 +99,9 @@
   * Recursive token expansion in a filterset can now be disabled by
     setting its recurse attribute to false.
   
  +* Pathconvert no longer requires that one of (targetos|pathsep|dirsep)
  +  be set; platform defaults are used when this is the case.
  +
   Fixed bugs:
   -----------
   
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +4 -0      ant/src/etc/testcases/taskdefs/pathconvert.xml
  
  Index: pathconvert.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/pathconvert.xml,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- pathconvert.xml	20 Apr 2004 22:32:28 -0000	1.1.2.1
  +++ pathconvert.xml	22 Feb 2005 18:32:40 -0000	1.1.2.2
  @@ -18,4 +18,8 @@
           </pathconvert>
       </target>
   
  +    <target name="testnotargetos">
  +        <pathconvert property="result" refid="testpath" />
  +    </target>
  +
   </project>
  
  
  
  No                   revision
  No                   revision
  1.12.2.4  +3 -6      ant/docs/manual/CoreTasks/pathconvert.html
  
  Index: pathconvert.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/pathconvert.html,v
  retrieving revision 1.12.2.3
  retrieving revision 1.12.2.4
  diff -u -r1.12.2.3 -r1.12.2.4
  --- pathconvert.html	20 Apr 2004 22:32:29 -0000	1.12.2.3
  +++ pathconvert.html	22 Feb 2005 18:32:40 -0000	1.12.2.4
  @@ -8,7 +8,7 @@
   
   <body>
   
  -<h2><a name="foreach">Pathconvert</a></h2>
  +<h2><a name="pathconvert">Pathconvert</a></h2>
   <h3>Description</h3>
   <p>Converts a nested <code>&lt;path&gt;</code> or reference to
a Path,
   FileSet, DirSet, or FileList into a path
  @@ -41,10 +41,7 @@
           <code>pathsep</code> and <code>dirsep</code>
           according to the specified target architecture.
       </td>
  -    <td valign="top" align="center">
  -       Yes, unless <code>pathsep</code> and/or
  -       <code>dirsep</code> are specified.
  -    </td>
  +    <td valign="top" align="center">No</td>
     </tr>
     <tr>
       <td valign="top">dirsep</td>
  @@ -186,7 +183,7 @@
   </p>
   
   <hr>
  -<p align="center">Copyright &copy; 2001-2004 The Apache Software Foundation.
  +<p align="center">Copyright &copy; 2001-2005 The Apache Software Foundation.
   All rights Reserved.</p>
   </body>
   </html>
  
  
  
  No                   revision
  No                   revision
  1.27.2.7  +59 -133   ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
  
  Index: PathConvert.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java,v
  retrieving revision 1.27.2.6
  retrieving revision 1.27.2.7
  diff -u -r1.27.2.6 -r1.27.2.7
  --- PathConvert.java	7 Feb 2005 10:51:34 -0000	1.27.2.6
  +++ PathConvert.java	22 Feb 2005 18:32:40 -0000	1.27.2.7
  @@ -89,13 +89,12 @@
       private Mapper mapper = null;
   
       /**
  -     * constructor
  +     * Construct a new instance of the PathConvert task.
        */
       public PathConvert() {
           onWindows = Os.isFamily("dos");
       }
   
  -
       /**
        * Helper class, holds the nested &lt;map&gt; values. Elements will look like
        * this: &lt;map from=&quot;d:&quot; to=&quot;/foo&quot;/&gt;
  @@ -105,39 +104,40 @@
        */
       public class MapEntry {
   
  -        /** Set the &quot;from&quot; attribute of the map entry  */
  +        // Members
  +        private String from = null;
  +        private String to = null;
  +
           /**
  -         * the prefix string to search for; required.
  +         * Set the &quot;from&quot; attribute of the map entry.
  +         * @param from the prefix string to search for; required.
            * Note that this value is case-insensitive when the build is
            * running on a Windows platform and case-sensitive when running on
            * a Unix platform.
  -         * @param from the prefix string to search for
            */
           public void setFrom(String from) {
               this.from = from;
           }
   
           /**
  -         *  The replacement text to use when from is matched; required.
  -         * @param to new prefix
  +         * Set the replacement text to use when from is matched; required.
  +         * @param to new prefix.
            */
           public void setTo(String to) {
               this.to = to;
           }
   
  -
           /**
  -         * Apply this map entry to a given path element
  +         * Apply this map entry to a given path element.
            *
  -         * @param elem Path element to process
  -         * @return String Updated path element after mapping
  +         * @param elem Path element to process.
  +         * @return String Updated path element after mapping.
            */
           public String apply(String elem) {
               if (from == null || to == null) {
                   throw new BuildException("Both 'from' and 'to' must be set "
                        + "in a map entry");
               }
  -
               // If we're on windows, then do the comparison ignoring case
               String cmpElem = onWindows ? elem.toLowerCase() : elem;
               String cmpFrom = onWindows ? from.toLowerCase() : from;
  @@ -145,96 +145,70 @@
               // If the element starts with the configured prefix, then
               // convert the prefix to the configured 'to' value.
   
  -            if (cmpElem.startsWith(cmpFrom)) {
  -                int len = from.length();
  -
  -                if (len >= elem.length()) {
  -                    elem = to;
  -                } else {
  -                    elem = to + elem.substring(len);
  -                }
  -            }
  -
  -            return elem;
  +            return cmpElem.startsWith(cmpFrom)
  +                ? to + elem.substring(from.length()) : elem;
           }
  -
  -        // Members
  -        private String from = null;
  -        private String to = null;
       }
   
  -
       /**
  -     * an enumeration of supported targets:
  -     * windows", "unix", "netware", and "os/2".
  +     * An enumeration of supported targets:
  +     * "windows", "unix", "netware", and "os/2".
        */
       public static class TargetOs extends EnumeratedAttribute {
           /**
  -         * @return the list of values for this enumerated attribute
  +         * @return the list of values for this enumerated attribute.
            */
           public String[] getValues() {
               return new String[]{"windows", "unix", "netware", "os/2", "tandem"};
           }
       }
   
  -
       /**
  -     * Create a nested PATH element
  -     * @return a Path to be used by ant reflection
  +     * Create a nested PATH element.
  +     * @return a Path to be used by Ant reflection.
        */
       public Path createPath() {
  -
           if (isReference()) {
               throw noChildrenAllowed();
           }
  -
           if (path == null) {
               path = new Path(getProject());
           }
           return path.createPath();
       }
   
  -
       /**
  -     * Create a nested MAP element
  -     * @return a Map to configure
  +     * Create a nested MAP element.
  +     * @return a Map to configure.
        */
       public MapEntry createMap() {
  -
           MapEntry entry = new MapEntry();
  -
           prefixMap.addElement(entry);
           return entry;
       }
   
  -
       /**
        * Set targetos to a platform to one of
  -     * "windows", "unix", "netware", or "os/2".
  -     *
  -     * Required unless unless pathsep and/or dirsep are specified.
  -     *
  -     * @deprecated use the method taking a TargetOs argument instead
  +     * "windows", "unix", "netware", or "os/2";
  +     * current platform settings are used by default.
  +     * @deprecated use the method taking a TargetOs argument instead.
        * @see #setTargetos(PathConvert.TargetOs)
        */
       public void setTargetos(String target) {
           TargetOs to = new TargetOs();
  -
           to.setValue(target);
           setTargetos(to);
       }
   
  -
       /**
        * Set targetos to a platform to one of
  -     * "windows", "unix", "netware", or "os/2"; required unless
  -     * unless pathsep and/or dirsep are specified.
  +     * "windows", "unix", "netware", or "os/2";
  +     * current platform settings are used by default.
        * @param target the target os
        *
        * @since Ant 1.5
        */
       public void setTargetos(TargetOs target) {
  -
           targetOS = target.getValue();
   
           // Currently, we deal with only two path formats: Unix and Windows
  @@ -248,10 +222,9 @@
       }
   
       /**
  -     * Set setonempty
  -     *
  -     * If false, don't set the new property if the result is the empty string.
  -     * @param setonempty true or false
  +     * Set whether the specified property will be set if the result
  +     * is the empty string.
  +     * @param setonempty true or false.
        *
        * @since Ant 1.5
        */
  @@ -260,33 +233,28 @@
        }
   
       /**
  -     * The property into which the converted path will be placed.
  -     * @param p the property name
  +     * Set the name of the property into which the converted path will be placed.
  +     * @param p the property name.
        */
       public void setProperty(String p) {
           property = p;
       }
   
  -
       /**
  -     * Adds a reference to a Path, FileSet, DirSet, or FileList defined
  -     * elsewhere.
  -     * @param r the reference to a path, fileset, dirset or filelist
  +     * Add a reference to a Path, FileSet, DirSet, or FileList defined elsewhere.
  +     * @param r the reference to a path, fileset, dirset or filelist.
        */
       public void setRefid(Reference r) {
           if (path != null) {
               throw noChildrenAllowed();
           }
  -
           refid = r;
       }
   
  -
       /**
  -     * Set the default path separator string;
  -     * defaults to current JVM
  -     * {@link java.io.File#pathSeparator File.pathSeparator}
  -     * @param sep path separator string
  +     * Set the default path separator string; defaults to current JVM
  +     * {@link java.io.File#pathSeparator File.pathSeparator}.
  +     * @param sep path separator string.
        */
       public void setPathSep(String sep) {
           pathSep = sep;
  @@ -295,25 +263,24 @@
   
       /**
        * Set the default directory separator string;
  -     * defaults to current JVM {@link java.io.File#separator File.separator}
  -     * @param sep directory separator string
  +     * defaults to current JVM {@link java.io.File#separator File.separator}.
  +     * @param sep directory separator string.
        */
       public void setDirSep(String sep) {
           dirSep = sep;
       }
   
  -
       /**
  -     * Has the refid attribute of this element been set?
  -     * @return true if refid is valid
  +     * Learn whether the refid attribute of this element been set.
  +     * @return true if refid is valid.
        */
       public boolean isReference() {
           return refid != null;
       }
   
  -
  -    /** Do the execution.
  -     * @throws BuildException if something is invalid
  +    /**
  +     * Do the execution.
  +     * @throws BuildException if something is invalid.
        */
       public void execute() throws BuildException {
           Path savedPath = path;
  @@ -324,31 +291,21 @@
               // If we are a reference, create a Path from the reference
               if (isReference()) {
                   path = new Path(getProject()).createPath();
  -
                   Object obj = refid.getReferencedObject(getProject());
   
                   if (obj instanceof Path) {
                       path.setRefid(refid);
                   } else if (obj instanceof FileSet) {
  -                    FileSet fs = (FileSet) obj;
  -
  -                    path.addFileset(fs);
  +                    path.addFileset((FileSet) obj);
                   } else if (obj instanceof DirSet) {
  -                    DirSet ds = (DirSet) obj;
  -
  -                    path.addDirset(ds);
  +                    path.addDirset((DirSet) obj);
                   } else if (obj instanceof FileList) {
  -                    FileList fl = (FileList) obj;
  -
  -                    path.addFilelist(fl);
  -
  +                    path.addFilelist((FileList) obj);
                   } else {
                       throw new BuildException("'refid' does not refer to a "
  -                         + "path, fileset, dirset, or "
  -                         + "filelist.");
  +                         + "path, fileset, dirset, or filelist.");
                   }
               }
  -
               validateSetup(); // validate our setup
   
               // Currently, we deal with only two path formats: Unix and Windows
  @@ -377,11 +334,8 @@
                   }
                   elems = (String[]) ret.toArray(new String[] {});
               }
  -
               for (int i = 0; i < elems.length; i++) {
  -                String elem = elems[i];
  -
  -                elem = mapElement(elem); // Apply the path prefix map
  +                String elem = mapElement(elems[i]); // Apply the path prefix map
   
                   // Now convert the path and file separator characters from the
                   // current os to the target os.
  @@ -389,35 +343,21 @@
                   if (i != 0) {
                       rslt.append(pathSep);
                   }
  -
                   StringTokenizer stDirectory =
                       new StringTokenizer(elem, fromDirSep, true);
  -                String token = null;
   
                   while (stDirectory.hasMoreTokens()) {
  -                    token = stDirectory.nextToken();
  -
  -                    if (fromDirSep.equals(token)) {
  -                        rslt.append(dirSep);
  -                    } else {
  -                        rslt.append(token);
  -                    }
  +                    String token = stDirectory.nextToken();
  +                    rslt.append(fromDirSep.equals(token) ? dirSep : token);
                   }
               }
  -
               // Place the result into the specified property,
               // unless setonempty == false
  -            String value = rslt.toString();
  -            if (setonempty) {
  +            if (setonempty || rslt.length() > 0) {
  +                String value = rslt.toString();
                   log("Set property " + property + " = " + value,
                       Project.MSG_VERBOSE);
                   getProject().setNewProperty(property, value);
  -            } else {
  -                if (rslt.length() > 0) {
  -                    log("Set property " + property + " = " + value,
  -                        Project.MSG_VERBOSE);
  -                    getProject().setNewProperty(property, value);
  -                }
               }
           } finally {
               path = savedPath;
  @@ -426,14 +366,13 @@
           }
       }
   
  -
       /**
        * Apply the configured map to a path element. The map is used to convert
        * between Windows drive letters and Unix paths. If no map is configured,
        * then the input string is returned unchanged.
        *
  -     * @param elem The path element to apply the map to
  -     * @return String Updated element
  +     * @param elem The path element to apply the map to.
  +     * @return String Updated element.
        */
       private String mapElement(String elem) {
   
  @@ -457,14 +396,13 @@
                   }
               }
           }
  -
           return elem;
       }
   
       /**
        * Add a mapper to convert the file names.
        *
  -     * @param mapper a <code>Mapper</code> value
  +     * @param mapper a <code>Mapper</code> value.
        */
       public void addMapper(Mapper mapper) {
           if (this.mapper != null) {
  @@ -475,8 +413,8 @@
       }
   
       /**
  -     * A nested filenamemapper
  -     * @param fileNameMapper the mapper to add
  +     * Add a nested filenamemapper.
  +     * @param fileNameMapper the mapper to add.
        * @since Ant 1.6.3
        */
       public void add(FileNameMapper fileNameMapper) {
  @@ -489,25 +427,16 @@
       /**
        * Validate that all our parameters have been properly initialized.
        *
  -     * @throws BuildException if something is not setup properly
  +     * @throws BuildException if something is not set up properly.
        */
       private void validateSetup() throws BuildException {
   
           if (path == null) {
               throw new BuildException("You must specify a path to convert");
           }
  -
           if (property == null) {
               throw new BuildException("You must specify a property");
           }
  -
  -        // Must either have a target OS or both a dirSep and pathSep
  -
  -        if (targetOS == null && pathSep == null && dirSep == null) {
  -            throw new BuildException("You must specify at least one of "
  -                 + "targetOS, dirSep, or pathSep");
  -        }
  -
           // Determine the separator strings.  The dirsep and pathsep attributes
           // override the targetOS settings.
           String dsep = File.separator;
  @@ -517,25 +446,22 @@
               psep = targetWindows ? ";" : ":";
               dsep = targetWindows ? "\\" : "/";
           }
  -
           if (pathSep != null) {
               // override with pathsep=
               psep = pathSep;
           }
  -
           if (dirSep != null) {
               // override with dirsep=
               dsep = dirSep;
           }
  -
           pathSep = psep;
           dirSep = dsep;
       }
   
  -
       /**
        * Creates an exception that indicates that this XML element must not have
        * child elements if the refid attribute is set.
  +     * @return BuildException.
        */
       private BuildException noChildrenAllowed() {
           return new BuildException("You must not specify nested <path> "
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +5 -1      ant/src/testcases/org/apache/tools/ant/taskdefs/PathConvertTest.java
  
  Index: PathConvertTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/PathConvertTest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- PathConvertTest.java	20 Apr 2004 22:32:28 -0000	1.1.2.1
  +++ PathConvertTest.java	22 Feb 2005 18:32:40 -0000	1.1.2.2
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2004 The Apache Software Foundation.
  + * Copyright 2004-2005 The Apache Software Foundation.
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -43,6 +43,10 @@
           test("testmapper");
       }
   
  +    public void testNoTargetOs() {
  +        executeTarget("testnotargetos");
  +    }
  +
       private void test(String target) {
           executeTarget(target);
           assertPropertyEquals("result", "test#" + BUILD_FILENAME);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message