holtdl 02/03/29 17:03:40
Modified: src/main/org/apache/tools/ant/taskdefs PathConvert.java
src/main/org/apache/tools/ant/types defaults.properties
Path.java
Added: src/main/org/apache/tools/ant/types DirSet.java
Log:
(Oh what the hell -- if the coding sucks, it can get backed out
or corrected :)
Added:
- new DirSet datatype
- support for DirSet and FileList to <path>
- support for DirSet and FileList to <pathconvert>
(Note: The added support for FileList doesn't have anything
to do with DirSet, I just figured while was there, might as
well add that as well.)
Will put through doc/testcases stuff in a separate commit.
Revision Changes Path
1.11 +12 -3
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
Index: PathConvert.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- PathConvert.java 3 Mar 2002 01:46:20 -0000 1.10
+++ PathConvert.java 30 Mar 2002 01:03:40 -0000 1.11
@@ -60,6 +60,8 @@
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.DirSet;
+import org.apache.tools.ant.types.FileList;
import java.util.Vector;
import java.io.File;
@@ -79,7 +81,7 @@
/**
* Helper class, holds the nested <map> values. Elements will look like
this:
- * <map from="d:" to="/foo"/>
+ * <map from="d:" to="/foo"/>
* <p>
* When running on windows, the prefix comparison will be case
insensitive.
*/
@@ -226,7 +228,7 @@
*/
public void execute() throws BuildException {
- // If we are a reference, the create a Path from the reference
+ // If we are a reference, create a Path from the reference
if( isReference() ) {
path = new Path(getProject()).createPath();
@@ -237,8 +239,15 @@
} else if( obj instanceof FileSet ) {
FileSet fs = (FileSet)obj;
path.addFileset( fs );
+ } else if( obj instanceof DirSet ) {
+ DirSet ds = (DirSet)obj;
+ path.addDirset( ds );
+ } else if( obj instanceof FileList ) {
+ FileList fl = (FileList)obj;
+ path.addFilelist( fl );
+
} else {
- throw new BuildException( "'refid' does not refer to a path
or fileset" );
+ throw new BuildException( "'refid' does not refer to a path,
fileset, dirset, or filelist." );
}
}
1.11 +1 -0
jakarta-ant/src/main/org/apache/tools/ant/types/defaults.properties
Index: defaults.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/defaults.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- defaults.properties 11 Mar 2002 09:40:21 -0000 1.10
+++ defaults.properties 30 Mar 2002 01:03:40 -0000 1.11
@@ -1,4 +1,5 @@
path=org.apache.tools.ant.types.Path
+dirset=org.apache.tools.ant.types.DirSet
fileset=org.apache.tools.ant.types.FileSet
filelist=org.apache.tools.ant.types.FileList
patternset=org.apache.tools.ant.types.PatternSet
1.32 +41 -0 jakarta-ant/src/main/org/apache/tools/ant/types/Path.java
Index: Path.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Path.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Path.java 26 Feb 2002 12:16:09 -0000 1.31
+++ Path.java 30 Mar 2002 01:03:40 -0000 1.32
@@ -199,6 +199,28 @@
}
/**
+ * Adds a nested <code><filelist></code> element.
+ */
+ public void addFilelist(FileList fl) throws BuildException {
+ if (isReference()) {
+ throw noChildrenAllowed();
+ }
+ elements.addElement(fl);
+ checked = false;
+ }
+
+ /**
+ * Adds a nested <code><dirset></code> element.
+ */
+ public void addDirset(DirSet dset) throws BuildException {
+ if (isReference()) {
+ throw noChildrenAllowed();
+ }
+ elements.addElement(dset);
+ checked = false;
+ }
+
+ /**
* Creates a nested <code><path></code> element.
*/
public Path createPath() throws BuildException {
@@ -305,6 +327,25 @@
for (int j=0; j<s.length; j++) {
File f = new File(dir, s[j]);
String absolutePath = f.getAbsolutePath();
+ addUnlessPresent(result, translateFile(absolutePath));
+ }
+ } else if (o instanceof DirSet) {
+ DirSet dset = (DirSet) o;
+ DirectoryScanner ds = dset.getDirectoryScanner(getProject());
+ String[] s = ds.getIncludedDirectories();
+ File dir = dset.getDir(getProject());
+ for (int j=0; j<s.length; j++) {
+ File d = new File(dir, s[j]);
+ String absolutePath = d.getAbsolutePath();
+ addUnlessPresent(result, translateFile(absolutePath));
+ }
+ } else if (o instanceof FileList) {
+ FileList fl = (FileList) o;
+ String[] s = fl.getFiles(getProject());
+ File dir = fl.getDir(getProject());
+ for (int j=0; j<s.length; j++) {
+ File d = new File(dir, s[j]);
+ String absolutePath = d.getAbsolutePath();
addUnlessPresent(result, translateFile(absolutePath));
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/types/DirSet.java
Index: DirSet.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.types;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.FileScanner;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import java.io.File;
import java.util.Stack;
import java.util.Vector;
/**
* Essentially a clone of FileSet, but gets a set of dirs instead of files.
*/
public class DirSet extends DataType implements Cloneable {
private PatternSet defaultPatterns = new PatternSet();
private Vector additionalPatterns = new Vector();
private File dir;
private boolean isCaseSensitive = true;
public DirSet() {
super();
}
protected DirSet(DirSet dirset) {
this.dir = dirset.dir;
this.defaultPatterns = dirset.defaultPatterns;
this.additionalPatterns = dirset.additionalPatterns;
this.isCaseSensitive = dirset.isCaseSensitive;
setProject(getProject());
}
/**
* Makes this instance in effect a reference to another PatternSet
* instance.
*
* <p>You must not set another attribute or nest elements inside
* this element if you make it a reference.</p>
*/
public void setRefid(Reference r) throws BuildException {
if (dir != null || defaultPatterns.hasPatterns()) {
throw tooManyAttributes();
}
if (!additionalPatterns.isEmpty()) {
throw noChildrenAllowed();
}
super.setRefid(r);
}
public void setDir(File dir) throws BuildException {
if (isReference()) {
throw tooManyAttributes();
}
this.dir = dir;
}
public File getDir(Project p) {
if (isReference()) {
return getRef(p).getDir(p);
}
return dir;
}
public PatternSet createPatternSet() {
if (isReference()) {
throw noChildrenAllowed();
}
PatternSet patterns = new PatternSet();
additionalPatterns.addElement(patterns);
return patterns;
}
/**
* add a name entry on the include list
*/
public PatternSet.NameEntry createInclude() {
if (isReference()) {
throw noChildrenAllowed();
}
return defaultPatterns.createInclude();
}
/**
* add a name entry on the include files list
*/
public PatternSet.NameEntry createIncludesFile() {
if (isReference()) {
throw noChildrenAllowed();
}
return defaultPatterns.createIncludesFile();
}
/**
* add a name entry on the exclude list
*/
public PatternSet.NameEntry createExclude() {
if (isReference()) {
throw noChildrenAllowed();
}
return defaultPatterns.createExclude();
}
/**
* add a name entry on the include files list
*/
public PatternSet.NameEntry createExcludesFile() {
if (isReference()) {
throw noChildrenAllowed();
}
return defaultPatterns.createExcludesFile();
}
/**
* Sets the set of include patterns. Patterns may be separated by a comma
* or a space.
*
* @param includes the string containing the include patterns
*/
public void setIncludes(String includes) {
if (isReference()) {
throw tooManyAttributes();
}
defaultPatterns.setIncludes(includes);
}
/**
* Sets the set of exclude patterns. Patterns may be separated by a comma
* or a space.
*
* @param excludes the string containing the exclude patterns
*/
public void setExcludes(String excludes) {
if (isReference()) {
throw tooManyAttributes();
}
defaultPatterns.setExcludes(excludes);
}
/**
* 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();
}
defaultPatterns.setIncludesfile(incl);
}
/**
* Sets the name of the file containing the includes patterns.
*
* @param excl The file to fetch the exclude patterns from.
*/
public void setExcludesfile(File excl) throws BuildException {
if (isReference()) {
throw tooManyAttributes();
}
defaultPatterns.setExcludesfile(excl);
}
/**
* Sets case sensitivity of the file system
*
* @param isCaseSensitive "true"|"on"|"yes" if file system is case
* sensitive, "false"|"off"|"no" when not.
*/
public void setCaseSensitive(boolean isCaseSensitive) {
this.isCaseSensitive = isCaseSensitive;
}
/**
* Returns the directory scanner needed to access the dirs to process.
*/
public DirectoryScanner getDirectoryScanner(Project p) {
if (isReference()) {
return getRef(p).getDirectoryScanner(p);
}
if (dir == null) {
throw new BuildException("No directory specified for dirset.");
}
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.scan();
ds.getIncludedDirectories();
return ds;
}
public void setupDirectoryScanner(FileScanner ds, Project p) {
if (ds == null) {
throw new IllegalArgumentException("ds cannot be null");
}
ds.setBasedir(dir);
final int count = additionalPatterns.size();
for (int i = 0; i < count; i++) {
Object o = additionalPatterns.elementAt(i);
defaultPatterns.append((PatternSet) o, p);
}
p.log( "DirSet: Setup dir scanner in dir " + dir +
" with " + defaultPatterns, Project.MSG_DEBUG );
ds.setIncludes(defaultPatterns.getIncludePatterns(p));
ds.setExcludes(defaultPatterns.getExcludePatterns(p));
ds.setCaseSensitive(isCaseSensitive);
}
/**
* Performs the check for circular references and returns the
* referenced DirSet.
*/
protected DirSet getRef(Project p) {
if (!checked) {
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, p);
}
Object o = ref.getReferencedObject(p);
if (!(o instanceof DirSet)) {
String msg = ref.getRefId()+" doesn\'t denote a dirset";
throw new BuildException(msg);
} else {
return (DirSet) o;
}
}
/**
* Return a DirSet that has the same basedir and same patternsets
* as this one.
*/
public Object clone() {
if (isReference()) {
return new DirSet(getRef(getProject()));
} else {
return new DirSet(this);
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>