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 2021/01/04 23:02:49 UTC
[freemarker-generator] 04/06: FREEMARKER-161 [freemarker-generator]
Allow multiple transformations on the CLI
This is an automated email from the ASF dual-hosted git repository.
sgoeschl pushed a commit to branch FREEMARKER-161
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git
commit 5f89acd1df8c90a8a330d469807572c28003d0a4
Author: Siegfried Goeschl <si...@gmail.com>
AuthorDate: Sat Dec 26 10:02:26 2020 +0100
FREEMARKER-161 [freemarker-generator] Allow multiple transformations on the CLI
---
.../generator/base/template/TemplateSource.java | 8 +--
.../base/template/TemplateTransformations.java | 47 --------------
.../template/TemplateTransformationsBuilder.java | 72 ++++++++--------------
.../template/TemplateTransformationsSupplier.java | 22 -------
.../template/TemplateSourceFactoryTest.java | 10 +--
.../TemplateTransformationsBuilderTest.java | 71 +++++++++++----------
.../freemarker/generator/cli/config/Suppliers.java | 10 +--
.../generator/cli/task/FreeMarkerTask.java | 17 +++--
8 files changed, 87 insertions(+), 170 deletions(-)
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 fb50b2a..5e57489 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
@@ -29,8 +29,8 @@ import java.nio.charset.StandardCharsets;
public class TemplateSource {
public enum Origin {
- PATH,
- CODE
+ TEMPLATE_LOADER,
+ TEMPLATE_CODE
}
/** Name of template for diagnostics */
@@ -50,7 +50,7 @@ public class TemplateSource {
private TemplateSource(String name, String code) {
this.name = name;
- this.origin = Origin.CODE;
+ this.origin = Origin.TEMPLATE_CODE;
this.code = code;
this.path = null;
this.encoding = StandardCharsets.UTF_8;
@@ -58,7 +58,7 @@ public class TemplateSource {
private TemplateSource(String name, String path, Charset encoding) {
this.name = name;
- this.origin = Origin.PATH;
+ this.origin = Origin.TEMPLATE_LOADER;
this.code = null;
this.path = path;
this.encoding = encoding;
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
deleted file mode 100644
index e41162d..0000000
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformations.java
+++ /dev/null
@@ -1,47 +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.base.template;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Keeps track of all transformations being executed.
- */
-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
index bdef609..261e3f4 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,32 +18,29 @@ package org.apache.freemarker.generator.base.template;
import org.apache.freemarker.generator.base.FreeMarkerConstants.Location;
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.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
-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.
+ * Maps user-supplied templates (interactive, files, directories, paths) to a
+ * list of TemplateTransformation.
*/
public class TemplateTransformationsBuilder {
/** Interactive template */
- private TemplateSource template;
+ private TemplateSource interactiveTemplate;
/** List of templates and/or template directories to be rendered */
- private final List<String> sources;
+ private final List<String> templateSources;
/** Optional include patterns for resolving source templates or template directories */
private final List<String> includes;
@@ -51,14 +48,14 @@ public class TemplateTransformationsBuilder {
/** Optional exclude patterns for resolving source templates or template directories */
private final List<String> excludes;
- /** Optional output file or directory */
+ /** Optional output file(s) or directory - if none is defined everything is written to a user-supplied writer */
private final List<String> outputs;
/** Optional user-supplied writer */
private Writer writer;
private TemplateTransformationsBuilder() {
- this.sources = new ArrayList<>();
+ this.templateSources = new ArrayList<>();
this.includes = new ArrayList<>();
this.excludes = new ArrayList<>();
this.outputs = new ArrayList<>();
@@ -69,7 +66,7 @@ public class TemplateTransformationsBuilder {
return new TemplateTransformationsBuilder();
}
- public TemplateTransformations build() {
+ public List<TemplateTransformation> build() {
validate();
final List<TemplateTransformation> result = new ArrayList<>();
@@ -78,32 +75,32 @@ public class TemplateTransformationsBuilder {
final File outputFile = getOutputFile(0).orElse(null);
result.add(resolveInteractiveTemplate(outputFile));
} else {
- for (int i = 0; i < sources.size(); i++) {
- final String source = sources.get(i);
+ for (int i = 0; i < templateSources.size(); i++) {
+ final String source = templateSources.get(i);
final File output = getOutputFile(i).orElse(null);
result.addAll(resolve(source, output));
}
}
- return new TemplateTransformations(result);
+ return result;
}
- public TemplateTransformationsBuilder setTemplate(String name, String code) {
+ public TemplateTransformationsBuilder setInteractiveTemplate(String code) {
if (StringUtils.isNotEmpty(code)) {
- this.template = TemplateSource.fromCode(name, code);
+ this.interactiveTemplate = TemplateSource.fromCode(Location.INTERACTIVE, code);
}
return this;
}
- public TemplateTransformationsBuilder addSource(String source) {
+ public TemplateTransformationsBuilder addTemplateSource(String source) {
if (StringUtils.isNotEmpty(source)) {
- this.sources.add(source);
+ this.templateSources.add(source);
}
return this;
}
- public TemplateTransformationsBuilder addSources(Collection<String> sources) {
- sources.forEach(this::addSource);
+ public TemplateTransformationsBuilder addTemplateSources(Collection<String> sources) {
+ sources.forEach(this::addTemplateSource);
return this;
}
@@ -114,13 +111,6 @@ public class TemplateTransformationsBuilder {
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);
@@ -128,13 +118,6 @@ public class TemplateTransformationsBuilder {
return this;
}
- public TemplateTransformationsBuilder addExcludes(Collection<String> excludes) {
- if (excludes != null) {
- this.excludes.addAll(excludes);
- }
- return this;
- }
-
public TemplateTransformationsBuilder addOutputs(Collection<String> outputs) {
if (outputs != null) {
this.outputs.addAll(outputs);
@@ -154,14 +137,9 @@ public class TemplateTransformationsBuilder {
return this;
}
- public TemplateTransformationsBuilder setStdOut() {
- this.writer = new NonClosableWriterWrapper(new BufferedWriter(new OutputStreamWriter(System.out, UTF_8)));
- 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");
+ Validate.isTrue(interactiveTemplate != null || !templateSources.isEmpty(), "Interactive template does not support multiple sources");
+ Validate.isTrue(interactiveTemplate == null || templateSources.isEmpty(), "No template was provided");
}
/**
@@ -172,9 +150,9 @@ public class TemplateTransformationsBuilder {
* @return list of <code>TemplateTransformation</code>
*/
private List<TemplateTransformation> resolve(String source, File output) {
- if (isTemplateFile(source)) {
+ if (isTemplateFileFound(source)) {
return resolveTemplateFile(source, output);
- } else if (isTemplateDirectory(source)) {
+ } else if (isTemplateDirectoryFound(source)) {
return resolveTemplateDirectory(source, output);
} else if (isTemplatePath(source)) {
return resolveTemplatePath(source, output);
@@ -214,7 +192,7 @@ public class TemplateTransformationsBuilder {
private TemplateTransformation resolveInteractiveTemplate(File out) {
final TemplateOutput templateOutput = templateOutput(out);
- return new TemplateTransformation(template, templateOutput);
+ return new TemplateTransformation(interactiveTemplate, templateOutput);
}
private List<TemplateTransformation> resolveTemplateCode(String source, File out) {
@@ -244,7 +222,7 @@ public class TemplateTransformationsBuilder {
}
private boolean hasInteractiveTemplate() {
- return template != null;
+ return interactiveTemplate != null;
}
private Optional<File> getOutputFile(int i) {
@@ -263,18 +241,18 @@ public class TemplateTransformationsBuilder {
return new File(outputDirectory, relativeOutputFileName);
}
- private static boolean isTemplateFile(String source) {
+ private static boolean isTemplateFileFound(String source) {
final File file = new File(source);
return file.exists() && file.isFile();
}
- private static boolean isTemplateDirectory(String source) {
+ private static boolean isTemplateDirectoryFound(String source) {
final File file = new File(source);
return file.exists() && file.isDirectory();
}
private static boolean isTemplatePath(String source) {
- return !isTemplateFile(source) && !isTemplateDirectory(source);
+ return !isTemplateFileFound(source) && !isTemplateDirectoryFound(source);
}
private static RecursiveFileSupplier templateFilesSupplier(String source, String include, String exclude) {
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
deleted file mode 100644
index ef06672..0000000
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformationsSupplier.java
+++ /dev/null
@@ -1,22 +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.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/TemplateSourceFactoryTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateSourceFactoryTest.java
index 0124a98..2088e4b 100644
--- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateSourceFactoryTest.java
+++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/template/TemplateSourceFactoryTest.java
@@ -39,7 +39,7 @@ public class TemplateSourceFactoryTest {
final TemplateSource templateSource = TemplateSourceFactory.create(ANY_TEMPLATE_PATH);
assertEquals(ANY_TEMPLATE_PATH, templateSource.getName());
- assertEquals(Origin.PATH, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_LOADER, templateSource.getOrigin());
assertEquals(ANY_TEMPLATE_PATH, templateSource.getPath());
assertNull(templateSource.getCode());
}
@@ -49,7 +49,7 @@ public class TemplateSourceFactoryTest {
final TemplateSource templateSource = TemplateSourceFactory.create(ANY_FILE_NAME);
assertEquals(ANY_FILE_NAME, templateSource.getName());
- assertEquals(Origin.CODE, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_CODE, templateSource.getOrigin());
assertNull(templateSource.getPath());
assertFalse(templateSource.getCode().isEmpty());
}
@@ -59,7 +59,7 @@ public class TemplateSourceFactoryTest {
final TemplateSource templateSource = TemplateSourceFactory.create(ANY_ENV_URI);
assertEquals(ANY_ENV_VARIABLE, templateSource.getName());
- assertEquals(Origin.CODE, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_CODE, templateSource.getOrigin());
assertNull(templateSource.getPath());
assertFalse(templateSource.getCode().isEmpty());
}
@@ -70,7 +70,7 @@ public class TemplateSourceFactoryTest {
final TemplateSource templateSource = TemplateSourceFactory.create(ANY_URL);
assertNotNull(templateSource.getName());
- assertEquals(Origin.CODE, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_CODE, templateSource.getOrigin());
assertNull(templateSource.getPath());
assertFalse(templateSource.getCode().isEmpty());
}
@@ -81,7 +81,7 @@ public class TemplateSourceFactoryTest {
final TemplateSource templateSource = TemplateSourceFactory.create("info=" + ANY_URL);
assertEquals("info", templateSource.getName());
- assertEquals(Origin.CODE, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_CODE, templateSource.getOrigin());
assertNull(templateSource.getPath());
assertFalse(templateSource.getCode().isEmpty());
}
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 0c082a0..1d86574 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
@@ -20,13 +20,19 @@ import org.apache.freemarker.generator.base.FreeMarkerConstants.Location;
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.TemplateTransformation;
import org.apache.freemarker.generator.base.template.TemplateTransformationsBuilder;
+import org.apache.freemarker.generator.base.util.NonClosableWriterWrapper;
import org.junit.Test;
+import java.io.BufferedWriter;
import java.io.File;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.nio.charset.StandardCharsets;
+import java.util.List;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -42,9 +48,9 @@ public class TemplateTransformationsBuilderTest {
@Test
public void shouldCreateFromInteractiveTemplate() {
- final TemplateTransformations transformations = builder()
- .setTemplate(Location.INTERACTIVE, "Hello World")
- .setStdOut()
+ final List<TemplateTransformation> transformations = builder()
+ .setInteractiveTemplate("Hello World")
+ .setWriter(stdoutWriter())
.build();
assertEquals(1, transformations.size());
@@ -53,7 +59,7 @@ public class TemplateTransformationsBuilderTest {
final TemplateOutput templateOutput = transformations.get(0).getTemplateOutput();
assertEquals(Location.INTERACTIVE, templateSource.getName());
- assertEquals(Origin.CODE, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_CODE, templateSource.getOrigin());
assertEquals("Hello World", templateSource.getCode());
assertNull(templateSource.getPath());
assertEquals(StandardCharsets.UTF_8, templateSource.getEncoding());
@@ -65,20 +71,19 @@ public class TemplateTransformationsBuilderTest {
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWheMixingInteractiveTemplateWithSources() {
builder()
- .setTemplate(Location.INTERACTIVE, "Hello World")
- .addSource(ANY_TEMPLATE_FILE_NAME)
- .setStdOut()
+ .setInteractiveTemplate("Hello World")
+ .addTemplateSource(ANY_TEMPLATE_FILE_NAME)
+ .setWriter(stdoutWriter())
.build();
}
-
// === Template File ====================================================
@Test
public void shouldCreateFromTemplateFile() {
- final TemplateTransformations transformations = builder()
- .addSource(ANY_TEMPLATE_FILE_NAME)
- .setStdOut()
+ final List<TemplateTransformation> transformations = builder()
+ .addTemplateSource(ANY_TEMPLATE_FILE_NAME)
+ .setWriter(stdoutWriter())
.build();
assertEquals(1, transformations.size());
@@ -87,7 +92,7 @@ public class TemplateTransformationsBuilderTest {
final TemplateOutput templateOutput = transformations.get(0).getTemplateOutput();
assertNotNull(templateSource.getName());
- assertEquals(Origin.CODE, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_CODE, templateSource.getOrigin());
assertNotNull(templateSource.getCode());
assertNull(templateSource.getPath());
assertEquals(StandardCharsets.UTF_8, templateSource.getEncoding());
@@ -98,10 +103,10 @@ public class TemplateTransformationsBuilderTest {
@Test
public void shouldCreateFromMultipleTemplateFiles() {
- final TemplateTransformations transformations = builder()
- .addSource(ANY_TEMPLATE_FILE_NAME)
+ final List<TemplateTransformation> transformations = builder()
+ .addTemplateSource(ANY_TEMPLATE_FILE_NAME)
.addOutput("foo/first.out")
- .addSource(OTHER_TEMPLATE_FILE_NAME)
+ .addTemplateSource(OTHER_TEMPLATE_FILE_NAME)
.addOutput("foo/second.out")
.build();
@@ -114,9 +119,9 @@ public class TemplateTransformationsBuilderTest {
@Test
public void shouldCreateFromTemplatePath() {
- final TemplateTransformations transformations = builder()
- .addSource(ANY_TEMPLATE_PATH)
- .setStdOut()
+ final List<TemplateTransformation> transformations = builder()
+ .addTemplateSource(ANY_TEMPLATE_PATH)
+ .setWriter(stdoutWriter())
.build();
assertEquals(1, transformations.size());
@@ -125,7 +130,7 @@ public class TemplateTransformationsBuilderTest {
final TemplateOutput templateOutput = transformations.get(0).getTemplateOutput();
assertNotNull(templateSource.getName());
- assertEquals(Origin.PATH, templateSource.getOrigin());
+ assertEquals(Origin.TEMPLATE_LOADER, templateSource.getOrigin());
assertNull(templateSource.getCode());
assertNotNull(templateSource.getPath());
assertEquals(StandardCharsets.UTF_8, templateSource.getEncoding());
@@ -138,9 +143,9 @@ public class TemplateTransformationsBuilderTest {
@Test
public void shouldCreateFromTemplateDirectory() {
- final TemplateTransformations transformations = builder()
- .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
- .setStdOut()
+ final List<TemplateTransformation> transformations = builder()
+ .addTemplateSource(ANY_TEMPLATE_DIRECTORY_NAME)
+ .setWriter(stdoutWriter())
.build();
assertEquals(2, transformations.size());
@@ -150,8 +155,8 @@ public class TemplateTransformationsBuilderTest {
@Test
public void shouldCreateFromTemplateDirectoryWithOutputDirectory() {
- final TemplateTransformations transformations = builder()
- .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
+ final List<TemplateTransformation> transformations = builder()
+ .addTemplateSource(ANY_TEMPLATE_DIRECTORY_NAME)
.addOutput("/foo")
.build();
@@ -162,10 +167,10 @@ public class TemplateTransformationsBuilderTest {
@Test
public void shouldCreateFromTemplateDirectoryWithInclude() {
- final TemplateTransformations transformations = builder()
- .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
+ final List<TemplateTransformation> transformations = builder()
+ .addTemplateSource(ANY_TEMPLATE_DIRECTORY_NAME)
.addInclude("*.properties")
- .setStdOut()
+ .setWriter(stdoutWriter())
.build();
assertEquals(1, transformations.size());
@@ -174,10 +179,10 @@ public class TemplateTransformationsBuilderTest {
@Test
public void shouldCreateFromTemplateDirectoryWithExclude() {
- final TemplateTransformations transformations = builder()
- .addSource(ANY_TEMPLATE_DIRECTORY_NAME)
+ final List<TemplateTransformation> transformations = builder()
+ .addTemplateSource(ANY_TEMPLATE_DIRECTORY_NAME)
.addExclude("*.ftl")
- .setStdOut()
+ .setWriter(stdoutWriter())
.build();
assertEquals(1, transformations.size());
@@ -188,4 +193,8 @@ public class TemplateTransformationsBuilderTest {
return TemplateTransformationsBuilder
.builder();
}
+
+ private Writer stdoutWriter() {
+ return new NonClosableWriterWrapper(new BufferedWriter(new OutputStreamWriter(System.out, UTF_8)));
+ }
}
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 b6e6fd0..a7bc21d 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
@@ -17,14 +17,14 @@
package org.apache.freemarker.generator.cli.config;
import freemarker.cache.TemplateLoader;
-import org.apache.freemarker.generator.base.FreeMarkerConstants.Location;
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.TemplateTransformation;
import org.apache.freemarker.generator.base.template.TemplateTransformationsBuilder;
-import org.apache.freemarker.generator.base.template.TemplateTransformationsSupplier;
+import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
@@ -68,10 +68,10 @@ public class Suppliers {
return settings::getUserParameters;
}
- public static TemplateTransformationsSupplier templateTransformationsSupplier(Settings settings) {
+ public static Supplier<List<TemplateTransformation>> templateTransformationsSupplier(Settings settings) {
return () -> TemplateTransformationsBuilder.builder()
- .setTemplate(Location.INTERACTIVE, settings.getInteractiveTemplate())
- .addSources(settings.getTemplates())
+ .setInteractiveTemplate(settings.getInteractiveTemplate())
+ .addTemplateSources(settings.getTemplates())
.addInclude(settings.getTemplateFileIncludePattern())
.addExclude(settings.getTemplateFileExcludePattern())
.addOutputs(settings.getOutputs())
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 3842508..cc20d76 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
@@ -27,7 +27,6 @@ import org.apache.freemarker.generator.base.datasource.DataSources;
import org.apache.freemarker.generator.base.template.TemplateOutput;
import org.apache.freemarker.generator.base.template.TemplateSource;
import org.apache.freemarker.generator.base.template.TemplateTransformation;
-import org.apache.freemarker.generator.base.template.TemplateTransformations;
import org.apache.freemarker.generator.base.util.UriUtils;
import org.apache.freemarker.generator.cli.config.Settings;
@@ -70,7 +69,7 @@ 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;
+ private final Supplier<List<TemplateTransformation>> templateTransformationsSupplier;
public FreeMarkerTask(Settings settings) {
@@ -86,7 +85,7 @@ public class FreeMarkerTask implements Callable<Integer> {
public FreeMarkerTask(Settings settings,
Supplier<Configuration> configurationSupplier,
- Supplier<TemplateTransformations> templateTransformationsSupplier,
+ Supplier<List<TemplateTransformation>> templateTransformationsSupplier,
Supplier<List<DataSource>> dataSourcesSupplier,
Supplier<Map<String, Object>> dataModelsSupplier,
Supplier<Map<String, Object>> parameterModelSupplier,
@@ -104,10 +103,10 @@ public class FreeMarkerTask implements Callable<Integer> {
public Integer call() {
try {
final Configuration configuration = configurationSupplier.get();
- final TemplateTransformations templateTransformations = templateTransformationsSupplier.get();
+ final List<TemplateTransformation> templateTransformations = templateTransformationsSupplier.get();
final DataSources dataSources = dataSources(settings, dataSourcesSupplier);
final Map<String, Object> dataModel = dataModel(dataSources, parameterModelSupplier, dataModelsSupplier, toolsSupplier);
- templateTransformations.getList().forEach(t -> process(configuration, t, dataModel));
+ templateTransformations.forEach(t -> process(configuration, t, dataModel));
return SUCCESS;
} catch (RuntimeException e) {
throw new RuntimeException("Failed to process templates", e);
@@ -177,16 +176,16 @@ public class FreeMarkerTask implements Callable<Integer> {
*/
private static Template template(Configuration configuration, TemplateSource templateSource) {
switch (templateSource.getOrigin()) {
- case PATH:
- return fromTemplatePath(configuration, templateSource);
- case CODE:
+ case TEMPLATE_LOADER:
+ return fromTemplateLoader(configuration, templateSource);
+ case TEMPLATE_CODE:
return fromTemplateCode(configuration, templateSource);
default:
throw new IllegalArgumentException("Don't know how to handle: " + templateSource.getOrigin());
}
}
- private static Template fromTemplatePath(Configuration configuration, TemplateSource templateSource) {
+ private static Template fromTemplateLoader(Configuration configuration, TemplateSource templateSource) {
final String path = templateSource.getPath();
try {
return configuration.getTemplate(path);