Browse Source

Added a nested patternsetref element to fileset.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267812 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
2054505cbb
3 changed files with 148 additions and 9 deletions
  1. +12
    -0
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  2. +37
    -9
      src/main/org/apache/tools/ant/types/FileSet.java
  3. +99
    -0
      src/main/org/apache/tools/ant/types/Reference.java

+ 12
- 0
src/main/org/apache/tools/ant/taskdefs/AntStructure.java View File

@@ -178,6 +178,16 @@ public class AntStructure extends Task {
StringBuffer sb = new StringBuffer("<!ELEMENT "); StringBuffer sb = new StringBuffer("<!ELEMENT ");
sb.append(name).append(" "); sb.append(name).append(" ");


if (org.apache.tools.ant.types.Reference.class.equals(element)) {
sb.append("EMPTY>").append(lSep);
sb.append("<!ATTLIST ").append(name);
sb.append(lSep).append(" id ID #IMPLIED");
sb.append(lSep).append(" refid IDREF #IMPLIED");
sb.append(">").append(lSep);
out.println(sb);
return;
}

Vector v = new Vector(); Vector v = new Vector();
if (ih.supportsCharacters()) { if (ih.supportsCharacters()) {
v.addElement("#PCDATA"); v.addElement("#PCDATA");
@@ -218,6 +228,8 @@ public class AntStructure extends Task {
if (type.equals(java.lang.Boolean.class) || if (type.equals(java.lang.Boolean.class) ||
type.equals(java.lang.Boolean.TYPE)) { type.equals(java.lang.Boolean.TYPE)) {
sb.append("%boolean; "); sb.append("%boolean; ");
} else if (org.apache.tools.ant.types.Reference.class.isAssignableFrom(type)) {
sb.append("IDREF ");
} else if (org.apache.tools.ant.EnumeratedAttribute.class.isAssignableFrom(type)) { } else if (org.apache.tools.ant.EnumeratedAttribute.class.isAssignableFrom(type)) {
try { try {
EnumeratedAttribute ea = EnumeratedAttribute ea =


+ 37
- 9
src/main/org/apache/tools/ant/types/FileSet.java View File

@@ -57,7 +57,9 @@ package org.apache.tools.ant.types;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;

import java.io.File; import java.io.File;
import java.util.Vector;


/** /**
* Moved out of MatchingTask to make it a standalone object that could * Moved out of MatchingTask to make it a standalone object that could
@@ -71,7 +73,8 @@ import java.io.File;
*/ */
public class FileSet { public class FileSet {
private PatternSet patterns = new PatternSet();
private PatternSet defaultPatterns = new PatternSet();
private Vector additionalPatterns = new Vector();


private File dir; private File dir;
private boolean useDefaultExcludes = true; private boolean useDefaultExcludes = true;
@@ -95,21 +98,29 @@ public class FileSet {
} }


public PatternSet createPatternSet() { public PatternSet createPatternSet() {
PatternSet patterns = new PatternSet();
additionalPatterns.addElement(patterns);
return patterns; return patterns;
} }


public Reference createPatternSetRef() {
Reference r = new Reference();
additionalPatterns.addElement(r);
return r;
}

/** /**
* add a name entry on the include list * add a name entry on the include list
*/ */
public PatternSet.NameEntry createInclude() { public PatternSet.NameEntry createInclude() {
return patterns.createInclude();
return defaultPatterns.createInclude();
} }
/** /**
* add a name entry on the exclude list * add a name entry on the exclude list
*/ */
public PatternSet.NameEntry createExclude() { public PatternSet.NameEntry createExclude() {
return patterns.createExclude();
return defaultPatterns.createExclude();
} }


/** /**
@@ -119,7 +130,7 @@ public class FileSet {
* @param includes the string containing the include patterns * @param includes the string containing the include patterns
*/ */
public void setIncludes(String includes) { public void setIncludes(String includes) {
patterns.setIncludes(includes);
defaultPatterns.setIncludes(includes);
} }


/** /**
@@ -129,7 +140,7 @@ public class FileSet {
* @param excludes the string containing the exclude patterns * @param excludes the string containing the exclude patterns
*/ */
public void setExcludes(String excludes) { public void setExcludes(String excludes) {
patterns.setExcludes(excludes);
defaultPatterns.setExcludes(excludes);
} }


/** /**
@@ -139,7 +150,7 @@ public class FileSet {
* the include patterns from. * the include patterns from.
*/ */
public void setIncludesfile(File incl) throws BuildException { public void setIncludesfile(File incl) throws BuildException {
patterns.setIncludesfile(incl);
defaultPatterns.setIncludesfile(incl);
} }


/** /**
@@ -149,7 +160,7 @@ public class FileSet {
* the include patterns from. * the include patterns from.
*/ */
public void setExcludesfile(File excl) throws BuildException { public void setExcludesfile(File excl) throws BuildException {
patterns.setExcludesfile(excl);
defaultPatterns.setExcludesfile(excl);
} }


/** /**
@@ -169,8 +180,25 @@ public class FileSet {
public DirectoryScanner getDirectoryScanner(Project p) { public DirectoryScanner getDirectoryScanner(Project p) {
DirectoryScanner ds = new DirectoryScanner(); DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(dir); ds.setBasedir(dir);
ds.setIncludes(patterns.getIncludePatterns(p));
ds.setExcludes(patterns.getExcludePatterns(p));

for (int i=0; i<additionalPatterns.size(); i++) {
Object o = additionalPatterns.elementAt(i);
if (o instanceof PatternSet) {
defaultPatterns.append((PatternSet) o);
} else {
Reference r = (Reference) o;
o = r.getReferencedObject(p);
if (o instanceof PatternSet) {
defaultPatterns.append((PatternSet) o);
} else {
String msg = r.getRefId()+" doesn\'t denote a patternset";
throw new BuildException(msg);
}
}
}
ds.setIncludes(defaultPatterns.getIncludePatterns(p));
ds.setExcludes(defaultPatterns.getExcludePatterns(p));
if (useDefaultExcludes) ds.addDefaultExcludes(); if (useDefaultExcludes) ds.addDefaultExcludes();
ds.scan(); ds.scan();
return ds; return ds;


+ 99
- 0
src/main/org/apache/tools/ant/types/Reference.java View File

@@ -0,0 +1,99 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 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", "Tomcat", 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.Project;
import org.apache.tools.ant.BuildException;

/**
* Named collection of include/exclude tags.
*
* <p>Class to hold a reference to another object in the project.
*
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
*/
public class Reference {

private String refid;

public Reference() {
super();
}

public Reference(String id) {
this();
setRefId(id);
}

public void setRefId(String id) {
refid = id;
}

public String getRefId() {
return refid;
}

public Object getReferencedObject(Project project) throws BuildException {
if (refid == null) {
throw new BuildException("No reference specified");
}
Object o = project.getReferences().get(refid);
if (o == null) {
throw new BuildException("Refernce "+refid+" not found.");
}
return o;
}
}

Loading…
Cancel
Save