KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > DefaultExcludes


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs;
20
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.DirectoryScanner;
25 import org.apache.tools.ant.util.StringUtils;
26
27 /**
28  * Alters the default excludes for the <strong>entire</strong> build..
29  *
30  * @since Ant 1.6
31  *
32  * @ant.task category="utility"
33  */

34 public class DefaultExcludes extends Task {
35     private String JavaDoc add = "";
36     private String JavaDoc remove = "";
37     private boolean defaultrequested = false;
38     private boolean echo = false;
39
40     // by default, messages are always displayed
41
private int logLevel = Project.MSG_WARN;
42
43     /**
44      * Does the work.
45      *
46      * @exception BuildException if something goes wrong with the build
47      */

48     public void execute() throws BuildException {
49         if (!defaultrequested && add.equals("") && remove.equals("") && !echo) {
50             throw new BuildException("<defaultexcludes> task must set "
51                 + "at least one attribute (echo=\"false\""
52                 + " doesn't count since that is the default");
53         }
54         if (defaultrequested) {
55             DirectoryScanner.resetDefaultExcludes();
56         }
57         if (!add.equals("")) {
58             DirectoryScanner.addDefaultExclude(add);
59         }
60         if (!remove.equals("")) {
61             DirectoryScanner.removeDefaultExclude(remove);
62         }
63         if (echo) {
64             StringBuffer JavaDoc message
65                 = new StringBuffer JavaDoc("Current Default Excludes:");
66             message.append(StringUtils.LINE_SEP);
67             String JavaDoc[] excludes = DirectoryScanner.getDefaultExcludes();
68             for (int i = 0; i < excludes.length; i++) {
69                 message.append(" ");
70                 message.append(excludes[i]);
71                 message.append(StringUtils.LINE_SEP);
72             }
73             log(message.toString(), logLevel);
74         }
75     }
76
77     /**
78      * go back to standard default patterns
79      *
80      * @param def if true go back to default patterns
81      */

82     public void setDefault(boolean def) {
83         defaultrequested = def;
84     }
85     /**
86      * Pattern to add to the default excludes
87      *
88      * @param add Sets the value for the pattern to exclude.
89      */

90     public void setAdd(String JavaDoc add) {
91         this.add = add;
92     }
93
94      /**
95      * Pattern to remove from the default excludes.
96      *
97      * @param remove Sets the value for the pattern that
98      * should no longer be excluded.
99      */

100     public void setRemove(String JavaDoc remove) {
101         this.remove = remove;
102     }
103
104     /**
105      * If true, echo the default excludes.
106      *
107      * @param echo whether or not to echo the contents of
108      * the default excludes.
109      */

110     public void setEcho(boolean echo) {
111         this.echo = echo;
112     }
113
114
115 }
116
Popular Tags