View Javadoc

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 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  package org.apache.jetspeed.util.ant;
18  
19  import java.io.File;
20  
21  import org.apache.tools.ant.Task;
22  import org.apache.tools.ant.BuildException;
23  
24  import org.apache.jetspeed.util.OverwriteProperties;
25  
26  /***
27   * <code>OverwritePropertiesTask</code> is the task definition for an Ant
28   * interface to the <code>OverwriteProperties</code>.
29   * 
30   * @created January 29, 2003
31   * @author Eric Pugh
32   * @version $Revision: 1.3 $
33   * @see org.apache.tools.ant.Task
34   */
35  
36  public class OverwritePropertiesTask extends Task
37  {
38      /*** File to merge properties into */
39      private File mergeBaseProperties;
40  
41      /*** File to merge properties from */
42      private File mergeProperties;
43  
44      /*** Directory to look for includes in */
45      private File includesDir;
46  
47      /*** Fail on error flag */
48      private boolean failonerror = true;
49  
50      /***
51       *  Sets the File to merge properties into
52       * 
53       * @param mergeBaseProperties
54       *               File to merge properties into
55       */
56  
57      public void setMergeBaseProperties(File mergeBaseProperties)
58      {
59          this.mergeBaseProperties = mergeBaseProperties;
60      }
61  
62      /***
63       *  Sets the File to merge properties from
64       *
65       * @param  mergeProperties  File to merge properties from
66       */
67  
68      public void setMergeProperties(File mergeProperties)
69      {
70          this.mergeProperties = mergeProperties;
71      }
72  
73      /***
74       *  Sets the Directory to look for includes in
75       *
76       * @param  includesDir  Directory to look for includes in
77       */
78      public void setIncludesDir(File includesDir)
79      {
80  
81          this.includesDir = includesDir;
82      }
83  
84      /***
85       * If false, note errors to the output but keep going.
86       * @param failonerror true or false
87       */
88       public void setFailOnError(boolean failonerror) 
89       {
90           this.failonerror = failonerror;
91       }
92  
93      /***
94       *  Gets the File to merge properties into
95       * 
96       * @return File to merge properties into
97       */
98      public File getMergeBaseProperties()
99      {
100 
101         return mergeBaseProperties;
102     }
103 
104     /***
105      *  Gets the File to merge properties from
106      * 
107      * @return File to merge properties from
108      */
109     public File getMergeProperties()
110     {
111 
112         return mergeProperties;
113     }
114 
115     /***
116      *  Gets the Directory to look for includes in
117      * 
118      * @return Directory to look for includes in
119      */
120     public File getIncludesDir()
121     {
122 
123         return includesDir;
124     }
125 
126     /***
127      * Load the step and then execute it
128      * 
129      * @exception BuildException
130      *                   Description of the Exception
131      */
132     public void execute() throws BuildException 
133     {
134 
135         try
136         {
137             OverwriteProperties overwriteProperties = new OverwriteProperties();
138             overwriteProperties.setBaseProperties(getMergeBaseProperties());
139             overwriteProperties.setProperties(getMergeProperties());
140             overwriteProperties.setIncludeRoot(getIncludesDir());
141 
142             overwriteProperties.execute();
143         }
144         catch (Exception e)
145         {
146             if (!this.failonerror) 
147             {
148                 log(e.toString());
149             } 
150             else 
151             {
152                 throw new BuildException(e.toString());
153             }
154         }
155     }
156 }