use of edu.princeton.cs.algs4.ST in project che by eclipse.
the class GwtXmlGenerator method generateGwtXml.
public File generateGwtXml() throws IOException {
File gwtXml = new File(config.getGenerationRoot(), config.getGwtFileName());
if (gwtXml.isDirectory() || gwtXml.exists()) {
throw new IOException(gwtXml.getAbsolutePath() + " already exists or directory");
}
ST template = getTemplate();
template.add("config", config);
// flush content
FileUtils.writeStringToFile(gwtXml, template.render());
return gwtXml;
}
use of edu.princeton.cs.algs4.ST in project buck by facebook.
the class ProjectGenerator method getBuildWithBuckShellScript.
private String getBuildWithBuckShellScript(TargetNode<?, ?> targetNode) {
ST template;
try {
template = new ST(Resources.toString(Resources.getResource(ProjectGenerator.class, BUILD_WITH_BUCK_TEMPLATE), Charsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("There was an error loading '" + BUILD_WITH_BUCK_TEMPLATE + "' template", e);
}
String buildFlags = getBuildFlags();
String escapedBuildTarget = Escaper.escapeAsBashString(targetNode.getBuildTarget().getFullyQualifiedName());
Optional<String> productName = getProductNameForTargetNode(targetNode);
String binaryName = AppleBundle.getBinaryName(targetNode.getBuildTarget(), productName);
Path bundleDestination = getScratchPathForAppBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
Path dsymDestination = getScratchPathForDsymBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
Path resolvedBundleDestination = projectFilesystem.resolve(bundleDestination);
Path resolvedDsymDestination = projectFilesystem.resolve(dsymDestination);
ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(targetNode.getBuildTarget().getFlavors());
CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
String oldCompDir = cxxPlatform.getCompilerDebugPathSanitizer().getCompilationDirectory();
// Use the hostname for padding instead of the directory, this way the directory matches without
// having to resolve it.
String dsymPaddedCompDirWithHost = Strings.padStart(":" + projectFilesystem.getRootPath().toString(), oldCompDir.length(), 'f');
template.add("path_to_build_with_buck_py", getBuildWithBuckPythonScriptPath(projectFilesystem));
template.add("path_to_fix_uuid_script", getFixUUIDScriptPath(projectFilesystem));
template.add("repo_root", projectFilesystem.getRootPath());
template.add("path_to_buck", getPathToBuck(executableFinder, environment));
template.add("build_flags", buildFlags);
template.add("escaped_build_target", escapedBuildTarget);
template.add("buck_dwarf_flavor", (appleConfig.forceDsymModeInBuildWithBuck() ? AppleDebugFormat.DWARF_AND_DSYM : AppleDebugFormat.DWARF).getFlavor().getName());
template.add("buck_dsym_flavor", AppleDebugFormat.DWARF_AND_DSYM.getFlavor().getName());
template.add("binary_name", binaryName);
template.add("comp_dir", oldCompDir);
template.add("new_comp_dir", projectFilesystem.getRootPath().toString());
template.add("padded_source_dir", dsymPaddedCompDirWithHost);
template.add("resolved_bundle_destination", resolvedBundleDestination);
template.add("resolved_bundle_destination_parent", resolvedBundleDestination.getParent());
template.add("resolved_dsym_destination", resolvedDsymDestination);
template.add("force_dsym", appleConfig.forceDsymModeInBuildWithBuck() ? "true" : "false");
return template.render();
}
use of edu.princeton.cs.algs4.ST in project buck by facebook.
the class BuckPyFunction method toPythonFunction.
public String toPythonFunction(BuildRuleType type, Object dto) {
@Nullable TargetName defaultName = dto.getClass().getAnnotation(TargetName.class);
ImmutableList.Builder<StParamInfo> mandatory = ImmutableList.builder();
ImmutableList.Builder<StParamInfo> optional = ImmutableList.builder();
for (ParamInfo param : ImmutableSortedSet.copyOf(argMarshaller.getAllParamInfo(dto))) {
if (isSkippable(param)) {
continue;
}
if (param.isOptional()) {
optional.add(new StParamInfo(param));
} else {
mandatory.add(new StParamInfo(param));
}
}
optional.add(StParamInfo.ofOptionalValue("autodeps", "autodeps"));
optional.add(StParamInfo.ofOptionalValue("visibility", "visibility"));
STGroup group = buckPyFunctionTemplate.get();
ST st;
// See discussion in: https://github.com/antlr/stringtemplate4/issues/61
synchronized (group) {
st = group.getInstanceOf("buck_py_function");
}
st.add("name", type.getName());
// Mandatory params must come before optional ones.
st.add("params", ImmutableList.builder().addAll(mandatory.build()).addAll(optional.build()).build());
st.add("typePropName", TYPE_PROPERTY_NAME);
st.add("defaultName", defaultName == null ? null : defaultName.name());
StringWriter stringWriter = new StringWriter();
try {
st.write(new AutoIndentWriter(stringWriter, "\n"));
} catch (IOException e) {
throw new IllegalStateException("ST writer should not throw with StringWriter", e);
}
return stringWriter.toString();
}
use of edu.princeton.cs.algs4.ST in project buck by facebook.
the class PythonInPlaceBinary method getScript.
private static Supplier<String> getScript(final BuildRuleResolver resolver, final PythonPlatform pythonPlatform, final CxxPlatform cxxPlatform, final String mainModule, final PythonPackageComponents components, final Path relativeLinkTreeRoot, final ImmutableSet<String> preloadLibraries) {
final String relativeLinkTreeRootStr = Escaper.escapeAsPythonString(relativeLinkTreeRoot.toString());
final Linker ld = cxxPlatform.getLd().resolve(resolver);
return () -> {
ST st = new ST(getRunInplaceResource()).add("PYTHON", pythonPlatform.getEnvironment().getPythonPath()).add("MAIN_MODULE", Escaper.escapeAsPythonString(mainModule)).add("MODULES_DIR", relativeLinkTreeRootStr);
// Only add platform-specific values when the binary includes native libraries.
if (components.getNativeLibraries().isEmpty()) {
st.add("NATIVE_LIBS_ENV_VAR", "None");
st.add("NATIVE_LIBS_DIR", "None");
} else {
st.add("NATIVE_LIBS_ENV_VAR", Escaper.escapeAsPythonString(ld.searchPathEnvVar()));
st.add("NATIVE_LIBS_DIR", relativeLinkTreeRootStr);
}
if (preloadLibraries.isEmpty()) {
st.add("NATIVE_LIBS_PRELOAD_ENV_VAR", "None");
st.add("NATIVE_LIBS_PRELOAD", "None");
} else {
st.add("NATIVE_LIBS_PRELOAD_ENV_VAR", Escaper.escapeAsPythonString(ld.preloadEnvVar()));
st.add("NATIVE_LIBS_PRELOAD", Escaper.escapeAsPythonString(Joiner.on(':').join(preloadLibraries)));
}
return st.render();
};
}
use of edu.princeton.cs.algs4.ST in project buck by facebook.
the class LogConfig method addInputStreamForTemplate.
private static boolean addInputStreamForTemplate(Path path, LogConfigSetup logConfigSetup, ImmutableList.Builder<InputStream> inputStreamsBuilder) throws IOException {
try {
String template = new String(Files.readAllBytes(path), Charsets.UTF_8);
ST st = new ST(template);
st.add("default_file_pattern", MorePaths.pathWithUnixSeparators(logConfigSetup.getLogFilePath()).toString());
st.add("default_count", logConfigSetup.getCount());
st.add("default_max_size_bytes", logConfigSetup.getMaxLogSizeBytes());
String result = st.render();
inputStreamsBuilder.add(new ByteArrayInputStream(result.getBytes(Charsets.UTF_8)));
inputStreamsBuilder.add(new ByteArrayInputStream(NEWLINE));
return true;
} catch (FileNotFoundException e) {
return false;
}
}
Aggregations