You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by sg...@apache.org on 2020/05/23 16:22:16 UTC

[freemarker-generator] branch FREEMARKER-142 updated (af3b8d5 -> ce2c917)

This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a change to branch FREEMARKER-142
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git.


    from af3b8d5  FREEMARKER-142 First draft of supporting multiple templates on the command line
     new ec6fefb  FREEMARKER-142 First draft of supporting multiple templates on the command line
     new ce2c917  FREEMARKER-142 First draft of supporting multiple templates on the command line

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../generator/base/template/TemplateOutput.java    |  24 +-
 .../template/TemplateProcessingInfoSupplier.java   | 153 -----------
 .../generator/base/template/TemplateSource.java    |   6 +-
 ...essingInfo.java => TemplateTransformation.java} |   7 +-
 .../base/template/TemplateTransformations.java     |  28 ++
 .../template/TemplateTransformationsBuilder.java   | 288 +++++++++++++++++++++
 .../template/TemplateTransformationsSupplier.java  |   6 +
 .../TemplateProcessingInfoSupplierTest.java        |  77 ------
 .../TemplateTransformationsBuilderTest.java        | 190 ++++++++++++++
 .../freemarker/generator/cli/config/Settings.java  |   1 +
 .../freemarker/generator/cli/config/Suppliers.java |  13 +
 .../generator/cli/task/FreeMarkerTask.java         |  17 +-
 12 files changed, 557 insertions(+), 253 deletions(-)
 delete mode 100644 freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateProcessingInfoSupplier.java
 rename freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/{TemplateProcessingInfo.java => TemplateTransformation.java} (77%)
 create mode 100644 freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformations.java
 create mode 100644 freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java
 create mode 100644 freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsSupplier.java
 delete mode 100644 freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateProcessingInfoSupplierTest.java
 create mode 100644 freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java


[freemarker-generator] 01/02: FREEMARKER-142 First draft of supporting multiple templates on the command line

Posted by sg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a commit to branch FREEMARKER-142
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git

commit ec6fefb4b90b0418b5c69456e4c768fb8acc702a
Author: Siegfried Goeschl <si...@gmail.com>
AuthorDate: Sat May 23 15:19:10 2020 +0200

    FREEMARKER-142 First draft of supporting multiple templates on the command line
---
 .../generator/base/template/TemplateOutput.java    |  24 +-
 .../template/TemplateProcessingInfoSupplier.java   | 153 -------------
 .../generator/base/template/TemplateSource.java    |   6 +-
 ...essingInfo.java => TemplateTransformation.java} |   7 +-
 .../base/template/TemplateTransformations.java     |  28 +++
 .../template/TemplateTransformationsBuilder.java   | 247 +++++++++++++++++++++
 .../TemplateProcessingInfoSupplierTest.java        |  77 -------
 .../TemplateTransformationsBuilderTest.java        | 141 ++++++++++++
 8 files changed, 434 insertions(+), 249 deletions(-)

diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java
index 53001f4..e0efc42 100644
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java
@@ -1,37 +1,34 @@
 package org.apache.freemarker.generator.base.template;
 
-import org.apache.freemarker.generator.base.util.CloseableReaper;
 import org.apache.freemarker.generator.base.util.Validate;
 
-import java.io.Closeable;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Information about where to write the ouput of a template. Initially we
  * wanted to use a <code>FileWriter</code> but it requires actually an
  * existing output file (otherwise a FileNotFound exception is thrown).
+ *
+ * TODO what to do with created FileWriter?
  */
-public class TemplateOutput implements Closeable {
+public class TemplateOutput {
 
     private final Writer writer;
     private final File file;
 
-    /** Collect all closables handed out to the caller to be closed when the instance is closed */
-    private final CloseableReaper closables;
-
     private TemplateOutput(File file) {
         this.writer = null;
-        this.file = file;
-        this.closables = new CloseableReaper();
+        this.file = requireNonNull(file);
     }
 
     private TemplateOutput(Writer writer) {
-        this.writer = writer;
+        this.writer = requireNonNull(writer);
         this.file = null;
-        this.closables = new CloseableReaper();
     }
 
     public static TemplateOutput fromWriter(Writer writer) {
@@ -62,16 +59,11 @@ public class TemplateOutput implements Closeable {
         return writer != null ? writer : fileWriter();
     }
 
-    @Override
-    public void close() throws IOException {
-        closables.close();
-    }
-
     private FileWriter fileWriter() {
         Validate.notNull(file, "Output file is null");
 
         try {
-            return closables.add(new FileWriter(file));
+            return new FileWriter(file);
         } catch (IOException e) {
             throw new RuntimeException("Failed to create FileWriter: " + file.getAbsolutePath(), e);
         }
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateProcessingInfoSupplier.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateProcessingInfoSupplier.java
deleted file mode 100644
index 4c6a42e..0000000
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateProcessingInfoSupplier.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package org.apache.freemarker.generator.base.template;
-
-import org.apache.freemarker.generator.base.file.RecursiveFileSupplier;
-import org.apache.freemarker.generator.base.util.Validate;
-
-import java.io.File;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.function.Supplier;
-
-import static java.util.Collections.singletonList;
-import static java.util.stream.Collectors.toList;
-
-public class TemplateProcessingInfoSupplier implements Supplier<List<TemplateProcessingInfo>> {
-
-    /** List of templates and/or template directories to be rendered */
-    private final Collection<String> sources;
-
-    /** Optional include pattern for resolving source templates or directory */
-    private final String include;
-
-    /** Optional exclude pattern for resolving source templates or directory */
-    private final String exclude;
-
-    /** Optional output file or directory */
-    private final File out;
-
-    /** Optional user-supplied writer */
-    private final Writer writer;
-
-    public TemplateProcessingInfoSupplier(Collection<String> sources, String include, String exclude, File out) {
-        this.sources = new ArrayList<>(sources);
-        this.include = include;
-        this.exclude = exclude;
-        this.out = out;
-        this.writer = null;
-    }
-
-    public TemplateProcessingInfoSupplier(Collection<String> sources, String include, String exclude, Writer writer) {
-        this.sources = new ArrayList<>(sources);
-        this.include = include;
-        this.exclude = exclude;
-        this.out = null;
-        this.writer = writer;
-    }
-
-    @Override
-    public List<TemplateProcessingInfo> get() {
-        return sources.stream()
-                .map(this::get)
-                .flatMap(Collection::stream)
-                .collect(toList());
-    }
-
-    /**
-     * Resolve a <code>source</code> to a list of <code>TemplateProcessingInfo</code>.
-     *
-     * @param source the source being a file name, an URI or <code>NamedUri</code>
-     * @return list of <code>TemplateProcessingInfo</code>
-     */
-    private List<TemplateProcessingInfo> get(String source) {
-        if (isTemplateFile(source)) {
-            return resolveTemplateFile(source);
-        } else if (isTemplateDirectory(source)) {
-            return resolveTemplateDirectory(source);
-        } else if (isTemplatePath(source)) {
-            return resolveTemplatePath(source);
-        } else {
-            throw new RuntimeException("Don't know how to resolve: " + source);
-        }
-    }
-
-    private List<TemplateProcessingInfo> resolveTemplateFile(String source) {
-        final TemplateSource templateSource = templateSource(source);
-        final TemplateOutput templateOutput = templateOutput(out);
-        return singletonList(new TemplateProcessingInfo(templateSource, templateOutput));
-    }
-
-    private List<TemplateProcessingInfo> resolveTemplateDirectory(String source) {
-        Validate.fileExists(new File(source), "Template directory does not exist: " + source);
-
-        final File templateDirectory = new File(source);
-        final List<File> templateFiles = templateFilesSupplier(source, include, exclude).get();
-        final List<TemplateProcessingInfo> templateProcessingInfos = new ArrayList<>();
-
-        for (File templateFile : templateFiles) {
-            final TemplateSource templateSource = templateSource(templateFile.getAbsolutePath());
-            final File outputFile = getTemplateOutputFile(templateDirectory, templateFile, out);
-            final TemplateOutput templateOutput = templateOutput(outputFile);
-            templateProcessingInfos.add(new TemplateProcessingInfo(templateSource, templateOutput));
-        }
-
-        return templateProcessingInfos;
-    }
-
-    private List<TemplateProcessingInfo> resolveTemplatePath(String source) {
-        final TemplateSource templateSource = templateSource(source);
-        final TemplateOutput templateOutput = templateOutput(out);
-        return singletonList(new TemplateProcessingInfo(templateSource, templateOutput));
-    }
-
-    private TemplateOutput templateOutput(File templateOutputFile) {
-        if (writer != null) {
-            return TemplateOutput.fromWriter(writer);
-        } else {
-            return TemplateOutput.fromFile(templateOutputFile);
-        }
-    }
-
-    private TemplateSource templateSource(String source) {
-        return TemplateSourceFactory.create(source);
-    }
-
-    private static File getTemplateOutputFile(File templateDirectory, File templateFile, File outputDirectory) {
-        final String relativePath = relativePath(templateDirectory, templateFile);
-        final String relativeOutputFileName = mapExtension(relativePath);
-        return new File(outputDirectory, relativeOutputFileName);
-    }
-
-    private static boolean isTemplateFile(String source) {
-        final File file = new File(source);
-        return file.exists() && file.isFile();
-    }
-
-    private static boolean isTemplateDirectory(String source) {
-        final File file = new File(source);
-        return file.exists() && file.isDirectory();
-    }
-
-    private static boolean isTemplatePath(String source) {
-        return !isTemplateFile(source) && !isTemplateDirectory(source);
-    }
-
-    private static RecursiveFileSupplier templateFilesSupplier(String source, String include, String exclude) {
-        return new RecursiveFileSupplier(singletonList(source), singletonList(include), singletonList(exclude));
-    }
-
-    private static String relativePath(File directory, File file) {
-        return file.getAbsolutePath()
-                .substring(directory.getAbsolutePath().length())
-                .substring(1);
-    }
-
-    private static String mapExtension(String fileName) {
-        if (fileName.toLowerCase().endsWith(".ftl")) {
-            return fileName.substring(0, fileName.length() - 4);
-        } else {
-            return fileName;
-        }
-    }
-}
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateSource.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateSource.java
index f9f7f10..0659d22 100644
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateSource.java
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateSource.java
@@ -37,7 +37,7 @@ public class TemplateSource {
         this.origin = Origin.CODE;
         this.code = code;
         this.path = null;
-        this.encoding = null;
+        this.encoding = StandardCharsets.UTF_8;
     }
 
     private TemplateSource(String name, String path, Charset encoding) {
@@ -81,6 +81,10 @@ public class TemplateSource {
         return name;
     }
 
+    public Charset getEncoding() {
+        return encoding;
+    }
+
     @Override
     public String toString() {
         return "TemplateSource{" +
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateProcessingInfo.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformation.java
similarity index 77%
rename from freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateProcessingInfo.java
rename to freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformation.java
index fb94e96..8840e50 100644
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateProcessingInfo.java
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformation.java
@@ -2,7 +2,10 @@ package org.apache.freemarker.generator.base.template;
 
 import static java.util.Objects.requireNonNull;
 
-public class TemplateProcessingInfo {
+/**
+ * Information about loading templates and writing their output.
+ */
+public class TemplateTransformation {
 
     /** Source of template */
     private final TemplateSource templateSource;
@@ -10,7 +13,7 @@ public class TemplateProcessingInfo {
     /** Output of template */
     private final TemplateOutput templateOutput;
 
-    public TemplateProcessingInfo(TemplateSource templateSource, TemplateOutput templateOutput) {
+    public TemplateTransformation(TemplateSource templateSource, TemplateOutput templateOutput) {
         this.templateSource = requireNonNull(templateSource);
         this.templateOutput = requireNonNull(templateOutput);
     }
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformations.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformations.java
new file mode 100644
index 0000000..380e76a
--- /dev/null
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformations.java
@@ -0,0 +1,28 @@
+package org.apache.freemarker.generator.base.template;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+public class TemplateTransformations {
+
+    private final List<TemplateTransformation> templateTransformations;
+
+    public TemplateTransformations(Collection<? extends TemplateTransformation> templateTransformations) {
+        this.templateTransformations = new ArrayList<>(requireNonNull(templateTransformations));
+    }
+
+    public List<? extends TemplateTransformation> getList() {
+        return templateTransformations;
+    }
+
+    public TemplateTransformation get(int index) {
+        return templateTransformations.get(index);
+    }
+
+    public int size() {
+        return templateTransformations.size();
+    }
+}
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java
new file mode 100644
index 0000000..834e3aa
--- /dev/null
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java
@@ -0,0 +1,247 @@
+package org.apache.freemarker.generator.base.template;
+
+import org.apache.freemarker.generator.base.file.RecursiveFileSupplier;
+import org.apache.freemarker.generator.base.util.NonClosableWriterWrapper;
+import org.apache.freemarker.generator.base.util.StringUtils;
+import org.apache.freemarker.generator.base.util.Validate;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.Collections.singletonList;
+
+public class TemplateTransformationsBuilder {
+
+    /** List of templates and/or template directories to be rendered */
+    private final List<String> sources;
+
+    /** Optional include patterns for resolving source templates or template directories */
+    private final List<String> includes;
+
+    /** Optional exclude patterns for resolving source templates or template directories */
+    private final List<String> excludes;
+
+    /** Optional output file or directory */
+    private final List<File> outputs;
+
+    /** Optional user-supplied writer */
+    private Writer writer;
+
+    private TemplateTransformationsBuilder() {
+        this.sources = new ArrayList<>();
+        this.includes = new ArrayList<>();
+        this.excludes = new ArrayList<>();
+        this.outputs = new ArrayList<>();
+        this.writer = null;
+    }
+
+    public static TemplateTransformationsBuilder builder() {
+        return new TemplateTransformationsBuilder();
+    }
+
+    public TemplateTransformations build() {
+        final List<TemplateTransformation> result = new ArrayList<>();
+
+        for (int i = 0; i < sources.size(); i++) {
+            final String source = sources.get(i);
+            final File output = i < outputs.size() ? outputs.get(i) : null;
+            result.addAll(resolve(source, output));
+        }
+
+        return new TemplateTransformations(result);
+    }
+
+    public TemplateTransformationsBuilder addSource(String source) {
+        if (StringUtils.isNotEmpty(source)) {
+            this.sources.add(source);
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder addSources(Collection<String> sources) {
+        if (sources != null) {
+            this.sources.addAll(sources);
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder addInclude(String include) {
+        if (StringUtils.isNotEmpty(include)) {
+            this.includes.add(include);
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder addIncludes(Collection<String> includes) {
+        if (includes != null) {
+            this.includes.addAll(includes);
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder addExclude(String exclude) {
+        if (StringUtils.isNotEmpty(exclude)) {
+            this.excludes.add(exclude);
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder addExcludes(Collection<String> excludes) {
+        if (excludes != null) {
+            this.excludes.addAll(excludes);
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder addOutput(String output) {
+        if (StringUtils.isNotEmpty(output)) {
+            this.outputs.add(new File(output));
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder addOutputs(Collection<String> outputs) {
+        if (outputs != null) {
+            outputs.forEach(this::addOutput);
+        }
+        return this;
+    }
+
+    public TemplateTransformationsBuilder setWriter(Writer writer) {
+        this.writer = writer;
+        return this;
+    }
+
+    public TemplateTransformationsBuilder setStdOut() {
+        this.writer = new NonClosableWriterWrapper(new BufferedWriter(new OutputStreamWriter(System.out, UTF_8)));
+        return this;
+    }
+
+    /**
+     * Resolve a <code>source</code> to a list of <code>TemplateTransformation</code>.
+     *
+     * @param source the source being a file name, an URI or <code>NamedUri</code>
+     * @param output Optional output file or directory
+     * @return list of <code>TemplateTransformation</code>
+     */
+    private List<TemplateTransformation> resolve(String source, File output) {
+        if (isTemplateFile(source)) {
+            return resolveTemplateFile(source, output);
+        } else if (isTemplateDirectory(source)) {
+            return resolveTemplateDirectory(source, output);
+        } else if (isTemplatePath(source)) {
+            return resolveTemplatePath(source, output);
+        } else {
+            throw new RuntimeException("Don't know how to resolve: " + source);
+        }
+    }
+
+    private List<TemplateTransformation> resolveTemplateFile(String source, File outputFile) {
+        final TemplateSource templateSource = templateSource(source);
+        final TemplateOutput templateOutput = templateOutput(outputFile);
+        return singletonList(new TemplateTransformation(templateSource, templateOutput));
+    }
+
+    private List<TemplateTransformation> resolveTemplateDirectory(String source, File outputDirectory) {
+        Validate.fileExists(new File(source), "Template directory does not exist: " + source);
+
+        final File templateDirectory = new File(source);
+        final List<File> templateFiles = templateFilesSupplier(source, getInclude(), getExclude()).get();
+        final List<TemplateTransformation> templateTransformations = new ArrayList<>();
+
+        for (File templateFile : templateFiles) {
+            final TemplateSource templateSource = templateSource(templateFile.getAbsolutePath());
+            final File outputFile = getTemplateOutputFile(templateDirectory, templateFile, outputDirectory);
+            final TemplateOutput templateOutput = templateOutput(outputFile);
+            templateTransformations.add(new TemplateTransformation(templateSource, templateOutput));
+        }
+
+        return templateTransformations;
+    }
+
+    private List<TemplateTransformation> resolveTemplatePath(String source, File out) {
+        final TemplateSource templateSource = templateSource(source);
+        final TemplateOutput templateOutput = templateOutput(out);
+        return singletonList(new TemplateTransformation(templateSource, templateOutput));
+    }
+
+    private TemplateOutput templateOutput(File templateOutputFile) {
+        if (templateOutputFile != null) {
+            return TemplateOutput.fromFile(templateOutputFile);
+        } else {
+            return TemplateOutput.fromWriter(writer);
+        }
+    }
+
+    private TemplateSource templateSource(String source) {
+        return TemplateSourceFactory.create(source);
+    }
+
+    private String getInclude() {
+        return includes.isEmpty() ? null : includes.get(0);
+    }
+
+    private String getExclude() {
+        return excludes.isEmpty() ? null : excludes.get(0);
+    }
+
+    private Writer writer(String outputFile, String outputEncoding) {
+        try {
+            if (writer != null) {
+                return writer;
+            } else if (!StringUtils.isEmpty(outputFile)) {
+                return new BufferedWriter(new FileWriter(outputFile));
+            } else {
+                return new BufferedWriter(new OutputStreamWriter(System.out, outputEncoding));
+            }
+        } catch (IOException e) {
+            throw new RuntimeException("Unable to create writer", e);
+        }
+    }
+
+    private static File getTemplateOutputFile(File templateDirectory, File templateFile, File outputDirectory) {
+        final String relativePath = relativePath(templateDirectory, templateFile);
+        final String relativeOutputFileName = mapExtension(relativePath);
+        return new File(outputDirectory, relativeOutputFileName);
+    }
+
+    private static boolean isTemplateFile(String source) {
+        final File file = new File(source);
+        return file.exists() && file.isFile();
+    }
+
+    private static boolean isTemplateDirectory(String source) {
+        final File file = new File(source);
+        return file.exists() && file.isDirectory();
+    }
+
+    private static boolean isTemplatePath(String source) {
+        return !isTemplateFile(source) && !isTemplateDirectory(source);
+    }
+
+    private static RecursiveFileSupplier templateFilesSupplier(String source, String include, String exclude) {
+        return new RecursiveFileSupplier(singletonList(source), singletonList(include), singletonList(exclude));
+    }
+
+    private static String relativePath(File directory, File file) {
+        return file.getAbsolutePath()
+                .substring(directory.getAbsolutePath().length())
+                .substring(1);
+    }
+
+    private static String mapExtension(String fileName) {
+        if (fileName.toLowerCase().endsWith(".ftl")) {
+            return fileName.substring(0, fileName.length() - 4);
+        } else {
+            return fileName;
+        }
+    }
+}
diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateProcessingInfoSupplierTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateProcessingInfoSupplierTest.java
deleted file mode 100644
index 129fd71..0000000
--- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateProcessingInfoSupplierTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.freemarker.generator.template;
-
-import org.apache.freemarker.generator.base.template.TemplateProcessingInfo;
-import org.apache.freemarker.generator.base.template.TemplateProcessingInfoSupplier;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class TemplateProcessingInfoSupplierTest {
-
-    private static final File ROOT_DIR = new File("./target/out");
-    private static final String ANY_TEMPLATE_FILE_NAME = "src/test/template/application.properties";
-    private static final String ANY_TEMPLATE_PATH = "template/info.ftl";
-    private static final String ANY_TEMPLATE_DIRECTORY_NAME = "src/test/template";
-
-    private static final String NO_INCLUDE = null;
-    private static final String NO_EXCLUDE = null;
-
-    @Test
-    public void shouldCreateFromTemplateFile() {
-        final TemplateProcessingInfoSupplier supplier = supplier(ANY_TEMPLATE_FILE_NAME);
-
-        final List<TemplateProcessingInfo> templateProcessingInfos = supplier.get();
-
-        assertNotNull(templateProcessingInfos);
-        assertEquals(1, templateProcessingInfos.size());
-    }
-
-    @Test
-    public void shouldCreateFromTemplatePath() {
-        final TemplateProcessingInfoSupplier supplier = supplier(ANY_TEMPLATE_PATH);
-
-        final List<TemplateProcessingInfo> templateProcessingInfos = supplier.get();
-
-        assertNotNull(templateProcessingInfos);
-        assertEquals(1, templateProcessingInfos.size());
-    }
-
-    @Test
-    public void shouldCreateFromTemplateDirectory() {
-        final TemplateProcessingInfoSupplier supplier = supplier(ANY_TEMPLATE_DIRECTORY_NAME);
-
-        final List<TemplateProcessingInfo> templateProcessingInfos = supplier.get();
-
-        assertNotNull(templateProcessingInfos);
-        assertEquals(2, templateProcessingInfos.size());
-    }
-
-    private TemplateProcessingInfoSupplier supplier(String source) {
-        return new TemplateProcessingInfoSupplier(
-                Collections.singleton(source),
-                NO_INCLUDE,
-                NO_EXCLUDE,
-                ROOT_DIR);
-    }
-}
diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java
new file mode 100644
index 0000000..f1e4067
--- /dev/null
+++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.freemarker.generator.template;
+
+import org.apache.freemarker.generator.base.template.TemplateOutput;
+import org.apache.freemarker.generator.base.template.TemplateSource;
+import org.apache.freemarker.generator.base.template.TemplateSource.Origin;
+import org.apache.freemarker.generator.base.template.TemplateTransformations;
+import org.apache.freemarker.generator.base.template.TemplateTransformationsBuilder;
+import org.junit.Test;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class TemplateTransformationsBuilderTest {
+
+    private static final String ANY_TEMPLATE_FILE_NAME = "src/test/template/application.properties";
+    private static final String ANY_TEMPLATE_PATH = "template/info.ftl";
+    private static final String ANY_TEMPLATE_DIRECTORY_NAME = "src/test/template";
+
+    // === Template File ====================================================
+
+    @Test
+    public void shouldCreateFromTemplateFile() {
+        final TemplateTransformations transformations = builder()
+                .addSource(ANY_TEMPLATE_FILE_NAME)
+                .setStdOut()
+                .build();
+
+        assertEquals(1, transformations.size());
+
+        final TemplateSource templateSource = transformations.get(0).getTemplateSource();
+        final TemplateOutput templateOutput = transformations.get(0).getTemplateOutput();
+
+        assertNotNull(templateSource.getName());
+        assertEquals(Origin.CODE, templateSource.getOrigin());
+        assertNotNull(templateSource.getCode());
+        assertNull(templateSource.getPath());
+        assertEquals(StandardCharsets.UTF_8, templateSource.getEncoding());
+
+        assertNotNull(templateOutput.getWriter());
+        assertNull(templateOutput.getFile());
+    }
+
+    // === Template Path ====================================================
+
+    @Test
+    public void shouldCreateFromTemplatePath() {
+        final TemplateTransformations transformations = builder()
+                .addSource(ANY_TEMPLATE_PATH)
+                .setStdOut()
+                .build();
+
+        assertEquals(1, transformations.size());
+
+        final TemplateSource templateSource = transformations.get(0).getTemplateSource();
+        final TemplateOutput templateOutput = transformations.get(0).getTemplateOutput();
+
+        assertNotNull(templateSource.getName());
+        assertEquals(Origin.PATH, templateSource.getOrigin());
+        assertNull(templateSource.getCode());
+        assertNotNull(templateSource.getPath());
+        assertEquals(StandardCharsets.UTF_8, templateSource.getEncoding());
+
+        assertNotNull(templateOutput.getWriter());
+        assertNull(templateOutput.getFile());
+    }
+
+    // === Template Directory ===============================================
+
+    @Test
+    public void shouldCreateFromTemplateDirectory() {
+        final TemplateTransformations transformations = builder()
+                .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
+                .setStdOut()
+                .build();
+
+        assertEquals(2, transformations.size());
+        assertEquals(new File("nginx/nginx.conf"), transformations.get(0).getTemplateOutput().getFile());
+        assertEquals(new File("application.properties"), transformations.get(1).getTemplateOutput().getFile());
+    }
+
+    @Test
+    public void shouldCreateFromTemplateDirectoryWithOutputDirectory() {
+        final TemplateTransformations transformations = builder()
+                .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
+                .addOutput("/tmp")
+                .build();
+
+        assertEquals(2, transformations.size());
+        assertEquals(new File("/tmp/nginx/nginx.conf"), transformations.get(0).getTemplateOutput().getFile());
+        assertEquals(new File("/tmp/application.properties"), transformations.get(1).getTemplateOutput().getFile());
+    }
+
+    @Test
+    public void shouldCreateFromTemplateDirectoryWithInclude() {
+        final TemplateTransformations transformations = builder()
+                .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
+                .addInclude("*.properties")
+                .setStdOut()
+                .build();
+
+        assertEquals(1, transformations.size());
+        assertEquals(new File("application.properties"), transformations.get(0).getTemplateOutput().getFile());
+    }
+
+    @Test
+    public void shouldCreateFromTemplateDirectoryWithExclude() {
+        final TemplateTransformations transformations = builder()
+                .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
+                .addExclude("*.ftl")
+                .setStdOut()
+                .build();
+
+        assertEquals(1, transformations.size());
+        assertEquals(new File("application.properties"), transformations.get(0).getTemplateOutput().getFile());
+    }
+
+    private TemplateTransformationsBuilder builder() {
+        return TemplateTransformationsBuilder
+                .builder();
+    }
+}


[freemarker-generator] 02/02: FREEMARKER-142 First draft of supporting multiple templates on the command line

Posted by sg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a commit to branch FREEMARKER-142
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git

commit ce2c917339f4c3ffbc7794387bab63e5e7eb365a
Author: Siegfried Goeschl <si...@gmail.com>
AuthorDate: Sat May 23 18:22:04 2020 +0200

    FREEMARKER-142 First draft of supporting multiple templates on the command line
---
 .../template/TemplateTransformationsBuilder.java   | 57 +++++++++++++++++++---
 .../template/TemplateTransformationsSupplier.java  |  6 +++
 .../TemplateTransformationsBuilderTest.java        | 55 +++++++++++++++++++--
 .../freemarker/generator/cli/config/Settings.java  |  1 +
 .../freemarker/generator/cli/config/Suppliers.java | 13 +++++
 .../generator/cli/task/FreeMarkerTask.java         | 17 +++++--
 6 files changed, 134 insertions(+), 15 deletions(-)

diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java
index 834e3aa..bb74883 100644
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsBuilder.java
@@ -18,8 +18,14 @@ import java.util.List;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.Collections.singletonList;
 
+/**
+ * Provide the logic to define multiple transformations from the user input.
+ */
 public class TemplateTransformationsBuilder {
 
+    /** Interactive template */
+    private TemplateSource template;
+
     /** List of templates and/or template directories to be rendered */
     private final List<String> sources;
 
@@ -48,17 +54,31 @@ public class TemplateTransformationsBuilder {
     }
 
     public TemplateTransformations build() {
+        validate();
+
         final List<TemplateTransformation> result = new ArrayList<>();
 
-        for (int i = 0; i < sources.size(); i++) {
-            final String source = sources.get(i);
-            final File output = i < outputs.size() ? outputs.get(i) : null;
-            result.addAll(resolve(source, output));
+        if (template != null) {
+            final File outputFile = outputs.isEmpty() ? null : outputs.get(0);
+            result.add(resolveInteractiveTemplate(outputFile));
+        } else {
+            for (int i = 0; i < sources.size(); i++) {
+                final String source = sources.get(i);
+                final File output = i < outputs.size() ? outputs.get(i) : null;
+                result.addAll(resolve(source, output));
+            }
         }
 
         return new TemplateTransformations(result);
     }
 
+    public TemplateTransformationsBuilder setTemplate(String name, String code) {
+        if (StringUtils.isNotEmpty(code)) {
+            this.template = TemplateSource.fromCode(name, code);
+        }
+        return this;
+    }
+
     public TemplateTransformationsBuilder addSource(String source) {
         if (StringUtils.isNotEmpty(source)) {
             this.sources.add(source);
@@ -67,9 +87,7 @@ public class TemplateTransformationsBuilder {
     }
 
     public TemplateTransformationsBuilder addSources(Collection<String> sources) {
-        if (sources != null) {
-            this.sources.addAll(sources);
-        }
+        sources.forEach(this::addSource);
         return this;
     }
 
@@ -108,6 +126,13 @@ public class TemplateTransformationsBuilder {
         return this;
     }
 
+    public TemplateTransformationsBuilder addOutput(File output) {
+        if (output != null) {
+            this.outputs.add(output);
+        }
+        return this;
+    }
+
     public TemplateTransformationsBuilder addOutputs(Collection<String> outputs) {
         if (outputs != null) {
             outputs.forEach(this::addOutput);
@@ -125,6 +150,11 @@ public class TemplateTransformationsBuilder {
         return this;
     }
 
+    private void validate() {
+        Validate.isTrue(template != null || !sources.isEmpty(), "No template was provided");
+        Validate.isTrue(template == null || sources.isEmpty(), "Interactive template does not support multiple sources");
+    }
+
     /**
      * Resolve a <code>source</code> to a list of <code>TemplateTransformation</code>.
      *
@@ -140,7 +170,7 @@ public class TemplateTransformationsBuilder {
         } else if (isTemplatePath(source)) {
             return resolveTemplatePath(source, output);
         } else {
-            throw new RuntimeException("Don't know how to resolve: " + source);
+            return resolveTemplateCode(source, output);
         }
     }
 
@@ -173,6 +203,17 @@ public class TemplateTransformationsBuilder {
         return singletonList(new TemplateTransformation(templateSource, templateOutput));
     }
 
+    private TemplateTransformation resolveInteractiveTemplate(File out) {
+        final TemplateOutput templateOutput = templateOutput(out);
+        return new TemplateTransformation(template, templateOutput);
+    }
+
+    private List<TemplateTransformation> resolveTemplateCode(String source, File out) {
+        final TemplateSource templateSource = TemplateSource.fromCode("interactive", source);
+        final TemplateOutput templateOutput = templateOutput(out);
+        return singletonList(new TemplateTransformation(templateSource, templateOutput));
+    }
+
     private TemplateOutput templateOutput(File templateOutputFile) {
         if (templateOutputFile != null) {
             return TemplateOutput.fromFile(templateOutputFile);
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsSupplier.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsSupplier.java
new file mode 100644
index 0000000..d0472b2
--- /dev/null
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsSupplier.java
@@ -0,0 +1,6 @@
+package org.apache.freemarker.generator.base.template;
+
+import java.util.function.Supplier;
+
+public interface TemplateTransformationsSupplier extends Supplier<TemplateTransformations> {
+}
diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java
index f1e4067..617ae5b 100644
--- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java
+++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateTransformationsBuilderTest.java
@@ -33,9 +33,44 @@ import static org.junit.Assert.assertNull;
 public class TemplateTransformationsBuilderTest {
 
     private static final String ANY_TEMPLATE_FILE_NAME = "src/test/template/application.properties";
+    private static final String OTHER_TEMPLATE_FILE_NAME = "src/test/template/nginx/nginx.conf.ftl";
     private static final String ANY_TEMPLATE_PATH = "template/info.ftl";
     private static final String ANY_TEMPLATE_DIRECTORY_NAME = "src/test/template";
 
+    // === Interactive Template =============================================
+
+    @Test
+    public void shouldCreateFromInteractiveTemplate() {
+        final TemplateTransformations transformations = builder()
+                .setTemplate("interactive", "Hello World")
+                .setStdOut()
+                .build();
+
+        assertEquals(1, transformations.size());
+
+        final TemplateSource templateSource = transformations.get(0).getTemplateSource();
+        final TemplateOutput templateOutput = transformations.get(0).getTemplateOutput();
+
+        assertEquals("interactive", templateSource.getName());
+        assertEquals(Origin.CODE, templateSource.getOrigin());
+        assertEquals("Hello World", templateSource.getCode());
+        assertNull(templateSource.getPath());
+        assertEquals(StandardCharsets.UTF_8, templateSource.getEncoding());
+
+        assertNotNull(templateOutput.getWriter());
+        assertNull(templateOutput.getFile());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldThrowIllegalArgumentExceptionWheMixingInteractiveTemplateWithSources() {
+        builder()
+                .setTemplate("interactive", "Hello World")
+                .addSource(ANY_TEMPLATE_FILE_NAME)
+                .setStdOut()
+                .build();
+    }
+
+
     // === Template File ====================================================
 
     @Test
@@ -60,6 +95,20 @@ public class TemplateTransformationsBuilderTest {
         assertNull(templateOutput.getFile());
     }
 
+    @Test
+    public void shouldCreateFromMultipleTemplateFiles() {
+        final TemplateTransformations transformations = builder()
+                .addSource(ANY_TEMPLATE_FILE_NAME)
+                .addOutput("foo/first.out")
+                .addSource(OTHER_TEMPLATE_FILE_NAME)
+                .addOutput("foo/second.out")
+                .build();
+
+        assertEquals(2, transformations.size());
+        assertEquals(new File("foo/first.out"), transformations.get(0).getTemplateOutput().getFile());
+        assertEquals(new File("foo/second.out"), transformations.get(1).getTemplateOutput().getFile());
+    }
+
     // === Template Path ====================================================
 
     @Test
@@ -102,12 +151,12 @@ public class TemplateTransformationsBuilderTest {
     public void shouldCreateFromTemplateDirectoryWithOutputDirectory() {
         final TemplateTransformations transformations = builder()
                 .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
-                .addOutput("/tmp")
+                .addOutput("/foo")
                 .build();
 
         assertEquals(2, transformations.size());
-        assertEquals(new File("/tmp/nginx/nginx.conf"), transformations.get(0).getTemplateOutput().getFile());
-        assertEquals(new File("/tmp/application.properties"), transformations.get(1).getTemplateOutput().getFile());
+        assertEquals(new File("/foo/nginx/nginx.conf"), transformations.get(0).getTemplateOutput().getFile());
+        assertEquals(new File("/foo/application.properties"), transformations.get(1).getTemplateOutput().getFile());
     }
 
     @Test
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java
index 29443f7..2b78758 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java
@@ -171,6 +171,7 @@ public class Settings {
         return templates;
     }
 
+    // TODO remove later on
     public String getTemplateName() {
         return templates.isEmpty() ? null : templates.get(0);
     }
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Suppliers.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Suppliers.java
index ac7fb9f..2c220b2 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Suppliers.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Suppliers.java
@@ -21,6 +21,8 @@ import org.apache.freemarker.generator.base.datasource.DataSourcesSupplier;
 import org.apache.freemarker.generator.base.file.PropertiesClassPathSupplier;
 import org.apache.freemarker.generator.base.file.PropertiesFileSystemSupplier;
 import org.apache.freemarker.generator.base.file.PropertiesSupplier;
+import org.apache.freemarker.generator.base.template.TemplateTransformationsBuilder;
+import org.apache.freemarker.generator.base.template.TemplateTransformationsSupplier;
 
 import java.util.Map;
 import java.util.function.Supplier;
@@ -65,6 +67,17 @@ public class Suppliers {
         return settings::getParameters;
     }
 
+    public static TemplateTransformationsSupplier templateTransformationsSupplier(Settings settings) {
+        return (() -> TemplateTransformationsBuilder.builder()
+                .setTemplate("interactive", settings.getInteractiveTemplate())
+                .addSources(settings.getTemplates())
+                .addInclude(settings.getTemplateFileIncludePattern())
+                .addExclude(settings.getTemplateFileExcludePattern())
+                .addOutput(settings.getOutput())
+                .setWriter(settings.getWriter())
+                .build());
+    }
+
     public static PropertiesSupplier propertiesSupplier(String fileName) {
         return new PropertiesSupplier(
                 new PropertiesFileSystemSupplier(fileName),
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/task/FreeMarkerTask.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/task/FreeMarkerTask.java
index 618fef9..f8955b0 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/task/FreeMarkerTask.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/task/FreeMarkerTask.java
@@ -23,6 +23,7 @@ import org.apache.freemarker.generator.base.FreeMarkerConstants.Location;
 import org.apache.freemarker.generator.base.datasource.DataSource;
 import org.apache.freemarker.generator.base.datasource.DataSourceFactory;
 import org.apache.freemarker.generator.base.datasource.DataSources;
+import org.apache.freemarker.generator.base.template.TemplateTransformations;
 import org.apache.freemarker.generator.base.util.UriUtils;
 import org.apache.freemarker.generator.cli.config.Settings;
 
@@ -47,6 +48,7 @@ import static org.apache.freemarker.generator.cli.config.Suppliers.configuration
 import static org.apache.freemarker.generator.cli.config.Suppliers.dataModelSupplier;
 import static org.apache.freemarker.generator.cli.config.Suppliers.dataSourcesSupplier;
 import static org.apache.freemarker.generator.cli.config.Suppliers.parameterSupplier;
+import static org.apache.freemarker.generator.cli.config.Suppliers.templateTransformationsSupplier;
 import static org.apache.freemarker.generator.cli.config.Suppliers.toolsSupplier;
 
 /**
@@ -62,32 +64,39 @@ public class FreeMarkerTask implements Callable<Integer> {
     private final Supplier<Map<String, Object>> dataModelsSupplier;
     private final Supplier<Map<String, Object>> parameterModelSupplier;
     private final Supplier<Configuration> configurationSupplier;
+    private final Supplier<TemplateTransformations> templateTransformationsSupplier;
+
 
     public FreeMarkerTask(Settings settings) {
         this(settings,
-                toolsSupplier(settings),
+                configurationSupplier(settings),
+                templateTransformationsSupplier(settings),
                 dataSourcesSupplier(settings),
                 dataModelSupplier(settings),
                 parameterSupplier(settings),
-                configurationSupplier(settings));
+                toolsSupplier(settings)
+        );
     }
 
     public FreeMarkerTask(Settings settings,
-                          Supplier<Map<String, Object>> toolsSupplier,
+                          Supplier<Configuration> configurationSupplier,
+                          Supplier<TemplateTransformations> templateTransformationsSupplier,
                           Supplier<List<DataSource>> dataSourcesSupplier,
                           Supplier<Map<String, Object>> dataModelsSupplier,
                           Supplier<Map<String, Object>> parameterModelSupplier,
-                          Supplier<Configuration> configurationSupplier) {
+                          Supplier<Map<String, Object>> toolsSupplier) {
         this.settings = requireNonNull(settings);
         this.toolsSupplier = requireNonNull(toolsSupplier);
         this.dataSourcesSupplier = requireNonNull(dataSourcesSupplier);
         this.dataModelsSupplier = requireNonNull(dataModelsSupplier);
         this.parameterModelSupplier = requireNonNull(parameterModelSupplier);
         this.configurationSupplier = requireNonNull(configurationSupplier);
+        this.templateTransformationsSupplier = requireNonNull(templateTransformationsSupplier);
     }
 
     @Override
     public Integer call() {
+        final TemplateTransformations templateTransformations = templateTransformationsSupplier.get();
         final Template template = template(settings, configurationSupplier);
         try (Writer writer = settings.getWriter(); DataSources dataSources = dataSources(settings, dataSourcesSupplier)) {
             final Map<String, Object> dataModel = dataModel(dataSources, parameterModelSupplier, dataModelsSupplier, toolsSupplier);