KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > distributed > util > PropertiesHelper


1 /****************************************************************************
2 * CruiseControl, a Continuous Integration Toolkit
3 * Copyright (c) 2001, ThoughtWorks, Inc.
4 * 651 W Washington Ave. Suite 600
5 * Chicago, IL 60661 USA
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * + Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * + Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 *
20 * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21 * names of its contributors may be used to endorse or promote
22 * products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 ****************************************************************************/

37
38 package net.sourceforge.cruisecontrol.distributed.util;
39
40 import java.io.IOException JavaDoc;
41 import java.io.InputStream JavaDoc;
42 import java.util.Map JavaDoc;
43 import java.util.Properties JavaDoc;
44
45 import org.apache.log4j.Logger;
46 import net.sourceforge.cruisecontrol.PluginXMLHelper;
47 import net.sourceforge.cruisecontrol.ProjectXMLHelper;
48
49 public final class PropertiesHelper {
50
51     private static final Logger LOG = Logger.getLogger(PropertiesHelper.class);
52
53     public static final String JavaDoc DISTRIBUTED_OVERRIDE_TARGET = "distributed.overrideTarget";
54     public static final String JavaDoc DISTRIBUTED_MODULE = "distributed.module";
55     public static final String JavaDoc DISTRIBUTED_AGENT_LOGDIR = "distributed.agentlogdir";
56     public static final String JavaDoc DISTRIBUTED_AGENT_OUTPUTDIR = "distributed.agentoutputdir";
57
58     public static final String JavaDoc RESULT_TYPE_LOGS = "logs";
59     public static final String JavaDoc RESULT_TYPE_OUTPUT = "output";
60
61     private PropertiesHelper() { }
62
63     public static Map JavaDoc loadOptionalProperties(final String JavaDoc filename) {
64         Properties JavaDoc optionalProperties = new Properties JavaDoc();
65         try {
66             optionalProperties = (Properties JavaDoc) loadRequiredProperties(filename);
67         } catch (RuntimeException JavaDoc e) {
68             LOG.warn("Failed to load optional properties file '" + filename + "'", e);
69         }
70         return optionalProperties;
71     }
72
73     public static Map JavaDoc loadRequiredProperties(final String JavaDoc filename) throws RuntimeException JavaDoc {
74         final Properties JavaDoc requiredProperties = new Properties JavaDoc();
75         try {
76             // resource loading technique below dies in webstart
77
//InputStream fileStream = ClassLoader.getSystemResourceAsStream(filename);
78
final InputStream JavaDoc fileStream = PropertiesHelper.class.getClassLoader().getResourceAsStream(filename);
79             requiredProperties.load(fileStream);
80         } catch (NullPointerException JavaDoc e) {
81             throw new RuntimeException JavaDoc("Failed to load required properties file '" + filename + "'", e);
82         } catch (IOException JavaDoc e) {
83             throw new RuntimeException JavaDoc("Failed to load required properties file '" + filename + "'", e);
84         }
85         return requiredProperties;
86     }
87
88     /**
89      * Create a PlugingXMLHelper configured with the given overrideTarget (which may be "" or null).
90      * @param overrideTarget overrideTarget (which may be "" or null).
91      * @return a PlugingXMLHelper configured with the given overrideTarget (which may be "" or null).
92      */

93     public static PluginXMLHelper createPluginXMLHelper(final String JavaDoc overrideTarget) {
94         final ProjectXMLHelper projectXMLHelper = new ProjectXMLHelper();
95         if (overrideTarget != null && !"".equals(overrideTarget)) {
96             // @todo Does ProjectConfig/Schedule/Builder refactor handle this already???
97
LOG.info("!!!Ignoring Override Target on projectXMLHelper: " + overrideTarget);
98             //LOG.info("Setting Override Target on projectXMLHelper to: " + overrideTarget);
99
//projectXMLHelper.setOverrideTarget(overrideTarget);
100
}
101         final PluginXMLHelper pluginXMLHelper = new PluginXMLHelper(projectXMLHelper);
102         return pluginXMLHelper;
103     }
104 }
105
Popular Tags