Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/util/ant/MergePropertiesTask.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * 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.activemq.util.ant;
20  
21  /**
22   *
23   *<code>MergePropertiesTask</code> is the task definition for an Ant
24   * interface to the <code>MergeProperties</code>.
25   */
26  
27  import java.io.File;
28  
29  import org.apache.tools.ant.Task;
30  import org.apache.tools.ant.BuildException;
31  
32  import org.activemq.util.MergeProperties;
33  
34  
35  public class MergePropertiesTask extends Task{
36  
37      /** File to merge properties into */
38      private File mergeBaseProperties;
39  
40      /** File to merge properties from */
41      private File mergeProperties;
42  
43      /** Fail on error flag */
44      private boolean failonerror = true;
45  
46      /**
47       *  Sets the File to merge properties into
48       *
49       * @param mergeBaseProperties
50       *               File to merge properties into
51       */
52  
53      public void setMergeBaseProperties(File mergeBaseProperties)
54      {
55          this.mergeBaseProperties = mergeBaseProperties;
56      }
57  
58      /**
59       *  Sets the File to merge properties from
60       *
61       * @param  mergeProperties  File to merge properties from
62       */
63  
64      public void setMergeProperties(File mergeProperties)
65      {
66          this.mergeProperties = mergeProperties;
67      }
68  
69       public void setFailOnError(boolean failonerror)
70       {
71           this.failonerror = failonerror;
72       }
73  
74      /**
75       *  Gets the File to merge properties into
76       *
77       * @return File to merge properties into
78       */
79      public File getMergeBaseProperties()
80      {
81  
82          return mergeBaseProperties;
83      }
84  
85      /**
86       *  Gets the File to merge properties from
87       *
88       * @return File to merge properties from
89       */
90      public File getMergeProperties()
91      {
92  
93          return mergeProperties;
94      }
95  
96      /**
97       * Load the step and then execute it
98       *
99       * @exception BuildException
100      *                   Description of the Exception
101      */
102     public void execute() throws BuildException
103     {
104 
105         try
106         {
107             MergeProperties mergeProperties = new MergeProperties();
108             mergeProperties.setBaseFile(getMergeBaseProperties());
109             mergeProperties.setMergeFile(getMergeProperties());
110 
111             mergeProperties.mergePropertyFiles();
112         }
113         catch (Exception e)
114         {
115             if (!this.failonerror)
116             {
117                 log(e.toString());
118             }
119             else
120             {
121                 throw new BuildException(e.toString());
122             }
123         }
124     }
125 }