This is an automated email from the ASF dual-hosted git repository. sgoeschl pushed a commit to branch FREEMARKER-134 in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git
commit 30ec9ca6c3822a35da1e12d55afc7a444c463c32 Author: Siegfried Goeschl <[email protected]> AuthorDate: Fri Feb 28 16:44:19 2020 +0100 FREEMARKER-134 Rename "Document" to "Datasource" --- CHANGELOG.md | 4 +- freemarker-generator-base/README.md | 6 +- .../generator/base/FreeMarkerConstants.java | 6 +- .../Document.java => datasource/Datasource.java} | 32 ++--- .../DatasourceFactory.java} | 24 ++-- .../Documents.java => datasource/Datasources.java} | 74 +++++------ .../DatasourcesSupplier.java} | 20 +-- .../datasource/DatasourceFactoryTest.java | 83 ++++++++++++ .../generator/datasource/DatasourceTest.java | 146 +++++++++++++++++++++ .../DatasourcesSupplierTest.java} | 20 +-- .../generator/datasource/DatasourcesTest.java | 117 +++++++++++++++++ .../{document => datasource}/UriTest.java | 2 +- .../generator/document/DocumentFactoryTest.java | 83 ------------ .../generator/document/DocumentTest.java | 146 --------------------- .../generator/document/DocumentsTest.java | 117 ----------------- freemarker-generator-cli/README.md | 85 ++++++------ freemarker-generator-cli/run-samples.sh | 6 +- .../org/apache/freemarker/generator/cli/Main.java | 8 +- .../freemarker/generator/cli/config/Suppliers.java | 6 +- .../generator/cli/task/FreeMarkerTask.java | 36 ++--- .../src/main/scripts/run-samples.sh | 6 +- .../freemarker/generator/cli/ExamplesTest.java | 6 +- .../freemarker/generator/cli/ManualTest.java | 6 +- .../src/test/templates/echo.ftl | 6 +- .../src/test/templates/tools/csv.ftl | 2 +- .../templates/accesslog/combined-access.ftl | 4 +- freemarker-generator-cli/templates/cat.ftl | 2 +- .../templates/csv/csv/gatling-user-credentials.ftl | 4 +- .../templates/csv/fo/transactions.ftl | 6 +- .../templates/csv/fo/transform.ftl | 2 +- .../templates/csv/html/transactions.ftl | 6 +- .../templates/csv/html/transform.ftl | 6 +- .../templates/csv/md/filter.ftl | 14 +- .../templates/csv/md/transform.ftl | 2 +- .../templates/csv/shell/curl.ftl | 2 +- .../templates/csv/transform.ftl | 6 +- freemarker-generator-cli/templates/demo.ftl | 28 ++-- .../templates/excel/csv/custom.ftl | 4 +- .../templates/excel/csv/transform.ftl | 4 +- .../templates/excel/html/transform.ftl | 10 +- .../templates/excel/md/transform.ftl | 8 +- .../templates/html/csv/dependencies.ftl | 6 +- freemarker-generator-cli/templates/info.ftl | 6 +- .../templates/json/csv/swagger-endpoints.ftl | 2 +- .../templates/json/md/github-users.ftl | 2 +- .../templates/properties/csv/locker-test-users.ftl | 4 +- .../templates/tsv/fo/transactions.ftl | 2 +- .../templates/xml/txt/recipients.ftl | 2 +- .../templates/yaml/txt/transform.ftl | 2 +- freemarker-generator-tools/README.md | 4 +- freemarker-generator-tools/pom.xml | 2 +- .../generator/tools/commonscsv/CommonsCSVTool.java | 20 +-- .../generator/tools/excel/ExcelTool.java | 12 +- .../generator/tools/jsonpath/JsonPathTool.java | 6 +- .../generator/tools/jsoup/JsoupTool.java | 10 +- .../generator/tools/properties/PropertiesTool.java | 8 +- .../generator/tools/snakeyaml/SnakeYamlTool.java | 8 +- .../freemarker/generator/tools/xml/XmlTool.java | 10 +- .../tools/commonscsv/CommonsCSVToolTest.java | 26 ++-- .../generator/tools/excel/ExcelToolTest.java | 10 +- .../tools/properties/PropertiesToolTest.java | 14 +- .../tools/snakeyaml/SnakeYamlToolTest.java | 14 +- .../generator/tools/xml/XmlToolTest.java | 14 +- 63 files changed, 670 insertions(+), 669 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a227d..4a91545 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. We try to a * [FREEMARKER-129] Migrate `freemarker-cli` into `freemarker-generator` project (see [https://github.com/sgoeschl/freemarker-cli](https://github.com/sgoeschl/freemarker-cli)) ### Changed +* [FREEMARKER-134] Rename `Document` to `Datasource * [FREEMARKER-129] Use `freemarker.configuration.setting` in `freemarker-cli.properties` to configure FreeMarker * [FREEMARKER-129] Provide a `toString()` metheod for all tools * [FREEMARKER-129] Use version "0.X.Y" to cater for API changes according to [Semantic Versioning](https://semver.org) @@ -24,4 +25,5 @@ All notable changes to this project will be documented in this file. We try to a [FREEMARKER-127]: https://issues.apache.org/jira/browse/FREEMARKER-127 [FREEMARKER-128]: https://issues.apache.org/jira/browse/FREEMARKER-128 -[FREEMARKER-129]: https://issues.apache.org/jira/browse/FREEMARKER-129 \ No newline at end of file +[FREEMARKER-129]: https://issues.apache.org/jira/browse/FREEMARKER-129 +[FREEMARKER-`134`]: https://issues.apache.org/jira/browse/FREEMARKER-134 \ No newline at end of file diff --git a/freemarker-generator-base/README.md b/freemarker-generator-base/README.md index 9dd180d..3a17212 100644 --- a/freemarker-generator-base/README.md +++ b/freemarker-generator-base/README.md @@ -2,8 +2,8 @@ This module provides common functionality for `freemarker-generator-cli` and `freemarker-generator-maven-plugin` such as -* Various implementation of `DataSources` -* Implementation of `Document` and utitity methods -* Creating `Documents` +* Various implementation of `javax.activation.DataSources` +* Implementation of `Datasource` and utitity methods +* Creating `Datasources` The code actually does not depend on Apache FreeMarker since it useful for other command line tools as well. \ No newline at end of file diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/FreeMarkerConstants.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/FreeMarkerConstants.java index ab6a11f..94508d1 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/FreeMarkerConstants.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/FreeMarkerConstants.java @@ -17,8 +17,8 @@ public class FreeMarkerConstants { /** Content type for binary data */ public static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; - /** Unknown length for a <code>Document </code> */ - public static final int DOCUMENT_UNKNOWN_LENGTH = -1; + /** Unknown length for a <code>Datasource</code> */ + public static final int DATASOURCE_UNKNOWN_LENGTH = -1; /** Default locale for rendering templates */ public static final Locale DEFAULT_LOCALE = US; @@ -59,7 +59,7 @@ public class FreeMarkerConstants { private Model() { } - public static final String DOCUMENTS = "Documents"; + public static final String DATASOURCES = "Datasources"; public static final String FREEMARKER_CLI_ARGS = "freemarker.cli.args"; public static final String FREEMARKER_LOCALE = "freemarker.locale"; diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Document.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/Datasource.java similarity index 87% rename from freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Document.java rename to freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/Datasource.java index 6fddd42..5de9cae 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Document.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/Datasource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.freemarker.generator.base.document; +package org.apache.freemarker.generator.base.datasource; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -35,31 +35,31 @@ import java.util.List; import static java.nio.charset.Charset.forName; import static java.util.Objects.requireNonNull; import static org.apache.commons.io.IOUtils.lineIterator; -import static org.apache.freemarker.generator.base.FreeMarkerConstants.DOCUMENT_UNKNOWN_LENGTH; +import static org.apache.freemarker.generator.base.FreeMarkerConstants.DATASOURCE_UNKNOWN_LENGTH; /** - * Source document which encapsulates a data source. When accessing - * content it is loaded on demand on not kept in memory to allow - * processing of large volumes of data. + * Datasource which encapsulates data to be used for rendering + * a template. When accessing content it is loaded on demand on not + * kept in memory to allow processing of large volumes of data. */ -public class Document implements Closeable { +public class Datasource implements Closeable { - /** Human-readable name of the document */ + /** Human-readable name of the datasource */ private final String name; /** Charset for directly accessing text-based content */ private final Charset charset; - /** The data source */ + /** The underlying "javax.activation.DataSource" */ private final DataSource dataSource; /** The location of the content, e.g. file name */ private final String location; - /** Collect all closables handed out to the caller to be closed when the document is closed itself */ + /** Collect all closables handed out to the caller to be closed when the datasource is closed itself */ private final CloseableReaper closables; - public Document(String name, DataSource dataSource, String location, Charset charset) { + public Datasource(String name, DataSource dataSource, String location, Charset charset) { this.name = requireNonNull(name); this.dataSource = requireNonNull(dataSource); this.location = requireNonNull(location); @@ -90,7 +90,7 @@ public class Document implements Closeable { /** * Try to get the length lazily, efficient and without consuming the input stream. * - * @return Length of document or UNKNOWN_LENGTH + * @return Length of datasource or UNKNOWN_LENGTH */ public long getLength() { if (dataSource instanceof FileDataSource) { @@ -100,12 +100,12 @@ public class Document implements Closeable { } else if (dataSource instanceof ByteArrayDataSource) { return ((ByteArrayDataSource) dataSource).length(); } else { - return DOCUMENT_UNKNOWN_LENGTH; + return DATASOURCE_UNKNOWN_LENGTH; } } /** - * Get an input stream which is closed together with this document. + * Get an input stream which is closed together with this datasource. * * @return InputStream * @throws IOException Operation failed @@ -193,8 +193,8 @@ public class Document implements Closeable { /** * Some tools create a {@link java.io.Closeable} which can bound to the - * lifecycle of the document. When the document is closed all the bound - * {@link java.io.Closeable} are closed as well. + * lifecycle of the datasource. When the datasource is closed all the + * associated {@link java.io.Closeable} are closed as well. * * @param closeable Closable * @param <T> Type of closable @@ -211,7 +211,7 @@ public class Document implements Closeable { @Override public String toString() { - return "Document{" + + return "Datasource{" + "name='" + name + '\'' + ", location=" + location + ", charset='" + charset + '\'' + diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/DocumentFactory.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/DatasourceFactory.java similarity index 75% rename from freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/DocumentFactory.java rename to freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/DatasourceFactory.java index de4ed51..c54aa4e 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/DocumentFactory.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/DatasourceFactory.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.freemarker.generator.base.document; +package org.apache.freemarker.generator.base.datasource; import org.apache.freemarker.generator.base.FreeMarkerConstants.Location; import org.apache.freemarker.generator.base.activation.ByteArrayDataSource; @@ -32,45 +32,45 @@ import java.nio.charset.Charset; import static java.nio.charset.StandardCharsets.UTF_8; /** - * Creates a document from various sources. + * Creates a Datasource from various sources. */ -public class DocumentFactory { +public class DatasourceFactory { - private DocumentFactory() { + private DatasourceFactory() { } - public static Document create(URL url) { + public static Datasource create(URL url) { final String location = url.getProtocol() + "://" + url.getHost(); final URLDataSource dataSource = new URLDataSource(url); return create(url.getHost(), dataSource, location, UTF_8); } - public static Document create(String name, String content) { + public static Datasource create(String name, String content) { final StringDataSource dataSource = new StringDataSource(name, content, UTF_8); return create(name, dataSource, Location.STRING, UTF_8); } - public static Document create(File file, Charset charset) { + public static Datasource create(File file, Charset charset) { final FileDataSource dataSource = new FileDataSource(file); return create(file.getName(), dataSource, file.getAbsolutePath(), charset); } - public static Document create(String name, byte[] content) { + public static Datasource create(String name, byte[] content) { final ByteArrayDataSource dataSource = new ByteArrayDataSource(name, content); return create(name, dataSource, Location.BYTES, UTF_8); } - public static Document create(String name, InputStream is, Charset charset) { + public static Datasource create(String name, InputStream is, Charset charset) { final InputStreamDataSource dataSource = new InputStreamDataSource(name, is); return create(name, dataSource, Location.INPUTSTREAM, charset); } - public static Document create(String name, InputStream is, String location, Charset charset) { + public static Datasource create(String name, InputStream is, String location, Charset charset) { final InputStreamDataSource dataSource = new InputStreamDataSource(name, is); return create(name, dataSource, location, charset); } - public static Document create(String name, DataSource dataSource, String location, Charset charset) { - return new Document(name, dataSource, location, charset); + public static Datasource create(String name, DataSource dataSource, String location, Charset charset) { + return new Datasource(name, dataSource, location, charset); } } diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Documents.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/Datasources.java similarity index 50% rename from freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Documents.java rename to freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/Datasources.java index c1c4680..51d2804 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Documents.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/Datasources.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.freemarker.generator.base.document; +package org.apache.freemarker.generator.base.datasource; import org.apache.freemarker.generator.base.util.ClosableUtils; @@ -27,98 +27,98 @@ import static java.util.stream.Collectors.toList; import static org.apache.commons.io.FilenameUtils.wildcardMatch; /** - * Container for documents with a couple of convenience functions to select - * a subset of documents. + * Container for datasources with a couple of convenience functions to select + * a subset of datasources. */ -public class Documents implements Closeable { +public class Datasources implements Closeable { - private final List<Document> documents; + private final List<Datasource> datasources; - public Documents(Collection<Document> documents) { - this.documents = new ArrayList<>(documents); + public Datasources(Collection<Datasource> datasources) { + this.datasources = new ArrayList<>(datasources); } /** - * Get the names of all documents. + * Get the names of all datasources. * - * @return document names + * @return datasource names */ public List<String> getNames() { - return documents.stream() - .map(Document::getName) + return datasources.stream() + .map(Datasource::getName) .collect(toList()); } public int size() { - return documents.size(); + return datasources.size(); } public boolean isEmpty() { - return documents.isEmpty(); + return datasources.isEmpty(); } - public Document getFirst() { - return documents.get(0); + public Datasource getFirst() { + return datasources.get(0); } - public List<Document> getList() { - return new ArrayList<>(documents); + public List<Datasource> getList() { + return new ArrayList<>(datasources); } - public Document get(int index) { - return documents.get(index); + public Datasource get(int index) { + return datasources.get(index); } - public boolean add(Document document) { - return documents.add(document); + public boolean add(Datasource datasource) { + return datasources.add(datasource); } - public Document remove(int index) { - return documents.remove(index); + public Datasource remove(int index) { + return datasources.remove(index); } /** - * Get exactly one document. If not exactly one document + * Get exactly one datasource. If not exactly one datasource * is found an exception is thrown. * - * @param name name of the document - * @return document + * @param name name of the datasource + * @return datasource */ - public Document get(String name) { - final List<Document> list = find(name); + public Datasource get(String name) { + final List<Datasource> list = find(name); if (list.isEmpty()) { - throw new IllegalArgumentException("Document not found : " + name); + throw new IllegalArgumentException("Datasource not found : " + name); } if (list.size() > 1) { - throw new IllegalArgumentException("More than one document found : " + name); + throw new IllegalArgumentException("More than one datasource found : " + name); } return list.get(0); } /** - * Find document based on theit name and globbing pattern. + * Find datasources based on their name and globbing pattern. * * @param wildcard globbing pattern - * @return list of mathching documents + * @return list of mathching datasources */ - public List<Document> find(String wildcard) { - return documents.stream() + public List<Datasource> find(String wildcard) { + return datasources.stream() .filter(d -> wildcardMatch(d.getName(), wildcard)) .collect(toList()); } @Override public void close() { - documents.forEach(ClosableUtils::closeQuietly); + datasources.forEach(ClosableUtils::closeQuietly); } @Override public String toString() { - return "Documents{" + - "documents=" + documents + + return "Datasources{" + + "datasources=" + datasources + '}'; } } diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/DocumentsSupplier.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/DatasourcesSupplier.java similarity index 81% rename from freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/DocumentsSupplier.java rename to freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/DatasourcesSupplier.java index e4b85a9..3e5a686 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/DocumentsSupplier.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/datasource/DatasourcesSupplier.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.freemarker.generator.base.document; +package org.apache.freemarker.generator.base.datasource; import org.apache.freemarker.generator.base.file.RecursiveFileSupplier; @@ -31,10 +31,10 @@ import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; /** - * Create a list of <code>Document</code> based on a list of sources consisting of + * Create a list of <code>Datasource</code> based on a list of sources consisting of * URLs, directories and files. */ -public class DocumentsSupplier implements Supplier<List<Document>> { +public class DatasourcesSupplier implements Supplier<List<Datasource>> { /** List of source files and/or directories */ private final Collection<String> sources; @@ -55,7 +55,7 @@ public class DocumentsSupplier implements Supplier<List<Document>> { * @param include Optional include pattern for resolving source files or directory * @param charset The charset for loading text files */ - public DocumentsSupplier(Collection<String> sources, String include, String exclude, Charset charset) { + public DatasourcesSupplier(Collection<String> sources, String include, String exclude, Charset charset) { this.sources = new ArrayList<>(sources); this.include = include; this.exclude = exclude; @@ -63,14 +63,14 @@ public class DocumentsSupplier implements Supplier<List<Document>> { } @Override - public List<Document> get() { + public List<Datasource> get() { return sources.stream() .map(this::get) .flatMap(Collection::stream) .collect(toList()); } - private List<Document> get(String source) { + private List<Datasource> get(String source) { if (isHttpUrl(source)) { return singletonList(resolveHttpUrl(source)); } else { @@ -78,13 +78,13 @@ public class DocumentsSupplier implements Supplier<List<Document>> { } } - private static Document resolveHttpUrl(String url) { - return DocumentFactory.create(toUrl(url)); + private static Datasource resolveHttpUrl(String url) { + return DatasourceFactory.create(toUrl(url)); } - private static List<Document> resolveFile(String source, String include, String exclude, Charset charset) { + private static List<Datasource> resolveFile(String source, String include, String exclude, Charset charset) { return fileResolver(source, include, exclude).get().stream() - .map(file -> DocumentFactory.create(file, charset)) + .map(file -> DatasourceFactory.create(file, charset)) .collect(toList()); } diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourceFactoryTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourceFactoryTest.java new file mode 100644 index 0000000..677f991 --- /dev/null +++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourceFactoryTest.java @@ -0,0 +1,83 @@ +/* + * 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.datasource; + +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourceFactory; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; + +public class DatasourceFactoryTest { + + private static final String ANY_TEXT = "Hello World"; + private static final String ANY_FILE_NAME = "pom.xml"; + private static final Charset ANY_CHAR_SET = UTF_8; + private static final File ANY_FILE = new File(ANY_FILE_NAME); + + @Test + public void shouldCreateFileBasedDatasource() throws IOException { + final Datasource datasource = DatasourceFactory.create(ANY_FILE, ANY_CHAR_SET); + + assertEquals(ANY_FILE_NAME, datasource.getName()); + assertEquals(UTF_8, datasource.getCharset()); + assertEquals(ANY_FILE.getAbsolutePath(), datasource.getLocation()); + assertTrue(!datasource.getLines().isEmpty()); + } + + @Test + public void shouldCreateStringBasedDatasource() throws IOException { + final Datasource datasource = DatasourceFactory.create("test.txt", ANY_TEXT); + + assertEquals("test.txt", datasource.getName()); + assertEquals(UTF_8, datasource.getCharset()); + assertEquals("string", datasource.getLocation()); + assertEquals(ANY_TEXT, datasource.getText()); + assertEquals(1, datasource.getLines().size()); + } + + @Test + public void shouldCreateByteArrayBasedDatasource() throws IOException { + final Datasource datasource = DatasourceFactory.create("test.txt", ANY_TEXT.getBytes(UTF_8)); + + assertEquals("test.txt", datasource.getName()); + assertEquals(UTF_8, datasource.getCharset()); + assertEquals("bytes", datasource.getLocation()); + assertEquals(ANY_TEXT, datasource.getText()); + assertEquals(1, datasource.getLines().size()); + } + + @Test + public void shouldCreateInputStreamBasedDatasource() throws IOException { + final InputStream is = new ByteArrayInputStream(ANY_TEXT.getBytes(UTF_8)); + final Datasource datasource = DatasourceFactory.create("test.txt", is, UTF_8); + + assertEquals("test.txt", datasource.getName()); + assertEquals(UTF_8, datasource.getCharset()); + assertEquals("inputstream", datasource.getLocation()); + assertEquals(ANY_TEXT, datasource.getText()); + } + +} diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourceTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourceTest.java new file mode 100644 index 0000000..878dd2c --- /dev/null +++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourceTest.java @@ -0,0 +1,146 @@ +/* + * 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.datasource; + +import org.apache.commons.io.LineIterator; +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourceFactory; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.Iterator; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class DatasourceTest { + + private static final String ANY_TEXT = "Hello World"; + private static final String ANY_FILE_NAME = "pom.xml"; + private static final Charset ANY_CHAR_SET = UTF_8; + private static final File ANY_FILE = new File(ANY_FILE_NAME); + + @Test + public void shouldSupportTextDatasource() throws IOException { + try (Datasource datasource = DatasourceFactory.create("stdin", ANY_TEXT)) { + assertEquals("stdin", datasource.getName()); + assertEquals("stdin", datasource.getBaseName()); + assertEquals("", datasource.getExtension()); + assertEquals("string", datasource.getLocation()); + assertEquals(UTF_8, datasource.getCharset()); + assertTrue(datasource.getLength() > 0); + assertEquals(ANY_TEXT, datasource.getText()); + } + } + + @Test + public void shouldSupportFileDatasource() throws IOException { + try (Datasource datasource = DatasourceFactory.create(ANY_FILE, ANY_CHAR_SET)) { + assertEquals(ANY_FILE_NAME, datasource.getName()); + assertEquals("pom", datasource.getBaseName()); + assertEquals("xml", datasource.getExtension()); + assertEquals(ANY_FILE.getAbsolutePath(), datasource.getLocation()); + assertEquals(Charset.defaultCharset(), datasource.getCharset()); + assertTrue(datasource.getLength() > 0); + assertFalse(datasource.getText().isEmpty()); + } + } + + @Ignore + @Test + public void shouldSupportUrlDatasource() throws IOException { + try (Datasource datasource = DatasourceFactory.create(new URL("https://google.com?foo=bar"))) { + assertEquals("google.com", datasource.getName()); + assertEquals("google", datasource.getBaseName()); + assertEquals("com", datasource.getExtension()); + assertEquals("https://google.com", datasource.getLocation()); + assertEquals(UTF_8, datasource.getCharset()); + assertEquals(-1, datasource.getLength()); + assertFalse(datasource.getText().isEmpty()); + } + } + + @Test + public void shouldSupportLineIterator() throws IOException { + try (Datasource datasource = textDatasource()) { + try (LineIterator iterator = datasource.getLineIterator(ANY_CHAR_SET.name())) { + assertEquals(1, count(iterator)); + } + } + } + + @Test + public void shouldReadLines() throws IOException { + try (Datasource datasource = textDatasource()) { + assertEquals(1, datasource.getLines().size()); + assertEquals(ANY_TEXT, datasource.getLines().get(0)); + } + } + + @Test + public void shouldGetBytes() throws IOException { + try (Datasource datasource = textDatasource()) { + assertEquals(11, datasource.getBytes().length); + } + } + + @Test + public void shouldCloseDatasource() { + final Datasource datasource = textDatasource(); + final TestClosable closable1 = datasource.addClosable(new TestClosable()); + final TestClosable closable2 = datasource.addClosable(new TestClosable()); + + datasource.close(); + + assertTrue(closable1.isClosed()); + assertTrue(closable2.isClosed()); + } + + private static int count(Iterator<String> iterator) { + int count = 0; + while (iterator.hasNext()) { + count++; + iterator.next(); + } + return count; + } + + private static Datasource textDatasource() { + return DatasourceFactory.create("stdin", ANY_TEXT); + } + + private static final class TestClosable implements Closeable { + + private boolean closed = false; + + @Override + public void close() throws IOException { + closed = true; + } + + public boolean isClosed() { + return closed; + } + } +} diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsSupplierTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourcesSupplierTest.java similarity index 85% rename from freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsSupplierTest.java rename to freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourcesSupplierTest.java index 2a87db1..d06f16f 100644 --- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsSupplierTest.java +++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourcesSupplierTest.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.freemarker.generator.document; +package org.apache.freemarker.generator.datasource; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentsSupplier; +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourcesSupplier; import org.junit.Test; import java.nio.charset.Charset; @@ -28,7 +28,7 @@ import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -public class DocumentsSupplierTest { +public class DatasourcesSupplierTest { private static final String NO_EXCLUDE = null; private static final String ANY_FILE = "./pom.xml"; @@ -85,8 +85,8 @@ public class DocumentsSupplierTest { @Test public void shouldResolveLargeDirectory() { - final List<Document> documents = supplier(".", null, null).get(); - assertFalse(documents.isEmpty()); + final List<Datasource> datasources = supplier(".", null, null).get(); + assertFalse(datasources.isEmpty()); } @Test(expected = RuntimeException.class) @@ -100,11 +100,11 @@ public class DocumentsSupplierTest { assertEquals(2, supplier(sources, "*.xml", null).get().size()); } - private static DocumentsSupplier supplier(String directory, String include, String exclude) { - return new DocumentsSupplier(singletonList(directory), include, exclude, Charset.defaultCharset()); + private static DatasourcesSupplier supplier(String directory, String include, String exclude) { + return new DatasourcesSupplier(singletonList(directory), include, exclude, Charset.defaultCharset()); } - private static DocumentsSupplier supplier(List<String> files, String include, String exclude) { - return new DocumentsSupplier(files, include, exclude, Charset.defaultCharset()); + private static DatasourcesSupplier supplier(List<String> files, String include, String exclude) { + return new DatasourcesSupplier(files, include, exclude, Charset.defaultCharset()); } } diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourcesTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourcesTest.java new file mode 100644 index 0000000..b580191 --- /dev/null +++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/DatasourcesTest.java @@ -0,0 +1,117 @@ +/* + * 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.datasource; + +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.junit.Test; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +public class DatasourcesTest { + + private static final String UNKNOWN = "unknown"; + private static final String ANY_TEXT = "Hello World"; + private static final String ANY_FILE_NAME = "pom.xml"; + private static final String ANY_FILE_EXTENSION = "xml"; + private static final File ANY_FILE = new File(ANY_FILE_NAME); + private static final String ANY_URL = "https://server.invalid?foo=bar"; + + @Test + public void shouldFindByWildcard() { + final Datasources datasources = datasources(); + + assertEquals(0, datasources.find(null).size()); + assertEquals(0, datasources.find("").size()); + assertEquals(0, datasources.find("*.bar").size()); + assertEquals(0, datasources.find("foo.*").size()); + assertEquals(0, datasources.find("foo.bar").size()); + + assertEquals(2, datasources.find("*.*").size()); + assertEquals(1, datasources.find("*." + ANY_FILE_EXTENSION).size()); + assertEquals(1, datasources.find("*.???").size()); + assertEquals(1, datasources.find("*om*").size()); + assertEquals(1, datasources.find("*o*.xml").size()); + + assertEquals(1, datasources.find(ANY_FILE_NAME).size()); + assertEquals(1, datasources.find(ANY_FILE_NAME.charAt(0) + "*").size()); + + assertEquals(3, datasources.find("*").size()); + } + + @Test + public void shouldGetDatasource() { + assertNotNull(datasources().get(ANY_FILE_NAME)); + } + + @Test + public void shouldGetAllDatasources() { + final Datasources datasources = datasources(); + + assertEquals("unknown", datasources().get(0).getName()); + assertEquals("pom.xml", datasources().get(1).getName()); + assertEquals("server.invalid", datasources().get(2).getName()); + assertEquals("unknown", datasources().getFirst().getName()); + assertEquals(3, datasources.getList().size()); + assertEquals(3, datasources.size()); + assertFalse(datasources.isEmpty()); + } + + @Test + public void shouldGetNames() { + assertEquals(asList("unknown", "pom.xml", "server.invalid"), datasources().getNames()); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionWhenGetDoesNotFindDatasource() { + datasources().get("file-does-not-exist"); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionWhenGetFindsMultipleDatasources() { + datasources().get("*"); + } + + private static Datasources datasources() { + return new Datasources(asList(textDatasource(), fileDatasource(), urlDatasource())); + } + + private static Datasource textDatasource() { + return DatasourceFactory.create(UNKNOWN, ANY_TEXT); + } + + private static Datasource fileDatasource() { + return DatasourceFactory.create(ANY_FILE, UTF_8); + } + + private static Datasource urlDatasource() { + try { + return DatasourceFactory.create(new URL(ANY_URL)); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } +} diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/UriTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/UriTest.java similarity index 98% rename from freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/UriTest.java rename to freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/UriTest.java index d6b66b1..bf5f865 100644 --- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/UriTest.java +++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/datasource/UriTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.freemarker.generator.document; +package org.apache.freemarker.generator.datasource; import org.junit.Test; diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentFactoryTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentFactoryTest.java deleted file mode 100644 index 172e0c6..0000000 --- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentFactoryTest.java +++ /dev/null @@ -1,83 +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.document; - -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; - -public class DocumentFactoryTest { - - private static final String ANY_TEXT = "Hello World"; - private static final String ANY_FILE_NAME = "pom.xml"; - private static final Charset ANY_CHAR_SET = UTF_8; - private static final File ANY_FILE = new File(ANY_FILE_NAME); - - @Test - public void shouldCreateFileBasedDocument() throws IOException { - final Document document = DocumentFactory.create(ANY_FILE, ANY_CHAR_SET); - - assertEquals(ANY_FILE_NAME, document.getName()); - assertEquals(UTF_8, document.getCharset()); - assertEquals(ANY_FILE.getAbsolutePath(), document.getLocation()); - assertTrue(!document.getLines().isEmpty()); - } - - @Test - public void shouldCreateStringBasedDocument() throws IOException { - final Document document = DocumentFactory.create("test.txt", ANY_TEXT); - - assertEquals("test.txt", document.getName()); - assertEquals(UTF_8, document.getCharset()); - assertEquals("string", document.getLocation()); - assertEquals(ANY_TEXT, document.getText()); - assertEquals(1, document.getLines().size()); - } - - @Test - public void shouldCreateByteArrayBasedDocument() throws IOException { - final Document document = DocumentFactory.create("test.txt", ANY_TEXT.getBytes(UTF_8)); - - assertEquals("test.txt", document.getName()); - assertEquals(UTF_8, document.getCharset()); - assertEquals("bytes", document.getLocation()); - assertEquals(ANY_TEXT, document.getText()); - assertEquals(1, document.getLines().size()); - } - - @Test - public void shouldCreateInputStreamBasedDocument() throws IOException { - final InputStream is = new ByteArrayInputStream(ANY_TEXT.getBytes(UTF_8)); - final Document document = DocumentFactory.create("test.txt", is, UTF_8); - - assertEquals("test.txt", document.getName()); - assertEquals(UTF_8, document.getCharset()); - assertEquals("inputstream", document.getLocation()); - assertEquals(ANY_TEXT, document.getText()); - } - -} diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentTest.java deleted file mode 100644 index 22d5952..0000000 --- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentTest.java +++ /dev/null @@ -1,146 +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.document; - -import org.apache.commons.io.LineIterator; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.Closeable; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.nio.charset.Charset; -import java.util.Iterator; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class DocumentTest { - - private static final String ANY_TEXT = "Hello World"; - private static final String ANY_FILE_NAME = "pom.xml"; - private static final Charset ANY_CHAR_SET = UTF_8; - private static final File ANY_FILE = new File(ANY_FILE_NAME); - - @Test - public void shouldSupportTextDocument() throws IOException { - try (Document document = DocumentFactory.create("stdin", ANY_TEXT)) { - assertEquals("stdin", document.getName()); - assertEquals("stdin", document.getBaseName()); - assertEquals("", document.getExtension()); - assertEquals("string", document.getLocation()); - assertEquals(UTF_8, document.getCharset()); - assertTrue(document.getLength() > 0); - assertEquals(ANY_TEXT, document.getText()); - } - } - - @Test - public void shouldSupportFileDocument() throws IOException { - try (Document document = DocumentFactory.create(ANY_FILE, ANY_CHAR_SET)) { - assertEquals(ANY_FILE_NAME, document.getName()); - assertEquals("pom", document.getBaseName()); - assertEquals("xml", document.getExtension()); - assertEquals(ANY_FILE.getAbsolutePath(), document.getLocation()); - assertEquals(Charset.defaultCharset(), document.getCharset()); - assertTrue(document.getLength() > 0); - assertFalse(document.getText().isEmpty()); - } - } - - @Ignore - @Test - public void shouldSupportUrlDocument() throws IOException { - try (Document document = DocumentFactory.create(new URL("https://google.com?foo=bar"))) { - assertEquals("google.com", document.getName()); - assertEquals("google", document.getBaseName()); - assertEquals("com", document.getExtension()); - assertEquals("https://google.com", document.getLocation()); - assertEquals(UTF_8, document.getCharset()); - assertEquals(-1, document.getLength()); - assertFalse(document.getText().isEmpty()); - } - } - - @Test - public void shouldSupportLineIterator() throws IOException { - try (Document document = textDocument()) { - try (LineIterator iterator = document.getLineIterator(ANY_CHAR_SET.name())) { - assertEquals(1, count(iterator)); - } - } - } - - @Test - public void shouldReadLines() throws IOException { - try (Document document = textDocument()) { - assertEquals(1, document.getLines().size()); - assertEquals(ANY_TEXT, document.getLines().get(0)); - } - } - - @Test - public void shouldGetBytes() throws IOException { - try (Document document = textDocument()) { - assertEquals(11, document.getBytes().length); - } - } - - @Test - public void shouldCloseDocument() { - final Document document = textDocument(); - final TestClosable closable1 = document.addClosable(new TestClosable()); - final TestClosable closable2 = document.addClosable(new TestClosable()); - - document.close(); - - assertTrue(closable1.isClosed()); - assertTrue(closable2.isClosed()); - } - - private static int count(Iterator<String> iterator) { - int count = 0; - while (iterator.hasNext()) { - count++; - iterator.next(); - } - return count; - } - - private static Document textDocument() { - return DocumentFactory.create("stdin", ANY_TEXT); - } - - private static final class TestClosable implements Closeable { - - private boolean closed = false; - - @Override - public void close() throws IOException { - closed = true; - } - - public boolean isClosed() { - return closed; - } - } -} diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsTest.java deleted file mode 100644 index 5c7f90a..0000000 --- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsTest.java +++ /dev/null @@ -1,117 +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.document; - -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; -import org.apache.freemarker.generator.base.document.Documents; -import org.junit.Test; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -public class DocumentsTest { - - private static final String UNKNOWN = "unknown"; - private static final String ANY_TEXT = "Hello World"; - private static final String ANY_FILE_NAME = "pom.xml"; - private static final String ANY_FILE_EXTENSION = "xml"; - private static final File ANY_FILE = new File(ANY_FILE_NAME); - private static final String ANY_URL = "https://server.invalid?foo=bar"; - - @Test - public void shouldFindByWildcard() { - final Documents documents = documents(); - - assertEquals(0, documents.find(null).size()); - assertEquals(0, documents.find("").size()); - assertEquals(0, documents.find("*.bar").size()); - assertEquals(0, documents.find("foo.*").size()); - assertEquals(0, documents.find("foo.bar").size()); - - assertEquals(2, documents.find("*.*").size()); - assertEquals(1, documents.find("*." + ANY_FILE_EXTENSION).size()); - assertEquals(1, documents.find("*.???").size()); - assertEquals(1, documents.find("*om*").size()); - assertEquals(1, documents.find("*o*.xml").size()); - - assertEquals(1, documents.find(ANY_FILE_NAME).size()); - assertEquals(1, documents.find(ANY_FILE_NAME.charAt(0) + "*").size()); - - assertEquals(3, documents.find("*").size()); - } - - @Test - public void shouldGetDocument() { - assertNotNull(documents().get(ANY_FILE_NAME)); - } - - @Test - public void shouldGetAllDocuments() { - final Documents documents = documents(); - - assertEquals("unknown", documents().get(0).getName()); - assertEquals("pom.xml", documents().get(1).getName()); - assertEquals("server.invalid", documents().get(2).getName()); - assertEquals("unknown", documents().getFirst().getName()); - assertEquals(3, documents.getList().size()); - assertEquals(3, documents.size()); - assertFalse(documents.isEmpty()); - } - - @Test - public void shouldGetNames() { - assertEquals(asList("unknown", "pom.xml", "server.invalid"), documents().getNames()); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionWhenGetDoesNotFindDocument() { - documents().get("file-does-not-exist"); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionWhenGetFindsMultipleDocuments() { - documents().get("*"); - } - - private static Documents documents() { - return new Documents(asList(textDocument(), fileDocument(), urlDocument())); - } - - private static Document textDocument() { - return DocumentFactory.create(UNKNOWN, ANY_TEXT); - } - - private static Document fileDocument() { - return DocumentFactory.create(ANY_FILE, UTF_8); - } - - private static Document urlDocument() { - try { - return DocumentFactory.create(new URL(ANY_URL)); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/freemarker-generator-cli/README.md b/freemarker-generator-cli/README.md index 06b7680..5bdee27 100644 --- a/freemarker-generator-cli/README.md +++ b/freemarker-generator-cli/README.md @@ -58,7 +58,7 @@ Some years later the not-so-small-any-longer-and-not-having-tests Groovy script * Support transformation of HTML using [JSoup](https://jsoup.org) * Support transformation of structured logfiles using [Grok](https://github.com/thekrakken/java-grok) * XML & XPath is supported by FreeMarker [out-of-the-box](http://freemarker.org/docs/xgui.html) -* Support for reading document content from STDIN to integrate with command line tools +* Support for reading a datasource content from STDIN to integrate with command line tools * Support execution of arbitrary commands using [Apache Commons Exec](https://commons.apache.org/proper/commons-exec/) * Add some commonly useful information such as `System Properties`, `Enviroment Variables` * Support embedding the code in existing applications @@ -106,7 +106,7 @@ FreeMarker CLI Tools - XmlTool : Process XML files using Apache FreeMarker (see https://freemarker.apache.org/docs/xgui.html) - YamlTool : Process YAML files using SnakeYAML(see https://bitbucket.org/asomov/snakeyaml/wiki/Home) -FreeMarker CLI Documents +FreeMarker CLI Datasources --------------------------------------------------------------------------- User Supplied Parameters @@ -255,7 +255,7 @@ or pipe a cURL response ```text <#ftl output_format="plainText" > -<#assign json = JsonPathTool.parse(Documents.get(0))> +<#assign json = JsonPathTool.parse(Datasources.get(0))> <#assign users = json.read("$[*]")> <#---------------------------------------------------------------------------> # GitHub Users @@ -293,7 +293,7 @@ The FreeMarker template is shown below ```text <#ftl output_format="plainText"> <#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader()> -<#assign csvParser = CSVTool.parse(Documents.get(0), cvsFormat)> +<#assign csvParser = CSVTool.parse(Datasources.get(0), cvsFormat)> <#assign csvHeaders = csvParser.getHeaderMap()?keys> <#assign csvRecords = csvParser.records> <#---------------------------------------------------------------------------> @@ -330,7 +330,7 @@ using the following template ```text <#ftl output_format="plainText" > -<#assign xml = XmlTool.parse(Documents.get(0))> +<#assign xml = XmlTool.parse(Datasources.get(0))> <#list xml.recipients.person as recipient> To: ${recipient.name} ${recipient.address} @@ -377,7 +377,7 @@ One day I was asked a to prepare a CSV files containing REST endpoints described ```text <#ftl output_format="plainText" strip_text="true"> -<#assign json = JsonPathTool.parse(Documents.get(0))> +<#assign json = JsonPathTool.parse(Datasources.get(0))> <#assign basePath = json.read("$.basePath")> <#assign paths = json.read("$.paths")> @@ -439,15 +439,15 @@ The provided FTL transforms an Excel into a HTML document supporting multiple Ex ```text <#ftl output_format="HTML" > -<#assign document = Documents.get(0)> -<#assign documentName = document.name> -<#assign workbook = ExcelTool.parse(document)> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> +<#assign workbook = ExcelTool.parse(datasource)> <#assign date = .now?iso_utc> <#---------------------------------------------------------------------------> <!DOCTYPE html> <html> <head> - <title>${documentName}</title> + <title>${name}</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> @@ -455,7 +455,7 @@ The provided FTL transforms an Excel into a HTML document supporting multiple Ex <body> <div class="container-fluid"> <h1>Excel Test - <small>${documentName}, ${date}</small> + <small>${name}, ${date}</small> </h1> <@writeSheets workbook/> </div> @@ -535,8 +535,8 @@ The FTL uses a couple of interesting features <#ftl output_format="plainText" strip_text="true"> <#compress> TENANT,SITE,USER_ID,DISPOSER_ID,PASSWORD,SMS_OTP,NAME,DESCRIPTION - <#list Documents.list as document> - <#assign properties = PropertiesTool.parse(document)> + <#list Datasources.list as datasource> + <#assign properties = PropertiesTool.parse(datasource)> <#assign environments = properties["ENVIRONMENTS"]!""> <#assign tenant = extractTenant(environments)> <#assign site = extractSite(environments)> @@ -565,10 +565,10 @@ For a POC (proof of concept) I created a sample transformation from CSV to XML-F ```text <#ftl output_format="XML" > -<#assign document = Documents.get(0)> -<#assign name = document.name> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> <#assign cvsFormat = CSVTool.formats.DEFAULT.withDelimiter('\t').withHeader()> -<#assign csvParser = CSVTool.parse(document, cvsFormat)> +<#assign csvParser = CSVTool.parse(datasource, cvsFormat)> <#assign csvHeaders = csvParser.getHeaderMap()?keys> <#assign csvRecords = csvParser.records> <#---------------------------------------------------------------------------> @@ -686,9 +686,8 @@ Recently I got the rather unusual question how to determine the list of dependen ```text <#ftl output_format="plainText" strip_text="true"> -<#assign document = Documents.get(0)> -<#assign documentName = document.name> -<#assign html = JsoupTool.parse(document)> +<#assign datasource = Datasources.get(0)> +<#assign html = JsoupTool.parse(datasource)> <#compress> <@writeHeader/> @@ -762,7 +761,7 @@ and the final FTL is found below ```text <#ftl output_format="plainText"> <#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader()> -<#assign csvParser = CSVTool.parse(Documents.get(0), cvsFormat)> +<#assign csvParser = CSVTool.parse(Datasources.get(0), cvsFormat)> <#assign records = csvParser.records> <#assign csvMap = CSVTool.toMap(records, "disposer")> <#---------------------------------------------------------------------------> @@ -846,8 +845,8 @@ using the following FreeMarker template ```text <#ftl output_format="plainText" strip_whitespace=true> <#assign grok = GrokTool.compile("%{COMBINEDAPACHELOG}")> -<#assign document = Documents.get(0)> -<#assign lines = document.getLineIterator()> +<#assign datasource = Datasources.get(0)> +<#assign lines = datasource.getLineIterator()> <#compress> TIMESTAMP;VERB;REQUEST;HTTPVERSION @@ -865,7 +864,7 @@ using the following FreeMarker template While this looks small and tidy there are some nifty features * `GrokTool.compile("%{COMBINEDAPACHELOG}")` builds the `Grok` instance to parse access logs in `Combined Format` -* The source document is streamed line by line and not loaded into memory in one piece +* The datasource is streamed line by line and not loaded into memory in one piece * This also works for using `stdin` so are able to parse GB of access log or other files ## 6.11 CSV Transformation @@ -878,7 +877,7 @@ renders the following template ```text <#ftl output_format="plainText" strip_text="true"> -<#assign csvParser = createCsvParser(Documents.get(0))> +<#assign csvParser = createCsvParser(Datasources.get(0))> <#assign csvPrinter = createCsvPrinter()> <#-- Print each line without materializing the CSV in memory --> <#compress> @@ -887,11 +886,11 @@ renders the following template </#list> </#compress> -<#function createCsvParser document> +<#function createCsvParser datasource> <#assign initialCvsInFormat = CSVTool.formats[SystemTool.getParameter("csv.in.format", "DEFAULT")]> <#assign csvInDelimiter = CSVTool.toDelimiter(SystemTool.getParameter("csv.in.delimiter", initialCvsInFormat.getDelimiter()))> <#assign cvsInFormat = initialCvsInFormat.withDelimiter(csvInDelimiter)> - <#return CSVTool.parse(document, cvsInFormat)> + <#return CSVTool.parse(datasource, cvsInFormat)> </#function> <#function createCsvPrinter> @@ -981,13 +980,13 @@ Sometime you need to apply a CSS, JSON or XPath query in ad ad-hoc way without i > bin/freemarker-cli -i 'Hello ${SystemTool.envs["USER"]}'; echo Hello sgoeschl -> bin/freemarker-cli -i '${JsonPathTool.parse(Documents.first).read("$.info.title")}' site/sample/json/swagger-spec.json; echo +> bin/freemarker-cli -i '${JsonPathTool.parse(Datasources.first).read("$.info.title")}' site/sample/json/swagger-spec.json; echo Swagger Petstore -> bin/freemarker-cli -i '${XmlTool.parse(Documents.first)["recipients/person[1]/name"]}' site/sample/xml/recipients.xml; echo +> bin/freemarker-cli -i '${XmlTool.parse(Datasources.first)["recipients/person[1]/name"]}' site/sample/xml/recipients.xml; echo John Smith -> bin/freemarker-cli -i '${JsoupTool.parse(Documents.first).select("a")[0]}' site/sample/html/dependencies.html; echo +> bin/freemarker-cli -i '${JsoupTool.parse(Datasources.first).select("a")[0]}' site/sample/html/dependencies.html; echo <a href="${project.url}" title="FreeMarker CLI">FreeMarker CLI</a> > ./bin/freemarker-cli -i '<#list SystemTool.envs as name,value>${name} ==> > ${value}${"\n"}</#list>' @@ -1016,8 +1015,8 @@ and Apache FreeMarker template ```text <#ftl output_format="plainText" strip_text="true"> -<#assign document = Documents.get(0)> -<#assign parser = parser(document)> +<#assign datasource = Datasources.get(0)> +<#assign parser = parser(datasource)> <#assign headers = parser.getHeaderNames()> <#assign column = SystemTool.getProperty("column")> <#assign values = SystemTool.getProperty("values")?split(",")> @@ -1025,7 +1024,7 @@ and Apache FreeMarker template <#-- Process each line without materializing the whole file in memory --> <#compress> - <@writePageHeader document/> + <@writePageHeader datasource/> <#list parser.iterator() as record> <#if filter(record)> <@writeCsvRecord headers record/> @@ -1033,18 +1032,18 @@ and Apache FreeMarker template </#list> </#compress> -<#function parser document> +<#function parser datasource> <#assign format = CSVTool.formats[SystemTool.getProperty("format", "DEFAULT")]> <#assign delimiter = CSVTool.toDelimiter(SystemTool.getProperty("delimiter", format.getDelimiter()))> - <#return CSVTool.parse(document, format.withFirstRecordAsHeader().withDelimiter(delimiter))> + <#return CSVTool.parse(datasource, format.withFirstRecordAsHeader().withDelimiter(delimiter))> </#function> <#function filter record> <#return values?seq_contains(record.get(column))> </#function> -<#macro writePageHeader document> - # ${document.name} +<#macro writePageHeader datasource> + # ${datasource.name} </#macro> <#macro writeCsvRecord headers record> @@ -1189,13 +1188,13 @@ user.home : /Users/sgoeschl - java.vendor.url ==> http://java.oracle.com/ - java.vm.name ==> Java HotSpot(TM) 64-Bit Server VM -11) Access Documents +11) Access Datasources --------------------------------------------------------------------------- -Get the number of documents: +Get the number of datasources: - 0 List all files containing "README" in the name List all files having "md" extension -Get all documents +Get all datasources 12) FreeMarker CLI Tools --------------------------------------------------------------------------- @@ -1215,7 +1214,7 @@ Get all documents 13) Document Data Model --------------------------------------------------------------------------- - CSVTool -- Documents +- Datasources - ExcelTool - ExecTool - FreeMarkerTool @@ -1255,19 +1254,19 @@ Sat Feb 22 16:54:20 CET 2020 ## 7.1 How It Works * The user-supplied files are loaded or input is read from `stdin` -* The FreeMarker data model containing the documents and tools is created and passed to the template +* The FreeMarker data model containing the datasources and tools is created and passed to the template * The generated output is written to the user-supplied file or to `stdout` ## 7.2 FreeMarker Data Model -Within the script a FreeMarker data model is set up and passed to the template - it contains the documents to be processed and the following tools +Within the script a FreeMarker data model is set up and passed to the template - it contains the datasources to be processed and the following tools | Entry | Description | |-----------------------|-----------------------------------------------------------------------------------------------------------| | CSVTool | Process CSV files using [Apache Commons CSV](https://commons.apache.org/proper/commons-csv/) | | ExecTool | Execute command line tools using [Apache Commons Exec](https://commons.apache.org/proper/commons-exec/) | | ExcelTool | Process Excels files (XLS, XLSX) using [Apache POI](https://poi.apache.org) | -| Documents | Helper class to find documents, e.g. by name, extension or index | +| Datasources | Helper class to find datasources, e.g. by name, extension or index | | FreeMarkerTool | Expose useful FreeMarker classes | | GrokTool | Process text files using [Grok](https://github.com/thekrakken/java-grok) instead of regular expressions | | JsonPathTool | Process JSON file using [Java JSON Path](https://github.com/json-path/JsonPath) | diff --git a/freemarker-generator-cli/run-samples.sh b/freemarker-generator-cli/run-samples.sh index 4e0e867..1bc86d2 100755 --- a/freemarker-generator-cli/run-samples.sh +++ b/freemarker-generator-cli/run-samples.sh @@ -46,9 +46,9 @@ $FREEMARKER_CMD -t templates/demo.ftl README.md > target/out/demo.txt || { echo # Interactive Mode ############################################################################# -$FREEMARKER_CMD -i '${JsonPathTool.parse(Documents.first).read("$.info.title")}' site/sample/json/swagger-spec.json > target/out/interactive-json.txt || { echo >&2 "Test failed. Aborting."; exit 1; } -$FREEMARKER_CMD -i '${XmlTool.parse(Documents.first)["recipients/person[1]/name"]}' site/sample/xml/recipients.xml > target/out/interactive-xml.txt || { echo >&2 "Test failed. Aborting."; exit 1; } -$FREEMARKER_CMD -i '${JsoupTool.parse(Documents.first).select("a")[0]}' site/sample/html/dependencies.html > target/out/interactive-html.txt || { echo >&2 "Test failed. Aborting."; exit 1; } +$FREEMARKER_CMD -i '${JsonPathTool.parse(Datasources.first).read("$.info.title")}' site/sample/json/swagger-spec.json > target/out/interactive-json.txt || { echo >&2 "Test failed. Aborting."; exit 1; } +$FREEMARKER_CMD -i '${XmlTool.parse(Datasources.first)["recipients/person[1]/name"]}' site/sample/xml/recipients.xml > target/out/interactive-xml.txt || { echo >&2 "Test failed. Aborting."; exit 1; } +$FREEMARKER_CMD -i '${JsoupTool.parse(Datasources.first).select("a")[0]}' site/sample/html/dependencies.html > target/out/interactive-html.txt || { echo >&2 "Test failed. Aborting."; exit 1; } ############################################################################# # CSV diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java index 5b7ac9b..82dbc6f 100644 --- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java +++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java @@ -67,7 +67,7 @@ public class Main implements Callable<Integer> { @Option(names = { "-D", "--system-property" }, description = "Set system property") private Properties systemProperties; - @Option(names = { "-e", "--input-encoding" }, description = "Encoding of input documents", defaultValue = "UTF-8") + @Option(names = { "-e", "--input-encoding" }, description = "Encoding of datasource", defaultValue = "UTF-8") private String inputEncoding; @Option(names = { "-E", "--expose-env" }, description = "Expose environment variables and user-supplied properties globally") @@ -85,16 +85,16 @@ public class Main implements Callable<Integer> { @Option(names = { "--config" }, defaultValue = FREEMARKER_CLI_PROPERTY_FILE, description = "FreeMarker CLI configuration file") private String configFile; - @Option(names = { "--include" }, description = "File pattern for document input directory") + @Option(names = { "--include" }, description = "File pattern for datasource input directory") private String include; - @Option(names = { "--exclude" }, description = "File pattern for document input directory") + @Option(names = { "--exclude" }, description = "File pattern for datasource input directory") private String exclude; @Option(names = { "--output-encoding" }, description = "Encoding of output, e.g. UTF-8", defaultValue = "UTF-8") private String outputEncoding; - @Option(names = { "--stdin" }, description = "Read input document from stdin") + @Option(names = { "--stdin" }, description = "Read datasource from stdin") private boolean readFromStdin; @Option(names = { "--times" }, defaultValue = "1", description = "Re-run X times for profiling") 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 084be3d..7d2f5f1 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 @@ -1,7 +1,7 @@ package org.apache.freemarker.generator.cli.config; import freemarker.cache.TemplateLoader; -import org.apache.freemarker.generator.base.document.DocumentsSupplier; +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; @@ -33,8 +33,8 @@ public class Suppliers { return new ToolsSupplier(settings.getConfiguration(), settings.toMap()); } - public static DocumentsSupplier documentsSupplier(Settings settings) { - return new DocumentsSupplier(settings.getSources(), + public static DatasourcesSupplier datasourcesSupplier(Settings settings) { + return new DatasourcesSupplier(settings.getSources(), settings.getInclude(), settings.getExclude(), settings.getInputEncoding()); 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 c09faae..f537309 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 @@ -20,9 +20,9 @@ import freemarker.template.Configuration; import freemarker.template.Template; import org.apache.commons.io.FileUtils; import org.apache.freemarker.generator.base.FreeMarkerConstants.Location; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; -import org.apache.freemarker.generator.base.document.Documents; +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.cli.config.Settings; import java.io.File; @@ -38,9 +38,9 @@ import java.util.function.Supplier; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; import static org.apache.freemarker.generator.base.FreeMarkerConstants.Location.STDIN; -import static org.apache.freemarker.generator.base.FreeMarkerConstants.Model.DOCUMENTS; +import static org.apache.freemarker.generator.base.FreeMarkerConstants.Model.DATASOURCES; import static org.apache.freemarker.generator.cli.config.Suppliers.configurationSupplier; -import static org.apache.freemarker.generator.cli.config.Suppliers.documentsSupplier; +import static org.apache.freemarker.generator.cli.config.Suppliers.datasourcesSupplier; import static org.apache.freemarker.generator.cli.config.Suppliers.toolsSupplier; /** @@ -52,28 +52,28 @@ public class FreeMarkerTask implements Callable<Integer> { private final Settings settings; private final Supplier<Map<String, Object>> toolsSupplier; - private final Supplier<List<Document>> documentsSupplier; + private final Supplier<List<Datasource>> datasourcesSupplier; private final Supplier<Configuration> configurationSupplier; public FreeMarkerTask(Settings settings) { - this(settings, toolsSupplier(settings), documentsSupplier(settings), configurationSupplier(settings)); + this(settings, toolsSupplier(settings), datasourcesSupplier(settings), configurationSupplier(settings)); } public FreeMarkerTask(Settings settings, Supplier<Map<String, Object>> toolsSupplier, - Supplier<List<Document>> documentsSupplier, + Supplier<List<Datasource>> datasourcesSupplier, Supplier<Configuration> configurationSupplier) { this.settings = requireNonNull(settings); this.toolsSupplier = requireNonNull(toolsSupplier); - this.documentsSupplier = requireNonNull(documentsSupplier); + this.datasourcesSupplier = requireNonNull(datasourcesSupplier); this.configurationSupplier = requireNonNull(configurationSupplier); } @Override public Integer call() { final Template template = template(settings, configurationSupplier); - try (Writer writer = settings.getWriter(); Documents documents = documents(settings, documentsSupplier)) { - final Map<String, Object> dataModel = dataModel(settings, documents, toolsSupplier); + try (Writer writer = settings.getWriter(); Datasources datasources = datasources(settings, datasourcesSupplier)) { + final Map<String, Object> dataModel = dataModel(settings, datasources, toolsSupplier); template.process(dataModel, writer); return SUCCESS; } catch (RuntimeException e) { @@ -83,16 +83,16 @@ public class FreeMarkerTask implements Callable<Integer> { } } - private static Documents documents(Settings settings, Supplier<List<Document>> documentsSupplier) { - final List<Document> documents = new ArrayList<>(documentsSupplier.get()); + private static Datasources datasources(Settings settings, Supplier<List<Datasource>> datasourcesSupplier) { + final List<Datasource> datasources = new ArrayList<>(datasourcesSupplier.get()); - // Add optional document from STDIN at the start of the list since + // Add optional datasource from STDIN at the start of the list since // this allows easy sequence slicing in FreeMarker. if (settings.isReadFromStdin()) { - documents.add(0, DocumentFactory.create(STDIN, System.in, STDIN, UTF_8)); + datasources.add(0, DatasourceFactory.create(STDIN, System.in, STDIN, UTF_8)); } - return new Documents(documents); + return new Datasources(datasources); } /** @@ -122,10 +122,10 @@ public class FreeMarkerTask implements Callable<Integer> { } } - private static Map<String, Object> dataModel(Settings settings, Documents documents, Supplier<Map<String, Object>> tools) { + private static Map<String, Object> dataModel(Settings settings, Datasources datasources, Supplier<Map<String, Object>> tools) { final Map<String, Object> dataModel = new HashMap<>(); - dataModel.put(DOCUMENTS, documents); + dataModel.put(DATASOURCES, datasources); if (settings.isEnvironmentExposed()) { // add all system & user-supplied properties as top-level entries diff --git a/freemarker-generator-cli/src/main/scripts/run-samples.sh b/freemarker-generator-cli/src/main/scripts/run-samples.sh index cf192cc..a751cc5 100755 --- a/freemarker-generator-cli/src/main/scripts/run-samples.sh +++ b/freemarker-generator-cli/src/main/scripts/run-samples.sh @@ -46,9 +46,9 @@ $FREEMARKER_CMD -t templates/demo.ftl README.md > target/out/demo.txt || { echo # Interactive Mode ############################################################################# -$FREEMARKER_CMD -i '${JsonPathTool.parse(Documents.first).read("$.info.title")}' site/sample/json/swagger-spec.json > target/out/interactive-json.txt || { echo >&2 "Test failed. Aborting."; exit 1; } -$FREEMARKER_CMD -i '${XmlTool.parse(Documents.first)["recipients/person[1]/name"]}' site/sample/xml/recipients.xml > target/out/interactive-xml.txt || { echo >&2 "Test failed. Aborting."; exit 1; } -$FREEMARKER_CMD -i '${JsoupTool.parse(Documents.first).select("a")[0]}' site/sample/html/dependencies.html > target/out/interactive-html.txt || { echo >&2 "Test failed. Aborting."; exit 1; } +$FREEMARKER_CMD -i '${JsonPathTool.parse(Datasources.first).read("$.info.title")}' site/sample/json/swagger-spec.json > target/out/interactive-json.txt || { echo >&2 "Test failed. Aborting."; exit 1; } +$FREEMARKER_CMD -i '${XmlTool.parse(Datasources.first)["recipients/person[1]/name"]}' site/sample/xml/recipients.xml > target/out/interactive-xml.txt || { echo >&2 "Test failed. Aborting."; exit 1; } +$FREEMARKER_CMD -i '${JsoupTool.parse(Datasources.first).select("a")[0]}' site/sample/html/dependencies.html > target/out/interactive-html.txt || { echo >&2 "Test failed. Aborting."; exit 1; } ############################################################################# # CSV diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java index 6e152dd..e5fa6ac 100644 --- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java +++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java @@ -102,9 +102,9 @@ public class ExamplesTest extends AbstractMainTest { @Test public void shouldRunInteractiveTemplateExamples() throws IOException { - assertValid(execute("-i ${JsonPathTool.parse(Documents.first).read(\"$.info.title\")} site/sample/json/swagger-spec.json")); - assertValid(execute("-i ${XmlTool.parse(Documents.first)[\"recipients/person[1]/name\"]} site/sample/xml/recipients.xml")); - assertValid(execute("-i ${JsoupTool.parse(Documents.first).select(\"a\")[0]} site/sample/html/dependencies.html")); + assertValid(execute("-i ${JsonPathTool.parse(Datasources.first).read(\"$.info.title\")} site/sample/json/swagger-spec.json")); + assertValid(execute("-i ${XmlTool.parse(Datasources.first)[\"recipients/person[1]/name\"]} site/sample/xml/recipients.xml")); + assertValid(execute("-i ${JsoupTool.parse(Datasources.first).select(\"a\")[0]} site/sample/html/dependencies.html")); } @Test diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java index 81f47eb..35b1069 100644 --- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java +++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java @@ -30,9 +30,9 @@ public class ManualTest { // private static final String CMD = "-b ./src/test -DFOO=foo -PBAR=bar -t templates/demo.ftl site/sample/csv/transactions.csv"; // private static final String CMD = "-b ./src/test -Dcsv.out.format=TDF -t templates/csv/transform.ftl site/sample/csv/contract.csv"; // private static final String CMD = "-t templates/excel/csv/transform.ftl -l de_AT site/sample/excel/test.xlsx"; - // private static final String CMD = "-i ${JsonPathTool.parse(Documents.first).read('$.info.title')} site/sample/json/swagger-spec.json"; - // private static final String CMD = "-i ${XmlTool.parse(Documents.first)['recipients/person[1]/name']} site/sample/xml/recipients.xml"; - // private static final String CMD = "-i ${JsoupTool.parse(Documents.first).select('a')[0]} site/sample/html/dependencies.html"; + // private static final String CMD = "-i ${JsonPathTool.parse(Datasources.first).read('$.info.title')} site/sample/json/swagger-spec.json"; + // private static final String CMD = "-i ${XmlTool.parse(Datasources.first)['recipients/person[1]/name']} site/sample/xml/recipients.xml"; + // private static final String CMD = "-i ${JsoupTool.parse(Datasources.first).select('a')[0]} site/sample/html/dependencies.html"; // private static final String CMD = "-b ./src/test -t templates/properties/csv/locker-test-users.ftl site/sample/properties"; // private static final String CMD = "-b ./src/test -e UTF-8 -l de_AT -Dcolumn=Order%20ID -Dvalues=226939189,957081544 -Dformat=DEFAULT -Ddelimiter=COMMA -t templates/csv/md/filter.ftl site/sample/csv/sales-records.csv"; private static final String CMD = "-E -b ./src/test -t templates/environment.ftl"; diff --git a/freemarker-generator-cli/src/test/templates/echo.ftl b/freemarker-generator-cli/src/test/templates/echo.ftl index 3499bb0..bbd148f 100644 --- a/freemarker-generator-cli/src/test/templates/echo.ftl +++ b/freemarker-generator-cli/src/test/templates/echo.ftl @@ -15,8 +15,8 @@ specific language governing permissions and limitations under the License. --> -<#list Documents.list as document> -${document.name}, ${document.location} +<#list Datasources.list as datasource> +${datasource.name}, ${datasource.location} ============================================================================= -${document.text} +${datasource.text} </#list> \ No newline at end of file diff --git a/freemarker-generator-cli/src/test/templates/tools/csv.ftl b/freemarker-generator-cli/src/test/templates/tools/csv.ftl index 93b53f8..d069b57 100644 --- a/freemarker-generator-cli/src/test/templates/tools/csv.ftl +++ b/freemarker-generator-cli/src/test/templates/tools/csv.ftl @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. --> -<#assign records = CSVTool.parse(Documents.get(0), CSVFormat.DEFAULT.withHeader()).records> +<#assign records = CSVTool.parse(Datasources.get(0), CSVFormat.DEFAULT.withHeader()).records> CSVTool.toMap(name) ============================================================================= diff --git a/freemarker-generator-cli/templates/accesslog/combined-access.ftl b/freemarker-generator-cli/templates/accesslog/combined-access.ftl index fbcb71e..817ec59 100644 --- a/freemarker-generator-cli/templates/accesslog/combined-access.ftl +++ b/freemarker-generator-cli/templates/accesslog/combined-access.ftl @@ -16,8 +16,8 @@ under the License. --> <#assign grok = GrokTool.compile("%{COMBINEDAPACHELOG}")> -<#assign document = Documents.get(0)> -<#assign lines = document.getLineIterator()> +<#assign datasource = Datasources.get(0)> +<#assign lines = datasource.getLineIterator()> <#compress> TIMESTAMP;VERB;REQUEST;HTTPVERSION diff --git a/freemarker-generator-cli/templates/cat.ftl b/freemarker-generator-cli/templates/cat.ftl index 77fd4c2..820e4ff 100644 --- a/freemarker-generator-cli/templates/cat.ftl +++ b/freemarker-generator-cli/templates/cat.ftl @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. --> -<#assign lines = Documents.get(0).getLineIterator()> +<#assign lines = Datasources.get(0).getLineIterator()> <#compress> <#list lines as line> ${line} diff --git a/freemarker-generator-cli/templates/csv/csv/gatling-user-credentials.ftl b/freemarker-generator-cli/templates/csv/csv/gatling-user-credentials.ftl index 3cfe9e8..19bb9b9 100644 --- a/freemarker-generator-cli/templates/csv/csv/gatling-user-credentials.ftl +++ b/freemarker-generator-cli/templates/csv/csv/gatling-user-credentials.ftl @@ -15,9 +15,9 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> +<#assign datasource = Datasources.get(0)> <#assign cvsFormat = CSVTool.formats["DEFAULT"].withDelimiter(';')> -<#assign csvParser = CSVTool.parse(document, cvsFormat)> +<#assign csvParser = CSVTool.parse(datasource, cvsFormat)> <#assign csvRecords = csvParser.records> <#compress> diff --git a/freemarker-generator-cli/templates/csv/fo/transactions.ftl b/freemarker-generator-cli/templates/csv/fo/transactions.ftl index 4715484..ff9c009 100644 --- a/freemarker-generator-cli/templates/csv/fo/transactions.ftl +++ b/freemarker-generator-cli/templates/csv/fo/transactions.ftl @@ -15,10 +15,10 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> -<#assign name = document.name> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> <#assign cvsFormat = CSVTool.formats.DEFAULT.withDelimiter('\t').withHeader()> -<#assign csvParser = CSVTool.parse(document, cvsFormat)> +<#assign csvParser = CSVTool.parse(datasource, cvsFormat)> <#assign csvHeaders = csvParser.getHeaderMap()?keys> <#assign csvRecords = csvParser.records> <#---------------------------------------------------------------------------> diff --git a/freemarker-generator-cli/templates/csv/fo/transform.ftl b/freemarker-generator-cli/templates/csv/fo/transform.ftl index 38594cd..d20f625 100644 --- a/freemarker-generator-cli/templates/csv/fo/transform.ftl +++ b/freemarker-generator-cli/templates/csv/fo/transform.ftl @@ -17,7 +17,7 @@ --> <#assign csvFormatName = SystemTool.parameters["csv.format"]!"DEFAULT"> <#assign cvsFormat = CSVTool.formats[csvFormatName].withHeader()> -<#assign csvParser = CSVTool.parse(Documents.get(0), cvsFormat)> +<#assign csvParser = CSVTool.parse(Datasources.get(0), cvsFormat)> <#assign csvHeaders = csvParser.getHeaderMap()?keys> <#assign csvRecords = csvParser.records> <#---------------------------------------------------------------------------> diff --git a/freemarker-generator-cli/templates/csv/html/transactions.ftl b/freemarker-generator-cli/templates/csv/html/transactions.ftl index b31d6c0..9fae075 100644 --- a/freemarker-generator-cli/templates/csv/html/transactions.ftl +++ b/freemarker-generator-cli/templates/csv/html/transactions.ftl @@ -15,10 +15,10 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> -<#assign name = document.name> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> <#assign cvsFormat = CSVTool.formats["DEFAULT"].withDelimiter('\t').withHeader()> -<#assign csvParser = CSVTool.parse(document, cvsFormat)> +<#assign csvParser = CSVTool.parse(datasource, cvsFormat)> <#assign csvHeaders = csvParser.getHeaderMap()?keys> <#assign csvRecords = csvParser.records> <#---------------------------------------------------------------------------> diff --git a/freemarker-generator-cli/templates/csv/html/transform.ftl b/freemarker-generator-cli/templates/csv/html/transform.ftl index 54a805e..5985857 100644 --- a/freemarker-generator-cli/templates/csv/html/transform.ftl +++ b/freemarker-generator-cli/templates/csv/html/transform.ftl @@ -15,10 +15,10 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> -<#assign name = document.name> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> <#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader()> -<#assign csvParser = CSVTool.parse(document, cvsFormat)> +<#assign csvParser = CSVTool.parse(datasource, cvsFormat)> <#assign csvHeaders = csvParser.getHeaderNames()> <#---------------------------------------------------------------------------> <!DOCTYPE html> diff --git a/freemarker-generator-cli/templates/csv/md/filter.ftl b/freemarker-generator-cli/templates/csv/md/filter.ftl index 3967e0c..92a0304 100644 --- a/freemarker-generator-cli/templates/csv/md/filter.ftl +++ b/freemarker-generator-cli/templates/csv/md/filter.ftl @@ -15,14 +15,14 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> -<#assign parser = parser(document)> +<#assign datasource = Datasources.get(0)> +<#assign parser = parser(datasource)> <#assign headers = parser.getHeaderNames()> <#assign column = SystemTool.getParameter("column")> <#assign values = SystemTool.getParameter("values")?split(",")> <#compress> - <@writePageHeader document/> + <@writePageHeader datasource/> <#-- Process each line without materializing the whole file in memory --> <#list parser.iterator() as record> <#if filter(record)> @@ -31,18 +31,18 @@ </#list> </#compress> -<#function parser document> +<#function parser datasource> <#assign format = CSVTool.formats[SystemTool.getParameter("format", "DEFAULT")]> <#assign delimiter = CSVTool.toDelimiter(SystemTool.getParameter("delimiter", format.getDelimiter()))> - <#return CSVTool.parse(document, format.withFirstRecordAsHeader().withDelimiter(delimiter))> + <#return CSVTool.parse(datasource, format.withFirstRecordAsHeader().withDelimiter(delimiter))> </#function> <#function filter record> <#return values?seq_contains(record.get(column))> </#function> -<#macro writePageHeader document> - # ${document.name} +<#macro writePageHeader datasource> + # ${datasource.name} </#macro> <#macro writeCsvRecord headers record> diff --git a/freemarker-generator-cli/templates/csv/md/transform.ftl b/freemarker-generator-cli/templates/csv/md/transform.ftl index efcf276..994e3f3 100644 --- a/freemarker-generator-cli/templates/csv/md/transform.ftl +++ b/freemarker-generator-cli/templates/csv/md/transform.ftl @@ -16,7 +16,7 @@ under the License. --> <#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader()> -<#assign csvParser = CSVTool.parse(Documents.get(0), cvsFormat)> +<#assign csvParser = CSVTool.parse(Datasources.get(0), cvsFormat)> <#assign csvHeaders = csvParser.getHeaderMap()?keys> <#assign csvRecords = csvParser.records> <#---------------------------------------------------------------------------> diff --git a/freemarker-generator-cli/templates/csv/shell/curl.ftl b/freemarker-generator-cli/templates/csv/shell/curl.ftl index 8df601f..d7c75c9 100644 --- a/freemarker-generator-cli/templates/csv/shell/curl.ftl +++ b/freemarker-generator-cli/templates/csv/shell/curl.ftl @@ -16,7 +16,7 @@ under the License. --> <#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader()> -<#assign csvParser = CSVTool.parse(Documents.get(0), cvsFormat)> +<#assign csvParser = CSVTool.parse(Datasources.get(0), cvsFormat)> <#assign records = csvParser.records> <#assign csvMap = CSVTool.toMap(records, "disposer")> <#---------------------------------------------------------------------------> diff --git a/freemarker-generator-cli/templates/csv/transform.ftl b/freemarker-generator-cli/templates/csv/transform.ftl index 0380abb..e13c9b5 100644 --- a/freemarker-generator-cli/templates/csv/transform.ftl +++ b/freemarker-generator-cli/templates/csv/transform.ftl @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. --> -<#assign csvParser = createCsvParser(Documents.get(0))> +<#assign csvParser = createCsvParser(Datasources.get(0))> <#assign csvPrinter = createCsvPrinter()> <#-- Print each line without materializing the CSV in memory --> <#compress> @@ -24,11 +24,11 @@ </#list> </#compress> -<#function createCsvParser document> +<#function createCsvParser datasource> <#assign initialCvsInFormat = CSVTool.formats[SystemTool.getParameter("csv.in.format", "DEFAULT")]> <#assign csvInDelimiter = CSVTool.toDelimiter(SystemTool.getParameter("csv.in.delimiter", initialCvsInFormat.getDelimiter()))> <#assign cvsInFormat = initialCvsInFormat.withDelimiter(csvInDelimiter)> - <#return CSVTool.parse(document, cvsInFormat)> + <#return CSVTool.parse(datasource, cvsInFormat)> </#function> <#function createCsvPrinter> diff --git a/freemarker-generator-cli/templates/demo.ftl b/freemarker-generator-cli/templates/demo.ftl index b3cad69..f981a9e 100644 --- a/freemarker-generator-cli/templates/demo.ftl +++ b/freemarker-generator-cli/templates/demo.ftl @@ -45,11 +45,11 @@ java.math.RoundingMode#UP: ${FreeMarkerTool.enums["java.math.RoundingMode"].UP} - java.math.RoundingMode.${roundingMode}<#lt> </#list> -6) Display list of input files +6) Display list of datasources --------------------------------------------------------------------------- -List all files: -<#list Documents.list as document> -- Document: name=${document.name} location=${document.location} length=${document.length} encoding=${document.encoding!""} +List all datasources: +<#list Datasources.list as datasource> +- Document: name=${datasource.name} location=${datasource.location} length=${datasource.length} encoding=${datasource.encoding!""} </#list> 7) SystemTool @@ -83,25 +83,25 @@ user.home : ${SystemTool.systemProperties["user.home"]!""} - ${name} ==> ${value}<#lt> </#list> -11) Access Documents +11) Access Datasources --------------------------------------------------------------------------- Get the number of documents: -- ${Documents.size()} -<#if !Documents.isEmpty()> +- ${Datasources.size()} +<#if !Datasources.isEmpty()> Get the first document -- ${Documents.get(0)!"NA"} +- ${Datasources.get(0)!"NA"} </#if> List all files containing "README" in the name -<#list Documents.find("*README*") as document> -- ${document.name} +<#list Datasources.find("*README*") as datasource> +- ${datasource.name} </#list> List all files having "md" extension -<#list Documents.find("*.md") as document> -- ${document.name} +<#list Datasources.find("*.md") as datasource> +- ${datasource.name} </#list> Get all documents -<#list Documents.list as document> -- ${document.name} => ${document.location} +<#list Datasources.list as datasource> +- ${datasource.name} => ${datasource.location} </#list> 12) FreeMarker CLI Tools diff --git a/freemarker-generator-cli/templates/excel/csv/custom.ftl b/freemarker-generator-cli/templates/excel/csv/custom.ftl index 9235460..6d6f90a 100644 --- a/freemarker-generator-cli/templates/excel/csv/custom.ftl +++ b/freemarker-generator-cli/templates/excel/csv/custom.ftl @@ -17,8 +17,8 @@ --> <#assign format = SystemTool.parameters["csv.format"]!"DEFAULT"> <#assign salt = SystemTool.parameters["salt"]!"salt"> -<#-- Parse the first document & sheet of the Excel document --> -<#assign workbook = ExcelTool.parse(Documents.get(0))> +<#-- Parse the first datasource & sheet of the Excel document --> +<#assign workbook = ExcelTool.parse(Datasources.get(0))> <#assign sheet = ExcelTool.getSheets(workbook)[0]> <#assign records = ExcelTool.toTable(sheet)> <#-- Setup CSVPrinter --> diff --git a/freemarker-generator-cli/templates/excel/csv/transform.ftl b/freemarker-generator-cli/templates/excel/csv/transform.ftl index a1e2497..4ddc529 100644 --- a/freemarker-generator-cli/templates/excel/csv/transform.ftl +++ b/freemarker-generator-cli/templates/excel/csv/transform.ftl @@ -16,8 +16,8 @@ under the License. --> <#assign format = SystemTool.parameters["csv.format"]!"DEFAULT"> -<#-- Parse the first document & sheet of the Excel document --> -<#assign workbook = ExcelTool.parse(Documents.get(0))> +<#-- Parse the first datasource & sheet of the Excel document --> +<#assign workbook = ExcelTool.parse(Datasources.get(0))> <#assign sheet = ExcelTool.getSheets(workbook)[0]> <#assign records = ExcelTool.toTable(sheet)> <#-- Setup CSVPrinter --> diff --git a/freemarker-generator-cli/templates/excel/html/transform.ftl b/freemarker-generator-cli/templates/excel/html/transform.ftl index 5fa4ad9..a261410 100644 --- a/freemarker-generator-cli/templates/excel/html/transform.ftl +++ b/freemarker-generator-cli/templates/excel/html/transform.ftl @@ -15,15 +15,15 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> -<#assign documentName = document.name> -<#assign workbook = ExcelTool.parse(document)> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> +<#assign workbook = ExcelTool.parse(datasource)> <#assign date = .now?iso_utc> <#---------------------------------------------------------------------------> <!DOCTYPE html> <html> <head> - <title>${documentName}</title> + <title>${name}</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> @@ -31,7 +31,7 @@ <body> <div class="container-fluid"> <h1>Excel Test - <small>${documentName}, ${date}</small> + <small>${name}, ${date}</small> </h1> <@writeSheets workbook/> </div> diff --git a/freemarker-generator-cli/templates/excel/md/transform.ftl b/freemarker-generator-cli/templates/excel/md/transform.ftl index 6ce112e..9b3a068 100644 --- a/freemarker-generator-cli/templates/excel/md/transform.ftl +++ b/freemarker-generator-cli/templates/excel/md/transform.ftl @@ -15,13 +15,13 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> -<#assign documentName = document.name> -<#assign workbook = ExcelTool.parse(document)> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> +<#assign workbook = ExcelTool.parse(datasource)> <#assign date = .now?iso_utc> <#compress> - # ${documentName} + # ${name} <@writeSheets workbook/> </#compress> ${'\n'} diff --git a/freemarker-generator-cli/templates/html/csv/dependencies.ftl b/freemarker-generator-cli/templates/html/csv/dependencies.ftl index 0eaad6c..b0df23e 100644 --- a/freemarker-generator-cli/templates/html/csv/dependencies.ftl +++ b/freemarker-generator-cli/templates/html/csv/dependencies.ftl @@ -15,9 +15,9 @@ specific language governing permissions and limitations under the License. --> -<#assign document = Documents.get(0)> -<#assign documentName = document.name> -<#assign html = JsoupTool.parse(document)> +<#assign datasource = Datasources.get(0)> +<#assign name = datasource.name> +<#assign html = JsoupTool.parse(datasource)> <#compress> <@writeHeader/> diff --git a/freemarker-generator-cli/templates/info.ftl b/freemarker-generator-cli/templates/info.ftl index 9f2fbe8..3ec4891 100644 --- a/freemarker-generator-cli/templates/info.ftl +++ b/freemarker-generator-cli/templates/info.ftl @@ -39,10 +39,10 @@ FreeMarker CLI Tools </#if> </#list> -FreeMarker CLI Documents +FreeMarker CLI Datasources --------------------------------------------------------------------------- -<#list Documents.list as document> -[${document?counter}] ${document.name}, ${document.location}, ${document.length} Bytes +<#list Datasources.list as datasource> +[${datasource?counter}] ${datasource.name}, ${datasource.location}, ${datasource.length} Bytes </#list> User Supplied Parameters diff --git a/freemarker-generator-cli/templates/json/csv/swagger-endpoints.ftl b/freemarker-generator-cli/templates/json/csv/swagger-endpoints.ftl index 7e34ac5..61b9f78 100644 --- a/freemarker-generator-cli/templates/json/csv/swagger-endpoints.ftl +++ b/freemarker-generator-cli/templates/json/csv/swagger-endpoints.ftl @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. --> -<#assign json = JsonPathTool.parse(Documents.get(0))> +<#assign json = JsonPathTool.parse(Datasources.get(0))> <#assign basePath = json.read("$.basePath")> <#assign paths = json.read("$.paths")> diff --git a/freemarker-generator-cli/templates/json/md/github-users.ftl b/freemarker-generator-cli/templates/json/md/github-users.ftl index 581d1ca..5aecf18 100644 --- a/freemarker-generator-cli/templates/json/md/github-users.ftl +++ b/freemarker-generator-cli/templates/json/md/github-users.ftl @@ -15,7 +15,7 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -<#assign json = JsonPathTool.parse(Documents.get(0))> +<#assign json = JsonPathTool.parse(Datasources.get(0))> <#assign users = json.read("$[*]")> <#---------------------------------------------------------------------------> # GitHub Users diff --git a/freemarker-generator-cli/templates/properties/csv/locker-test-users.ftl b/freemarker-generator-cli/templates/properties/csv/locker-test-users.ftl index 4328182..237b71f 100644 --- a/freemarker-generator-cli/templates/properties/csv/locker-test-users.ftl +++ b/freemarker-generator-cli/templates/properties/csv/locker-test-users.ftl @@ -17,8 +17,8 @@ --> <#compress> TENANT,SITE,USER_ID,DISPOSER_ID,PASSWORD,SMS_OTP,NAME,DESCRIPTION - <#list Documents.list as document> - <#assign properties = PropertiesTool.parse(document)> + <#list Datasources.list as datasource> + <#assign properties = PropertiesTool.parse(datasource)> <#assign environments = properties["ENVIRONMENTS"]!""> <#assign tenant = extractTenant(environments)> <#assign site = extractSite(environments)> diff --git a/freemarker-generator-cli/templates/tsv/fo/transactions.ftl b/freemarker-generator-cli/templates/tsv/fo/transactions.ftl index 2485e48..99b7a1c 100644 --- a/freemarker-generator-cli/templates/tsv/fo/transactions.ftl +++ b/freemarker-generator-cli/templates/tsv/fo/transactions.ftl @@ -16,7 +16,7 @@ under the License. --> <#assign cvsFormat = CSVTool.formats["TDF"].withHeader()> -<#assign csvParser = CSVTool.parse(Documents.get(0), cvsFormat)> +<#assign csvParser = CSVTool.parse(Datasources.get(0), cvsFormat)> <#assign csvHeaders = csvParser.getHeaderMap()?keys> <#assign csvRecords = csvParser.records> <#---------------------------------------------------------------------------> diff --git a/freemarker-generator-cli/templates/xml/txt/recipients.ftl b/freemarker-generator-cli/templates/xml/txt/recipients.ftl index 434d7ea..87a9f57 100644 --- a/freemarker-generator-cli/templates/xml/txt/recipients.ftl +++ b/freemarker-generator-cli/templates/xml/txt/recipients.ftl @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. --> -<#assign xml = XmlTool.parse(Documents.get(0))> +<#assign xml = XmlTool.parse(Datasources.get(0))> <#list xml.recipients.person as recipient> To: ${recipient.name} ${recipient.address} diff --git a/freemarker-generator-cli/templates/yaml/txt/transform.ftl b/freemarker-generator-cli/templates/yaml/txt/transform.ftl index 00911bc..07160cf 100644 --- a/freemarker-generator-cli/templates/yaml/txt/transform.ftl +++ b/freemarker-generator-cli/templates/yaml/txt/transform.ftl @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. --> -<#assign map = YamlTool.parse(Documents.get(0))> +<#assign map = YamlTool.parse(Datasources.get(0))> <#---------------------------------------------------------------------------> <#compress> <@print map 1/> diff --git a/freemarker-generator-tools/README.md b/freemarker-generator-tools/README.md index 12d1c61..6a1e74e 100644 --- a/freemarker-generator-tools/README.md +++ b/freemarker-generator-tools/README.md @@ -7,9 +7,9 @@ Design Considerations ------------------------------------------------------------------------------ * A tool shall expose a default constructor and/or a constructor taking a `Map<String, Object> settings` -* A tool processing documents shall provide a `parse(Document document)` method +* A tool processing datasources shall provide a `parse(Datasource)` method * A tool shall be stateless, multi-thread safe and potentially long-lived to enable usage in a different context -* A tool shall support arbitrary large source documents and process them efficiently +* A tool shall support arbitrary large source datasources and process them efficiently * A tool shall expose a `toString()` method for documentation purposes Available Tools diff --git a/freemarker-generator-tools/pom.xml b/freemarker-generator-tools/pom.xml index 32fa5b7..8a2d0c8 100644 --- a/freemarker-generator-tools/pom.xml +++ b/freemarker-generator-tools/pom.xml @@ -27,7 +27,7 @@ <artifactId>freemarker-generator-tools</artifactId> <name>Apache FreeMarker Generator: Tools</name> - <description>Document processing tools for Apache FreeMarker Generator</description> + <description>Datasource processing tools for Apache FreeMarker Generator</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java index da7779a..755ea33 100644 --- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java +++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java @@ -21,7 +21,7 @@ import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVPrinter; import org.apache.commons.csv.CSVRecord; import org.apache.commons.io.input.BOMInputStream; -import org.apache.freemarker.generator.base.document.Document; +import org.apache.freemarker.generator.base.datasource.Datasource; import org.apache.freemarker.generator.base.util.StringUtils; import java.io.IOException; @@ -44,23 +44,23 @@ import static org.apache.commons.io.IOUtils.toInputStream; public class CommonsCSVTool { - public CSVParser parse(Document document) { - return parse(document, CSVFormat.DEFAULT); + public CSVParser parse(Datasource da) { + return parse(da, CSVFormat.DEFAULT); } - public CSVParser parse(Document document, CSVFormat format) { - if (document == null) { - throw new IllegalArgumentException("No document was provided"); + public CSVParser parse(Datasource datasource, CSVFormat format) { + if (datasource == null) { + throw new IllegalArgumentException("No datasource was provided"); } try { // As stated in the documentation : "If you do not read all records from the given {@code reader}, // you should call {@link #close()} on the parser, unless you close the {@code reader}." - // The underlying input stream is closed by the document by its "CloseableReaper". - final InputStream is = new BOMInputStream(document.getInputStream(), false); - return parse(is, document.getCharset(), format); + // The underlying input stream is closed by the datasource by its "CloseableReaper". + final InputStream is = new BOMInputStream(datasource.getInputStream(), false); + return parse(is, datasource.getCharset(), format); } catch (IOException e) { - throw new RuntimeException("Failed to parse CSV: " + document, e); + throw new RuntimeException("Failed to parse CSV: " + datasource, e); } } diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/excel/ExcelTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/excel/ExcelTool.java index 43fa5ea..8f2d635 100644 --- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/excel/ExcelTool.java +++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/excel/ExcelTool.java @@ -16,7 +16,7 @@ */ package org.apache.freemarker.generator.tools.excel; -import org.apache.freemarker.generator.base.document.Document; +import org.apache.freemarker.generator.base.datasource.Datasource; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataFormatter; @@ -47,13 +47,13 @@ public class ExcelTool { private static final SimpleDateFormat TIME_DATE_FORMAT = new SimpleDateFormat("HH:mm:ss"); private static final SimpleDateFormat YEAR_TIME_FORMAT = new SimpleDateFormat("yyyy"); - public Workbook parse(Document document) { - try (InputStream is = document.getUnsafeInputStream()) { + public Workbook parse(Datasource datasource) { + try (InputStream is = datasource.getUnsafeInputStream()) { final Workbook workbook = WorkbookFactory.create(is); - // make sure that the workbook is closed together with the document - return document.addClosable(workbook); + // make sure that the workbook is closed together with the datasource + return datasource.addClosable(workbook); } catch (IOException e) { - throw new RuntimeException("Failed to parse Ecxel document: " + document, e); + throw new RuntimeException("Failed to parse Ecxel datasource: " + datasource, e); } } diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathTool.java index 3e31ffc..1859428 100644 --- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathTool.java +++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathTool.java @@ -20,15 +20,15 @@ import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Option; -import org.apache.freemarker.generator.base.document.Document; +import org.apache.freemarker.generator.base.datasource.Datasource; import java.io.IOException; import java.io.InputStream; public class JsonPathTool { - public DocumentContext parse(Document document) throws IOException { - try (InputStream is = document.getUnsafeInputStream()) { + public DocumentContext parse(Datasource datasource) throws IOException { + try (InputStream is = datasource.getUnsafeInputStream()) { return JsonPath.using(configuration()).parse(is); } } diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsoup/JsoupTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsoup/JsoupTool.java index 62d0944..0e18ad8 100644 --- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsoup/JsoupTool.java +++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/jsoup/JsoupTool.java @@ -16,7 +16,7 @@ */ package org.apache.freemarker.generator.tools.jsoup; -import org.apache.freemarker.generator.base.document.Document; +import org.apache.freemarker.generator.base.datasource.Datasource; import org.jsoup.Jsoup; import java.io.IOException; @@ -24,11 +24,11 @@ import java.io.InputStream; public class JsoupTool { - public org.jsoup.nodes.Document parse(Document document) { - try (InputStream is = document.getUnsafeInputStream()) { - return Jsoup.parse(is, document.getCharset().name(), ""); + public org.jsoup.nodes.Document parse(Datasource datasource) { + try (InputStream is = datasource.getUnsafeInputStream()) { + return Jsoup.parse(is, datasource.getCharset().name(), ""); } catch (IOException e) { - throw new RuntimeException("Failed to parse HTML document: " + document, e); + throw new RuntimeException("Failed to parse HTML datasource: " + datasource, e); } } diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/properties/PropertiesTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/properties/PropertiesTool.java index 96acb0d..09d2549 100644 --- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/properties/PropertiesTool.java +++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/properties/PropertiesTool.java @@ -16,7 +16,7 @@ */ package org.apache.freemarker.generator.tools.properties; -import org.apache.freemarker.generator.base.document.Document; +import org.apache.freemarker.generator.base.datasource.Datasource; import org.apache.freemarker.generator.base.util.PropertiesFactory; import java.io.IOException; @@ -25,11 +25,11 @@ import java.util.Properties; public class PropertiesTool { - public Properties parse(Document document) { - try (InputStream is = document.getUnsafeInputStream()) { + public Properties parse(Datasource datasource) { + try (InputStream is = datasource.getUnsafeInputStream()) { return PropertiesFactory.create(is); } catch (IOException e) { - throw new RuntimeException("Failed to parse properties: " + document, e); + throw new RuntimeException("Failed to parse properties: " + datasource, e); } } diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlTool.java index 96bc938..1ee005d 100644 --- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlTool.java +++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlTool.java @@ -16,7 +16,7 @@ */ package org.apache.freemarker.generator.tools.snakeyaml; -import org.apache.freemarker.generator.base.document.Document; +import org.apache.freemarker.generator.base.datasource.Datasource; import org.yaml.snakeyaml.Yaml; import java.io.IOException; @@ -25,11 +25,11 @@ import java.util.Map; public class SnakeYamlTool { - public Map<String, Object> parse(Document document) { - try (InputStream is = document.getUnsafeInputStream()) { + public Map<String, Object> parse(Datasource datasource) { + try (InputStream is = datasource.getUnsafeInputStream()) { return new Yaml().load(is); } catch (IOException e) { - throw new RuntimeException("Failed to load YAML document: " + document, e); + throw new RuntimeException("Failed to load YAML datasource: " + datasource, e); } } diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/xml/XmlTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/xml/XmlTool.java index 5977ae7..a80b579 100644 --- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/xml/XmlTool.java +++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/xml/XmlTool.java @@ -17,7 +17,7 @@ package org.apache.freemarker.generator.tools.xml; import freemarker.ext.dom.NodeModel; -import org.apache.freemarker.generator.base.document.Document; +import org.apache.freemarker.generator.base.datasource.Datasource; import org.xml.sax.InputSource; import java.io.InputStream; @@ -25,11 +25,11 @@ import java.io.StringReader; public class XmlTool { - public NodeModel parse(Document document) { - try (InputStream is = document.getUnsafeInputStream()) { + public NodeModel parse(Datasource datasource) { + try (InputStream is = datasource.getUnsafeInputStream()) { return NodeModel.parse(new InputSource(is)); } catch (Exception e) { - throw new RuntimeException("Failed to parse XML document: " + document, e); + throw new RuntimeException("Failed to parse XML datasource: " + datasource, e); } } @@ -37,7 +37,7 @@ public class XmlTool { try (StringReader reader = new StringReader(value)) { return NodeModel.parse(new InputSource(reader)); } catch (Exception e) { - throw new RuntimeException("Failed to parse XML document: " + value, e); + throw new RuntimeException("Failed to parse XML string: " + value, e); } } diff --git a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVToolTest.java b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVToolTest.java index 770309e..d60a070 100644 --- a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVToolTest.java +++ b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVToolTest.java @@ -20,8 +20,8 @@ import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVPrinter; import org.apache.commons.csv.CSVRecord; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourceFactory; import org.junit.Test; import java.io.File; @@ -48,7 +48,7 @@ public class CommonsCSVToolTest { @Test public void shallParseCvsFile() throws IOException { - try (CSVParser parser = commonsCsvTool().parse(document(), DEFAULT.withHeader())) { + try (CSVParser parser = commonsCsvTool().parse(datasource(), DEFAULT.withHeader())) { assertNotNull(parser); assertEquals(32, parser.getHeaderMap().size()); assertEquals(22, parser.getRecords().size()); @@ -57,7 +57,7 @@ public class CommonsCSVToolTest { @Test public void shallParseCvsString() throws IOException { - try (CSVParser parser = commonsCsvTool().parse(document().getText(), DEFAULT.withHeader())) { + try (CSVParser parser = commonsCsvTool().parse(datasource().getText(), DEFAULT.withHeader())) { assertNotNull(parser); assertEquals(32, parser.getHeaderMap().size()); assertEquals(22, parser.getRecords().size()); @@ -69,7 +69,7 @@ public class CommonsCSVToolTest { final CommonsCSVTool commonsCsvTool = commonsCsvTool(); final List<String> keys; - try (CSVParser parser = commonsCsvTool.parse(document(), DEFAULT.withHeader())) { + try (CSVParser parser = commonsCsvTool.parse(datasource(), DEFAULT.withHeader())) { keys = commonsCsvTool.toKeys(parser.getRecords(), CONTRACT_ID); } @@ -89,7 +89,7 @@ public class CommonsCSVToolTest { final CommonsCSVTool commonsCsvTool = commonsCsvTool(); final Map<String, CSVRecord> map; - try (CSVParser parser = commonsCsvTool.parse(document(), DEFAULT.withHeader())) { + try (CSVParser parser = commonsCsvTool.parse(datasource(), DEFAULT.withHeader())) { map = commonsCsvTool.toMap(parser.getRecords(), CONTRACT_ID); } @@ -102,7 +102,7 @@ public class CommonsCSVToolTest { final CommonsCSVTool commonsCsvTool = commonsCsvTool(); final Map<String, List<CSVRecord>> map; - try (CSVParser parser = commonsCsvTool.parse(document(), DEFAULT.withHeader())) { + try (CSVParser parser = commonsCsvTool.parse(datasource(), DEFAULT.withHeader())) { map = commonsCsvTool.toMultiMap(parser.getRecords(), CONTRACT_ID); } @@ -116,7 +116,7 @@ public class CommonsCSVToolTest { final CSVFormat cvsFormat = DEFAULT.withHeader(); final Writer writer = new StringWriter(); - try (CSVParser parser = commonsCsvTool.parse(document(), cvsFormat)) { + try (CSVParser parser = commonsCsvTool.parse(datasource(), cvsFormat)) { try (CSVPrinter printer = commonsCsvTool.printer(cvsFormat, writer)) { printer.printRecord(parser.getHeaderMap()); } @@ -127,7 +127,7 @@ public class CommonsCSVToolTest { @Test public void shallStripBomFromCsvFile() throws IOException { - try (CSVParser parser = commonsCsvTool().parse(document(BOM_CSV), EXCEL.withHeader().withDelimiter(';'))) { + try (CSVParser parser = commonsCsvTool().parse(datasource(BOM_CSV), EXCEL.withHeader().withDelimiter(';'))) { assertEquals("Text", parser.getHeaderNames().get(0)); } } @@ -139,12 +139,12 @@ public class CommonsCSVToolTest { assertEquals('^', commonsCsvTool().toDelimiter("^")); } - private Document document() { - return document(TEST_CSV); + private Datasource datasource() { + return datasource(TEST_CSV); } - private Document document(File file) { - return DocumentFactory.create(file, UTF_8); + private Datasource datasource(File file) { + return DatasourceFactory.create(file, UTF_8); } private CommonsCSVTool commonsCsvTool() { diff --git a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/excel/ExcelToolTest.java b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/excel/ExcelToolTest.java index 9003a38..1583001 100644 --- a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/excel/ExcelToolTest.java +++ b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/excel/ExcelToolTest.java @@ -16,8 +16,8 @@ */ package org.apache.freemarker.generator.tools.excel; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourceFactory; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.junit.Test; @@ -102,14 +102,14 @@ public class ExcelToolTest { } private Workbook workbook(File file) { - return excelTool().parse(document(file)); + return excelTool().parse(datasource(file)); } private ExcelTool excelTool() { return new ExcelTool(); } - private Document document(File file) { - return DocumentFactory.create(file, UTF_8); + private Datasource datasource(File file) { + return DatasourceFactory.create(file, UTF_8); } } diff --git a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/properties/PropertiesToolTest.java b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/properties/PropertiesToolTest.java index 8e010e7..3a29908 100644 --- a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/properties/PropertiesToolTest.java +++ b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/properties/PropertiesToolTest.java @@ -16,8 +16,8 @@ */ package org.apache.freemarker.generator.tools.properties; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourceFactory; import org.junit.Test; import static junit.framework.TestCase.assertEquals; @@ -27,9 +27,9 @@ public class PropertiesToolTest { private static final String ANY_PROPERTIES_STRING = "foo=bar"; @Test - public void shallParsePropertiesDocument() { - try (Document document = document(ANY_PROPERTIES_STRING)) { - assertEquals("bar", propertiesTool().parse(document).getProperty("foo")); + public void shallParsePropertiesDatasource() { + try (Datasource datasource = datasource(ANY_PROPERTIES_STRING)) { + assertEquals("bar", propertiesTool().parse(datasource).getProperty("foo")); } } @@ -42,7 +42,7 @@ public class PropertiesToolTest { return new PropertiesTool(); } - private Document document(String value) { - return DocumentFactory.create("test.properties", value); + private Datasource datasource(String value) { + return DatasourceFactory.create("test.properties", value); } } diff --git a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlToolTest.java b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlToolTest.java index 4a522b6..ee34a28 100644 --- a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlToolTest.java +++ b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/snakeyaml/SnakeYamlToolTest.java @@ -16,8 +16,8 @@ */ package org.apache.freemarker.generator.tools.snakeyaml; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourceFactory; import org.junit.Test; import java.util.List; @@ -34,9 +34,9 @@ public class SnakeYamlToolTest { " - image: postgres:9.4.1"; @Test - public void shallParseYamlDocument() { - try (Document document = document(ANY_YAML_STRING)) { - final Map<String, Object> map = snakeYamlTool().parse(document); + public void shallParseYamlDatasource() { + try (Datasource datasource = datasource(ANY_YAML_STRING)) { + final Map<String, Object> map = snakeYamlTool().parse(datasource); assertEquals(1, map.size()); assertEquals(3, ((List<?>) map.get("docker")).size()); @@ -55,7 +55,7 @@ public class SnakeYamlToolTest { return new SnakeYamlTool(); } - private Document document(String value) { - return DocumentFactory.create("test.yml", value); + private Datasource datasource(String value) { + return DatasourceFactory.create("test.yml", value); } } diff --git a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/xml/XmlToolTest.java b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/xml/XmlToolTest.java index de69881..79a5432 100644 --- a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/xml/XmlToolTest.java +++ b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/xml/XmlToolTest.java @@ -17,8 +17,8 @@ package org.apache.freemarker.generator.tools.xml; import freemarker.ext.dom.NodeModel; -import org.apache.freemarker.generator.base.document.Document; -import org.apache.freemarker.generator.base.document.DocumentFactory; +import org.apache.freemarker.generator.base.datasource.Datasource; +import org.apache.freemarker.generator.base.datasource.DatasourceFactory; import org.junit.Test; import static junit.framework.TestCase.assertEquals; @@ -35,9 +35,9 @@ public class XmlToolTest { "</note>"; @Test - public void shallParseXmlDocument() throws Exception { - try (Document document = document(ANY_XML_STRING)) { - final NodeModel model = xmlTool().parse(document); + public void shallParseXmlDatasource() throws Exception { + try (Datasource datasource = datasource(ANY_XML_STRING)) { + final NodeModel model = xmlTool().parse(datasource); assertNotNull(model); assertEquals(1, model.getChildNodes().size()); @@ -56,7 +56,7 @@ public class XmlToolTest { return new XmlTool(); } - private Document document(String value) { - return DocumentFactory.create("test.xml", value); + private Datasource datasource(String value) { + return DatasourceFactory.create("test.xml", value); } }
