/** * Creates a list of configuration infos from the single location and if they are * optional. * * @param <T> the type of location. Only {@code String} and {@code URL} are * supported. */ public static <T> List<ConfigurationInfo<T>> newList(boolean isOptional, T location) { if (location == null) { throw new IllegalArgumentException("location cannot be null"); } return newList(Collections.<T>singletonList(location), isOptional); }
/** * Creates a list of configuration infos from the single location and if they are * optional. * * @param <T> the type of location. Only {@code String} and {@code URL} are * supported. */ public static <T> List<ConfigurationInfo<T>> newList(boolean isOptional, T location) { if (location == null) { throw new IllegalArgumentException("location cannot be null"); } return newList(Collections.<T>singletonList(location), isOptional); }
/** * Gets a combined configuration list with the default added last so that * {@code filePaths} will override {@code defaultFilePath}. */ private List<ConfigurationHelper.ConfigurationInfo<String>> getFilePathConfigurationListWithDefault(@Nullable List<String> filePaths, String defaultFilePath) { List<ConfigurationHelper.ConfigurationInfo<String>> defaultConfigList = ConfigurationHelper.newList(true, defaultFilePath); List<ConfigurationHelper.ConfigurationInfo<String>> filePathConfigList = ConfigurationHelper.newList(filePaths, true); if (defaultConfigList != null) { if (filePathConfigList == null) { filePathConfigList = defaultConfigList; } else { filePathConfigList.addAll(defaultConfigList); } } return filePathConfigList; } }
/** * Gets a combined configuration list with the default added last so that * {@code filePaths} will override {@code defaultFilePath}. */ private List<ConfigurationHelper.ConfigurationInfo<String>> getFilePathConfigurationListWithDefault(@Nullable List<String> filePaths, String defaultFilePath) { List<ConfigurationHelper.ConfigurationInfo<String>> defaultConfigList = ConfigurationHelper.newList(true, defaultFilePath); List<ConfigurationHelper.ConfigurationInfo<String>> filePathConfigList = ConfigurationHelper.newList(filePaths, true); if (defaultConfigList != null) { if (filePathConfigList == null) { filePathConfigList = defaultConfigList; } else { filePathConfigList.addAll(defaultConfigList); } } return filePathConfigList; } }
protected void configureConfigurations(URL propertiesUrl) { bind(Configuration.class).annotatedWith(Names.named("productFramework")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(false, propertiesUrl), null)); } }
protected void configureConfigurations(URL propertiesUrl) { bind(Configuration.class).annotatedWith(Names.named("productFramework")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(false, propertiesUrl), null)); } }
bind(AdsLibConfiguration.class).to(adsLibConfigurationClass).asEagerSingleton(); bind(Configuration.class).annotatedWith(Names.named("api")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(apiPropertyUrls, false), ConfigurationHelper.newList(apiPropertyFilePaths, true))); bind(Configuration.class).annotatedWith(Names.named("lib")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(libPropertyUrls, false), getFilePathConfigurationListWithDefault(libPropertyFilePaths, Builder.DEFAULT_CONFIGURATION_FILENAME))); bind(Configuration.class).annotatedWith(Names.named("build")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList( Lists.newArrayList(ConfigurationModule.class.getResource(BUILD_PROPERTIES)), false), null)); bind(Configuration.class).annotatedWith(Names.named("product")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(productPropertyUrls, false), null));
bind(AdsLibConfiguration.class).to(adsLibConfigurationClass).asEagerSingleton(); bind(Configuration.class).annotatedWith(Names.named("api")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(apiPropertyUrls, false), ConfigurationHelper.newList(apiPropertyFilePaths, true))); bind(Configuration.class).annotatedWith(Names.named("lib")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(libPropertyUrls, false), getFilePathConfigurationListWithDefault(libPropertyFilePaths, Builder.DEFAULT_CONFIGURATION_FILENAME))); bind(Configuration.class).annotatedWith(Names.named("build")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList( Lists.newArrayList(ConfigurationModule.class.getResource(BUILD_PROPERTIES)), false), null)); bind(Configuration.class).annotatedWith(Names.named("product")).toProvider( new ConfigurationProvider(ConfigurationHelper.newList(productPropertyUrls, false), null));
@Test public void testNewConfigurationInfoList_nullArguments() throws Exception { thrown.expect(IllegalArgumentException.class); ConfigurationHelper.newList(true, (Object[]) null); }
@Test public void testNewConfigurationInfoList_null() throws Exception { assertNull(ConfigurationHelper.newList(null, true)); }
@Test public void testNewConfigurationInfoList_optional() throws Exception { List<ConfigurationInfo<URL>> configurationInfos = ConfigurationHelper.newList( Lists.newArrayList(new URL("http://google.com"), new URL("https://google.com")), true); assertEquals(2, configurationInfos.size()); assertEquals(new URL("http://google.com"), configurationInfos.get(0).getLocation()); assertTrue(configurationInfos.get(0).isOptional()); assertEquals(new URL("https://google.com"), configurationInfos.get(1).getLocation()); assertTrue(configurationInfos.get(1).isOptional()); }
@Test public void testNewConfigurationInfoList_required() { List<ConfigurationInfo<String>> configurationInfos = ConfigurationHelper.newList(Lists.newArrayList("1234", "5678"), false); assertEquals(2, configurationInfos.size()); assertEquals("1234", configurationInfos.get(0).getLocation()); assertFalse(configurationInfos.get(0).isOptional()); assertEquals("5678", configurationInfos.get(1).getLocation()); assertFalse(configurationInfos.get(1).isOptional()); }