001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * NbPatternset.java
043: *
044: * Created on May 2, 2001, 7:04 PM
045: */
046:
047: package org.netbeans.xtest;
048:
049: import org.apache.tools.ant.*;
050: import org.apache.tools.ant.types.*;
051:
052: import java.util.Vector;
053: import java.util.Iterator;
054: import java.io.File;
055:
056: /** This Ant's task merges together nested patternsets and patternset
057: * refereced by the id ettribute. If patternset denoted by id attribute
058: * doesn't exist new one is created and added among project references.
059: *
060: * @author <a href="mailto:vitezslav.stejskal@czech.sun.com">Vitezslav Stejskal</a>
061: * @version 1.0
062: */
063: public class NbPatternset extends Task {
064: private PatternSet defaultPatterns = new PatternSet();
065: private Vector additionalPatterns = new Vector();
066: private String id;
067:
068: public void setUseId(String id) {
069: this .id = id;
070: }
071:
072: public PatternSet createPatternSet() {
073: PatternSet patterns = new PatternSet();
074: additionalPatterns.addElement(patterns);
075: return patterns;
076: }
077:
078: /**
079: * add a name entry on the include list
080: */
081: public PatternSet.NameEntry createInclude() {
082: return defaultPatterns.createInclude();
083: }
084:
085: /**
086: * add a name entry on the exclude list
087: */
088: public PatternSet.NameEntry createExclude() {
089: return defaultPatterns.createExclude();
090: }
091:
092: /**
093: * Sets the set of include patterns. Patterns may be separated by a comma
094: * or a space.
095: *
096: * @param includes the string containing the include patterns
097: */
098: public void setIncludes(String includes) {
099: defaultPatterns.setIncludes(includes);
100: }
101:
102: /**
103: * Sets the set of exclude patterns. Patterns may be separated by a comma
104: * or a space.
105: *
106: * @param excludes the string containing the exclude patterns
107: */
108: public void setExcludes(String excludes) {
109: defaultPatterns.setExcludes(excludes);
110: }
111:
112: /**
113: * Sets the name of the file containing the includes patterns.
114: *
115: * @param incl The file to fetch the include patterns from.
116: */
117: public void setIncludesfile(File incl) throws BuildException {
118: defaultPatterns.setIncludesfile(incl);
119: }
120:
121: /**
122: * Sets the name of the file containing the includes patterns.
123: *
124: * @param excl The file to fetch the exclude patterns from.
125: */
126: public void setExcludesfile(File excl) throws BuildException {
127: defaultPatterns.setExcludesfile(excl);
128: }
129:
130: public void execute() throws BuildException {
131: if (null == id)
132: throw new BuildException("The id attribute must be set.");
133:
134: // try to get reference
135: PatternSet patternset;
136: Object ref = getProject().getReferences().get(id);
137: if (null != ref) {
138: if (!(ref instanceof PatternSet)) {
139: log("Object denoted by " + id
140: + " isn't valid PatternSet.",
141: Project.MSG_VERBOSE);
142: return;
143: }
144: patternset = (PatternSet) ref;
145: } else
146: patternset = new PatternSet();
147:
148: Iterator i = additionalPatterns.iterator();
149:
150: patternset.append(defaultPatterns, getProject());
151: while (i.hasNext()) {
152: PatternSet p = (PatternSet) i.next();
153: patternset.append(p, getProject());
154: }
155:
156: getProject().getReferences().put(id, patternset);
157: }
158: }
|