freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject [freemarker-generator] 03/03: FREEMARKER-129 Minor refactorings
Date Fri, 07 Feb 2020 11:27:43 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 3106948faf1253926ac1b7f8ec66f03ad86f3b7a
Author: Siegfried Goeschl <siegfried.goeschl@gmail.com>
AuthorDate: Fri Feb 7 12:27:26 2020 +0100

    FREEMARKER-129 Minor refactorings
---
 .../freemarker/generator/base/document/DocumentFactory.java   | 11 +++++------
 .../freemarker/generator/document/DocumentFactoryTest.java    |  6 +++---
 .../apache/freemarker/generator/document/DocumentTest.java    |  2 +-
 .../apache/freemarker/generator/document/DocumentsTest.java   |  3 +--
 .../org/apache/freemarker/generator/cli/FreeMarkerTask.java   |  6 +++---
 5 files changed, 13 insertions(+), 15 deletions(-)

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/document/DocumentFactory.java
index b25e5c9..632c3b1 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/document/DocumentFactory.java
@@ -35,20 +35,19 @@ import static java.nio.charset.StandardCharsets.UTF_8;
  */
 public class DocumentFactory {
 
-    private static final String DEFAULT_LOCATION = "unknown";
-    private static final String NAME_URL = "url";
+    public static final String LOCATION_STDIN = "stdin";
 
     private DocumentFactory() {
     }
 
     public static Document create(URL url) {
         final URLDataSource dataSource = new URLDataSource(url);
-        return create(NAME_URL, dataSource, url.toExternalForm(), UTF_8);
+        return create("url", dataSource, url.toExternalForm(), UTF_8);
     }
 
     public static Document create(String name, String content) {
         final StringDataSource dataSource = new StringDataSource(name, content, UTF_8);
-        return create(name, dataSource, DEFAULT_LOCATION, UTF_8);
+        return create(name, dataSource, "string", UTF_8);
     }
 
     public static Document create(File file, Charset charset) {
@@ -58,12 +57,12 @@ public class DocumentFactory {
 
     public static Document create(String name, byte[] content) {
         final ByteArrayDataSource dataSource = new ByteArrayDataSource(name, content);
-        return create(name, dataSource, DEFAULT_LOCATION, UTF_8);
+        return create(name, dataSource, "bytes", UTF_8);
     }
 
     public static Document create(String name, InputStream is, Charset charset) {
         final InputStreamDataSource dataSource = new InputStreamDataSource(name, is);
-        return create(name, dataSource, DEFAULT_LOCATION, charset);
+        return create(name, dataSource, "is", charset);
     }
 
     public static Document create(String name, InputStream is, String location, Charset charset)
{
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
index d837761..35fb4e4 100644
--- 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
@@ -54,7 +54,7 @@ public class DocumentFactoryTest {
 
         assertEquals("test.txt", document.getName());
         assertEquals(UTF_8, document.getCharset());
-        assertEquals(UNKOWN_LOCATION, document.getLocation());
+        assertEquals("string", document.getLocation());
         assertEquals(ANY_TEXT, document.getText());
         assertEquals(1, document.getLines().size());
     }
@@ -65,7 +65,7 @@ public class DocumentFactoryTest {
 
         assertEquals("test.txt", document.getName());
         assertEquals(UTF_8, document.getCharset());
-        assertEquals(UNKOWN_LOCATION, document.getLocation());
+        assertEquals("bytes", document.getLocation());
         assertEquals(ANY_TEXT, document.getText());
         assertEquals(1, document.getLines().size());
     }
@@ -77,7 +77,7 @@ public class DocumentFactoryTest {
 
         assertEquals("test.txt", document.getName());
         assertEquals(UTF_8, document.getCharset());
-        assertEquals(UNKOWN_LOCATION, document.getLocation());
+        assertEquals("is", 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
index b3421ac..bc343fa 100644
--- 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
@@ -42,7 +42,7 @@ public class DocumentTest {
     public void shouldSupportTextDocument() throws IOException {
         try (Document document = DocumentFactory.create("stdin", ANY_TEXT)) {
             assertEquals("stdin", document.getName());
-            assertEquals("unknown", document.getLocation());
+            assertEquals("string", document.getLocation());
             assertEquals(UTF_8, document.getCharset());
             assertTrue(document.getLength() > 0);
             assertEquals(ANY_TEXT, document.getText());
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
index 5848f46..496a594 100644
--- 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
@@ -32,13 +32,12 @@ import static org.junit.Assert.assertNotNull;
 
 public class DocumentsTest {
 
-    private static final String STDIN = "stdin";
     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";
+    private static final String ANY_URL = "https://server.invalid?foo=bar";
 
     @Test
     public void shouldFindByWildcard() {
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/FreeMarkerTask.java
b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/FreeMarkerTask.java
index 3f10caf..d9bb61d 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/FreeMarkerTask.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/FreeMarkerTask.java
@@ -22,8 +22,8 @@ import freemarker.template.Template;
 import org.apache.commons.io.FileUtils;
 import org.apache.freemarker.generator.base.document.Document;
 import org.apache.freemarker.generator.base.document.DocumentFactory;
-import org.apache.freemarker.generator.base.document.DocumentsSupplier;
 import org.apache.freemarker.generator.base.document.Documents;
+import org.apache.freemarker.generator.base.document.DocumentsSupplier;
 import org.apache.freemarker.generator.cli.impl.ConfigurationSupplier;
 import org.apache.freemarker.generator.cli.impl.TemplateLoaderSupplier;
 import org.apache.freemarker.generator.cli.impl.ToolsSupplier;
@@ -41,6 +41,7 @@ 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.document.DocumentFactory.LOCATION_STDIN;
 
 /**
  * Renders a FreeMarker template.
@@ -48,7 +49,6 @@ import static java.util.Objects.requireNonNull;
 public class FreeMarkerTask implements Callable<Integer> {
 
     private static final int SUCCESS = 0;
-    private static final String STDIN = "stdin";
 
     private final Settings settings;
 
@@ -98,7 +98,7 @@ public class FreeMarkerTask implements Callable<Integer> {
         // Add optional document 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));
+            documents.add(0, DocumentFactory.create(LOCATION_STDIN, System.in, LOCATION_STDIN,
UTF_8));
         }
 
         return new Documents(documents);


Mime
View raw message