Refine search
/** * Resolve the given interface mappings, turning class names into Class objects. * @param mappings the specified interface mappings * @return the resolved interface mappings (with Class objects as values) */ private Map<String, Class<?>[]> resolveInterfaceMappings(Properties mappings) { Map<String, Class<?>[]> resolvedMappings = new HashMap<>(mappings.size()); for (Enumeration<?> en = mappings.propertyNames(); en.hasMoreElements();) { String beanKey = (String) en.nextElement(); String[] classNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey)); Class<?>[] classes = resolveClassNames(classNames, beanKey); resolvedMappings.put(beanKey, classes); } return resolvedMappings; }
Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null"); Map<String, Object> map = new LinkedHashMap<>(); Properties props = new Properties(); throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex); Assert.state(props.size() == 1, () -> "Failed to load exactly one test environment property from [" + pair + "]"); for (String name : props.stringPropertyNames()) { map.put(name, props.getProperty(name));
private static Map loadProperty(String prop) { Map ret = new HashMap<>(); Properties properties = new Properties(); try { InputStream stream = new FileInputStream(prop); properties.load(stream); if (properties.size() == 0) { return null; } else { ret.putAll(properties); } } catch (Exception e1) { throw new RuntimeException(e1); } return ret; }
private void loadConfig() { try { final Properties p = new Properties(); try (Reader reader = new BufferedReader(new FileReader(file))) { p.load(reader); } final Map<String, String> map = new LinkedHashMap<>(p.size()); for (String key : p.stringPropertyNames()) { map.put(key, tryTrim(p.getProperty(key))); } config = Collections.unmodifiableMap(map); } catch (IOException e) { LOG.error("load local config failed. config: {}", file.getAbsolutePath(), e); } }
public static ScramCredential credentialFromString(String str) { Properties props = toProps(str); if (props.size() != 4 || !props.containsKey(SALT) || !props.containsKey(STORED_KEY) || !props.containsKey(SERVER_KEY) || !props.containsKey(ITERATIONS)) { throw new IllegalArgumentException("Credentials not valid: " + str); } byte[] salt = Base64.getDecoder().decode(props.getProperty(SALT)); byte[] storedKey = Base64.getDecoder().decode(props.getProperty(STORED_KEY)); byte[] serverKey = Base64.getDecoder().decode(props.getProperty(SERVER_KEY)); int iterations = Integer.parseInt(props.getProperty(ITERATIONS)); return new ScramCredential(salt, storedKey, serverKey, iterations); }
public static Optional<Config> getOptionalRuntimeConfig(Properties properties) { Properties runtimeConfigProps = new Properties(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { if (entry.getKey().toString().startsWith(ConfigurationKeys.CONFIG_RUNTIME_PREFIX)) { runtimeConfigProps.put(entry.getKey().toString().replace(ConfigurationKeys.CONFIG_RUNTIME_PREFIX, ""), entry.getValue().toString()); } } if (runtimeConfigProps.size() == 0) { return Optional.<Config>absent(); } Config config = ConfigUtils.propertiesToConfig(runtimeConfigProps); return Optional.fromNullable(config); } }
/** * @return an array of strings, made up of all the environment variables available in the VM, format var=value. To be * used for Runtime.exec(cmd, envp) */ public static final String[] getEnvironmentVariablesForRuntimeExec() { Properties sysprops = new Properties(); sysprops.putAll( getEnv() ); sysprops.putAll( System.getProperties() ); addInternalVariables( sysprops ); String[] envp = new String[sysprops.size()]; List<Object> list = new ArrayList<Object>( sysprops.keySet() ); for ( int i = 0; i < list.size(); i++ ) { String var = (String) list.get( i ); String val = sysprops.getProperty( var ); envp[i] = var + "=" + val; } return envp; }
/** * Creates a new PropertiesExpander. * @param properties the underlying properties to use for * property resolution. * @throws IllegalArgumentException indicates null was passed */ public PropertiesExpander(Properties properties) { if (properties == null) { throw new IllegalArgumentException("cannot pass null"); } values = new HashMap<>(properties.size()); for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) { final String name = (String) e.nextElement(); values.put(name, properties.getProperty(name)); } }
@Override public void start() { if (dataSourceName == null || dataSourceName.equals("")) { Log.error("No name specified for DataSource. JNDI lookup will fail", new Throwable()); return; } try { Properties contextProperties = new Properties(); for (String key: jndiPropertyKeys) { String value = JiveGlobals.getXMLProperty(key); if (value != null) { contextProperties.setProperty(key, value); } } Context context; if (contextProperties.size() > 0) { context = new InitialContext(contextProperties); } else { context = new InitialContext(); } dataSource = (DataSource)context.lookup(dataSourceName); } catch (Exception e) { Log.error("Could not lookup DataSource at '" + dataSourceName + "'", e); } }
@Test public void testPropertiesToConfiguration() { final Properties properties = new Properties(); final int entries = 10; for (int i = 0; i < entries; i++) { properties.setProperty("key" + i, "value" + i); } final Configuration configuration = ConfigurationUtils.createConfiguration(properties); for (String key : properties.stringPropertyNames()) { assertThat(configuration.getString(key, ""), is(equalTo(properties.getProperty(key)))); } assertThat(configuration.toMap().size(), is(properties.size())); }
/** * Resolve the given interface mappings, turning class names into Class objects. * @param mappings the specified interface mappings * @return the resolved interface mappings (with Class objects as values) */ private Map<String, Class<?>[]> resolveInterfaceMappings(Properties mappings) { Map<String, Class<?>[]> resolvedMappings = new HashMap<>(mappings.size()); for (Enumeration<?> en = mappings.propertyNames(); en.hasMoreElements();) { String beanKey = (String) en.nextElement(); String[] classNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey)); Class<?>[] classes = resolveClassNames(classNames, beanKey); resolvedMappings.put(beanKey, classes); } return resolvedMappings; }
public static <T> T createPropertiesConfiguration(Class<T> clazz, String[] locations) { if (clazz == null) { throw new IllegalArgumentException("clazz should not be null"); } if (!clazz.isAnnotationPresent(ConfigurationProperties.class)) { throw new IllegalArgumentException(clazz.getName() + " must annotation with @" + ConfigurationProperties.class.getName()); } if (locations == null || locations.length == 0) { throw new IllegalArgumentException(clazz.getName() + " must specified the properties locations"); } Properties properties = new Properties(); for (String location : locations) { try { properties.load(PropertiesConfigurationFactory.class.getClassLoader().getResourceAsStream(location.trim())); } catch (IOException e) { throw new IllegalStateException("Load properties [" + location + "] error", e); } } Map<String, String> map = new HashMap<String, String>(properties.size()); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue() == null ? null : entry.getValue().toString(); if (value != null) { map.put(key, value); } } return createPropertiesConfiguration(clazz, map); } }
@Test public void testMonkeyPropertiesParsing() { final Configuration conf = new Configuration(false); conf.set(MonkeyConstants.BATCH_RESTART_RS_RATIO, "0.85"); conf.set(MonkeyConstants.MOVE_REGIONS_MAX_TIME, "60000"); conf.set("hbase.rootdir", "/foo/bar/baz"); final Properties props = new Properties(); IntegrationTestBase testBase = new IntegrationTestDDLMasterFailover(); assertEquals(0, props.size()); testBase.loadMonkeyProperties(props, conf); assertEquals(2, props.size()); assertEquals("0.85", props.getProperty(MonkeyConstants.BATCH_RESTART_RS_RATIO)); assertEquals("60000", props.getProperty(MonkeyConstants.MOVE_REGIONS_MAX_TIME)); } }
/** * Create a new JNDI initial context. Invoked by {@link #execute}. * <p>The default implementation use this template's environment settings. * Can be subclassed for custom contexts, e.g. for testing. * * @return the initial Context instance * @throws NamingException in case of initialization errors */ @SuppressWarnings({"unchecked"}) protected Context createInitialContext() throws NamingException { Properties env = getEnvironment(); Hashtable icEnv = null; if (env != null) { icEnv = new Hashtable(env.size()); for (Enumeration en = env.propertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); icEnv.put(key, env.getProperty(key)); } } return new InitialContext(icEnv); }
public static <T> T createPropertiesConfiguration(Class<T> clazz, String[] locations) { if (clazz == null) { throw new IllegalArgumentException("clazz should not be null"); } if (!clazz.isAnnotationPresent(ConfigurationProperties.class)) { throw new IllegalArgumentException(clazz.getName() + " must annotation with @" + ConfigurationProperties.class.getName()); } if (locations == null || locations.length == 0) { throw new IllegalArgumentException(clazz.getName() + " must specified the properties locations"); } Properties properties = new Properties(); for (String location : locations) { try { properties.load(PropertiesConfigurationFactory.class.getClassLoader().getResourceAsStream(location.trim())); } catch (IOException e) { throw new IllegalStateException("Load properties [" + location + "] error", e); } } Map<String, String> map = new HashMap<String, String>(properties.size()); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue() == null ? null : entry.getValue().toString(); if (value != null) { map.put(key, value); } } return createPropertiesConfiguration(clazz, map); } }
final Properties cacheAfterFirstRun = new Properties(); cacheAfterFirstRun.load(Files.newBufferedReader(cacheFile.toPath())); final Properties cacheAfterSecondRun = new Properties(); cacheAfterSecondRun.load(Files.newBufferedReader(cacheFile.toPath())); cacheAfterFirstRun.getProperty(pathToEmptyFile), cacheAfterSecondRun.getProperty(pathToEmptyFile) ); assertEquals( "Cache has changed its hash", cacheAfterFirstRun.getProperty(PropertyCacheFile.CONFIG_HASH_KEY), cacheAfterSecondRun.getProperty(PropertyCacheFile.CONFIG_HASH_KEY) ); final int expectedNumberOfObjectsInCache = 2; assertEquals("Number of items in cache differs from expected", expectedNumberOfObjectsInCache, cacheAfterFirstRun.size()); assertEquals("Number of items in cache differs from expected", expectedNumberOfObjectsInCache, cacheAfterSecondRun.size());
@Override public void write(DataOutput out) throws IOException { out.writeInt(this.commonProperties.size() + this.specProperties.size()); for (Object key : this.commonProperties.keySet()) { TextSerializer.writeStringAsText(out, (String) key); TextSerializer.writeStringAsText(out, this.commonProperties.getProperty((String) key)); } for (Object key : this.specProperties.keySet()) { TextSerializer.writeStringAsText(out, (String) key); TextSerializer.writeStringAsText(out, this.specProperties.getProperty((String) key)); } }
@SuppressWarnings("rawtypes") public void setConnectProperties(Properties properties) { if (properties == null) { properties = new Properties(); if (properties.size() == this.connectProperties.size()) { equals = true; for (Map.Entry entry : properties.entrySet()) {
@Test public void testGetRestartJobParametersWithDefaults() { JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator; JobExecution jobExecution = new JobExecution(1L, new JobParametersBuilder().addString("prevKey1", "prevVal1").addString("prevKey2", "prevVal2").toJobParameters()); Properties defaultProperties = new Properties(); defaultProperties.setProperty("prevKey2", "not value 2"); Properties userProperties = new Properties(defaultProperties); Properties properties = jobOperator.getJobRestartProperties(userProperties, jobExecution); assertTrue(properties.size() == 2); assertTrue(properties.getProperty("prevKey1").equals("prevVal1")); assertTrue("prevKey2 = " + properties.getProperty("prevKey2"), properties.getProperty("prevKey2").equals("not value 2")); }
public static Config fromProperties(Properties properties) { if (properties == null || properties.size() == 0) return null; return new Implementation( parseSdkArrayProperty(properties.getProperty("sdk", "")), parseSdkInt(properties.getProperty("minSdk", "-1")), parseSdkInt(properties.getProperty("maxSdk", "-1")), properties.getProperty("manifest", DEFAULT_VALUE_STRING), properties.getProperty("qualifiers", DEFAULT_QUALIFIERS), properties.getProperty("packageName", DEFAULT_PACKAGE_NAME), properties.getProperty("resourceDir", DEFAULT_RES_FOLDER), properties.getProperty("assetDir", DEFAULT_ASSET_FOLDER), parseClasses(properties.getProperty("shadows", "")), parseStringArrayProperty(properties.getProperty("instrumentedPackages", "")), parseApplication( properties.getProperty("application", DEFAULT_APPLICATION.getCanonicalName())), parseStringArrayProperty(properties.getProperty("libraries", ""))); }