001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.Task;
022: import org.apache.tools.ant.Project;
023: import org.apache.tools.ant.BuildException;
024: import org.apache.tools.ant.DirectoryScanner;
025: import org.apache.tools.ant.util.StringUtils;
026:
027: /**
028: * Alters the default excludes for the <strong>entire</strong> build..
029: *
030: * @since Ant 1.6
031: *
032: * @ant.task category="utility"
033: */
034: public class DefaultExcludes extends Task {
035: private String add = "";
036: private String remove = "";
037: private boolean defaultrequested = false;
038: private boolean echo = false;
039:
040: // by default, messages are always displayed
041: private int logLevel = Project.MSG_WARN;
042:
043: /**
044: * Does the work.
045: *
046: * @exception BuildException if something goes wrong with the build
047: */
048: public void execute() throws BuildException {
049: if (!defaultrequested && add.equals("") && remove.equals("")
050: && !echo) {
051: throw new BuildException("<defaultexcludes> task must set "
052: + "at least one attribute (echo=\"false\""
053: + " doesn't count since that is the default");
054: }
055: if (defaultrequested) {
056: DirectoryScanner.resetDefaultExcludes();
057: }
058: if (!add.equals("")) {
059: DirectoryScanner.addDefaultExclude(add);
060: }
061: if (!remove.equals("")) {
062: DirectoryScanner.removeDefaultExclude(remove);
063: }
064: if (echo) {
065: StringBuffer message = new StringBuffer(
066: "Current Default Excludes:");
067: message.append(StringUtils.LINE_SEP);
068: String[] excludes = DirectoryScanner.getDefaultExcludes();
069: for (int i = 0; i < excludes.length; i++) {
070: message.append(" ");
071: message.append(excludes[i]);
072: message.append(StringUtils.LINE_SEP);
073: }
074: log(message.toString(), logLevel);
075: }
076: }
077:
078: /**
079: * go back to standard default patterns
080: *
081: * @param def if true go back to default patterns
082: */
083: public void setDefault(boolean def) {
084: defaultrequested = def;
085: }
086:
087: /**
088: * Pattern to add to the default excludes
089: *
090: * @param add Sets the value for the pattern to exclude.
091: */
092: public void setAdd(String add) {
093: this .add = add;
094: }
095:
096: /**
097: * Pattern to remove from the default excludes.
098: *
099: * @param remove Sets the value for the pattern that
100: * should no longer be excluded.
101: */
102: public void setRemove(String remove) {
103: this .remove = remove;
104: }
105:
106: /**
107: * If true, echo the default excludes.
108: *
109: * @param echo whether or not to echo the contents of
110: * the default excludes.
111: */
112: public void setEcho(boolean echo) {
113: this.echo = echo;
114: }
115:
116: }
|