KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > migration > b18b19 > MigrateProperties


1 /* ================================================================
2  * Copyright (c) 2004 CollabNet. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * 3. The end-user documentation included with the redistribution, if
16  * any, must include the following acknowlegement: "This product includes
17  * software developed by Collab.Net <http://www.Collab.Net/>."
18  * Alternately, this acknowlegement may appear in the software itself, if
19  * and wherever such third-party acknowlegements normally appear.
20  *
21  * 4. The hosted project names must not be used to endorse or promote
22  * products derived from this software without prior written
23  * permission. For written permission, please contact info@collab.net.
24  *
25  * 5. Products derived from this software may not use the "Tigris" or
26  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
27  * prior written permission of Collab.Net.
28  *
29  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
30  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
33  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
35  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
37  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
38  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
39  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * ====================================================================
42  *
43  * This software consists of voluntary contributions made by many
44  * individuals on behalf of Collab.Net.
45  */

46 package org.tigris.scarab.migration.b18b19;
47
48 import java.io.BufferedOutputStream JavaDoc;
49 import java.io.FileOutputStream JavaDoc;
50 import java.io.IOException JavaDoc;
51 import java.io.PrintWriter JavaDoc;
52 import java.io.Writer JavaDoc;
53
54 import org.apache.tools.ant.BuildException;
55 import org.apache.tools.ant.Task;
56
57 public class MigrateProperties extends Task
58 {
59     //
60
// Need to initialise this so that we have an object to lock on.
61
//
62
private static String JavaDoc[] propertyMap = new String JavaDoc[0];
63     
64     static
65     {
66         synchronized(propertyMap)
67         {
68             if (propertyMap.length == 0) {
69                 //
70
// This array maps the old properties (source) to the new
71
// ones (target), where the first of each pair is the target
72
// and the second is the source.
73
//
74
// Some of the source properties have a '+' character in them
75
// - this means that the text following the '+' should be
76
// appended to the property value before being assigned to the
77
// target property.
78
//
79
propertyMap = new String JavaDoc[] {
80                     // Target prop. Source prop.
81

82                     // Scarab.properties
83
"scarab.site.name", "scarab.site.name",
84                     "scarab.http.domain", "scarab.http.domain",
85                     "scarab.http.scheme", "scarab.http.scheme",
86                     "scarab.http.scriptname", "scarab.http.scriptname",
87                     "scarab.http.port", "scarab.http.port",
88                     "scarab.automatic.role.approval", "scarab.automatic.role.approval",
89                     "scarab.timezone", "scarab.timezone",
90                     "scarab.email.encoding", "scarab.email.encoding",
91                     "scarab.email.default.fromName", "scarab.email.default.fromName",
92                     "scarab.email.default.fromAddress", "scarab.email.default.fromAddress",
93                     "scarab.register.email.checkValidA", "scarab.register.email.checkValidA",
94                     "scarab.register.email.badEmails", "scarab.register.email.badEmails",
95                     "scarab.email.register.fromName", "scarab.email.register.fromName",
96                     "scarab.email.register.fromAddress", "scarab.email.register.fromAddress",
97                     "scarab.email.forgotpassword.fromName", "scarab.email.forgotpassword.fromName",
98                     "scarab.email.forgotpassword.fromAddress", "scarab.email.forgotpassword.fromAddress",
99                     "scarab.attachments.repository", "scarab.attachments.path",
100                     "searchindex.path", "scarab.lucene.index.path",
101                     "services.TorqueService.classname", "scarab.torque.service",
102                     "services.DatabaseInitializer.classname", "scarab.dbinit.service",
103                     "torque.managed_class.org.tigris.scarab.om.Module.manager", "scarab.module.service",
104                     "torque.managed_class.org.tigris.scarab.om.ScarabUser.manager", "scarab.user.service",
105                     "scarab.dataexport.encoding", "scarab.dataexport.encoding",
106                     
107                     // TurbineResources.properties
108
"turbine.mode", "scarab.mode",
109                     "template.homepage", "scarab.homepage",
110                     "session.timeout", "scarab.session.timeout",
111                     "system.mail.host", "scarab.system.mail.host",
112                     "services.LocalizationService.locale.default.language", "scarab.locale.default.language",
113                     "services.LocalizationService.locale.default.country", "scarab.locale.default.country",
114                     "services.UploadService.repository", "scarab.file.upload.path",
115                     "services.UploadService.size.max", "scarab.file.max.size",
116                     "resolver.cache.template", "scarab.template.cache",
117                     "resolver.cache.module", "scarab.template.cache",
118                     "services.VelocityService.file.resource.loader.cache", "scarab.template.cache",
119                     "services.EmailService.file.resource.loader.cache", "scarab.template.cache",
120                     "services.VelocityService.file.resource.loader.path", "template.path+/templates",
121                     "services.EmailService.file.resource.loader.path", "template.path+/templates",
122                     "module.packages", "scarab.module.packages",
123                     
124                     "services.LocalizationService.classname", "scarab.localization.service",
125                     "torque.manager.useCache", "scarab.torque.manager.cache",
126                     "action.sessionvalidator", "scarab.sessionvalidator",
127                     "pipeline.default.descriptor", "scarab.default.pipeline.descriptor",
128                     "exceptionHandler.default", "scarab.request.error.handler",
129                     "services.PullService.tool.request.link", "scarab.pull.link",
130                     "services.PullService.tool.request.staticLink", "scarab.pull.staticlink",
131                     "services.SecurityService.user.manager", "scarab.security.user.manager",
132                     "services.IntakeService.serialize.path", "scarab.intake.serialize.file",
133                     
134                     "log4j.category.default", "scarab.log.level.turbine+, turbine",
135                     "log4j.category.org.tigris.scarab", "scarab.log.level.scarab+, scarab",
136                     "log4j.appender.scarab.file", "scarab.log.file.scarab",
137                     "log4j.appender.scarab.layout.conversionPattern", "scarab.log.pattern",
138                     "log4j.appender.scarab.append", "scarab.log.append.scarab",
139                     "log4j.category.org.tigris.scarab.util.xmlissues", "scarab.log.level.scarabxmlimport+, scarabxmlimport",
140                     "log4j.appender.scarabxmlimport.file", "scarab.log.file.scarabxmlimport",
141                     "log4j.appender.scarabxmlimport.layout.conversionPattern", "scarab.log.pattern",
142                     "log4j.appender.scarabxmlimport.append", "scarab.log.append.scarabxmlimport",
143                     "log4j.category.org.apache.turbine", "scarab.log.level.turbine+, turbine",
144                     "log4j.appender.turbine.file", "scarab.log.file.turbine",
145                     "log4j.appender.turbine.layout.conversionPattern", "scarab.log.pattern",
146                     "log4j.appender.turbine.append", "scarab.log.append.turbine",
147                     "log4j.category.org.apache.torque", "scarab.log.level.torque+, torque",
148                     "log4j.appender.torque.file", "scarab.log.file.torque",
149                     "log4j.appender.torque.layout.conversionPattern", "scarab.log.pattern",
150                     "log4j.appender.torque.append", "scarab.log.append.torque",
151                     "log4j.category.org.apache.fulcrum", "scarab.log.level.fulcrum+, services",
152                     "log4j.appender.services.file", "scarab.log.file.fulcrum",
153                     "log4j.appender.services.layout.conversionPattern", "scarab.log.pattern",
154                     "log4j.appender.services.append", "scarab.log.append.fulcrum",
155                     "log4j.category.org.apache.stratum", "scarab.log.level.stratum+, stratum",
156                     "log4j.appender.stratum.file", "scarab.log.file.stratum",
157                     "log4j.appender.stratum.layout.conversionPattern", "scarab.log.pattern",
158                     "log4j.appender.stratum.append", "scarab.log.append.stratum",
159                     "log4j.category.org.apache.jcs", "scarab.log.level.jcs+, jcs",
160                     "log4j.appender.jcs.file", "scarab.log.file.jcs",
161                     "log4j.appender.jcs.layout.conversionPattern", "scarab.log.pattern",
162                     "log4j.appender.jcs.append", "scarab.log.append.jcs",
163                     "log4j.category.org.apache.fulcrum.db", "scarab.log.level.torque+, torque",
164                     "log4j.category.org.apache.commons", "scarab.log.level.turbine+, turbine",
165                     "log4j.category.org.apache.commons.beanutils", "scarab.log.level.beanutils+, turbine",
166                     "log4j.category.org.apache.velocity", "scarab.log.level.velocity+, velocity",
167                     "log4j.appender.velocity.file", "scarab.log.file.velocity",
168                     "log4j.appender.velocity.layout.conversionPattern", "scarab.log.pattern",
169                     "log4j.appender.velocity.append", "scarab.log.append.velocity"
170                 };
171             }
172         }
173     }
174     
175     private String JavaDoc outputFile = "CustomSettings.properties";
176     
177     public void execute() throws BuildException
178     {
179         PrintWriter JavaDoc writer = null;
180         try
181         {
182             //
183
// Open the output file for writing.
184
//
185
writer = new PrintWriter JavaDoc(
186                          new BufferedOutputStream JavaDoc(
187                              new FileOutputStream JavaDoc(this.outputFile)));
188             
189             //
190
// Now iterate through each property in the map, check whether it
191
// exists within the ant properties, and if so add it to the output
192
// file.
193
//
194
for (int i = 0; i < propertyMap.length; i += 2)
195             {
196                 //
197
// Work out the name of the ant property associated with
198
// this output property. The value from the map may contain
199
// a '+' character which separates the ant property name
200
// from the string that should be appended to its value
201
// when it is written to the output file.
202
//
203
String JavaDoc outProperty = propertyMap[i];
204                 String JavaDoc inProperty = propertyMap[i + 1];
205                 String JavaDoc appendString = "";
206                 int splitPos = inProperty.indexOf('+');
207                 if (splitPos >= 0)
208                 {
209                     appendString = inProperty.substring(splitPos + 1);
210                     inProperty = inProperty.substring(0, splitPos);
211                 }
212                 
213                 String JavaDoc antPropertyValue = getProject().getProperty(inProperty);
214                 if (antPropertyValue != null)
215                 {
216                     //
217
// The ant property may contain a '=' character due
218
// to the way the property has been set up to work
219
// with filtered copies. In these cases, only the
220
// part of the value after the '=' needs to be written
221
// to the output file.
222
//
223
splitPos = antPropertyValue.indexOf('=');
224                     if (splitPos >= 0)
225                     {
226                         antPropertyValue =
227                             antPropertyValue.substring(splitPos + 1);
228                     }
229                     
230                     //
231
// Now we have all the information we need, so write the
232
// property to the output file.
233
//
234
writer.println(outProperty + '='
235                                    + antPropertyValue
236                                    + appendString);
237                 }
238             }
239         }
240         catch (IOException JavaDoc ex)
241         {
242             throw new BuildException(ex);
243         }
244         finally
245         {
246             writer.close();
247         }
248     }
249     
250     public void setOutput(String JavaDoc filename)
251     {
252         this.outputFile = filename;
253     }
254 }
255
Popular Tags