/** * 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); } }
@OnEnabled public void onEnabled(final ConfigurationContext context) throws InitializationException { final String config = context.getProperty(CONFIGURATION_FILE).evaluateAttributeExpressions().getValue(); final FileBasedBuilderParameters params = new Parameters().fileBased().setFile(new File(config)); this.builder = new ReloadingFileBasedConfigurationBuilder<>(resultClass).configure(params); builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST, new EventListener<ConfigurationBuilderEvent>() { @Override public void onEvent(ConfigurationBuilderEvent event) { if (builder.getReloadingController().checkForReloading(null)) { getLogger().debug("Reloading " + config); } } }); try { // Try getting configuration to see if there is any issue, for example wrong file format. // Then throw InitializationException to keep this service in 'Enabling' state. builder.getConfiguration(); } catch (ConfigurationException e) { throw new InitializationException(e); } }
/** * Convenience method for creating a file-based parameters object * initialized with the given file. * * @param file the file to be loaded * @return the initialized parameters object */ private FileBasedBuilderParameters fileParams(final File file) { return fileParams().setFile(file); }
/** * Creates a new instance of {@code Configurations} and initializes it with * the specified {@code Parameters} object. * * @param params the {@code Parameters} (may be <b>null</b>, then a default * instance is created) */ public Configurations(final Parameters params) { parameters = (params != null) ? params : new Parameters(); }
/** * Convenience method for creating a parameters object for a file-based * configuration. * * @return the newly created parameters object */ private FileBasedBuilderParameters fileParams() { return getParameters().fileBased(); }
/** * Convenience method for creating a file-based parameters object * initialized with the given file. * * @param url the URL to be loaded * @return the initialized parameters object */ private FileBasedBuilderParameters fileParams(final URL url) { return fileParams().setURL(url); }
/** * Creates a {@code FileBasedConfigurationBuilder} for the specified * configuration class and initializes it with the file to be loaded. * * @param configClass the configuration class * @param file the file to be loaded * @param <T> the type of the configuration to be constructed * @return the new {@code FileBasedConfigurationBuilder} */ public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder( final Class<T> configClass, final File file) { return createFileBasedBuilder(configClass, fileParams(file)); }
/** * Creates a builder for a {@code XMLConfiguration} and initializes it with * the given file to be loaded. * * @param file the file to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(final File file) { return fileBasedBuilder(XMLConfiguration.class, file); }
/** * Convenience method for creating a file-based parameters object * initialized with the given file path. * * @param path the path to the file to be loaded * @return the initialized parameters object */ private FileBasedBuilderParameters fileParams(final String path) { return fileParams().setFileName(path); } }
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[] } }
/** * Creates a {@code FileBasedConfigurationBuilder} for the specified * configuration class and initializes it with the path to the file to be * loaded. * * @param configClass the configuration class * @param path the path to the file to be loaded * @param <T> the type of the configuration to be constructed * @return the new {@code FileBasedConfigurationBuilder} */ public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder( final Class<T> configClass, final String path) { return createFileBasedBuilder(configClass, fileParams(path)); }
/** * Creates a builder for a {@code INIConfiguration} and initializes it with * the given URL to be loaded. * * @param url the URL to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(final URL url) { return fileBasedBuilder(INIConfiguration.class, url); }
/** * Creates a {@code FileBasedConfigurationBuilder} for the specified * configuration class and initializes it with the URL to the file to be * loaded. * * @param configClass the configuration class * @param url the URL to be loaded * @param <T> the type of the configuration to be constructed * @return the new {@code FileBasedConfigurationBuilder} */ public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder( final Class<T> configClass, final URL url) { return createFileBasedBuilder(configClass, fileParams(url)); }
/** * Creates a builder for a {@code INIConfiguration} and initializes it with * the file file identified by the given path. * * @param path the path to the file to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<INIConfiguration> iniBuilder( final String path) { return fileBasedBuilder(INIConfiguration.class, path); }
/** * Creates a builder for a {@code PropertiesConfiguration} and initializes * it with the given URL to be loaded. * * @param url the URL to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder( final URL url) { return fileBasedBuilder(PropertiesConfiguration.class, url); }
/** * Creates a builder for a {@code PropertiesConfiguration} and initializes * it with the given path to the file to be loaded. * * @param path the path to the file to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder( final String path) { return fileBasedBuilder(PropertiesConfiguration.class, path); }
/** * Creates a builder for a {@code XMLConfiguration} and initializes it with * the given URL to be loaded. * * @param url the URL to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(final URL url) { return fileBasedBuilder(XMLConfiguration.class, url); }
/** * Creates a builder for a {@code XMLConfiguration} and initializes it with * the given path to the file to be loaded. * * @param path the path to the file to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder( final String path) { return fileBasedBuilder(XMLConfiguration.class, path); }
/** * Creates a builder for a {@code PropertiesConfiguration} and initializes * it with the given file to be loaded. * * @param file the file to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder( final File file) { return fileBasedBuilder(PropertiesConfiguration.class, file); }
/** * Creates a builder for a {@code INIConfiguration} and initializes it with * the given file to be loaded. * * @param file the file to be loaded * @return the newly created {@code FileBasedConfigurationBuilder} */ public FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(final File file) { return fileBasedBuilder(INIConfiguration.class, file); }