Debian Codegraph @

src/main/java/net/sf/antcontrib/property/AbstractPropertySetterTask.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
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 package net.sf.antcontrib.property;
17
18 import org.apache.tools.ant.BuildException;
19 import org.apache.tools.ant.Task;
20 import org.apache.tools.ant.taskdefs.Property;
21
22
23 /****************************************************************************
24 * Place class description here.
25 *
26 * @author <a href='mailto:[email protected]'>Matthew Inger</a>
27 * @author <additional author>
28 *
29 * @since
30 *
31 ****************************************************************************/
32
33
34 public abstract class AbstractPropertySetterTask
35 extends Task
36 {
37 private boolean override;
38 private String property;
39
40 public AbstractPropertySetterTask()
41 {
42 super();
43 }
44
45
46 public void setOverride(boolean override)
47 {
48 this.override = override;
49 }
50
51
52 public void setProperty(String property)
53 {
54 this.property = property;
55 }
56
57 protected void validate()
58 {
59 if (property == null)
60 throw new BuildException("You must specify a property to set.");
61 }
62
63
64 protected final void setPropertyValue(String value)
65 {
66 if (value != null)
67 {
68 if (override)
69 {
70 if (getProject().getUserProperty(property) == null)
71 getProject().setProperty(property, value);
72 else
73 getProject().setUserProperty(property, value);
74 }
75 else
76 {
77 Property p = (Property)project.createTask("property");
78 p.setName(property);
79 p.setValue(value);
80 p.execute();
81 }
82 }
83 }
84 }