Browse Source

Modified to return a cached DirectoryScanner instance until

changes are made to the AbstractFileSet.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277637 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 21 years ago
parent
commit
4732c52135
1 changed files with 78 additions and 51 deletions
  1. +78
    -51
      src/main/org/apache/tools/ant/types/AbstractFileSet.java

+ 78
- 51
src/main/org/apache/tools/ant/types/AbstractFileSet.java View File

@@ -66,6 +66,9 @@ public abstract class AbstractFileSet extends DataType
private boolean caseSensitive = true; private boolean caseSensitive = true;
private boolean followSymlinks = true; private boolean followSymlinks = true;


/* cached DirectoryScanner instance for our own Project only */
private DirectoryScanner directoryScanner = null;

/** /**
* Construct a new <code>AbstractFileSet</code>. * Construct a new <code>AbstractFileSet</code>.
*/ */
@@ -113,11 +116,12 @@ public abstract class AbstractFileSet extends DataType
* Sets the base-directory for this instance. * Sets the base-directory for this instance.
* @param dir the directory's <code>File</code> 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()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
this.dir = dir; this.dir = dir;
directoryScanner = null;
} }


/** /**
@@ -134,7 +138,7 @@ public abstract class AbstractFileSet extends DataType
* reference is resolved, if set. * reference is resolved, if set.
* @return <code>File</code>. * @return <code>File</code>.
*/ */
public File getDir(Project p) {
public synchronized File getDir(Project p) {
return (isReference()) ? getRef(p).getDir(p) : dir; return (isReference()) ? getRef(p).getDir(p) : dir;
} }


@@ -142,12 +146,13 @@ public abstract class AbstractFileSet extends DataType
* Creates a nested patternset. * Creates a nested patternset.
* @return <code>PatternSet</code>. * @return <code>PatternSet</code>.
*/ */
public PatternSet createPatternSet() {
public synchronized PatternSet createPatternSet() {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
PatternSet patterns = new PatternSet(); PatternSet patterns = new PatternSet();
additionalPatterns.addElement(patterns); additionalPatterns.addElement(patterns);
directoryScanner = null;
return patterns; return patterns;
} }


@@ -155,10 +160,11 @@ public abstract class AbstractFileSet extends DataType
* Add a name entry to the include list. * Add a name entry to the include list.
* @return <code>PatternSet.NameEntry</code>. * @return <code>PatternSet.NameEntry</code>.
*/ */
public PatternSet.NameEntry createInclude() {
public synchronized PatternSet.NameEntry createInclude() {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
directoryScanner = null;
return defaultPatterns.createInclude(); return defaultPatterns.createInclude();
} }


@@ -166,10 +172,11 @@ public abstract class AbstractFileSet extends DataType
* Add a name entry to the include files list. * Add a name entry to the include files list.
* @return <code>PatternSet.NameEntry</code>. * @return <code>PatternSet.NameEntry</code>.
*/ */
public PatternSet.NameEntry createIncludesFile() {
public synchronized PatternSet.NameEntry createIncludesFile() {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
directoryScanner = null;
return defaultPatterns.createIncludesFile(); return defaultPatterns.createIncludesFile();
} }


@@ -177,10 +184,11 @@ public abstract class AbstractFileSet extends DataType
* Add a name entry to the exclude list. * Add a name entry to the exclude list.
* @return <code>PatternSet.NameEntry</code>. * @return <code>PatternSet.NameEntry</code>.
*/ */
public PatternSet.NameEntry createExclude() {
public synchronized PatternSet.NameEntry createExclude() {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
directoryScanner = null;
return defaultPatterns.createExclude(); return defaultPatterns.createExclude();
} }


@@ -188,10 +196,11 @@ public abstract class AbstractFileSet extends DataType
* Add a name entry to the excludes files list. * Add a name entry to the excludes files list.
* @return <code>PatternSet.NameEntry</code>. * @return <code>PatternSet.NameEntry</code>.
*/ */
public PatternSet.NameEntry createExcludesFile() {
public synchronized PatternSet.NameEntry createExcludesFile() {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
directoryScanner = null;
return defaultPatterns.createExcludesFile(); return defaultPatterns.createExcludesFile();
} }


@@ -216,11 +225,12 @@ public abstract class AbstractFileSet extends DataType
* *
* @param includes the <code>String</code> containing the include patterns. * @param includes the <code>String</code> containing the include patterns.
*/ */
public void setIncludes(String includes) {
public synchronized void setIncludes(String includes) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
defaultPatterns.setIncludes(includes); defaultPatterns.setIncludes(includes);
directoryScanner = null;
} }


/** /**
@@ -230,7 +240,7 @@ public abstract class AbstractFileSet extends DataType
* @param includes array containing the include patterns. * @param includes array containing the include patterns.
* @since Ant 1.7 * @since Ant 1.7
*/ */
public void appendIncludes(String[] includes) {
public synchronized void appendIncludes(String[] includes) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
@@ -238,6 +248,7 @@ public abstract class AbstractFileSet extends DataType
for (int i = 0; i < includes.length; i++) { for (int i = 0; i < includes.length; i++) {
defaultPatterns.createInclude().setName(includes[i]); defaultPatterns.createInclude().setName(includes[i]);
} }
directoryScanner = null;
} }
} }


@@ -249,11 +260,12 @@ public abstract class AbstractFileSet extends DataType
* *
* @param excludes the <code>String</code> containing the exclude patterns. * @param excludes the <code>String</code> containing the exclude patterns.
*/ */
public void setExcludes(String excludes) {
public synchronized void setExcludes(String excludes) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
defaultPatterns.setExcludes(excludes); defaultPatterns.setExcludes(excludes);
directoryScanner = null;
} }


/** /**
@@ -263,7 +275,7 @@ public abstract class AbstractFileSet extends DataType
* @param excludes array containing the exclude patterns. * @param excludes array containing the exclude patterns.
* @since Ant 1.7 * @since Ant 1.7
*/ */
public void appendExcludes(String[] excludes) {
public synchronized void appendExcludes(String[] excludes) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
@@ -271,6 +283,7 @@ public abstract class AbstractFileSet extends DataType
for (int i = 0; i < excludes.length; i++) { for (int i = 0; i < excludes.length; i++) {
defaultPatterns.createExclude().setName(excludes[i]); defaultPatterns.createExclude().setName(excludes[i]);
} }
directoryScanner = null;
} }
} }


@@ -279,42 +292,45 @@ public abstract class AbstractFileSet extends DataType
* *
* @param incl <code>File</code> instance. * @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. * Sets the <code>File</code> containing the excludes patterns.
* *
* @param excl <code>File</code> instance. * @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. * Sets whether default exclusions should be used or not.
* *
* @param useDefaultExcludes <code>boolean</code>. * @param useDefaultExcludes <code>boolean</code>.
*/ */
public void setDefaultexcludes(boolean useDefaultExcludes) {
public synchronized void setDefaultexcludes(boolean useDefaultExcludes) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
this.useDefaultExcludes = useDefaultExcludes; this.useDefaultExcludes = useDefaultExcludes;
directoryScanner = null;
} }


/** /**
* Whether default exclusions should be used or not. * Whether default exclusions should be used or not.
* @since Ant 1.7 * @since Ant 1.7
*/ */
public boolean getDefaultexcludes() {
public synchronized boolean getDefaultexcludes() {
return (isReference()) return (isReference())
? getRef(getProject()).getDefaultexcludes() : useDefaultExcludes; ? getRef(getProject()).getDefaultexcludes() : useDefaultExcludes;
} }
@@ -324,11 +340,12 @@ public abstract class AbstractFileSet extends DataType
* *
* @param isCaseSensitive <code>boolean</code>. * @param isCaseSensitive <code>boolean</code>.
*/ */
public void setCaseSensitive(boolean caseSensitive) {
public synchronized void setCaseSensitive(boolean caseSensitive) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
this.caseSensitive = caseSensitive; this.caseSensitive = caseSensitive;
directoryScanner = null;
} }


/** /**
@@ -339,7 +356,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @since Ant 1.7 * @since Ant 1.7
*/ */
public boolean isCaseSensitive() {
public synchronized boolean isCaseSensitive() {
return (isReference()) return (isReference())
? getRef(getProject()).isCaseSensitive() : caseSensitive; ? getRef(getProject()).isCaseSensitive() : caseSensitive;
} }
@@ -349,11 +366,12 @@ public abstract class AbstractFileSet extends DataType
* *
* @param followSymlinks whether or not symbolic links should be followed. * @param followSymlinks whether or not symbolic links should be followed.
*/ */
public void setFollowSymlinks(boolean followSymlinks) {
public synchronized void setFollowSymlinks(boolean followSymlinks) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
this.followSymlinks = followSymlinks; this.followSymlinks = followSymlinks;
directoryScanner = null;
} }


/** /**
@@ -364,7 +382,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @since Ant 1.6 * @since Ant 1.6
*/ */
public boolean isFollowSymlinks() {
public synchronized boolean isFollowSymlinks() {
return (isReference()) return (isReference())
? getRef(getProject()).isFollowSymlinks() : followSymlinks; ? getRef(getProject()).isFollowSymlinks() : followSymlinks;
} }
@@ -407,20 +425,29 @@ public abstract class AbstractFileSet extends DataType
if (isReference()) { if (isReference()) {
return getRef(p).getDirectoryScanner(p); 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 = 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;
}
} }
DirectoryScanner ds = new DirectoryScanner();
setupDirectoryScanner(ds, p);
ds.setFollowSymlinks(followSymlinks);
ds.scan(); ds.scan();
return ds; return ds;
} }
@@ -439,7 +466,7 @@ public abstract class AbstractFileSet extends DataType
* @param ds a <code>FileScanner</code> instance. * @param ds a <code>FileScanner</code> instance.
* @param p an Ant <code>Project</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()) { if (isReference()) {
getRef(p).setupDirectoryScanner(ds, p); getRef(p).setupDirectoryScanner(ds, p);
return; return;
@@ -490,7 +517,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @return whether any selectors are in this container. * @return whether any selectors are in this container.
*/ */
public boolean hasSelectors() {
public synchronized boolean hasSelectors() {
return (isReference() && getProject() != null) return (isReference() && getProject() != null)
? getRef(getProject()).hasSelectors() : !(selectors.isEmpty()); ? getRef(getProject()).hasSelectors() : !(selectors.isEmpty());
} }
@@ -500,7 +527,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @return whether any patterns are in this container. * @return whether any patterns are in this container.
*/ */
public boolean hasPatterns() {
public synchronized boolean hasPatterns() {
if (isReference() && getProject() != null) { if (isReference() && getProject() != null) {
return getRef(getProject()).hasPatterns(); return getRef(getProject()).hasPatterns();
} }
@@ -522,7 +549,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @return the number of selectors in this container as an <code>int</code>. * @return the number of selectors in this container as an <code>int</code>.
*/ */
public int selectorCount() {
public synchronized int selectorCount() {
return (isReference() && getProject() != null) return (isReference() && getProject() != null)
? getRef(getProject()).selectorCount() : selectors.size(); ? getRef(getProject()).selectorCount() : selectors.size();
} }
@@ -532,7 +559,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @return a <code>FileSelector[]</code> of the selectors in this container. * @return a <code>FileSelector[]</code> of the selectors in this container.
*/ */
public FileSelector[] getSelectors(Project p) {
public synchronized FileSelector[] getSelectors(Project p) {
return (isReference()) return (isReference())
? getRef(p).getSelectors(p) : (FileSelector[])(selectors.toArray( ? getRef(p).getSelectors(p) : (FileSelector[])(selectors.toArray(
new FileSelector[selectors.size()])); new FileSelector[selectors.size()]));
@@ -543,7 +570,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @return an <code>Enumeration</code> of selectors. * @return an <code>Enumeration</code> of selectors.
*/ */
public Enumeration selectorElements() {
public synchronized Enumeration selectorElements() {
return (isReference() && getProject() != null) return (isReference() && getProject() != null)
? getRef(getProject()).selectorElements() : selectors.elements(); ? getRef(getProject()).selectorElements() : selectors.elements();
} }
@@ -553,7 +580,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @param selector the new <code>FileSelector</code> to add. * @param selector the new <code>FileSelector</code> to add.
*/ */
public void appendSelector(FileSelector selector) {
public synchronized void appendSelector(FileSelector selector) {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
@@ -742,7 +769,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @since Ant 1.6 * @since Ant 1.6
*/ */
public Object clone() {
public synchronized Object clone() {
if (isReference()) { if (isReference()) {
return (getRef(getProject())).clone(); return (getRef(getProject())).clone();
} else { } else {
@@ -789,7 +816,7 @@ public abstract class AbstractFileSet extends DataType
* *
* @since Ant 1.7 * @since Ant 1.7
*/ */
public PatternSet mergePatterns(Project p) {
public synchronized PatternSet mergePatterns(Project p) {
if (isReference()) { if (isReference()) {
return getRef(p).mergePatterns(p); return getRef(p).mergePatterns(p);
} }


Loading…
Cancel
Save