r2478 - trunk/nuiton-utils/src/main/java/org/nuiton/util
Author: tchemit Date: 2013-01-28 14:57:54 +0100 (Mon, 28 Jan 2013) New Revision: 2478 Url: http://nuiton.org/projects/nuiton-utils/repository/revisions/2478 Log: fixes #2515: [ApplicationConfig] Get back all detected options Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigHelper.java Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigHelper.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigHelper.java 2013-01-28 08:28:02 UTC (rev 2477) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigHelper.java 2013-01-28 13:57:54 UTC (rev 2478) @@ -116,31 +116,21 @@ } /** - * Load default options from all config provider found in classpath. + * Load default options from all given config providers. * - * @param config config where to add default options. - * @param classLoader optional classLoader - * @param includes config to include (if none given all is include) - * @param excludes config to exclude (if none given, no exclude) - * @param verbose verbose flag - * @since 2.6.6 + * @param config config where to add default options. + * @param providers providers to use + * @since 2.6.7 */ public static void loadAllDefaultOption(ApplicationConfig config, - ClassLoader classLoader, - Set<String> includes, - Set<String> excludes, - boolean verbose) { + Set<ApplicationConfigProvider> providers) { - Set<ApplicationConfigProvider> providers = getProviders(classLoader, - includes, - excludes, - verbose); for (ApplicationConfigProvider provider : providers) { if (log.isInfoEnabled()) { log.info("Load default options from configuration: " + provider.getName()); } - if (verbose && log.isInfoEnabled()) { + if (log.isInfoEnabled()) { for (ApplicationConfig.OptionDef optionDef : provider.getOptions()) { log.info(" " + optionDef.getKey() + " (" + optionDef.getDefaultValue() + ')'); @@ -148,6 +138,69 @@ } config.loadDefaultOptions(provider.getOptions()); } + } + /** + * Gets all transient options from the given providers. + * + * @param providers providers to inspect + * @return the set of all options that are transient + * @see ApplicationConfig.OptionDef#isTransient() + * @since 2.6.7 + */ + public static Set<ApplicationConfig.OptionDef> getTransientOptions(Set<ApplicationConfigProvider> providers) { + Set<ApplicationConfig.OptionDef> result = new HashSet<ApplicationConfig.OptionDef>(); + for (ApplicationConfigProvider provider : providers) { + for (ApplicationConfig.OptionDef def : provider.getOptions()) { + if (def.isTransient()) { + result.add(def); + } + } + } + return result; } + + + /** + * Gets all final options from the given providers. + * + * @param providers providers to inspect + * @return the set of all options that are final + * @see ApplicationConfig.OptionDef#isFinal() + * @since 2.6.7 + */ + public static Set<ApplicationConfig.OptionDef> getFinalOptions(Set<ApplicationConfigProvider> providers) { + Set<ApplicationConfig.OptionDef> result = new HashSet<ApplicationConfig.OptionDef>(); + for (ApplicationConfigProvider provider : providers) { + for (ApplicationConfig.OptionDef def : provider.getOptions()) { + if (def.isFinal()) { + result.add(def); + } + } + } + return result; + } + + /** + * Get all option keys that should not be saved in the user config file + * from the given options providers. + * <p/> + * Such options are {@code transient} or {@code final}. + * + * @param providers providers to inspect + * @return the set of options key not to store in the config file + * @see ApplicationConfig.OptionDef#isFinal() + * @see ApplicationConfig.OptionDef#isTransient() + * @since 2.6.7 + */ + public static Set<String> getTransientOrFinalOptionKey(Set<ApplicationConfigProvider> providers) { + Set<String> result = new HashSet<String>(); + for (ApplicationConfig.OptionDef def : getTransientOptions(providers)) { + result.add(def.getKey()); + } + for (ApplicationConfig.OptionDef def : getFinalOptions(providers)) { + result.add(def.getKey()); + } + return result; + } }
participants (1)
-
tchemit@users.nuiton.org