Search in sources :

Example 11 with Jinjava

use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.

the class UpdateIntelliJSdksTaskTest method testTemplate.

private String testTemplate(String path) {
    String template = resource(path);
    Jinjava jinjava = new Jinjava();
    return jinjava.render(template, ImmutableMap.<String, Object>builder().put("gradleHome", testGradleHome.toAbsolutePath().toString().replace('\\', '/')).put("jdkFolder", "jdk-zulu13.28.11-ca-jdk13.0.1").put("javaVersion", "zulu13.28.11-ca-jdk13.0.1").put("goVersion", ToolDependencies.getDefaultVersion("golang")).build());
}
Also used : Jinjava(com.hubspot.jinjava.Jinjava)

Example 12 with Jinjava

use of com.hubspot.jinjava.Jinjava in project kork by spinnaker.

the class JinjaArtifactExtractor method jinjaTransform.

private String jinjaTransform(String messagePayload) {
    if (StringUtils.isEmpty(jinjaTemplate)) {
        return messagePayload;
    }
    Jinjava jinja = jinjavaFactory.create();
    Map<String, ?> context = readMapValue(messagePayload);
    return jinja.render(jinjaTemplate, context);
}
Also used : Jinjava(com.hubspot.jinjava.Jinjava)

Example 13 with Jinjava

use of com.hubspot.jinjava.Jinjava in project badge-plugin by jenkinsci.

the class ReadmeGenerator method main.

public static void main(String... args) throws IOException {
    Jinjava jinjava = new Jinjava();
    jinjava.getGlobalContext().registerTag(new ListImagesTag());
    jinjava.getGlobalContext().registerTag(new DescribeStepTag());
    Map<String, Object> context = Maps.newHashMap();
    String template = Resources.toString(Resources.getResource("readme/README.tmpl"), Charsets.UTF_8);
    String renderedTemplate = jinjava.render(template, context);
    try (PrintWriter out = new PrintWriter("README.md")) {
        out.println(renderedTemplate);
    }
}
Also used : Jinjava(com.hubspot.jinjava.Jinjava) PrintWriter(java.io.PrintWriter)

Example 14 with Jinjava

use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.

the class UpdateIntelliJSdksTask method addJdkSnippet.

private static void addJdkSnippet(String templatePath, Map<String, Object> templateVars, ImmutableList.Builder<String> lines, boolean skipStart) throws IOException {
    Jinjava jinjava = new Jinjava();
    String template = Resources.toString(Resources.getResource(templatePath), StandardCharsets.UTF_8);
    String rendered = jinjava.render(template, templateVars);
    rendered.lines().skip(skipStart ? 2 : 0).forEach(lines::add);
}
Also used : Jinjava(com.hubspot.jinjava.Jinjava)

Example 15 with Jinjava

use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.

the class ConvertConfigsToJsonTask method exec.

@TaskAction
void exec() {
    var jinJava = new Jinjava(JinjavaConfig.newBuilder().withTrimBlocks(true).build());
    try {
        jinJava.setResourceLocator(new FileLocator(getProject().getProjectDir()));
    } catch (FileNotFoundException e) {
        throw new IllegalStateException("Could not initialize Jinjava");
    }
    var project = getProject();
    for (var file : getInputFiles()) {
        Path path = file.toPath();
        if (!path.toString().endsWith(".tf.yml") && !path.toString().endsWith(".tf.yaml")) {
            var outDir = outputDir.resolve(project.getProjectDir().toPath().relativize(path.getParent()));
            if (path.toString().contains(".jinja.")) {
                var outPath = outDir.resolve(path.getFileName().toString().replace(".jinja.", "."));
                try {
                    Files.createDirectories(outDir);
                    Files.writeString(outPath, jinJava.render(Files.readString(path), ImmutableMap.of()));
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            } else {
                // Copy non-config files (usually templates) as is.
                project.copy(copy -> {
                    copy.from(path);
                    copy.into(outDir);
                });
            }
            continue;
        }
        String jsonFilename = getNameWithoutExtension(path.getFileName().toString()) + ".json";
        Path relativePath = getProject().getProjectDir().toPath().relativize(path);
        final Path outPath;
        if (relativePath.getNameCount() > 1) {
            if (!relativePath.startsWith("modules")) {
                outPath = outputDir.resolve(flattenFilename(relativePath, jsonFilename));
            } else {
                // Modules will always have a top-level directory where this should go.
                outPath = outputDir.resolve(relativePath.subpath(0, 3)).resolveSibling(flattenFilename(relativePath, jsonFilename));
            }
        } else {
            outPath = outputDir.resolve(project.getProjectDir().toPath().relativize(file.toPath())).resolveSibling(jsonFilename);
        }
        try {
            createDirectories(outPath.getParent());
        } catch (IOException e) {
            throw new UncheckedIOException("Could not create output directory.", e);
        }
        workerExecutor.noIsolation().submit(ConvertToJson.class, parameters -> {
            parameters.getProjectDirectory().set(project.getProjectDir());
            parameters.getSourceFile().set(file);
            parameters.getOutFile().set(outPath.toFile());
        });
    }
}
Also used : Path(java.nio.file.Path) Jinjava(com.hubspot.jinjava.Jinjava) FileLocator(com.hubspot.jinjava.loader.FileLocator) FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

Jinjava (com.hubspot.jinjava.Jinjava)19 URL (java.net.URL)9 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 InterpreterResultMessageOutput (org.apache.zeppelin.interpreter.InterpreterResultMessageOutput)5 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2 Properties (java.util.Properties)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CommandLine (org.apache.commons.exec.CommandLine)2 DefaultExecuteResultHandler (org.apache.commons.exec.DefaultExecuteResultHandler)2 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)2 ExecuteException (org.apache.commons.exec.ExecuteException)2 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)2 LogOutputStream (org.apache.commons.exec.LogOutputStream)2 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)2 SubmarineUI (org.apache.zeppelin.submarine.commons.SubmarineUI)2 TaskAction (org.gradle.api.tasks.TaskAction)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 JinjavaConfig (com.hubspot.jinjava.JinjavaConfig)1