Browse Source

(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.
PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272100 13f79535-47bb-0310-9956-ffa450edef68
master
Diane Holt 23 years ago
parent
commit
e98e1462b5
4 changed files with 367 additions and 3 deletions
  1. +12
    -3
      src/main/org/apache/tools/ant/taskdefs/PathConvert.java
  2. +313
    -0
      src/main/org/apache/tools/ant/types/DirSet.java
  3. +41
    -0
      src/main/org/apache/tools/ant/types/Path.java
  4. +1
    -0
      src/main/org/apache/tools/ant/types/defaults.properties

+ 12
- 3
src/main/org/apache/tools/ant/taskdefs/PathConvert.java View File

@@ -60,6 +60,8 @@ import org.apache.tools.ant.Task;
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 @@ public class PathConvert extends Task {

/**
* Helper class, holds the nested <map> values. Elements will look like this:
* &lt;map from="d:" to="/foo"/>
* &lt;map from="d:" to="/foo"/&gt;
* <p>
* When running on windows, the prefix comparison will be case insensitive.
*/
@@ -226,7 +228,7 @@ public class PathConvert extends Task {
*/
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 @@ public class PathConvert extends Task {
} 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." );
}
}



+ 313
- 0
src/main/org/apache/tools/ant/types/DirSet.java View File

@@ -0,0 +1,313 @@
/*
* 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 apache@apache.org.
*
* 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);
}
}

}

+ 41
- 0
src/main/org/apache/tools/ant/types/Path.java View File

@@ -198,6 +198,28 @@ public class Path extends DataType implements Cloneable {
checked = false;
}

/**
* Adds a nested <code>&lt;filelist&gt;</code> element.
*/
public void addFilelist(FileList fl) throws BuildException {
if (isReference()) {
throw noChildrenAllowed();
}
elements.addElement(fl);
checked = false;
}

/**
* Adds a nested <code>&lt;dirset&gt;</code> element.
*/
public void addDirset(DirSet dset) throws BuildException {
if (isReference()) {
throw noChildrenAllowed();
}
elements.addElement(dset);
checked = false;
}

/**
* Creates a nested <code>&lt;path&gt;</code> element.
*/
@@ -307,6 +329,25 @@ public class Path extends DataType implements Cloneable {
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));
}
}
}
String[] res = new String[result.size()];


+ 1
- 0
src/main/org/apache/tools/ant/types/defaults.properties View File

@@ -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


Loading…
Cancel
Save