source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Filter.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 2.7 KB
Line 
1/*
2 * Copyright 2000-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs;
19
20import java.io.File;
21import org.apache.tools.ant.BuildException;
22import org.apache.tools.ant.Project;
23import org.apache.tools.ant.Task;
24
25/**
26 * Sets a token filter that is used by the file copy tasks
27 * to do token substitution. Sets multiple tokens by
28 * reading these from a file.
29 *
30 * @since Ant 1.1
31 *
32 * @ant.task category="filesystem"
33 */
34public class Filter extends Task {
35
36 private String token;
37 private String value;
38 private File filtersFile;
39
40 /**
41 * The token string without @ delimiters.
42 * @param token token to set
43 */
44 public void setToken(String token) {
45 this.token = token;
46 }
47
48 /**
49 * The string that should replace the token during filtered copies.
50 * @param value token replace value
51 */
52 public void setValue(String value) {
53 this.value = value;
54 }
55
56 /**
57 * The file from which the filters must be read.
58 * This file must be a formatted as a property file.
59 *
60 * @param filtersFile filter file
61 */
62 public void setFiltersfile(File filtersFile) {
63 this.filtersFile = filtersFile;
64 }
65
66 public void execute() throws BuildException {
67 boolean isFiltersFromFile =
68 filtersFile != null && token == null && value == null;
69 boolean isSingleFilter =
70 filtersFile == null && token != null && value != null;
71
72 if (!isFiltersFromFile && !isSingleFilter) {
73 throw new BuildException("both token and value parameters, or "
74 + "only a filtersFile parameter is "
75 + "required", getLocation());
76 }
77
78 if (isSingleFilter) {
79 getProject().getGlobalFilterSet().addFilter(token, value);
80 }
81
82 if (isFiltersFromFile) {
83 readFilters();
84 }
85 }
86
87 protected void readFilters() throws BuildException {
88 log("Reading filters from " + filtersFile, Project.MSG_VERBOSE);
89 getProject().getGlobalFilterSet().readFiltersFromFile(filtersFile);
90 }
91}
Note: See TracBrowser for help on using the repository browser.