/** * Test for LANG-1055: StrSubstitutor.replaceSystemProperties does not work consistently */ @Test public void testLANG1055() { System.setProperty("test_key", "test_value"); final String expected = StrSubstitutor.replace("test_key=${test_key}", System.getProperties()); final String actual = StrSubstitutor.replaceSystemProperties("test_key=${test_key}"); assertEquals(expected, actual); }
/** * Tests interpolation with system properties. */ @Test public void testStaticReplaceSystemProperties() { final StrBuilder buf = new StrBuilder(); buf.append("Hi ").append(System.getProperty("user.name")); buf.append(", you are working with "); buf.append(System.getProperty("os.name")); buf.append(", your home directory is "); buf.append(System.getProperty("user.home")).append('.'); assertEquals(buf.toString(), StrSubstitutor.replaceSystemProperties("Hi ${user.name}, you are " + "working with ${os.name}, your home " + "directory is ${user.home}.")); }
public static String replacePlaceholdersWithWhiteSpace(final String templateContent) { return StrSubstitutor.replaceSystemProperties(templateContent); }
public static String replacePlaceholdersWithWhiteSpace(final String templateContent) { return StrSubstitutor.replaceSystemProperties(templateContent); }
public static void expandPropertyAndEnvironmentReferences(Map<String, String> runnerEnvironmentVariables,Properties properties) { Set<String> names = properties.stringPropertyNames(); for (String name : names) { String value = properties.getProperty(name); // Replace System Property References ${sys.property.any} String expandedValue = StrSubstitutor.replaceSystemProperties(value); // Replace Environment References ${A_DEFINED_ENVIRONMENT_VARIABLE} expandedValue = StrSubstitutor.replace(expandedValue, runnerEnvironmentVariables); properties.setProperty(name, expandedValue); } } }
public static JsonNode json(String s, boolean systemPropertySubstitution) throws IOException { String jsonString; if (systemPropertySubstitution) { // do system property expansion jsonString = StrSubstitutor.replaceSystemProperties(s); } else { jsonString = s; } return getObjectMapper().readTree(jsonString); }
public static JsonNode json(String s, boolean systemPropertySubstitution) throws IOException { String jsonString; if (systemPropertySubstitution) { // do system property expansion jsonString = StrSubstitutor.replaceSystemProperties(s); } else { jsonString = s; } return getObjectMapper().readTree(jsonString); }
private static List<String> generateClasspath(String classPath) throws FileNotFoundException { List<String> urlStr = new ArrayList<>(); String realClassPath = StrSubstitutor.replaceSystemProperties(classPath); File classPathUrl = new File(realClassPath); if (!classPathUrl.exists()) { throw new FileNotFoundException("The classpath: " + realClassPath + " does not exist."); } if (classPathUrl.isFile()) { urlStr.add(classPathUrl.toURI().toString()); return urlStr; } FileUtils.listFiles(classPathUrl, new String[] { "jar" }, false) .forEach((file) -> urlStr.add(file.toURI().toString())); return urlStr; } }
public static StoreManager get(final String filename, final char[] passphrase, final String storeType, final boolean create) { final Long id = id(filename, passphrase); StoreManager storeManager = MANAGERS.get(id); // if create, then we need to anyway, read again and create a new storemanager if (create) { MANAGERS.remove(id, storeManager); // terminate the watch service if (storeManager != null) { storeManager.changeWatchService.stop(); } storeManager = null; } // found a previous keystore? if (storeManager != null) return storeManager; storeManager = new StoreManager(StrSubstitutor.replaceSystemProperties(filename), passphrase, storeType, create); final StoreManager previous = MANAGERS.putIfAbsent(id, storeManager); if (previous != null) return previous; return storeManager; }
/** * Resolves the system variable placeholders specified among the configurations. */ private void resolveSystemProperties() { if (classLoaderEnvironments != null) { classLoaderEnvironments.getEnvironments().getEnvironments(). forEach(environment -> environment.setClasspath( StrSubstitutor.replaceSystemProperties(environment.getClasspath()))); } securityConfiguration.getKeystore(). setLocation(StrSubstitutor.replaceSystemProperties(securityConfiguration.getKeystore().getLocation())); securityConfiguration.getTruststore().setLocation( StrSubstitutor.replaceSystemProperties(securityConfiguration.getTruststore().getLocation())); } }
private static AppServerClassLoading prepareClassLoaderEnv() { AppServerClassLoading classloadingEnvironments = new AppServerClassLoading(); AppServerClassLoading.Environment cxf = new AppServerClassLoading.Environment(); cxf.setName(Constants.CXF_ENV_NAME); cxf.setClasspath(Constants.CXF_ENV_CLASSPATH); List<AppServerClassLoading.Environment> envList = new ArrayList<>(); envList.add(cxf); envList .forEach(environment -> environment.setClasspath(STRING_SUB.replace(environment.getClasspath()))); envList .forEach(environment -> environment. setClasspath(StrSubstitutor.replaceSystemProperties(environment.getClasspath()))); AppServerClassLoading.Environments environments = new AppServerClassLoading.Environments(); environments.setEnvironments(envList); classloadingEnvironments.setEnvironments(environments); return classloadingEnvironments; }
private static AppServerSecurity prepareSecurityConfigs() { AppServerSecurity configuration = new AppServerSecurity(); AppServerSecurity.Keystore keystore = new AppServerSecurity.Keystore(); keystore.setLocation(Constants.KEYSTORE_PATH); keystore.setPassword(Constants.KEYSTORE_PASSWORD); keystore.setType(Constants.TYPE); keystore.setKeyAlias(Constants.PRIVATE_KEY_ALIAS); keystore.setKeyPassword(Constants.PRIVATE_KEY_PASSWORD); AppServerSecurity.Truststore truststore = new AppServerSecurity.Truststore(); truststore.setLocation(Constants.TRUSTSTORE_PATH); truststore.setType(Constants.TYPE); truststore.setPassword(Constants.TRUSTSTORE_PASSWORD); configuration.setKeystore(keystore); configuration.setTruststore(truststore); configuration.getKeystore().setLocation(STRING_SUB.replace(configuration.getKeystore().getLocation())); configuration.getTruststore().setLocation(STRING_SUB.replace(configuration.getTruststore().getLocation())); configuration.getKeystore(). setLocation(StrSubstitutor.replaceSystemProperties(configuration.getKeystore().getLocation())); configuration.getTruststore(). setLocation(StrSubstitutor.replaceSystemProperties(configuration.getTruststore().getLocation())); return configuration; }