ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/proposal/mutant/src/main/org/apache/ant/core/types DataType.java PatternSet.java DirectoryFileset.java Fileset.java
Date Sat, 19 May 2001 08:00:26 GMT
conor       01/05/19 01:00:26

  Modified:    proposal/mutant/src/main/org/apache/ant/core/types
                        DataType.java PatternSet.java
  Removed:     proposal/mutant/src/main/org/apache/ant/core/types
                        DirectoryFileset.java Fileset.java
  Log:
  Working on my data types :-)
  
  Revision  Changes    Path
  1.2       +16 -11    jakarta-ant/proposal/mutant/src/main/org/apache/ant/core/types/DataType.java
  
  Index: DataType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/main/org/apache/ant/core/types/DataType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataType.java	2001/05/18 13:38:12	1.1
  +++ DataType.java	2001/05/19 08:00:24	1.2
  @@ -64,11 +64,11 @@
    */
   public abstract class DataType extends AbstractTask {
       private String reference = null;
  +    private Object referencedObject = null;
   
  -    final public void execute() throws ExecutionException {
  +    public void execute() throws ExecutionException {
       }
   
  -
       /**
        * Creates an exception that indicates that refid has to be the
        * only attribute if it is set.  
  @@ -100,29 +100,34 @@
        */
       public void setRefid(String reference) throws ExecutionException {
           this.reference = reference;
  -        // check the reference now
  -        getReferencedObject();
  +        Object referencedObject = getTaskContext().getDataValue(reference);
  +
  +        if (referencedObject == null) {
  +            throw new ExecutionException("Unable to locate the reference specified by refid
'" +
  +                                         getReference() + "'");
  +        }
  +        
  +        if (!this.getClass().isAssignableFrom(referencedObject.getClass())) {
  +            throw new ExecutionException("The object referenced by refid '" +
  +                                         getReference() + "' is not compatible with this
element ");
  +        }
       }
   
       /**
        * Has the refid attribute of this element been set?
        */
       public boolean isReference() {
  -        return reference != null;
  +        return referencedObject != null;
       }
   
  +
       protected Object getReferencedObject() throws ExecutionException {
           if (!isReference()) {
               throw new ExecutionException("You cannot get a referenced value from a data
type " + 
                                            "which does not have the refid attribute");
           }
           
  -        Object referencedObject = getTaskContext().getDataValue(reference);
  -        if (referencedObject == null) {
  -            throw new ExecutionException("Unable to locate the reference specified by refid
'" +
  -                                         getReference() + "'");
  -        }
  -        return referencedObject;                                         
  +        return referencedObject;
       }
       
       protected String getReference() {
  
  
  
  1.2       +83 -76    jakarta-ant/proposal/mutant/src/main/org/apache/ant/core/types/PatternSet.java
  
  Index: PatternSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/main/org/apache/ant/core/types/PatternSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PatternSet.java	2001/05/18 13:38:12	1.1
  +++ PatternSet.java	2001/05/19 08:00:25	1.2
  @@ -57,13 +57,11 @@
   import java.io.*;
   import java.util.*;
   import org.apache.ant.core.execution.*;
  +import java.net.URL;
   
   /**
    * Named collection of include/exclude tags.
    *
  - * <p>Moved out of MatchingTask to make it a standalone object that
  - * could be referenced (by scripts for example).
  - *
    * @author Arnout J. Kuiper <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>

    * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
    * @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>
  @@ -74,9 +72,9 @@
       private List includeList = new ArrayList();
       private List excludeList = new ArrayList();
       
  -//    private File incl = null;
  -//    private File excl = null;
  -//
  +    private URL includeFile = null;
  +    private URL excludeFile = null;
  +
       /**
        * inner class to hold a name on list.  "If" and "Unless" attributes
        * may be used to invalidate the entry based on the existence of a 
  @@ -200,68 +198,77 @@
           return result;
       }
   
  -//    /**
  -//     * Sets the name of the file containing the includes patterns.
  -//     *
  -//     * @param incl The file to fetch the include patterns from.  
  -//     */
  -//     public void setIncludesfile(File incl) throws BuildException {
  -//         if (isReference()) {
  -//             throw tooManyAttributes();
  -//         }
  +    /**
  +     * Sets the name of the file containing the includes patterns.
  +     *
  +     * @param incl The file to fetch the include patterns from.  
  +     */
  +     public void setIncludesfile(URL includeFile) throws ExecutionException {
  +         if (isReference()) {
  +             throw tooManyAttributes();
  +         }
  +         
   //         if (!incl.exists()) {
   //             throw new BuildException("Includesfile "+incl.getAbsolutePath()
   //                                      +" not found.");
  -//         }
  -//         this.incl = incl;
  -//     }
  -//
  -//    /**
  -//     * Sets the name of the file containing the excludes patterns.
  -//     *
  -//     * @param excl The file to fetch the exclude patterns from.  
  -//     */
  -//     public void setExcludesfile(File excl) throws BuildException {
  -//         if (isReference()) {
  -//             throw tooManyAttributes();
   //         }
  +         this.includeFile = includeFile;
  +     }
  +
  +    /**
  +     * Sets the name of the file containing the excludes patterns.
  +     *
  +     * @param excludeFile The file to fetch the exclude patterns from.  
  +     */
  +     public void setExcludesfile(URL excludeFile) throws ExecutionException {
  +         if (isReference()) {
  +             throw tooManyAttributes();
  +         }
   //         if (!excl.exists()) {
   //             throw new BuildException("Excludesfile "+excl.getAbsolutePath()
   //                                      +" not found.");
   //         }
  -//         this.excl = excl;
  -//     }
  -//    
  -//    /**
  -//     *  Reads path matching patterns from a file and adds them to the
  -//     *  includes or excludes list (as appropriate).  
  -//     */
  -//    private void readPatterns(File patternfile, Vector patternlist, Project p)
  -//        throws BuildException {
  -//        
  -//        try {
  -//            // Get a FileReader
  -//            BufferedReader patternReader = 
  -//                new BufferedReader(new FileReader(patternfile)); 
  -//        
  -//            // Create one NameEntry in the appropriate pattern list for each 
  -//            // line in the file.
  -//            String line = patternReader.readLine();
  -//            while (line != null) {
  -//                if (line.length() > 0) {
  -//                    line = ProjectHelper.replaceProperties(p, line,
  -//                                                           p.getProperties());
  -//                    addPatternToList(patternlist).setName(line);
  -//                }
  -//                line = patternReader.readLine();
  -//            }
  -//        } catch(IOException ioe)  {
  -//            String msg = "An error occured while reading from pattern file: " 
  -//                + patternfile;
  -//            throw new BuildException(msg, ioe);
  -//        }
  -//    }
  -//
  +         this.excludeFile = excludeFile;
  +     }
  +    
  +    /**
  +     *  Reads path matching patterns from a file and adds them to the
  +     *  includes or excludes list (as appropriate).  
  +     */
  +    private void readPatterns(URL patternFile, List patternList)
  +        throws ExecutionException {
  +        
  +        BufferedReader patternReader = null;
  +        try {
  +            // Get a FileReader
  +            patternReader = 
  +                new BufferedReader(new InputStreamReader(patternFile.openStream())); 
  +        
  +            // Create one NameEntry in the appropriate pattern list for each 
  +            // line in the file.
  +            String line = null;
  +            while ((line = patternReader.readLine()) != null) {
  +                if (line.length() > 0) {
  +                    line = getTaskContext().replacePropertyRefs(line);
  +                    addPatternToList(patternList).setName(line);
  +                }
  +            }
  +        } catch(IOException ioe)  {
  +            throw new ExecutionException("An error occured while reading from pattern file:
" 
  +                                         + patternFile, ioe);
  +        }
  +        finally {
  +            if (patternReader != null) {
  +                try {
  +                    patternReader.close();
  +                }
  +                catch (IOException e) {
  +                    // do nothing
  +                }
  +            }
  +        }
  +    }
  +
       /**
        * Adds the patterns of the other instance to this set.
        */
  @@ -292,7 +299,7 @@
           if (isReference()) {
               return getReferencedPatternSet().getIncludePatterns();
           } else {
  -//            readFiles(p);
  +            readFiles();
               return makeArray(includeList);
           }
       }
  @@ -304,7 +311,7 @@
           if (isReference()) {
               return getReferencedPatternSet().getExcludePatterns();
           } else {
  -//            readFiles(p);
  +            readFiles();
               return makeArray(excludeList);
           }
       }
  @@ -352,18 +359,18 @@
           return result;
       }
           
  -//    /**
  -//     * Read includefile ot excludefile if not already done so.
  -//     */
  -//    private void readFiles(Project p) {
  -//        if (incl != null) {
  -//            readPatterns(incl, includeList, p);
  -//            incl = null;
  -//        }
  -//        if (excl != null) {
  -//            readPatterns(excl, excludeList, p);
  -//            excl = null;
  -//        }
  -//    }
  -//
  +    /**
  +     * Read includefile ot excludefile if not already done so.
  +     */
  +    private void readFiles() throws ExecutionException {
  +        if (includeFile != null) {
  +            readPatterns(includeFile, includeList);
  +            includeFile = null;
  +        }
  +        if (excludeFile != null) {
  +            readPatterns(excludeFile, excludeList);
  +            excludeFile = null;
  +        }
  +    }
  +
   }
  
  
  

Mime
View raw message