This is an automated email from the ASF dual-hosted git repository. sgoeschl pushed a commit to branch FREEMARKER-151 in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git
The following commit(s) were added to refs/heads/FREEMARKER-151 by this push: new cb1b265 FREEMARKER-151 [freemarker-cli] Ensure that build and and examples are running on Windows cb1b265 is described below commit cb1b265062ce432c34c8959d9f27b1316b3e8e60 Author: Siegfried Goeschl <siegfried.goes...@gmail.com> AuthorDate: Tue Jul 7 11:56:25 2020 +0200 FREEMARKER-151 [freemarker-cli] Ensure that build and and examples are running on Windows --- .../base/mime/MimetypesFileTypeMapFactory.java | 2 +- .../freemarker/generator/base/util/UriUtils.java | 8 +- .../generator/uri/NamedUriStringParserTest.java | 13 +- freemarker-generator-cli/pom.xml | 1 + .../src/main/scripts/run-examples.bat | 173 +++++++++++++++++++++ 5 files changed, 194 insertions(+), 3 deletions(-) diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/mime/MimetypesFileTypeMapFactory.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/mime/MimetypesFileTypeMapFactory.java index b91d534..56e9efa 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/mime/MimetypesFileTypeMapFactory.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/mime/MimetypesFileTypeMapFactory.java @@ -46,7 +46,7 @@ public class MimetypesFileTypeMapFactory { mimeTypes.addMimeTypes(MIME_APPLICATION_XML + " xml XML"); mimeTypes.addMimeTypes(MIME_APPLICATION_XHTML + " xhtml XHTML"); mimeTypes.addMimeTypes(MIME_TEXT_CSV + " csv CSV"); - mimeTypes.addMimeTypes(MIME_TEXT_PLAIN + " adoc ADOC env ENV ini INI log LOG properties txt TXT"); + mimeTypes.addMimeTypes(MIME_TEXT_PLAIN + " adoc ADOC bat BAT env ENV ftl FTL ini INI log LOG properties txt TXT"); mimeTypes.addMimeTypes(MIME_TEXT_HTML + " htm HTM html HTML"); mimeTypes.addMimeTypes(MIME_TEXT_MARKDOWM + " md MD"); mimeTypes.addMimeTypes(MIME_TEXT_RTF + " rtf RTF"); diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java index 305822c..679f299 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java @@ -16,6 +16,8 @@ */ package org.apache.freemarker.generator.base.util; +import org.apache.commons.io.FilenameUtils; + import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -26,7 +28,7 @@ public class UriUtils { public static URI toURI(String str) { try { - return new URI(str); + return new URI(separatorsToUnix(str)); } catch (URISyntaxException e) { throw new RuntimeException("Failed to create URI: " + str, e); } @@ -64,4 +66,8 @@ public class UriUtils { } return "env".equalsIgnoreCase(uri.getScheme()); } + + private static String separatorsToUnix(String str) { + return FilenameUtils.separatorsToUnix(str); + } } diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/uri/NamedUriStringParserTest.java b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/uri/NamedUriStringParserTest.java index a4da79e..2d0bb4a 100644 --- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/uri/NamedUriStringParserTest.java +++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/uri/NamedUriStringParserTest.java @@ -63,7 +63,7 @@ public class NamedUriStringParserTest { } @Test - public void shouldParseAbsoluteFileName() { + public void shouldParseAbsoluteUnixFileName() { final NamedUri namedURI = parse("/data/users.csv"); assertNull(namedURI.getName()); @@ -74,6 +74,17 @@ public class NamedUriStringParserTest { } @Test + public void shouldParseAbsoluteWindosFileName() { + final NamedUri namedURI = parse("\\data\\users.csv"); + + assertNull(namedURI.getName()); + assertNull(namedURI.getGroup()); + assertEquals("/data/users.csv", namedURI.getUri().toString()); + assertEquals("users.csv", namedURI.getFile().getName()); + assertEquals(0, namedURI.getParameters().size()); + } + + @Test public void shouldParseDirectoryName() { final NamedUri namedURI = parse("users/"); diff --git a/freemarker-generator-cli/pom.xml b/freemarker-generator-cli/pom.xml index 20d7ce2..ff7c4b0 100644 --- a/freemarker-generator-cli/pom.xml +++ b/freemarker-generator-cli/pom.xml @@ -75,6 +75,7 @@ <copy file="README.md" todir="./target/appassembler" /> <copy file="LICENSE" todir="./target/appassembler" /> <copy file="NOTICE" todir="./target/appassembler" /> + <copy file="./src/main/scripts/run-examples.bat" todir="./target/appassembler" /> <copy file="./src/main/scripts/run-examples.sh" todir="./target/appassembler" /> <copy todir="./target/appassembler/templates"> <fileset dir="templates" /> diff --git a/freemarker-generator-cli/src/main/scripts/run-examples.bat b/freemarker-generator-cli/src/main/scripts/run-examples.bat new file mode 100644 index 0000000..ce35e5a --- /dev/null +++ b/freemarker-generator-cli/src/main/scripts/run-examples.bat @@ -0,0 +1,173 @@ +@ECHO OFF +REM +REM Licensed to the Apache Software Foundation (ASF) under one or more +REM contributor license agreements. See the NOTICE file distributed with +REM this work for additional information regarding copyright ownership. +REM The ASF licenses this file to You under the Apache License, Version 2.0 +REM (the "License"); you may not use this file except in compliance with +REM the License. You may obtain a copy of the License at +REM +REM http:\\www.apache.org\licenses\LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. +REM + +REM Run all the samples being documented + +mkdir target 2>NULL +mkdir target\out 2>NULL + +SET FREEMARKER_CMD=CALL .\bin\freemarker-cli.bat + +REM ========================================================================= +REM Info +REM ========================================================================= + +echo "templates\info.ftl" +%FREEMARKER_CMD% -t templates\info.ftl README.md > target\out\info.txt + +REM ========================================================================= +REM Demo +REM ========================================================================= + +echo "examples\templates\demo.ftl" +%FREEMARKER_CMD% -t examples\templates\demo.ftl README.md > target\out\demo.txt + +REM ========================================================================= +REM Interactive Mode +REM ========================================================================= + +%FREEMARKER_CMD% -i '${JsonPathTool.parse(DataSources.first).read("$.info.title")}' examples\data\json\swagger-spec.json > target\out\interactive-json.txt +%FREEMARKER_CMD% -i '${XmlTool.parse(DataSources.first)["recipients\person[1]\name"]}' examples\data\xml\recipients.xml > target\out\interactive-xml.txt +%FREEMARKER_CMD% -i '${JsoupTool.parse(DataSources.first).select("a")[0]}' examples\data\html\dependencies.html > target\out\interactive-html.txt +%FREEMARKER_CMD% -i '${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}' examples\data\yaml\swagger-spec.yaml > target\out\interactive-swagger.json +%FREEMARKER_CMD% -i '${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))}' examples\data\json\swagger-spec.json > target\out\interactive-swagger.yaml +%FREEMARKER_CMD% -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))}' examples\data\json\github-users.json > target\out\interactive-dataframe.txt + +REM ========================================================================= +REM CSV +REM ========================================================================= + +echo "templates\csv\html\transform.ftl" +%FREEMARKER_CMD% -t templates\csv\html\transform.ftl examples\data\csv\contract.csv > target\out\contract.html + +echo "templates\csv\md\transform.ftl" +%FREEMARKER_CMD% -t templates\csv\md\transform.ftl examples\data\csv\contract.csv > target\out\contract.md + +echo "examples\templates\csv\shell\curl.ftl" +%FREEMARKER_CMD% -t .\examples\templates\csv\shell\curl.ftl examples\data\csv\user.csv > target\out\curl.sh + +echo "examples\templates\csv\md\filter.ftl" +%FREEMARKER_CMD% -e UTF-8 -l de_AT -Pcolumn="Order ID" -Pvalues=226939189,957081544 -Pformat=DEFAULT -Pdelimiter=COMMA -t examples\templates\csv\md\filter.ftl examples\data\csv\sales-records.csv > target\out\sales-records.md + +REM ========================================================================= +REM CSV To XML-FO & PDF +REM ========================================================================= + +echo "examples\templates\csv\fo\transform.ftl" +%FREEMARKER_CMD% -t examples\templates\csv\fo\transform.ftl examples\data\csv\locker-test-users.csv > target\out\locker-test-users.fo + +echo "examples\templates\csv\fo\transactions.ftl" +%FREEMARKER_CMD% -t examples\templates\csv\fo\transactions.ftl examples\data\csv\transactions.csv > target\out\transactions.fo + +REM ========================================================================= +REM CSV to HTML & PDF +REM ========================================================================= + +echo "templates\csv\html\transform.ftl" +%FREEMARKER_CMD% -t examples\templates\csv\html\transactions.ftl examples\data\csv\transactions.csv > target\out\transactions.html + +REM ========================================================================= +REM DataFrame +REM ========================================================================= + +echo "examples\templates\dataframe\example.ftl" +%FREEMARKER_CMD% -PCSV_SOURCE_DELIMITER=SEMICOLON -PCSV_SOURCE_WITH_HEADER=true -t examples\templates\dataframe\example.ftl examples\data\csv\dataframe.csv > target\out\dataframe.txt + +REM ========================================================================= +REM Grok +REM ========================================================================= + +echo "examples\templates\accesslog\combined-access.ftl" +%FREEMARKER_CMD% -t examples\templates\accesslog\combined-access.ftl examples\data\accesslog\combined-access.log > target\out\combined-access.log.txt + +REM ========================================================================= +REM Excel +REM ========================================================================= + +echo "examples\templates\excel\dataframe\transform.ftl" +%FREEMARKER_CMD% -t examples\templates\excel\dataframe\transform.ftl examples\data\excel\test.xls > target\out\test.xls.dataframe.txt + +echo "templates\excel\html\transform.ftl" +%FREEMARKER_CMD% -t templates\excel\html\transform.ftl examples\data\excel\test.xls > target\out\test.xls.html +%FREEMARKER_CMD% -t templates\excel\html\transform.ftl examples\data\excel\test.xlsx > target\out\test.xslx.html +%FREEMARKER_CMD% -t templates\excel\html\transform.ftl examples\data\excel\test-multiple-sheets.xlsx > target\out\test-multiple-sheets.xlsx.html + +echo "templates\excel\md\transform.ftl" +%FREEMARKER_CMD% -t templates\excel\md\transform.ftl examples\data\excel\test-multiple-sheets.xlsx > target\out\test-multiple-sheets.xlsx.md + +echo "templates\excel\csv\transform.ftl" +%FREEMARKER_CMD% -t templates\excel\csv\transform.ftl examples\data\excel\test-multiple-sheets.xlsx > target\out\test-multiple-sheets.xlsx.csv + +echo "examples\templates\excel\csv\custom.ftl" +%FREEMARKER_CMD% -t examples\templates\excel\csv\custom.ftl -Pcsv.format=MYSQL examples\data\excel\test.xls > target\out\test-transform-xls.csv + +REM ========================================================================= +REM HTML +REM ========================================================================= + +echo "examples\templates\html\csv\dependencies.ftl" +%FREEMARKER_CMD% -t examples\templates\html\csv\dependencies.ftl examples\data\html\dependencies.html > target\out\dependencies.csv + +REM ========================================================================= +REM JSON +REM ========================================================================= + +echo "examples\templates\json\csv\swagger-endpoints.ftl" +%FREEMARKER_CMD% -t examples\templates\json\csv\swagger-endpoints.ftl examples\data\json\swagger-spec.json > target\out\swagger-spec.csv + +echo "templates\json\yaml\transform.ftl" +%FREEMARKER_CMD% -t templates\json\yaml\transform.ftl examples\data\json\swagger-spec.json > target\out\swagger-spec.yaml + +if hash curl 2>\dev\null; then +echo "examples\templates\json\md\github-users.ftl" +%FREEMARKER_CMD% -t examples\templates\json\md\github-users.ftl examples\data\json\github-users.json > target\out\github-users-curl.md +fi + +REM ========================================================================= +REM Properties +REM ========================================================================= + +echo "examples\templates\properties\csv\locker-test-users.ftl" +%FREEMARKER_CMD% -t examples\templates\properties\csv\locker-test-users.ftl examples\data\properties > target\out\locker-test-users.csv + +REM ========================================================================= +REM Template Directory +REM ========================================================================= + +echo "examples\data\template" +%FREEMARKER_CMD% -t examples\data\template -PNGINX_HOSTNAME=localhost -o target\out\template + +REM ========================================================================= +REM YAML +REM ========================================================================= + +echo "examples\templates\yaml\txt\transform.ftl" +%FREEMARKER_CMD% -t examples\templates\yaml\txt\transform.ftl examples\data\yaml\customer.yaml > target\out\customer.txt + +echo "templates\yaml\json\transform.ftl" +%FREEMARKER_CMD% -t templates\yaml\json\transform.ftl examples\data\yaml\swagger-spec.yaml > target\out\swagger-spec.json + +REM ========================================================================= +REM XML +REM ========================================================================= + +echo "examples\templates\xml\txt\recipients.ftl" +%FREEMARKER_CMD% -t .\examples\templates\xml\txt\recipients.ftl examples\data\xml\recipients.xml > target\out\recipients.txt + +echo "Created the following sample files in .\target\out" +dir .\target\out \ No newline at end of file