List of usage examples for org.apache.commons.configuration ConfigurationUtils locate
public static URL locate(String name)
From source file:com.vmware.bdd.specpolicy.TemplateClusterSpec.java
private static void init() { String homeDir = System.getProperties().getProperty("serengeti.home.dir"); File templateFile = null;//from w ww .j a v a2 s . co m if (homeDir != null && homeDir.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(homeDir).append(File.separator).append("conf").append(File.separator) .append(TEMPLATE_CLUSTER_SPEC_JSON); templateFile = new File(builder.toString()); } else { URL filePath = ConfigurationUtils.locate(TEMPLATE_CLUSTER_SPEC_JSON); if (filePath != null) { templateFile = ConfigurationUtils.fileFromURL(filePath); } } if (templateFile == null) { logger.error("cluster template spec is not found, using the default cluster value."); loadDefaultValue(); } try { Reader fileReader = new FileReader(templateFile); createTemplate(fileReader); } catch (FileNotFoundException e) { logger.error("cluster template spec is not found, using the default cluster value."); loadDefaultValue(); } }
From source file:com.vmware.bdd.utils.CommonUtil.java
public static File getConfigurationFile(final String filename, final String typeName) { // try to locate file directly File specFile = new File(filename); if (specFile.exists()) { return specFile; }/* w ww. java 2s .c o m*/ // search ${serengeti.home.dir}/conf directory String homeDir = System.getProperties().getProperty("serengeti.home.dir"); if (homeDir != null && !homeDir.trim().isEmpty()) { StringBuilder builder = new StringBuilder(); builder.append(getConfDir()).append(File.separator).append(filename); specFile = new File(builder.toString()); if (!specFile.exists()) { logger.warn(typeName + " file does not exist: " + builder); } else { return specFile; } } // search in class paths URL filePath = ConfigurationUtils.locate(filename); if (filePath != null) { specFile = ConfigurationUtils.fileFromURL(filePath); } if (!specFile.exists()) { String errorMsg = "Can not find file " + filename; logger.fatal(errorMsg); throw new RuntimeException(errorMsg); } return specFile; }
From source file:com.bitcup.configurator.FileConfig.java
private void createCompositeConfiguration(String filename) { if (Context.getInstance().hasConfigPath()) { final String fn = Context.getInstance().getConfigPath() + File.separator + filename; URL fileUrl = ConfigurationUtils.locate(fn); if (fileUrl != null) { try { PropertiesConfiguration pc = new PropertiesConfiguration(fileUrl); pc.setReloadingStrategy(getReloadingStrategy()); configuration.addConfiguration(pc); logger.info("Loaded non-classpath config file " + fn); } catch (ConfigurationException e) { logger.warn("Config file " + fn + " not found"); }// w w w. j av a2 s . c om } else { logger.warn("Config file " + fn + " not found"); } } // hostname-prefixed filename on classpath if (Context.getInstance().hasHostName()) { final String contextFilename = Context.getInstance().getHostName() + SEPARATOR + filename; addToCompositeConfig(contextFilename, false); } // env-prefixed filename on classpath if (Context.getInstance().hasEnv()) { final String contextFilename = Context.getInstance().getEnv() + SEPARATOR + filename; addToCompositeConfig(contextFilename, false); } // filename on classpath addToCompositeConfig(filename, !Context.getInstance().hasConfigPath() && !Context.getInstance().hasHostName() && !Context.getInstance().hasEnv()); }
From source file:com.vmware.bdd.specpolicy.ClusterSpecFactory.java
private static File locateSpecFile(String filename, String appManagerType) { // try to locate file directly File specFile = new File(filename); if (specFile.exists()) { return specFile; }/* ww w . j ava 2 s. co m*/ // search ${serengeti.home.dir}/conf directory String homeDir = System.getProperties().getProperty("serengeti.home.dir"); if (homeDir != null && !homeDir.trim().isEmpty()) { StringBuilder builder = new StringBuilder(); builder.append(homeDir).append(File.separator).append("conf").append(File.separator) .append(appManagerType).append(File.separator).append("spec-templates").append(File.separator) .append(filename); specFile = new File(builder.toString()); } if (!specFile.exists()) { logger.warn("template cluster file does not exist: " + specFile.getAbsolutePath()); // search in class paths URL filePath = ConfigurationUtils.locate(filename); if (filePath != null) { specFile = ConfigurationUtils.fileFromURL(filePath); } } if (!specFile.exists()) { throw BddException.INTERNAL(null, "Can not find template cluster spec file " + filename); } return specFile; }