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/main/org/apache/tools/ant/types AbstractFileSet.java
Date Fri, 11 Feb 2005 16:27:28 GMT
mbenson     2005/02/11 08:27:28

  Modified:    src/main/org/apache/tools/ant/types AbstractFileSet.java
  Log:
  Modified to return a cached DirectoryScanner instance until
  changes are made to the AbstractFileSet.
  
  Revision  Changes    Path
  1.40      +79 -52    ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java
  
  Index: AbstractFileSet.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- AbstractFileSet.java	4 Feb 2005 23:37:33 -0000	1.39
  +++ AbstractFileSet.java	11 Feb 2005 16:27:28 -0000	1.40
  @@ -66,6 +66,9 @@
       private boolean caseSensitive = true;
       private boolean followSymlinks = true;
   
  +    /* cached DirectoryScanner instance for our own Project only */
  +    private DirectoryScanner directoryScanner = null;
  +
       /**
        * Construct a new <code>AbstractFileSet</code>.
        */
  @@ -113,11 +116,12 @@
        * Sets the base-directory for this instance.
        * @param dir the directory's <code>File</code> instance.
        */
  -    public void setDir(File dir) throws BuildException {
  +    public synchronized void setDir(File dir) throws BuildException {
           if (isReference()) {
               throw tooManyAttributes();
           }
           this.dir = dir;
  +        directoryScanner = null;
       }
   
       /**
  @@ -134,7 +138,7 @@
        *          reference is resolved, if set.
        * @return <code>File</code>.
        */
  -    public File getDir(Project p) {
  +    public synchronized File getDir(Project p) {
           return (isReference()) ? getRef(p).getDir(p) : dir;
       }
   
  @@ -142,12 +146,13 @@
        * Creates a nested patternset.
        * @return <code>PatternSet</code>.
        */
  -    public PatternSet createPatternSet() {
  +    public synchronized PatternSet createPatternSet() {
           if (isReference()) {
               throw noChildrenAllowed();
           }
           PatternSet patterns = new PatternSet();
           additionalPatterns.addElement(patterns);
  +        directoryScanner = null;
           return patterns;
       }
   
  @@ -155,10 +160,11 @@
        * Add a name entry to the include list.
        * @return <code>PatternSet.NameEntry</code>.
        */
  -    public PatternSet.NameEntry createInclude() {
  +    public synchronized PatternSet.NameEntry createInclude() {
           if (isReference()) {
               throw noChildrenAllowed();
           }
  +        directoryScanner = null;
           return defaultPatterns.createInclude();
       }
   
  @@ -166,10 +172,11 @@
        * Add a name entry to the include files list.
        * @return <code>PatternSet.NameEntry</code>.
        */
  -    public PatternSet.NameEntry createIncludesFile() {
  +    public synchronized PatternSet.NameEntry createIncludesFile() {
           if (isReference()) {
               throw noChildrenAllowed();
           }
  +        directoryScanner = null;
           return defaultPatterns.createIncludesFile();
       }
   
  @@ -177,10 +184,11 @@
        * Add a name entry to the exclude list.
        * @return <code>PatternSet.NameEntry</code>.
        */
  -    public PatternSet.NameEntry createExclude() {
  +    public synchronized PatternSet.NameEntry createExclude() {
           if (isReference()) {
               throw noChildrenAllowed();
           }
  +        directoryScanner = null;
           return defaultPatterns.createExclude();
       }
   
  @@ -188,10 +196,11 @@
        * Add a name entry to the excludes files list.
        * @return <code>PatternSet.NameEntry</code>.
        */
  -    public PatternSet.NameEntry createExcludesFile() {
  +    public synchronized PatternSet.NameEntry createExcludesFile() {
           if (isReference()) {
               throw noChildrenAllowed();
           }
  +        directoryScanner = null;
           return defaultPatterns.createExcludesFile();
       }
   
  @@ -216,11 +225,12 @@
        *
        * @param includes the <code>String</code> containing the include patterns.
        */
  -    public void setIncludes(String includes) {
  +    public synchronized void setIncludes(String includes) {
           if (isReference()) {
               throw tooManyAttributes();
           }
           defaultPatterns.setIncludes(includes);
  +        directoryScanner = null;
       }
   
       /**
  @@ -230,7 +240,7 @@
        * @param includes array containing the include patterns.
        * @since Ant 1.7
        */
  -    public void appendIncludes(String[] includes) {
  +    public synchronized void appendIncludes(String[] includes) {
           if (isReference()) {
               throw tooManyAttributes();
           }
  @@ -238,6 +248,7 @@
               for (int i = 0; i < includes.length; i++) {
                   defaultPatterns.createInclude().setName(includes[i]);
               }
  +            directoryScanner = null;
           }
       }
   
  @@ -249,11 +260,12 @@
        *
        * @param excludes the <code>String</code> containing the exclude patterns.
        */
  -    public void setExcludes(String excludes) {
  +    public synchronized void setExcludes(String excludes) {
           if (isReference()) {
               throw tooManyAttributes();
           }
           defaultPatterns.setExcludes(excludes);
  +        directoryScanner = null;
       }
   
       /**
  @@ -263,7 +275,7 @@
        * @param excludes array containing the exclude patterns.
        * @since Ant 1.7
        */
  -    public void appendExcludes(String[] excludes) {
  +    public synchronized void appendExcludes(String[] excludes) {
           if (isReference()) {
               throw tooManyAttributes();
           }
  @@ -271,6 +283,7 @@
               for (int i = 0; i < excludes.length; i++) {
                   defaultPatterns.createExclude().setName(excludes[i]);
               }
  +            directoryScanner = null;
           }
       }
   
  @@ -279,42 +292,45 @@
        *
        * @param incl <code>File</code> instance.
        */
  -     public void setIncludesfile(File incl) throws BuildException {
  -         if (isReference()) {
  -             throw tooManyAttributes();
  -         }
  -         defaultPatterns.setIncludesfile(incl);
  -     }
  +    public synchronized void setIncludesfile(File incl) throws BuildException {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +        defaultPatterns.setIncludesfile(incl);
  +        directoryScanner = null;
  +    }
   
       /**
        * Sets the <code>File</code> containing the excludes patterns.
        *
        * @param excl <code>File</code> instance.
        */
  -     public void setExcludesfile(File excl) throws BuildException {
  -         if (isReference()) {
  -             throw tooManyAttributes();
  -         }
  -         defaultPatterns.setExcludesfile(excl);
  -     }
  +    public synchronized void setExcludesfile(File excl) throws BuildException {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +        defaultPatterns.setExcludesfile(excl);
  +        directoryScanner = null;
  +    }
   
       /**
        * Sets whether default exclusions should be used or not.
        *
        * @param useDefaultExcludes <code>boolean</code>.
        */
  -    public void setDefaultexcludes(boolean useDefaultExcludes) {
  +    public synchronized void setDefaultexcludes(boolean useDefaultExcludes) {
           if (isReference()) {
               throw tooManyAttributes();
           }
           this.useDefaultExcludes = useDefaultExcludes;
  +        directoryScanner = null;
       }
   
       /**
        * Whether default exclusions should be used or not.
        * @since Ant 1.7
        */
  -    public boolean getDefaultexcludes() {
  +    public synchronized boolean getDefaultexcludes() {
           return (isReference())
               ? getRef(getProject()).getDefaultexcludes() : useDefaultExcludes;
       }
  @@ -324,11 +340,12 @@
        *
        * @param isCaseSensitive <code>boolean</code>.
        */
  -    public void setCaseSensitive(boolean caseSensitive) {
  +    public synchronized void setCaseSensitive(boolean caseSensitive) {
           if (isReference()) {
               throw tooManyAttributes();
           }
           this.caseSensitive = caseSensitive;
  +        directoryScanner = null;
       }
   
       /**
  @@ -339,7 +356,7 @@
        *
        * @since Ant 1.7
        */
  -    public boolean isCaseSensitive() {
  +    public synchronized boolean isCaseSensitive() {
           return (isReference())
               ? getRef(getProject()).isCaseSensitive() : caseSensitive;
       }
  @@ -349,11 +366,12 @@
        *
        * @param followSymlinks whether or not symbolic links should be followed.
        */
  -    public void setFollowSymlinks(boolean followSymlinks) {
  +    public synchronized void setFollowSymlinks(boolean followSymlinks) {
           if (isReference()) {
               throw tooManyAttributes();
           }
           this.followSymlinks = followSymlinks;
  +        directoryScanner = null;
       }
   
       /**
  @@ -364,7 +382,7 @@
        *
        * @since Ant 1.6
        */
  -    public boolean isFollowSymlinks() {
  +    public synchronized boolean isFollowSymlinks() {
           return (isReference())
               ? getRef(getProject()).isFollowSymlinks() : followSymlinks;
       }
  @@ -407,20 +425,29 @@
           if (isReference()) {
               return getRef(p).getDirectoryScanner(p);
           }
  -        if (dir == null) {
  -            throw new BuildException("No directory specified for "
  -                                     + getDataTypeName() + ".");
  -        }
  -        if (!dir.exists()) {
  -            throw new BuildException(dir.getAbsolutePath() + " not found.");
  -        }
  -        if (!dir.isDirectory()) {
  -            throw new BuildException(dir.getAbsolutePath()
  -                                     + " is not a directory.");
  -        }
  -        DirectoryScanner ds = new DirectoryScanner();
  -        setupDirectoryScanner(ds, p);
  -        ds.setFollowSymlinks(followSymlinks);
  +        DirectoryScanner ds = null;
  +        synchronized (this) {
  +            if (directoryScanner != null && p == getProject()) {
  +                ds = directoryScanner;
  +            } else {
  +                if (dir == null) {
  +                    throw new BuildException("No directory specified for "
  +                                             + getDataTypeName() + ".");
  +                }
  +                if (!dir.exists()) {
  +                    throw new BuildException(dir.getAbsolutePath()
  +                                             + " not found.");
  +                }
  +                if (!dir.isDirectory()) {
  +                    throw new BuildException(dir.getAbsolutePath()
  +                                             + " is not a directory.");
  +                }
  +                ds = new DirectoryScanner();
  +                setupDirectoryScanner(ds, p);
  +                ds.setFollowSymlinks(followSymlinks);
  +                directoryScanner = (p == getProject()) ? ds : directoryScanner;
  +            }
  +        }
           ds.scan();
           return ds;
       }
  @@ -439,7 +466,7 @@
        * @param ds a <code>FileScanner</code> instance.
        * @param p an Ant <code>Project</code> instance.
        */
  -    public void setupDirectoryScanner(FileScanner ds, Project p) {
  +    public synchronized void setupDirectoryScanner(FileScanner ds, Project p) {
           if (isReference()) {
               getRef(p).setupDirectoryScanner(ds, p);
               return;
  @@ -490,7 +517,7 @@
        *
        * @return whether any selectors are in this container.
        */
  -    public boolean hasSelectors() {
  +    public synchronized boolean hasSelectors() {
           return (isReference() && getProject() != null)
               ? getRef(getProject()).hasSelectors() : !(selectors.isEmpty());
       }
  @@ -500,7 +527,7 @@
        *
        * @return whether any patterns are in this container.
        */
  -    public boolean hasPatterns() {
  +    public synchronized boolean hasPatterns() {
           if (isReference() && getProject() != null) {
               return getRef(getProject()).hasPatterns();
           }
  @@ -522,7 +549,7 @@
        *
        * @return the number of selectors in this container as an <code>int</code>.
        */
  -    public int selectorCount() {
  +    public synchronized int selectorCount() {
           return (isReference() && getProject() != null)
               ? getRef(getProject()).selectorCount() : selectors.size();
       }
  @@ -532,7 +559,7 @@
        *
        * @return a <code>FileSelector[]</code> of the selectors in this container.
        */
  -    public FileSelector[] getSelectors(Project p) {
  +    public synchronized FileSelector[] getSelectors(Project p) {
           return (isReference())
               ? getRef(p).getSelectors(p) : (FileSelector[])(selectors.toArray(
               new FileSelector[selectors.size()]));
  @@ -543,7 +570,7 @@
        *
        * @return an <code>Enumeration</code> of selectors.
        */
  -    public Enumeration selectorElements() {
  +    public synchronized Enumeration selectorElements() {
           return (isReference() && getProject() != null)
               ? getRef(getProject()).selectorElements() : selectors.elements();
       }
  @@ -553,7 +580,7 @@
        *
        * @param selector the new <code>FileSelector</code> to add.
        */
  -    public void appendSelector(FileSelector selector) {
  +    public synchronized void appendSelector(FileSelector selector) {
           if (isReference()) {
               throw noChildrenAllowed();
           }
  @@ -742,7 +769,7 @@
        *
        * @since Ant 1.6
        */
  -    public Object clone() {
  +    public synchronized Object clone() {
           if (isReference()) {
               return (getRef(getProject())).clone();
           } else {
  @@ -789,7 +816,7 @@
        *
        * @since Ant 1.7
        */
  -    public PatternSet mergePatterns(Project p) {
  +    public synchronized PatternSet mergePatterns(Project p) {
           if (isReference()) {
               return getRef(p).mergePatterns(p);
           }
  
  
  

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


Mime
View raw message