use of org.apache.commons.text.StringSubstitutor in project dhis2-core by dhis2.
the class DefaultDhisConfigurationProvider method substituteEnvironmentVariables.
private void substituteEnvironmentVariables(Properties properties) {
// Matches on ${...}
final StringSubstitutor substitutor = new StringSubstitutor(System.getenv());
properties.entrySet().forEach(entry -> entry.setValue(substitutor.replace(entry.getValue()).trim()));
}
use of org.apache.commons.text.StringSubstitutor in project midpoint by Evolveum.
the class ModelDiagController method getMemoryInformation.
@Override
public String getMemoryInformation(Task task, OperationResult parentResult) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException, IOException {
OperationResult result = parentResult.createSubresult(GET_MEMORY_INFORMATION);
try {
securityEnforcer.authorize(AuthorizationConstants.AUTZ_ALL_URL, null, AuthorizationParameters.EMPTY, null, task, result);
String pid = SystemUtil.getMyPid();
if (pid == null) {
result.recordPartialError("Cannot determine current process ID");
return "Cannot determine current process ID";
}
StringSubstitutor substitutor = createCommandStringSubstitutor(pid);
PrismObject<SystemConfigurationType> configuration = systemObjectCache.getSystemConfiguration(result);
StringBuilder sb = new StringBuilder();
String heapInfoCommand = getHeapInfoCommand(configuration, substitutor);
sb.append("Getting heap information via: ").append(heapInfoCommand).append("\n\n");
boolean finished1 = SystemUtil.executeCommand(heapInfoCommand, "", sb, HEAP_DIAG_TIMEOUT);
if (!finished1) {
sb.append("\nBeware: the command execution has not finished in given time limit.\n\n");
} else {
String histogramCommand = getHeapObjectsHistogramCommand(configuration, substitutor);
sb.append("\n------------------------------------------------------------------------------------------------------------\n\n");
sb.append("Getting heap object histogram via: ").append(histogramCommand).append("\n\n");
boolean finished2 = SystemUtil.executeCommand(histogramCommand, "", sb, HEAP_DIAG_TIMEOUT);
if (!finished2) {
sb.append("\nBeware: the command execution has not finished in given time limit.\n\n");
}
}
result.recordSuccess();
return sb.toString();
} catch (Throwable t) {
result.recordFatalError(t.getMessage(), t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of org.apache.commons.text.StringSubstitutor in project Anserini by castorini.
the class GenerateRegressionDocsTest method main.
@Test
public void main() throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
URL templatesRoot = GenerateRegressionDocsTest.class.getResource("/docgen/templates/");
for (final File fileEntry : new File(templatesRoot.toURI()).listFiles()) {
String fileName = fileEntry.getName();
// This is the name of the test, which can be different from the name of the collection,
// e.g., multiple topics run on the same collection.
String testName = fileEntry.getName().replaceAll(".template", "");
URL yaml = GenerateRegressionDocsTest.class.getResource(String.format("/regression/%s.yaml", testName));
DataModel data = mapper.readValue(new File(yaml.toURI()), DataModel.class);
String corpus = data.getCorpus();
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("yaml", String.format("../src/main/resources/regression/%s.yaml", testName));
valuesMap.put("template", String.format("../src/main/resources/docgen/templates/%s.template", testName));
valuesMap.put("test_name", testName);
valuesMap.put("corpus", corpus);
valuesMap.put("index_cmds", data.generateIndexingCommand(corpus));
valuesMap.put("ranking_cmds", data.generateRankingCommand(corpus));
valuesMap.put("eval_cmds", data.generateEvalCommand(corpus));
valuesMap.put("effectiveness", data.generateEffectiveness(corpus));
StringSubstitutor sub = new StringSubstitutor(valuesMap);
URL template = GenerateRegressionDocsTest.class.getResource(String.format("/docgen/templates/%s.template", testName));
Scanner scanner = new Scanner(new File(template.toURI()), "UTF-8");
String text = scanner.useDelimiter("\\A").next();
scanner.close();
String resolvedString = sub.replace(text);
FileUtils.writeStringToFile(new File(String.format("docs/regressions-%s.md", testName)), resolvedString, "UTF-8");
}
}
use of org.apache.commons.text.StringSubstitutor in project Anserini by castorini.
the class JDIQ2018EffectivenessDocsTest method main.
@Test
public void main() throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
URL yaml = JDIQ2018EffectivenessDocsTest.class.getResource("/jdiq2018/models.yaml");
Model data = mapper.readValue(new File(yaml.toURI()), Model.class);
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("results", data.generateEffectiveness());
StringSubstitutor sub = new StringSubstitutor(valuesMap);
URL template = GenerateRegressionDocsTest.class.getResource("/jdiq2018/doc.template");
Scanner scanner = new Scanner(new File(template.toURI()), "UTF-8");
String text = scanner.useDelimiter("\\A").next();
scanner.close();
String resolvedString = sub.replace(text);
FileUtils.writeStringToFile(new File("docs/experiments-jdiq2018.md"), resolvedString, "UTF-8");
}
use of org.apache.commons.text.StringSubstitutor in project cuba by cuba-platform.
the class TestContainer method initAppProperties.
@SuppressWarnings("ResultOfMethodCallIgnored")
protected void initAppProperties() {
Properties properties = new Properties();
List<String> locations = getAppPropertiesFiles();
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
for (String location : locations) {
Resource resource = resourceLoader.getResource(location);
if (resource.exists()) {
try (InputStream stream = resource.getInputStream()) {
BOMInputStream bomInputStream = new BOMInputStream(stream);
properties.load(bomInputStream);
} catch (IOException e) {
throw new RuntimeException("Unable to read app properties " + location, e);
}
} else {
log.warn("Resource {} not found, ignore it", location);
}
}
StringSubstitutor substitutor = new StringSubstitutor(key -> {
String subst = properties.getProperty(key);
return subst != null ? subst : System.getProperty(key);
});
for (Object key : properties.keySet()) {
String value = substitutor.replace(properties.getProperty((String) key));
appProperties.put((String) key, value);
}
File dir;
dir = new File(appProperties.get("cuba.confDir"));
dir.mkdirs();
dir = new File(appProperties.get("cuba.logDir"));
dir.mkdirs();
dir = new File(appProperties.get("cuba.tempDir"));
dir.mkdirs();
dir = new File(appProperties.get("cuba.dataDir"));
dir.mkdirs();
}
Aggregations