1 37 38 package net.sourceforge.cruisecontrol.distributed.util; 39 40 import java.io.IOException ; 41 import java.io.InputStream ; 42 import java.util.Map ; 43 import java.util.Properties ; 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 DISTRIBUTED_OVERRIDE_TARGET = "distributed.overrideTarget"; 54 public static final String DISTRIBUTED_MODULE = "distributed.module"; 55 public static final String DISTRIBUTED_AGENT_LOGDIR = "distributed.agentlogdir"; 56 public static final String DISTRIBUTED_AGENT_OUTPUTDIR = "distributed.agentoutputdir"; 57 58 public static final String RESULT_TYPE_LOGS = "logs"; 59 public static final String RESULT_TYPE_OUTPUT = "output"; 60 61 private PropertiesHelper() { } 62 63 public static Map loadOptionalProperties(final String filename) { 64 Properties optionalProperties = new Properties (); 65 try { 66 optionalProperties = (Properties ) loadRequiredProperties(filename); 67 } catch (RuntimeException e) { 68 LOG.warn("Failed to load optional properties file '" + filename + "'", e); 69 } 70 return optionalProperties; 71 } 72 73 public static Map loadRequiredProperties(final String filename) throws RuntimeException { 74 final Properties requiredProperties = new Properties (); 75 try { 76 final InputStream fileStream = PropertiesHelper.class.getClassLoader().getResourceAsStream(filename); 79 requiredProperties.load(fileStream); 80 } catch (NullPointerException e) { 81 throw new RuntimeException ("Failed to load required properties file '" + filename + "'", e); 82 } catch (IOException e) { 83 throw new RuntimeException ("Failed to load required properties file '" + filename + "'", e); 84 } 85 return requiredProperties; 86 } 87 88 93 public static PluginXMLHelper createPluginXMLHelper(final String overrideTarget) { 94 final ProjectXMLHelper projectXMLHelper = new ProjectXMLHelper(); 95 if (overrideTarget != null && !"".equals(overrideTarget)) { 96 LOG.info("!!!Ignoring Override Target on projectXMLHelper: " + overrideTarget); 98 } 101 final PluginXMLHelper pluginXMLHelper = new PluginXMLHelper(projectXMLHelper); 102 return pluginXMLHelper; 103 } 104 } 105 | Popular Tags |