001: /****************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ****************************************************************************/package net.sourceforge.cruisecontrol.distributed.core;
037:
038: import java.io.IOException;
039: import java.io.InputStream;
040: import java.util.Map;
041: import java.util.Properties;
042:
043: import org.apache.log4j.Logger;
044:
045: public final class PropertiesHelper {
046:
047: private static final Logger LOG = Logger
048: .getLogger(PropertiesHelper.class);
049:
050: // Property Names, used between DistributedMasterBuilder and Build Agent
051: public static final String DISTRIBUTED_OVERRIDE_TARGET = "distributed.overrideTarget";
052: public static final String PROJECT_NAME = "projectname";
053: public static final String DISTRIBUTED_AGENT_LOGDIR = "distributed.agentlogdir";
054: public static final String DISTRIBUTED_AGENT_OUTPUTDIR = "distributed.agentoutputdir";
055:
056: public static final String DISTRIBUTED_AGENT_DEBUG = "distributed.agentdebug";
057:
058: public static final String RESULT_TYPE_LOGS = "logs";
059: public static final String RESULT_TYPE_OUTPUT = "output";
060: public static final String RESULT_TYPE_DIR = "dir";
061:
062: private PropertiesHelper() {
063: }
064:
065: public static Map loadOptionalProperties(final String filename) {
066: Properties optionalProperties = new Properties();
067: try {
068: optionalProperties = (Properties) loadRequiredProperties(filename);
069: } catch (RuntimeException e) {
070: LOG.warn("Failed to load optional properties file '"
071: + filename + "'", e);
072: }
073: return optionalProperties;
074: }
075:
076: public static Map loadRequiredProperties(final String filename)
077: throws RuntimeException {
078: final Properties requiredProperties = new Properties();
079: try {
080: // resource loading technique below dies in webstart
081: //InputStream fileStream = ClassLoader.getSystemResourceAsStream(filename);
082: final InputStream fileStream = PropertiesHelper.class
083: .getClassLoader().getResourceAsStream(filename);
084: try {
085: requiredProperties.load(fileStream);
086: } finally {
087: fileStream.close();
088: }
089: } catch (NullPointerException e) {
090: throw new RuntimeException(
091: "Failed to load required properties file '"
092: + filename + "'", e);
093: } catch (IOException e) {
094: throw new RuntimeException(
095: "Failed to load required properties file '"
096: + filename + "'", e);
097: }
098: return requiredProperties;
099: }
100:
101: }
|