1/*2 * Copyright 2000-2001,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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.util.ant;
1819import java.io.File;
2021import org.apache.tools.ant.Task;
22import org.apache.tools.ant.BuildException;
2324import org.apache.jetspeed.util.OverwriteProperties;
2526/***27 * <code>OverwritePropertiesTask</code> is the task definition for an Ant28 * interface to the <code>OverwriteProperties</code>.29 * 30 * @created January 29, 200331 * @author Eric Pugh32 * @version $Revision: 1.3 $33 * @see org.apache.tools.ant.Task34 */3536publicclassOverwritePropertiesTaskextends Task
37 {
38/*** File to merge properties into */39private File mergeBaseProperties;
4041/*** File to merge properties from */42private File mergeProperties;
4344/*** Directory to look for includes in */45private File includesDir;
4647/*** Fail on error flag */48privateboolean failonerror = true;
4950/***51 * Sets the File to merge properties into52 * 53 * @param mergeBaseProperties54 * File to merge properties into55 */5657publicvoid setMergeBaseProperties(File mergeBaseProperties)
58 {
59this.mergeBaseProperties = mergeBaseProperties;
60 }
6162/***63 * Sets the File to merge properties from64 *65 * @param mergeProperties File to merge properties from66 */6768publicvoid setMergeProperties(File mergeProperties)
69 {
70this.mergeProperties = mergeProperties;
71 }
7273/***74 * Sets the Directory to look for includes in75 *76 * @param includesDir Directory to look for includes in77 */78publicvoid setIncludesDir(File includesDir)
79 {
8081this.includesDir = includesDir;
82 }
8384/***85 * If false, note errors to the output but keep going.86 * @param failonerror true or false87 */88publicvoid setFailOnError(boolean failonerror)
89 {
90this.failonerror = failonerror;
91 }
9293/***94 * Gets the File to merge properties into95 * 96 * @return File to merge properties into97 */98public File getMergeBaseProperties()
99 {
100101return mergeBaseProperties;
102 }
103104/***105 * Gets the File to merge properties from106 * 107 * @return File to merge properties from108 */109public File getMergeProperties()
110 {
111112return mergeProperties;
113 }
114115/***116 * Gets the Directory to look for includes in117 * 118 * @return Directory to look for includes in119 */120public File getIncludesDir()
121 {
122123return includesDir;
124 }
125126/***127 * Load the step and then execute it128 * 129 * @exception BuildException130 * Description of the Exception131 */132publicvoid execute() throws BuildException
133 {
134135try136 {
137OverwriteProperties overwriteProperties = newOverwriteProperties();
138 overwriteProperties.setBaseProperties(getMergeBaseProperties());
139 overwriteProperties.setProperties(getMergeProperties());
140 overwriteProperties.setIncludeRoot(getIncludesDir());
141142 overwriteProperties.execute();
143 }
144catch (Exception e)
145 {
146if (!this.failonerror)
147 {
148 log(e.toString());
149 }
150else151 {
152thrownew BuildException(e.toString());
153 }
154 }
155 }
156 }