/** * Loads the default properties from the classpath. * * @return the default properties */ private Configuration getDefaultConfiguration() { Configurations configs = new Configurations(); try { return configs.properties(PROPERTIES_DEFAULT); } catch (ConfigurationException e) { throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e); } }
public void swagger2MarkupConfigFromCommonsConfiguration() throws IOException, ConfigurationException { Path localSwaggerFile = Paths.get("/path/to/swagger.yaml"); // tag::swagger2MarkupConfigFromCommonsConfiguration[] Configurations configs = new Configurations(); Configuration configuration = configs.properties("config.properties"); //<1> Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configuration) //<2> .build(); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(localSwaggerFile) .withConfig(config) .build(); // end::swagger2MarkupConfigFromCommonsConfiguration[] } }
final Configuration props = new Configurations().properties(url); compositeConfiguration.addConfiguration(props);
URL urlOptions = SX.class.getClassLoader().getResource("Settings/sxoptions.txt"); if (!isNull(urlOptions)) { Configurations configs = new Configurations(); try { SXOPTIONS = configs.properties(urlOptions); Configurations configs = new Configurations(); try { extraOptions = configs.properties(fOptions);
/** * Loads the default properties from the classpath. * * @return the default properties */ private Configuration getDefaultConfiguration() { Configurations configs = new Configurations(); try { return configs.properties(PROPERTIES_DEFAULT); } catch (ConfigurationException e) { throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e); } }
/** * Loads the default properties from the classpath. * * @return the default properties */ private Configuration getDefaultConfiguration() { Configurations configs = new Configurations(); try { return configs.properties(PROPERTIES_DEFAULT); } catch (ConfigurationException e) { throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e); } }
public GlobalConfigImpl() { Configurations configs = new Configurations(); try { config = configs.properties(new File(CONFIG_FILE)); } catch (ConfigurationException e) { log.error(e.getMessage(), e); } }
private static Configuration loadFileConfiguration(File configFile) { try { return new Configurations().properties(configFile); } catch (ConfigurationException e) { throw new BatfishException( "Error loading configuration from " + configFile.getAbsolutePath(), e); } }
/** * Overwrite configuration parameters by using the given file * * @param path a path pointing to a file where the configuration should be read from */ public static void copyConfiguration(Path path) throws Exception { Configurations configs = new Configurations(); Configuration configuration = configs.properties(path.toFile()); copyConfiguration(configuration); }
public DoctorKafkaConfig(String configPath) throws Exception { try { Configurations configurations = new Configurations(); configuration = configurations.properties(new File(configPath)); drkafkaConfiguration = new SubsetConfiguration(configuration, DOCTORKAFKA_PREFIX); this.initialize(); } catch (Exception e) { LOG.error("Failed to initialize configuration file {}", configPath, e); } }
/** * Overwrite configuration parameters by using the given URL * * @param url a URL pointing to a file where the configuration should be read from */ public static void copyConfiguration(URL url) throws Exception { Configurations configs = new Configurations(); Configuration configuration = configs.properties(url); copyConfiguration(configuration); }
/** * Add Configuration Data loaded from "config.properties" resources. * * @param configuration the composite configuration to add to * @param rootPackageName the package where the configuration properties file is located * @param classLoader the class loader from which the configuration is read from * @throws Exception in case of error while reading test configuration */ private void addConfigurationData(CompositeConfiguration configuration, String rootPackageName, ClassLoader classLoader) throws Exception { URL configurationURL = classLoader.getResource(rootPackageName + "/config.properties"); if (configurationURL != null) { configuration.addConfiguration(new Configurations().properties(configurationURL)); } }
/** * Returns the version of the current build of Batfish, or {@link #UNKNOWN_VERSION} if the version * could not be detected. */ public static String getVersion() { try { Configuration config = new Configurations().properties(PROPERTIES_PATH); String version = config.getString("batfish_version"); if (version.contains("project.version")) { // For whatever reason, resource filtering didn't work. return UNKNOWN_VERSION; } return version; } catch (Exception e) { return UNKNOWN_VERSION; } }
public static org.apache.commons.configuration2.Configuration getConfig( String overridePropertyName, String defaultPropertyFilename, Class<?> defaultPropertyLocatorClass) { String overriddenPath = System.getProperty(overridePropertyName); URL propertiesUrl; if (overriddenPath != null) { // The user provided an override, so look up that configuration instead. try { propertiesUrl = new URL(new URL("file://"), overriddenPath); } catch (MalformedURLException e) { throw new BatfishException( "Error treating " + overriddenPath + " as a path to a properties file", e); } } else { // Find the default properties file. propertiesUrl = defaultPropertyLocatorClass.getClassLoader().getResource(defaultPropertyFilename); } try { return new Configurations().properties(propertiesUrl); } catch (Exception e) { throw new BatfishException("Error loading configuration from " + overriddenPath, e); } }
public void load(final File file) throws CommonFrameworkException { propertiesObject = null; final Configurations configs = new Configurations(); try { config = configs.properties(file); } catch (final ConfigurationException e) { throw new CommonFrameworkException("Error loading properties from file " + file.getAbsolutePath() + ": " + e.getMessage()); } getProperties(); }
public void run() { Swagger2MarkupConfig swagger2MarkupConfig = null; if(StringUtils.isNotBlank(configFile)) { Configurations configs = new Configurations(); Configuration config; try { config = configs.properties(configFile); } catch (ConfigurationException e) { throw new IllegalArgumentException("Failed to read configFile", e); } swagger2MarkupConfig = new Swagger2MarkupConfigBuilder(config).build(); } Swagger2MarkupConverter.Builder converterBuilder = Swagger2MarkupConverter.from(URIUtils.create(swaggerInput)); if(swagger2MarkupConfig != null){ converterBuilder.withConfig(swagger2MarkupConfig); } Swagger2MarkupConverter converter = converterBuilder.build(); if(StringUtils.isNotBlank(outputFile)){ converter.toFile(Paths.get(outputFile).toAbsolutePath()); }else if (StringUtils.isNotBlank(outputDir)){ converter.toFolder(Paths.get(outputDir).toAbsolutePath()); }else { throw new IllegalArgumentException("Either outputFile or outputDir option must be used"); } }
private static CombinedConfiguration readConfig(){ try{ // 指定文件编码方式,否则properties文件读取中文会是乱码,要求文件编码是UTF-8 FileBasedConfigurationBuilder.setDefaultEncoding(PropertiesConfiguration.class, ENCODING); // 使用默认表达式引擎 DefaultExpressionEngine engine = new DefaultExpressionEngine(DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS); Configurations configs = new Configurations(); CombinedConfiguration config = configs.combined(ROOT_URL); config.setExpressionEngine(engine); // 设置同步器 config.setSynchronizer(new ReadWriteSynchronizer()); return config; }catch(Exception e){ throw new ExceptionInInitializerError(e); } } private static PropertiesConfiguration createUserConfig(){
protected void loadConfiguration(ServletContext servletContext, FileObject applicationRoot) throws FileSystemException, ConfigurationException { FileObject configurationFile = applicationRoot.getChild("portofino.properties"); WritableCompositeConfiguration compositeConfiguration = new WritableCompositeConfiguration(); if(configurationFile != null) { Configurations configurations = new Configurations(); PropertiesConfiguration configuration = configurations.properties(configurationFile.getURL()); FileObject localConfigurationFile = applicationRoot.getChild("portofino-local.properties"); if (localConfigurationFile != null && localConfigurationFile.exists() && localConfigurationFile.getType() == FileType.FILE) { logger.info("Local configuration found: {}", localConfigurationFile); PropertiesConfiguration localConfiguration = configurations.properties(localConfigurationFile.getURL()); compositeConfiguration.addConfiguration(localConfiguration); } compositeConfiguration.addConfiguration(configuration); this.configuration = compositeConfiguration; } else { this.configuration = new PropertiesConfiguration(); logger.warn("portofino.properties file not found in " + applicationRoot); } servletContext.setAttribute("portofino.configuration", this.configuration); }
FileBasedSecStoreConfig(File userFile, File roleFile) throws Exception { Configurations configs = new Configurations(); userBuilder = configs.propertiesBuilder(userFile); roleBuilder = configs.propertiesBuilder(roleFile); userConfig = userBuilder.getConfiguration(); roleConfig = roleBuilder.getConfiguration(); String roleHeader = roleConfig.getLayout().getHeaderComment(); String userHeader = userConfig.getLayout().getHeaderComment(); if (userHeader == null) { if (userConfig.isEmpty()) { //clean and reset header userConfig.clear(); userConfig.setHeader(LICENSE_HEADER); } } if (roleHeader == null) { if (roleConfig.isEmpty()) { //clean and reset header roleConfig.clear(); roleConfig.setHeader(LICENSE_HEADER); } } }
FileBasedSecStoreConfig(File userFile, File roleFile) throws Exception { Configurations configs = new Configurations(); userBuilder = configs.propertiesBuilder(userFile); roleBuilder = configs.propertiesBuilder(roleFile); userConfig = userBuilder.getConfiguration(); roleConfig = roleBuilder.getConfiguration(); String roleHeader = roleConfig.getLayout().getHeaderComment(); String userHeader = userConfig.getLayout().getHeaderComment(); if (userHeader == null) { if (userConfig.isEmpty()) { //clean and reset header userConfig.clear(); userConfig.setHeader(LICENSE_HEADER); } } if (roleHeader == null) { if (roleConfig.isEmpty()) { //clean and reset header roleConfig.clear(); roleConfig.setHeader(LICENSE_HEADER); } } }