use of com.hubspot.jinjava.Jinjava in project zeppelin by apache.
the class K8sRemoteInterpreterProcess method sparkUiWebUrlFromTemplate.
@VisibleForTesting
String sparkUiWebUrlFromTemplate(String templateString, int port, String serviceName, String serviceDomain) {
ImmutableMap<String, Object> binding = ImmutableMap.of("PORT", port, "SERVICE_NAME", serviceName, ENV_SERVICE_DOMAIN, serviceDomain);
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
Jinjava jinja = new Jinjava();
return jinja.render(templateString, binding);
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
}
use of com.hubspot.jinjava.Jinjava in project zeppelin by apache.
the class K8sSpecTemplate method render.
public String render(String template) {
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
JinjavaConfig config = JinjavaConfig.newBuilder().withLstripBlocks(true).withTrimBlocks(true).build();
Jinjava jinja = new Jinjava(config);
return jinja.render(template, this);
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
}
use of com.hubspot.jinjava.Jinjava in project zeppelin by apache.
the class DockerSpecTemplate method render.
public String render(String template) {
ClassLoader oldClazzLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
Jinjava jinja = new Jinjava();
return jinja.render(template, this);
} finally {
Thread.currentThread().setContextClassLoader(oldClazzLoader);
}
}
use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.
the class GenerateApiServerTask method render.
private static void render(String templatePath, Map<String, Object> context, Path outputPath) {
if (!Files.exists(outputPath.getParent())) {
try {
Files.createDirectories(outputPath.getParent());
} catch (IOException e) {
throw new UncheckedIOException("Could not create directory.", e);
}
}
Jinjava jinjava = new Jinjava();
final String template;
try {
template = Resources.toString(Resources.getResource(templatePath), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new UncheckedIOException("Could not read template.", e);
}
String rendered = jinjava.render(template, context);
try {
Files.writeString(outputPath, rendered);
} catch (IOException e) {
throw new UncheckedIOException("Could not write file.", e);
}
}
use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.
the class UpdateGradleWrapperTask method exec.
@TaskAction
public void exec() throws IOException {
var rootProject = getProject().getRootProject();
String releaseName = null;
String urlLinux = null;
String urlMac = null;
String urlWindows = null;
var clients = new AOV3Clients();
final List<AOV3ListBinaryAssetView> releases;
try (var client = clients.createClient()) {
var errors = new ArrayList<AOV3Error>();
releases = client.assetsForLatest(errors::add, new BigInteger(ToolDependencies.getOpenJdkVersion(rootProject)), AOV3JVMImplementation.HOTSPOT).execute();
} catch (AOV3Exception | InterruptedException e) {
throw new GradleException("Could not query for latest AdoptOpenJDK release.", e);
}
for (var release : releases) {
releaseName = release.releaseName();
var binary = release.binary();
if (binary.architecture() != AOV3Architecture.X64 || binary.imageType() != AOV3ImageKind.JDK) {
continue;
}
switch(binary.operatingSystem()) {
case LINUX:
{
urlLinux = binary.package_().link().toASCIIString();
break;
}
case MAC:
{
urlMac = binary.package_().link().toASCIIString();
break;
}
case WINDOWS:
{
urlWindows = binary.package_().link().toASCIIString();
break;
}
default:
}
}
if (releaseName == null || urlLinux == null || urlMac == null || urlWindows == null) {
throw new GradleException("Could not find OpenJDK packages: " + releases);
}
Map<String, String> templateVars = ImmutableMap.<String, String>builder().put("dest_folder", releaseName).put("url_linux", urlLinux).put("url_mac", urlMac).put("url_windows", urlWindows).put("dest_archive_name", releaseName + ".tar.gz.or.zip").put("version", releaseName).build();
Jinjava jinjava = new Jinjava(JinjavaConfig.newBuilder().withFailOnUnknownTokens(true).build());
String rendered = jinjava.render(Resources.toString(Resources.getResource("curiostack/get-jdk.sh.tmpl"), StandardCharsets.UTF_8), templateVars);
Files.writeString(rootProject.file("gradle/get-jdk.sh").toPath(), rendered, StandardCharsets.UTF_8);
Files.writeString(rootProject.file(".gradle/jdk-release-name.txt").toPath(), releaseName);
var gradlew = rootProject.file("gradlew").toPath();
var gradleWrapperLines = Files.readAllLines(gradlew);
if (gradleWrapperLines.stream().anyMatch(line -> line.contains(". ./gradle/get-jdk.sh"))) {
return;
}
// First line is always shebang, skip it.
int lineIndexAfterCopyright = 1;
// Skip empty lines
for (; lineIndexAfterCopyright < gradleWrapperLines.size(); lineIndexAfterCopyright++) {
if (!gradleWrapperLines.get(lineIndexAfterCopyright).isEmpty()) {
break;
}
}
// Skip comment lines, they are all the license
for (; lineIndexAfterCopyright < gradleWrapperLines.size(); lineIndexAfterCopyright++) {
if (!gradleWrapperLines.get(lineIndexAfterCopyright).startsWith("#")) {
break;
}
}
// Found first empty line after license, insert our JDK download script and write it out.
var linesWithGetJdk = ImmutableList.<String>builderWithExpectedSize(gradleWrapperLines.size() + 2);
linesWithGetJdk.addAll(gradleWrapperLines.subList(0, lineIndexAfterCopyright));
linesWithGetJdk.add("").add(". ./gradle/get-jdk.sh");
linesWithGetJdk.addAll(gradleWrapperLines.subList(lineIndexAfterCopyright, gradleWrapperLines.size()));
Files.writeString(gradlew, String.join("\n", linesWithGetJdk.build()));
}
Aggregations