You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by sg...@apache.org on 2020/06/24 15:22:21 UTC
[freemarker-generator] branch master updated: FREEMARKER-146
Cleanly separate example templates and data from user-supplied content
(#15)
This is an automated email from the ASF dual-hosted git repository.
sgoeschl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git
The following commit(s) were added to refs/heads/master by this push:
new b9105f9 FREEMARKER-146 Cleanly separate example templates and data from user-supplied content (#15)
b9105f9 is described below
commit b9105f972efd4b52a2d450580d018edf84f35808
Author: Siegfried Goeschl <si...@gmail.com>
AuthorDate: Wed Jun 24 17:22:10 2020 +0200
FREEMARKER-146 Cleanly separate example templates and data from user-supplied content (#15)
---
.travis.yml | 2 +-
CHANGELOG.md | 4 +-
freemarker-generator-cli/README.md | 578 +++++++++++++++------
.../data}/accesslog/combined-access.log | 0
.../sample => examples/data}/csv/contract.csv | 0
.../sample => examples/data}/csv/dataframe.csv | 0
.../data}/csv/excel-export-utf8.csv | 0
.../data}/csv/locker-test-users.csv | 0
.../sample => examples/data}/csv/sales-records.csv | 0
.../sample => examples/data}/csv/transactions.csv | 0
.../{site/sample => examples/data}/csv/user.csv | 0
.../data}/excel/test-multiple-sheets.xlsx | Bin
.../{site/sample => examples/data}/excel/test.xls | Bin
.../{site/sample => examples/data}/excel/test.xlsx | Bin
.../data}/ftl/nginx/nginx.conf.ftl | 0
.../sample => examples/data}/ftl/nginx/nginx.env | 0
.../data}/html/dependencies.html | 0
.../data}/json/github-users.json | 0
.../data}/json/swagger-spec.json | 0
.../data}/properties/user_0001/user.properties | 0
.../data}/properties/user_0002/user.properties | 0
.../data}/properties/user_0003/user.properties | 0
.../data}/properties/user_0004/user.properties | 0
.../data}/template/application.properties | 0
.../data}/template/nginx/nginx.conf.ftl | 0
.../sample => examples/data}/xml/recipients.xml | 0
.../sample => examples/data}/yaml/customer.yaml | 0
.../data}/yaml/swagger-spec.yaml | 0
.../templates/accesslog/combined-access.ftl | 0
.../{ => examples}/templates/cat.ftl | 0
.../templates/csv/csv/gatling-user-credentials.ftl | 0
.../templates/csv/fo/transactions.ftl | 0
.../{ => examples}/templates/csv/fo/transform.ftl | 0
.../templates/csv/html/transactions.ftl | 0
.../{ => examples}/templates/csv/md/filter.ftl | 0
.../{ => examples}/templates/csv/shell/curl.ftl | 0
.../{ => examples}/templates/dataframe/example.ftl | 16 +-
.../templates/dataframe/html/print.ftl | 0
.../{ => examples}/templates/demo.ftl | 0
.../{ => examples}/templates/excel/csv/custom.ftl | 4 +-
.../templates/excel/dataframe/transform.ftl | 0
.../templates/html/csv/dependencies.ftl | 0
.../{ => examples}/templates/info.ftl | 0
.../templates/json/csv/swagger-endpoints.ftl | 0
.../templates/json/md/github-users.ftl | 0
.../templates/properties/csv/locker-test-users.ftl | 0
.../templates/tsv/fo/transactions.ftl | 0
.../templates/xml/txt/recipients.ftl | 0
.../templates/yaml/txt/transform.ftl | 0
freemarker-generator-cli/pom.xml | 9 +-
freemarker-generator-cli/run-examples.sh | 193 +++++++
freemarker-generator-cli/run-samples.sh | 193 -------
.../freemarker/generator/cli/config/Settings.java | 30 +-
.../freemarker/generator/cli/config/Suppliers.java | 2 +-
.../src/main/scripts/run-examples.sh | 193 +++++++
.../src/main/scripts/run-samples.sh | 193 -------
.../src/site/markdown/cli/concepts/data-sources.md | 12 +-
.../src/site/markdown/cli/concepts/named-uris.md | 8 +-
.../src/site/markdown/cli/tools/dataframe.md | 37 +-
.../markdown/cli/usage/transforming-directories.md | 22 +-
.../freemarker/generator/cli/ExamplesTest.java | 72 +--
.../freemarker/generator/cli/ManualTest.java | 28 +-
.../generator/cli/SecurityRelatedTest.java | 4 +-
.../generator/cli/SourceEncodingTest.java | 4 +-
.../generator/cli/UserSuppliedLocaleTest.java | 4 +-
.../generator/cli/config/SettingsTest.java | 4 +-
.../templates/{cat.ftl => csv/csv/transform.ftl} | 12 +-
.../templates/csv/html/transform.ftl | 33 +-
.../templates/csv/md/transform.ftl | 28 +-
.../templates/csv/transform.ftl | 39 --
.../templates/excel/csv/transform.ftl | 17 +-
.../templates/excel/html/transform.ftl | 1 +
freemarker-generator-cli/templates/info.ftl | 4 +-
.../templates/lib/commons-csv.ftl | 55 ++
.../tools/commonscsv/CommonsCSVPrinterFacade.java | 84 +++
.../generator/tools/commonscsv/CommonsCSVTool.java | 56 +-
.../generator/tools/dataframe/DataFrameTool.java | 10 +-
.../tools/dataframe/converter/MapConverter.java | 11 -
.../generator/tools/freemarker/FreeMarkerTool.java | 2 +-
.../generator/tools/system/SystemTool.java | 40 +-
.../tools/commonscsv/CommonsCSVToolTest.java | 10 +-
.../generator/tools/system/SystemToolTest.java | 19 +-
travis.sh | 4 +-
83 files changed, 1205 insertions(+), 832 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 1edf54c..b3680d5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,6 +9,6 @@ jdk:
script:
- mvn clean install
- cd ./freemarker-generator-cli
- - sh ./run-samples.sh
+ - sh ./run-examples.sh
- cd ../freemarker-generator-maven-plugin-sample
- mvn clean package
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 045191a..2d33b61 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,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-146] Cleanly separate example templates and data from user-supplied content
* `DataSource` use `uri` instead of `location`
* [FREEMARKER-138] freemarker-generator: Rename `Datasource` to `DataSource`
* [FREEMARKER-136] Fix broken `site:stage` build
@@ -40,4 +41,5 @@ All notable changes to this project will be documented in this file. We try to a
[FREEMARKER-138]: https://issues.apache.org/jira/browse/FREEMARKER-138
[FREEMARKER-139]: https://issues.apache.org/jira/browse/FREEMARKER-139
[FREEMARKER-142]: https://issues.apache.org/jira/browse/FREEMARKER-142
-[FREEMARKER-144]: https://issues.apache.org/jira/browse/FREEMARKER-144
\ No newline at end of file
+[FREEMARKER-144]: https://issues.apache.org/jira/browse/FREEMARKER-144
+[FREEMARKER-146]: https://issues.apache.org/jira/browse/FREEMARKER-146
\ No newline at end of file
diff --git a/freemarker-generator-cli/README.md b/freemarker-generator-cli/README.md
index 587dadb..70179f2 100644
--- a/freemarker-generator-cli/README.md
+++ b/freemarker-generator-cli/README.md
@@ -75,14 +75,14 @@ It is recommended
You can test the installation by executing
```text
-> ./bin/freemarker-cli -t templates/info.ftl
+> ./bin/freemarker-cli -t templates/info.ftl
FreeMarker CLI Information
------------------------------------------------------------------------------
FreeMarker version : 2.3.30
-Template name : templates/info.ftl
+Template name : info.ftl
Language : en
Locale : en_US
-Timestamp : Apr 14, 2020 11:34:13 PM
+Timestamp : Jun 18, 2020 10:55:04 AM
Output encoding : UTF-8
Output format : plainText
@@ -94,6 +94,7 @@ FreeMarker CLI Template Directories
FreeMarker CLI Tools
------------------------------------------------------------------------------
- CSVTool : Process CSV files using Apache Commons CSV (see https://commons.apache.org/proper/commons-csv/)
+- DataFrameTool : Bridge to nRo/DataFrame (see https://github.com/nRo/DataFrame)
- ExcelTool : Process Excels files (XLS, XLSX) using Apache POI (see https://poi.apache.org)
- ExecTool : Execute command line tools using Apache Commons Exec (see https://commons.apache.org/proper/commons-exec/)
- FreeMarkerTool : Expose useful Apache FreeMarker classes
@@ -107,86 +108,96 @@ 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 DataSources
-------------------------------------------------------------------------------
-
-User Supplied Parameters
-------------------------------------------------------------------------------
-
-User Supplied System Properties
-------------------------------------------------------------------------------
-
-SystemTool
-------------------------------------------------------------------------------
-Command line : -t, templates/info.ftl
-Host Name : W0GL5179.local
-Java Home : /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
-User Name : sgoeschl
-Timestamp : 1,586,900,053,355
-Writer : org.apache.freemarker.generator.base.util.NonClosableWriterWrapper
+FreeMarker CLI Data Model
+---------------------------------------------------------------------------
+- CSVTool
+- DataFrameTool
+- DataSources
+- ExcelTool
+- ExecTool
+- FreeMarkerTool
+- GrokTool
+- GsonTool
+- JsonPathTool
+- JsoupTool
+- PropertiesTool
+- SystemTool
+- UUIDTool
+- XmlTool
+- YamlTool
```
-There a many examples (see below) available you can execute - run `./run-samples.sh` and have a look at the generated output
+There a many examples (see below) available you can execute - run `./run-examples.sh` and have a look at the generated output
```text
-./run-samples.sh
+./run-examples.sh
templates/info.ftl
-templates/demo.ftl
+examples/templates/demo.ftl
templates/csv/html/transform.ftl
-templates/csv/md/transform.ftl
-templates/csv/shell/curl.ftl
-templates/csv/md/filter.ftl
-templates/csv/fo/transform.ftl
+examples/templates/csv/md/transform.ftl
+examples/templates/csv/shell/curl.ftl
+examples/templates/csv/md/filter.ftl
+examples/templates/csv/fo/transform.ftl
fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf
-templates/csv/fo/transactions.ftl
+examples/templates/csv/fo/transactions.ftl
fop -fo target/out/transactions.fo target/out/transactions-fo.pdf
templates/csv/html/transform.ftl
wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf
-templates/accesslog/combined-access.ftl
+examples/templates/dataframe/example.ftl
+examples/templates/accesslog/combined-access.ftl
+examples/templates/excel/dataframe/transform.ftl
templates/excel/html/transform.ftl
templates/excel/md/transform.ftl
templates/excel/csv/transform.ftl
-templates/excel/csv/custom.ftl
-templates/html/csv/dependencies.ftl
-templates/json/csv/swagger-endpoints.ftl
+examples/templates/excel/csv/custom.ftl
+examples/templates/html/csv/dependencies.ftl
+examples/templates/json/csv/swagger-endpoints.ftl
templates/json/yaml/transform.ftl
-templates/json/md/github-users.ftl
-templates/properties/csv/locker-test-users.ftl
-templates/yaml/txt/transform.ftl
+examples/templates/json/md/github-users.ftl
+examples/templates/properties/csv/locker-test-users.ftl
+examples/data/template
+examples/templates/yaml/txt/transform.ftl
templates/yaml/json/transform.ftl
-templates/xml/txt/recipients.ftl
+examples/templates/xml/txt/recipients.ftl
Created the following sample files in ./target/out
-total 1440
--rw-r--r-- 1 sgoeschl staff 646 Apr 4 13:03 combined-access.log.txt
--rw-r--r-- 1 sgoeschl staff 22548 Apr 4 13:03 contract.html
--rw-r--r-- 1 sgoeschl staff 7933 Apr 4 13:03 contract.md
--rw-r--r-- 1 sgoeschl staff 784 Apr 4 13:03 curl.sh
--rw-r--r-- 1 sgoeschl staff 232 Apr 4 13:03 customer.txt
--rw-r--r-- 1 sgoeschl staff 15268 Apr 4 13:03 demo.txt
--rw-r--r-- 1 sgoeschl staff 1310 Apr 4 13:03 dependencies.csv
--rw-r--r-- 1 sgoeschl staff 2029 Apr 4 13:03 github-users-curl.md
--rw-r--r-- 1 sgoeschl staff 2901 Apr 4 13:03 info.txt
--rw-r--r-- 1 sgoeschl staff 66 Apr 4 13:03 interactive-html.txt
--rw-r--r-- 1 sgoeschl staff 16 Apr 4 13:03 interactive-json.txt
--rw-r--r-- 1 sgoeschl staff 10 Apr 4 13:03 interactive-xml.txt
--rw-r--r-- 1 sgoeschl staff 285 Apr 4 13:03 locker-test-users.csv
--rw-r--r-- 1 sgoeschl staff 6341 Apr 4 13:03 locker-test-users.fo
--rw-r--r-- 1 sgoeschl staff 5526 Apr 4 13:03 locker-test-users.pdf
--rw-r--r-- 1 sgoeschl staff 921 Apr 4 13:03 recipients.txt
--rw-r--r-- 1 sgoeschl staff 910 Apr 4 13:03 sales-records.md
--rw-r--r-- 1 sgoeschl staff 2453 Apr 4 13:03 swagger-spec.csv
--rw-r--r-- 1 sgoeschl staff 25090 Apr 4 13:03 swagger-spec.json
--rw-r--r-- 1 sgoeschl staff 16870 Apr 4 13:03 swagger-spec.yaml
--rw-r--r-- 1 sgoeschl staff 156 Apr 4 13:03 test-multiple-sheets.xlsx.csv
--rw-r--r-- 1 sgoeschl staff 1917 Apr 4 13:03 test-multiple-sheets.xlsx.html
--rw-r--r-- 1 sgoeschl staff 389 Apr 4 13:03 test-multiple-sheets.xlsx.md
--rw-r--r-- 1 sgoeschl staff 150 Apr 4 13:03 test-transform-xls.csv
--rw-r--r-- 1 sgoeschl staff 1556 Apr 4 13:03 test.xls.html
--rw-r--r-- 1 sgoeschl staff 1558 Apr 4 13:03 test.xslx.html
--rw-r--r-- 1 sgoeschl staff 25756 Apr 4 13:03 transactions-fo.pdf
--rw-r--r-- 1 sgoeschl staff 66016 Apr 4 13:03 transactions-html.pdf
--rw-r--r-- 1 sgoeschl staff 330127 Apr 4 13:03 transactions.fo
--rw-r--r-- 1 sgoeschl staff 51008 Apr 4 13:03 transactions.html
+total 1576
+-rw-r--r-- 1 sgoeschl staff 646 Jun 18 10:56 combined-access.log.txt
+-rw-r--r-- 1 sgoeschl staff 22548 Jun 18 10:56 contract.html
+-rw-r--r-- 1 sgoeschl staff 7933 Jun 18 10:56 contract.md
+-rw-r--r-- 1 sgoeschl staff 784 Jun 18 10:56 curl.sh
+-rw-r--r-- 1 sgoeschl staff 232 Jun 18 10:56 customer.txt
+-rw-r--r-- 1 sgoeschl staff 6488 Jun 18 10:56 dataframe.txt
+-rw-r--r-- 1 sgoeschl staff 15632 Jun 18 10:56 demo.txt
+-rw-r--r-- 1 sgoeschl staff 1310 Jun 18 10:56 dependencies.csv
+-rw-r--r-- 1 sgoeschl staff 2029 Jun 18 10:56 github-users-curl.md
+-rw-r--r-- 1 sgoeschl staff 2630 Jun 18 10:56 info.txt
+-rw-r--r-- 1 sgoeschl staff 8075 Jun 18 10:56 interactive-dataframe.txt
+-rw-r--r-- 1 sgoeschl staff 66 Jun 18 10:56 interactive-html.txt
+-rw-r--r-- 1 sgoeschl staff 16 Jun 18 10:56 interactive-json.txt
+-rw-r--r-- 1 sgoeschl staff 25090 Jun 18 10:56 interactive-swagger.json
+-rw-r--r-- 1 sgoeschl staff 16870 Jun 18 10:56 interactive-swagger.yaml
+-rw-r--r-- 1 sgoeschl staff 10 Jun 18 10:56 interactive-xml.txt
+-rw-r--r-- 1 sgoeschl staff 285 Jun 18 10:56 locker-test-users.csv
+-rw-r--r-- 1 sgoeschl staff 6341 Jun 18 10:56 locker-test-users.fo
+-rw-r--r-- 1 sgoeschl staff 5526 Jun 18 10:56 locker-test-users.pdf
+-rw-r--r-- 1 sgoeschl staff 921 Jun 18 10:56 recipients.txt
+-rw-r--r-- 1 sgoeschl staff 910 Jun 18 10:56 sales-records.md
+-rw-r--r-- 1 sgoeschl staff 2453 Jun 18 10:56 swagger-spec.csv
+-rw-r--r-- 1 sgoeschl staff 25090 Jun 18 10:56 swagger-spec.json
+-rw-r--r-- 1 sgoeschl staff 16870 Jun 18 10:56 swagger-spec.yaml
+drwxr-xr-x 4 sgoeschl staff 128 Jun 18 10:49 template
+-rw-r--r-- 1 sgoeschl staff 156 Jun 18 10:56 test-multiple-sheets.xlsx.csv
+-rw-r--r-- 1 sgoeschl staff 1917 Jun 18 10:56 test-multiple-sheets.xlsx.html
+-rw-r--r-- 1 sgoeschl staff 389 Jun 18 10:56 test-multiple-sheets.xlsx.md
+-rw-r--r-- 1 sgoeschl staff 157 Jun 18 10:56 test-transform-xls.csv
+-rw-r--r-- 1 sgoeschl staff 1439 Jun 18 10:56 test.xls.dataframe.txt
+-rw-r--r-- 1 sgoeschl staff 1556 Jun 18 10:56 test.xls.html
+-rw-r--r-- 1 sgoeschl staff 1558 Jun 18 10:56 test.xslx.html
+-rw-r--r-- 1 sgoeschl staff 25760 Jun 18 10:56 transactions-fo.pdf
+-rw-r--r-- 1 sgoeschl staff 66016 Jun 18 10:56 transactions-html.pdf
+-rw-r--r-- 1 sgoeschl staff 330129 Jun 18 10:56 transactions.fo
+-rw-r--r-- 1 sgoeschl staff 51008 Jun 18 10:56 transactions.html
+
```
Please note that generated PDF files are very likely not found since they require `wkhtmltopdf` and `Apache FOP` installation.
@@ -195,42 +206,46 @@ Please note that generated PDF files are very likely not found since they requir
```text
> ./bin/freemarker-cli -h
-Usage: freemarker-cli (-t=<template> | -i=<interactiveTemplate>) [-hV]
- [--stdin] [-b=<baseDir>] [--config=<configFile>]
- [-e=<inputEncoding>] [--exclude=<exclude>]
- [--include=<include>] [-l=<locale>] [--mode=<mode>]
- [-o=<outputFile>] [--output-encoding=<outputEncoding>]
- [--times=<times>] [-D=<String=String>]...
- [-m=<dataModels>]... [-P=<String=String>]...
- [-s=<dataSources>]... [<sources>...]
+Usage: freemarker-cli (-t=<templates> [-t=<templates>]... |
+ -i=<interactiveTemplate>) [-hV] [--stdin] [-b=<baseDir>]
+ [--config=<configFile>] [--data-source-exclude=<exclude>]
+ [--data-source-include=<include>] [-e=<inputEncoding>]
+ [-l=<locale>] [-o=<outputFile>]
+ [--output-encoding=<outputEncoding>] [--times=<times>]
+ [-D=<String=String>]... [-m=<dataModels>]...
+ [-P=<String=String>]... [-s=<dataSources>]...
+ [<sources>...]
Apache FreeMarker CLI
- [<sources>...] List of input files and/or input directories
- -b, --basedir=<baseDir> Optional template base directory
+ [<sources>...] data source files and/or directories
+ -b, --basedir=<baseDir> optional template base directory
--config=<configFile> FreeMarker CLI configuration file
-D, --system-property=<String=String>
- Set system property
+ set system property
+ --data-source-exclude=<exclude>
+ file exclude pattern for data sources
+ --data-source-include=<include>
+ file include pattern for data sources
-e, --input-encoding=<inputEncoding>
- Encoding of data source
- --exclude=<exclude> File pattern for data source input directory
+ encoding of data source
-h, --help Show this help message and exit.
-i, --interactive=<interactiveTemplate>
- Interactive FreeMarker template
- --include=<include> File pattern for data source input directory
- -l, --locale=<locale> Locale being used for the output, e.g. 'en_US'
+ interactive template to process
+ -l, --locale=<locale> locale being used for the output, e.g. 'en_US'
-m, --data-model=<dataModels>
- Data model used for rendering
- --mode=<mode> [template|datasource]
- -o, --output=<outputFile> Output file
+ data model used for rendering
+ -o, --output=<outputFile> output file or directory
--output-encoding=<outputEncoding>
- Encoding of output, e.g. UTF-8
+ encoding of output, e.g. UTF-8
-P, --param=<String=String>
- Set parameter
+ set parameter
-s, --data-source=<dataSources>
- Data source used for rendering
- --stdin Read data source from stdin
- -t, --template=<template> FreeMarker template to render
- --times=<times> Re-run X times for profiling
+ data source used for redering
+ --stdin read data source from stdin
+ -t, --template=<templates>
+ template to process
+ --times=<times> re-run X times for profiling
-V, --version Print version information and exit.
+
```
# 6. Examples
@@ -253,11 +268,11 @@ A simple example with real JSON data to be transformed into Markdown
You can either use the existing JSON sample
-> ./bin/freemarker-cli -t templates/json/md/github-users.ftl site/sample/json/github-users.json
+> ./bin/freemarker-cli -t examples/templates/json/md/github-users.ftl examples/data/json/github-users.json
or pipe a cURL response
-> curl -s https://api.github.com/users | ./bin/freemarker-cli -t templates/json/md/github-users.ftl --stdin
+> curl -s https://api.github.com/users | ./bin/freemarker-cli -t examples/templates/json/md/github-users.ftl --stdin
### FreeMarker Template
@@ -292,8 +307,8 @@ creates the following output
Sometimes you have a CSV file which needs to be translated in Markdown or HTML - there are on-line solutions available such as [CSV To Markdown Table Generator](https://donatstudios.com/CsvToMarkdownTable) but having a local solution gives you more flexibility.
```text
-> ./bin/freemarker-cli -t templates/csv/md/transform.ftl site/sample/csv/contract.csv
-> ./bin/freemarker-cli -t templates/csv/html/transform.ftl site/sample/csv/contract.csv
+> ./bin/freemarker-cli -t templates/csv/md/transform.ftl examples/data/csv/contract.csv
+> ./bin/freemarker-cli -t templates/csv/html/transform.ftl examples/data/csv/contract.csv
```
The FreeMarker template is shown below
@@ -331,7 +346,7 @@ The resulting file actually looks pleasant when compared to raw CSV
Of course you can also transform a XML document
```text
-> ./bin/freemarker-cli -t templates/xml/txt/recipients.ftl site/sample/xml/recipients.xml
+> ./bin/freemarker-cli -t examples/templates/xml/txt/recipients.ftl examples/data/xml/recipients.xml
```
using the following template
@@ -420,7 +435,7 @@ ${'\n'}
Invoking the FTL template
-> ./bin/freemarker-cli -t templates/json/csv/swagger-endpoints.ftl site/sample/json/swagger-spec.json
+> ./bin/freemarker-cli -t examples/templates/json/csv/swagger-endpoints.ftl examples/data/json/swagger-spec.json
gives you
@@ -437,10 +452,10 @@ ENDPOINT;METHOD;CONSUMES;PRODUCES;SUMMARY;DESCRIPTION
Another day my project management asked me to create a CSV configuration file based on an Excel documents - as usual manual copying was not an option due to required data cleanup and data transformation. So I thought about Apache POI which support XLS and XLSX documents - integration of Apache POI was a breeze but the resulting code was not particularly useful example. So a more generic transformation was provided to show the transformation of Excel documents ...
```text
-> ./bin/freemarker-cli -t templates/excel/html/transform.ftl site/sample/excel/test.xls
-> ./bin/freemarker-cli -t templates/excel/html/transform.ftl site/sample/excel/test.xlsx
-> ./bin/freemarker-cli -t templates/excel/html/transform.ftl site/sample/excel/test-multiple-sheets.xlsx
-> ./bin/freemarker-cli -t templates/excel/md/transform.ftl site/sample/excel/test-multiple-sheets.xlsx
+> ./bin/freemarker-cli -t templates/excel/html/transform.ftl examples/data/excel/test.xls
+> ./bin/freemarker-cli -t templates/excel/html/transform.ftl examples/data/excel/test.xlsx
+> ./bin/freemarker-cli -t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx
+> ./bin/freemarker-cli -t templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx
```
The provided FTL transforms an Excel into a HTML document supporting multiple Excel sheets
@@ -524,7 +539,7 @@ but the result looks reasonable
In this sample we transform all property files found in a directory (recursive search using include pattern) to a CSV file
```text
-> ./bin/freemarker-cli --include *.properties -t templates/properties/csv/locker-test-users.ftl site/sample/properties
+> ./bin/freemarker-cli --data-source-include *.properties -t examples/templates/properties/csv/locker-test-users.ftl examples/data/properties
TENANT,SITE,USER_ID,DISPOSER_ID,PASSWORD,SMS_OTP,NAME,DESCRIPTION
TENANT_A,fat,user_0004,user_0004,password_0004,,,
TENANT_B,fat,user_0001,user_0001,password_0001,,,
@@ -655,7 +670,7 @@ For a POC (proof of concept) I created a sample transformation from CSV to XML-F
In order to create the PDF you need to execute the following commands (assuming that you have Apache FOP installed)
```text
-> ./bin/freemarker-cli -t templates/csv/fo/transform.ftl site/sample/csv/locker-test-users.csv > sample.fo
+> ./bin/freemarker-cli -t examples/templates/csv/fo/transform.ftl examples/data/csv/locker-test-users.csv > sample.fo
> fop -fo sample.fo sample.pdf
Dec 29, 2018 10:24:30 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
@@ -672,7 +687,7 @@ The result does not look very impressive but it is a PDF :-)
Further along the line of the POC we converted a transaction export from CSV to PDF using Apache FOP
```text
-> ./bin/freemarker-cli -t templates/csv/fo/transactions.ftl site/sample/csv/transactions.csv > transactions.fo
+> ./bin/freemarker-cli -t examples/templates/csv/fo/transactions.ftl examples/data/csv/transactions.csv > transactions.fo
> fop -fo transactions.fo transactions.pdf
Jan 16, 2019 11:15:21 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
@@ -733,7 +748,7 @@ Recently I got the rather unusual question how to determine the list of dependen
Your dependencies as CSV can be generated as shown below
```text
-> ./bin/freemarker-cli -t templates/html/csv/dependencies.ftl site/sample/html/dependencies.html
+> ./bin/freemarker-cli -t examples/templates/html/csv/dependencies.ftl examples/data/html/dependencies.html
GroupId,ArtifactId,Version,Type,Licenses
com.jayway.jsonpath,json-path,2.4.0,jar,The Apache Software License Version 2.0
commons-cli,commons-cli,1.4,jar,Apache License Version 2.0
@@ -788,7 +803,7 @@ date "+%FT%H:%M:%S" | tr -d '\n'; curl --write-out ',${record.disposer},%{http_c
Rendering the FreeMarker template
```
-> ./bin/freemarker-cli -t ./templates/csv/shell/curl.ftl site/sample/csv/user.csv
+> ./bin/freemarker-cli -t ./examples/templates/csv/shell/curl.ftl examples/data/csv/user.csv
```
generates the following shell script
@@ -830,7 +845,7 @@ QUOTEDSTRING (?>(?<!\\)(?>"(?>\\.|[^\\"]+)+"|""|(?>'(?>\\.|[^\\']+)+')|''|(?>`(?
And with `Grok` the `QUOTEDSTRING` is just a building block for an even more complex regular expession such as `COMBINEDAPACHELOG`
-> bin/freemarker-cli -t templates/accesslog/combined-access.ftl site/sample/accesslog/combined-access.log
+> bin/freemarker-cli -t examples/templates/accesslog/combined-access.ftl examples/data/accesslog/combined-access.log
which gives you the following output
@@ -879,34 +894,24 @@ While this looks small and tidy there are some nifty features
Sometimes you have a CSV file which is not quite right - you need to change the format. Lets have a look how `freemarker-cli` can help
-> bin/freemarker-cli -PCVS_IN_DELIMITER=COMMA -PCSV_OUT_DELIMITER=PIPE -t templates/csv/transform.ftl ./site/sample/csv/contract.csv
+> bin/freemarker-cli -PCVS_IN_DELIMITER=COMMA -PCSV_TARGET_DELIMITER=PIPE -t templates/csv/csv/transform.ftl ./examples/data/csv/contract.csv
renders the following template
```text
<#ftl output_format="plainText" strip_text="true">
-<#assign csvParser = createCsvParser(DataSources.get(0))>
-<#assign csvPrinter = createCsvPrinter()>
-<#-- Print each line without materializing the CSV in memory -->
+<#assign csvParser = CSVTool.parse(DataSources.get(0))>
+<#assign csvPrinter = CSVTool.printer(SystemTool.writer)>
+<#--
+ Print each record directly to the underyling writer without materializing the CSV in memory.
+ FreeMarker and CSV output are out of sync but millions of records can processed without
+ running out of memory.
+-->
<#compress>
<#list csvParser.iterator() as record>
${csvPrinter.printRecord(record)}
</#list>
</#compress>
-
-<#function createCsvParser dataSource>
- <#assign initialCvsInFormat = CSVTool.formats[CSV_IN_FORMAT!"DEFAULT"]>
- <#assign csvInDelimiter = CSVTool.toDelimiter(CSV_IN_DELIMITER!initialCvsInFormat.getDelimiter())>
- <#assign cvsInFormat = initialCvsInFormat.withDelimiter(csvInDelimiter)>
- <#return CSVTool.parse(dataSource, cvsInFormat)>
-</#function>
-
-<#function createCsvPrinter>
- <#assign initialCvsOutFormat = CSVTool.formats[CSV_OUT_FORMAT!"DEFAULT"]>
- <#assign csvOutDelimiter = CSVTool.toDelimiter(CSV_OUT_DELIMITER!initialCvsOutFormat.getDelimiter())>
- <#assign cvsOutFormat = initialCvsOutFormat.withDelimiter(csvOutDelimiter)>
- <#return CSVTool.printer(cvsOutFormat, SystemTool.writer)>
-</#function>
```
and generates the following output
@@ -988,16 +993,16 @@ 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(DataSources.first).read("$.info.title")}' site/sample/json/swagger-spec.json; echo
+> bin/freemarker-cli -i '${JsonPathTool.parse(DataSources.first).read("$.info.title")}' examples/data/json/swagger-spec.json; echo
Swagger Petstore
-> bin/freemarker-cli -i 'Post Title : ${JsonPathTool.parse(DataSources.first).read("$.title")}' https://jsonplaceholder.typicode.com/posts/2
+> bin/freemarker-cli -i 'Post Title : ${JsonPathTool.parse(DataSources.first).read("$.title")}' https://jsonplaceholder.typicode.com/posts/2; echo
Post Title : qui est esse
-> bin/freemarker-cli -i '${XmlTool.parse(DataSources.first)["recipients/person[1]/name"]}' site/sample/xml/recipients.xml; echo
+> bin/freemarker-cli -i '${XmlTool.parse(DataSources.first)["recipients/person[1]/name"]}' examples/data/xml/recipients.xml; echo
John Smith
-> bin/freemarker-cli -i '${JsoupTool.parse(DataSources.first).select("a")[0]}' site/sample/html/dependencies.html; echo
+> bin/freemarker-cli -i '${JsoupTool.parse(DataSources.first).select("a")[0]}' examples/data/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>'
@@ -1010,16 +1015,14 @@ EDITOR ==> vi
## 6.14 Filtering & Transforming CSV
-During an integration project we imported large transactions CSV files (500.000+ records) and in case of import failures the developers would be happy to get a nice outline of the transactions causing the problem (the CSV records have 60+ columns) - in essence it is filtering (based on some primary key) and and transforming into an output format (Markdown).
+During an integration project we imported large transactions CSV files (500.000+ records) and in case of import failures the developers would be happy to get a nice outline of the transactions causing the problem (the CSV records have 60+ columns) - in essence it is filtering (based on some primary key) and and transforming into a human-readable output format (Markdown).
So lets start the filtering & transformation using the following command line
```text
-> bin/freemarker-cli -e UTF-8 -l de_AT -Dcolumn="Order ID" \
- -Dvalues=226939189,957081544 \
- -Dformat=DEFAULT \
- -Ddelimiter=COMMA \
- -t templates/csv/md/filter.ftl site/sample/csv/sales-records.csv
+> bin/freemarker-cli -e UTF-8 -l de_AT -Pcolumn="Order ID" \
+ -Pvalues=226939189,957081544 \
+ -t examples/templates/csv/md/filter.ftl examples/data/csv/sales-records.csv
```
and Apache FreeMarker template
@@ -1029,13 +1032,12 @@ and Apache FreeMarker template
<#assign dataSource = DataSources.get(0)>
<#assign parser = parser(dataSource)>
<#assign headers = parser.getHeaderNames()>
-<#assign column = SystemTool.getProperty("column")>
-<#assign values = SystemTool.getProperty("values")?split(",")>
-
-<#-- Process each line without materializing the whole file in memory -->
+<#assign column = SystemTool.getParameter("column")>
+<#assign values = SystemTool.getParameter("values")?split(",")>
<#compress>
<@writePageHeader dataSource/>
+ <#-- Process each line without materializing the whole file in memory -->
<#list parser.iterator() as record>
<#if filter(record)>
<@writeCsvRecord headers record/>
@@ -1044,8 +1046,8 @@ and Apache FreeMarker template
</#compress>
<#function parser dataSource>
- <#assign format = CSVTool.formats[SystemTool.getProperty("format", "DEFAULT")]>
- <#assign delimiter = CSVTool.toDelimiter(SystemTool.getProperty("delimiter", format.getDelimiter()))>
+ <#assign format = CSVTool.formats[SystemTool.getParameter("format", "DEFAULT")]>
+ <#assign delimiter = CSVTool.toDelimiter(SystemTool.getParameter("delimiter", format.getDelimiter()))>
<#return CSVTool.parse(dataSource, format.withFirstRecordAsHeader().withDelimiter(delimiter))>
</#function>
@@ -1065,8 +1067,6 @@ and Apache FreeMarker template
| ${header} | ${record.get(header)} |
</#list>
</#macro>
-
-
```
yields
@@ -1114,16 +1114,209 @@ yields
Sometimes we simply need to transform a JSON into an equivalent YAML or the other way around
```
-> ./bin/freemarker-cli -t templates/yaml/json/transform.ftl site/sample/yaml/swagger-spec.yaml
-> ./bin/freemarker-cli -i '${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}' site/sample/yaml/swagger-spec.yaml
-> ./bin/freemarker-cli -i '${GsonTool.toJson(yaml)}' -m yaml=site/sample/yaml/swagger-spec.yaml
+> ./bin/freemarker-cli -t templates/yaml/json/transform.ftl examples/data/yaml/swagger-spec.yaml
+> ./bin/freemarker-cli -i '${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}' examples/data/yaml/swagger-spec.yaml
+> ./bin/freemarker-cli -i '${GsonTool.toJson(yaml)}' -m yaml=examples/data/yaml/swagger-spec.yaml
+
+> ./bin/freemarker-cli -t templates/json/yaml/transform.ftl examples/data/json/swagger-spec.json
+> ./bin/freemarker-cli -i '${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))}' examples/data/json/swagger-spec.json
+> ./bin/freemarker-cli -i '${YamlTool.toYaml(json)}' -m json=examples/data/json/swagger-spec.json
+```
+
+## 6.16 Using DataFrames
+
+The `DataFrameTool` uses [nRo/DataFrame](https://github.com/nRo/DataFrame) to convert tabular data into a `DataFrame`.
+
+A `DataFrame` allows declartive filtering and transformation of tabular data, i.e. less code to write.
+
+Currently the following sources are supported
+
+* Apache Commons CSV Parser
+* JSON arrays represented as collection of maps
+* Excel sheets represented as rows
+
+### CSV Examples
+
+[nRo/DataFrame]("https://raw.githubusercontent.com/nRo/DataFrame/master/src/test/resources/users.csv") provides the following CSV file
+
+```
+name;age;country
+Schmitt;24;Germany
+Parker;45;USA
+Meier;20;Germany
+Schmitt;30;France
+Peter;44;Germany
+Meier;24;Germany
+Green;33;UK
+Schmitt;30;Germany
+Meier;30;Germany
+```
+
+and create a `DateFrame` using the following code
+
+```
+<#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader().withDelimiter(';')>
+<#assign csvParser = CSVTool.parse(DataSources.get(0), cvsFormat)>
+<#assign users = DataFrameTool.toDataFrame(csvParser)>
+```
+
+#### Select By Age
+
+```
+${DataFrameTool.print(users.select("(age > 40)"))}
+```
+
+which shows
+
+```
+┌────────────┬────────────┬────────────┐
+│#name │#age │#country │
+├────────────┼────────────┼────────────┤
+│Parker │45 │USA │
+├────────────┼────────────┼────────────┤
+│Peter │44 │Germany │
+└────────────┴────────────┴────────────┘
+```
+
+#### Complex Select & Sort
+
+Now we want to create a new `DataFrame` by selecting `name` and `country`
+
+```
+<#assign country = "Germany">
+${DataFrameTool.print(users
+ .select("(name == 'Schmitt' || name == 'Meier') && country == '${country}'")
+ .sort("name", DataFrameTool.sortOrder["ASCENDING"]))}
+```
+
+which shows
+
+```
+┌────────────┬────────────┬────────────┐
+│#name │#age │#country │
+├────────────┼────────────┼────────────┤
+│Meier │20 │Germany │
+├────────────┼────────────┼────────────┤
+│Meier │24 │Germany │
+├────────────┼────────────┼────────────┤
+│Meier │30 │Germany │
+├────────────┼────────────┼────────────┤
+│Schmitt │24 │Germany │
+├────────────┼────────────┼────────────┤
+│Schmitt │30 │Germany │
+└────────────┴────────────┴────────────┘
+```
+
+#### Count Column Values
-> ./bin/freemarker-cli -t templates/json/yaml/transform.ftl site/sample/json/swagger-spec.json
-> ./bin/freemarker-cli -i '${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))}' site/sample/json/swagger-spec.json
-> ./bin/freemarker-cli -i '${YamlTool.toYaml(json)}' -m json=site/sample/json/swagger-spec.json
+Let's assume we want to count the records for each `country`
+
+```
+${DataFrameTool.print(users.getColumn("country").transform(DataFrameTool.transformer["COUNT"]))}
```
-## 6.16 Using Advanced FreeMarker Features
+returns the following `DataFrame`
+
+```
+┌────────────┬────────────┐
+│#country │#counts │
+├────────────┼────────────┤
+│Germany │6 │
+├────────────┼────────────┤
+│USA │1 │
+├────────────┼────────────┤
+│France │1 │
+├────────────┼────────────┤
+│UK │1 │
+└────────────┴────────────┘
+```
+
+#### Group By Age And Country
+
+Let's assume that we want to group the `DataFrame` by `age` and `country`
+
+```
+${DataFrameTool.print(users.groupBy("age", "country").sort("age"))}
+```
+
+which results in
+
+```
+┌────────────┬────────────┐
+│#age │#country │
+├────────────┼────────────┤
+│20 │Germany │
+├────────────┼────────────┤
+│24 │Germany │
+├────────────┼────────────┤
+│30 │France │
+├────────────┼────────────┤
+│30 │Germany │
+├────────────┼────────────┤
+│33 │UK │
+├────────────┼────────────┤
+│44 │Germany │
+├────────────┼────────────┤
+│45 │USA │
+└────────────┴────────────┘
+```
+
+### JSON Examples
+
+Here we load a `examples/data/json/github-users.json` which represents a tabular data be
+being parsed as a list of maps and print the JSOB as dataframe
+
+```
+./bin/freemarker-cli -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))}' examples/data/json/github-users.json
+
+┌────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┐
+│#login │#id │#avatar_ur │#gravatar_ │#url │#html_url │#followers │#following │#gists_url │#starred_u │#subscript │#organizat │#repos_url │#events_ur │#received_ │#type │#site_admi │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│mojombo │1.00000000 │https:/... │ │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │User │false │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│defunkt │2.00000000 │https:/... │ │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │User │true │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│pjhyett │3.00000000 │https:/... │ │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │User │true │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│wycats │4.00000000 │https:/... │ │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │User │false │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│ezmobius │5.00000000 │https:/... │ │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │User │false │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│ivey │6.00000000 │https:/... │ │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │User │false │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│evanphx │7.00000000 │https:/... │ │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │https:/... │User │false │
+└────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┘
+```
+
+### Excel Examples
+
+Let's transform an Excel Sheet to a `DataFrame` being printed using the following template
+
+```
+<#assign dataSource = DataSources.get(0)>
+<#assign workbook = ExcelTool.parse(dataSource)>
+<#list ExcelTool.getSheets(workbook) as sheet>
+ <#assign table = ExcelTool.toTable(sheet)>
+ <#assign df = DataFrameTool.fromRows(table, true)>
+ ${DataFrameTool.print(df)}<#t>
+</#list>
+```
+
+which is rendered by the following command line invocation
+
+```
+./bin/freemarker-cli -t examples/templates/excel/dataframe/transform.ftl examples/data/excel/test.xls
+
+┌────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┐
+│#Text │#Date │#Number │#Currency │#Time │#Percentag │#Forumula │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│Row 1 │01/01/17 │100.00 │€100.00 │10:00 │50.00% │C2*F2 │
+├────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┤
+│Row 2 │01/01/17 │100.00 │€100.00 │10:00 │50.00% │C3*F3 │
+└────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┘
+```
+
+## 6.17 Using Advanced FreeMarker Features
There is a `demo.ftl` which shows some advanced FreeMarker functionality
@@ -1135,7 +1328,7 @@ There is a `demo.ftl` which shows some advanced FreeMarker functionality
Running
-> ./bin/freemarker-cli -t templates/demo.ftl
+> ./bin/freemarker-cli -t examples/templates/demo.ftl
gives you
@@ -1143,11 +1336,12 @@ gives you
1) FreeMarker Special Variables
---------------------------------------------------------------------------
FreeMarker version : 2.3.30
-Template name : templates/demo.ftl
+Template name : demo.ftl
Language : en
Locale : en_US
-Timestamp : Apr 14, 2020 11:40:26 PM
+Timestamp : Jun 18, 2020 11:13:51 AM
Output encoding : UTF-8
+Output format : plainText
2) Invoke a constructor of a Java class
---------------------------------------------------------------------------
@@ -1155,8 +1349,8 @@ new java.utilDate(1000 * 3600 * 24): Jan 2, 1970 1:00:00 AM
3) Invoke a static method of an non-constructor class
---------------------------------------------------------------------------
-Random UUID : 1fdb5ead-80a3-418c-bcc7-242e41b4e950
-System.currentTimeMillis : 1,582,386,859,782
+Random UUID : ac6c8bb2-a8cf-423e-ad6b-a4eff09b1fb9
+System.currentTimeMillis : 1,592,471,631,655
4) Access an Enumeration
---------------------------------------------------------------------------
@@ -1173,23 +1367,23 @@ java.math.RoundingMode#UP: UP
- java.math.RoundingMode.HALF_EVEN
- java.math.RoundingMode.UNNECESSARY
-6) Display list of input files
+6) Display list of data sources
---------------------------------------------------------------------------
-List all files:
+List all data sources:
7) SystemTool
---------------------------------------------------------------------------
-Host name : W0GL5179.local
-Command line : -t, templates/demo.ftl
+Host name : W0GL5179.home
+Command line : -t, examples/templates/demo.ftl
System property : sgoeschl
-Timestamp : 1582386860080
+Timestamp : 1592471631667
Environment var : sgoeschl
8) Access System Properties
---------------------------------------------------------------------------
app.dir :
app.home : /Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler
-app.pid : 71792
+app.pid : 13037
basedir : /Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler
java.version : 1.8.0_192
user.name : sgoeschl
@@ -1198,11 +1392,45 @@ user.home : /Users/sgoeschl
9) List Environment Variables
---------------------------------------------------------------------------
+- PATH ==> /Users/sgoeschl/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/bin:/usr/local/opt/ruby/bin:HOME/.gem/ruby/2.7.0/bin:/usr/local/Cellar/git/2.19.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Java/apache-fop-2.3:/Applications/Java/freemarker-cli-2.0.0-BETA-2/bin:
+- GIT_HOME ==> /usr/local/Cellar/git/2.19.1
+- JAVA_8_HOME ==> /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
+- JAVA_HOME ==> /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
+- FOP_HOME ==> /Applications/Java/apache-fop-2.3
- TERM ==> xterm-256color
- LANG ==> en_US
+- MAVEN_OPTS ==> -Xmx2048m
- DISPLAY ==> :0.0
+- JAVA_11_HOME ==> /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
+- BEEONE_NEXUS_CREDENTIALS ==> H50N0OB:fRidnevo0420!
+- JAVA_9_HOME ==> /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
+- LOGNAME ==> sgoeschl
+- XPC_SERVICE_NAME ==> 0
+- PWD ==> /Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler
+- TERM_PROGRAM_VERSION ==> 433
+- RUBY_HOME ==> /usr/local/opt/ruby
+- JAVA_MAIN_CLASS_13037 ==> org.apache.freemarker.generator.cli.Main
- SHELL ==> /bin/bash
+- PROFILE_TYPE ==> development
+- TERM_PROGRAM ==> Apple_Terminal
+- LSCOLORS ==> ExFxCxDxBxegedabagacad
+- PROFILE_ENV ==> default
+- SECURITYSESSIONID ==> 186a8
+- USER ==> sgoeschl
+- CLICOLOR ==> 1
+- GATLING_HOME ==> /Applications/Java/gatling-3.1.2
+- LaunchInstanceID ==> E8DE55F6-626E-4D15-B3B4-FFE4704CEF4E
+- TMPDIR ==> /var/folders/cd/jbgc9cg14ld7dlsqk44tpmrw0000gn/T/
+- SSH_AUTH_SOCK ==> /private/tmp/com.apple.launchd.DTdlBj20Ka/Listeners
- EDITOR ==> vi
+- XPC_FLAGS ==> 0x0
+- FREEMARKER_CLI_HOME ==> /Applications/Java/freemarker-cli-2.0.0-BETA-2
+- TERM_SESSION_ID ==> 2745D6A3-543A-4DE3-830B-945678460311
+- LC_ALL ==> en_US.utf-8
+- __CF_USER_TEXT_ENCODING ==> 0x1F5:0x0:0x0
+- LC_CTYPE ==> UTF-8
+- HOME ==> /Users/sgoeschl
+- SHLVL ==> 1
10) List System Properties
---------------------------------------------------------------------------
@@ -1210,19 +1438,23 @@ user.home : /Users/sgoeschl
- java.vm.version ==> 25.192-b12
- java.vm.vendor ==> Oracle Corporation
- java.vendor.url ==> http://java.oracle.com/
+- path.separator ==> :
- java.vm.name ==> Java HotSpot(TM) 64-Bit Server VM
+- file.encoding.pkg ==> sun.io
+- user.country ==> AT
11) Access DataSources
---------------------------------------------------------------------------
-Get the number of data sources:
+Get the number of documents:
- 0
List all files containing "README" in the name
List all files having "md" extension
-Get all data sources
+Get all documents
12) FreeMarker CLI Tools
---------------------------------------------------------------------------
- CSVTool : Process CSV files using Apache Commons CSV (see https://commons.apache.org/proper/commons-csv/)
+- DataFrameTool : Bridge to nRo/DataFrame (see https://github.com/nRo/DataFrame)
- ExcelTool : Process Excels files (XLS, XLSX) using Apache POI (see https://poi.apache.org)
- ExecTool : Execute command line tools using Apache Commons Exec (see https://commons.apache.org/proper/commons-exec/)
- FreeMarkerTool : Expose useful Apache FreeMarker classes
@@ -1239,6 +1471,7 @@ Get all data sources
13) Document Data Model
---------------------------------------------------------------------------
- CSVTool
+- DataFrameTool
- DataSources
- ExcelTool
- ExecTool
@@ -1255,7 +1488,7 @@ Get all data sources
14) Create a UUID
---------------------------------------------------------------------------
-UUIDTool Random UUID : 936315a5-ee3d-44cd-a32c-2be10d2249a6
+UUIDTool Random UUID : 832a20fb-ac22-460a-b5d0-33c6fcc126d2
UUIDTool Named UUID : 298415f9-e888-3d98-90e7-6c0d63ad14dc
15) Printing Special Characters
@@ -1266,13 +1499,13 @@ German Special Characters: äöüßÄÖÜ
---------------------------------------------------------------------------
Small Number : 1.23
Large Number : 12,345,678.90
-Date : Apr 14, 2020
-Time : 11:40:26 PM
+Date : Jun 18, 2020
+Time : 11:13:51 AM
17) Execute a program
---------------------------------------------------------------------------
> date
-Tue Apr 14 23:40:26 CEST 2020
+Thu Jun 18 11:13:51 CEST 2020
```
# 7. Design Considerations
@@ -1290,6 +1523,7 @@ Within the script a FreeMarker data model is set up and passed to the template -
| Entry | Description |
|-----------------------|-----------------------------------------------------------------------------------------------------------|
| CSVTool | Process CSV files using [Apache Commons CSV](https://commons.apache.org/proper/commons-csv/) |
+| DataFrameTool | Bridge to [nRo/DataFrame](https://github.com/nRo/DataFrame) |
| 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) |
| DataSources | Helper class to find data sources, e.g. by name, extension or index |
@@ -1314,10 +1548,14 @@ When doing some ad-hoc scripting it is useful to rely on a base directory to res
* As a default the FTL templates are resolved relative to the script directory
* The caller can provide a `-b` or `--basedir` command line parameter
-> ./bin/freemarker-cli -t templates/json/html/customer-user-products.ftl freemarker-cli/site/sample/json/customer-user-products.jso
+```text
+./bin/freemarker-cli -b examples/templates -t json/md/github-users.ftl examples/data/json/github-users.json; echo
+```
## 8.2 Using Pipes
When doing ad-hoc scripting it useful to pipe the output of one command directly into "freemarker-cli"
-> cat site/sample/json/customer-user-products.json | ./bin/freemarker-cli -t ./templates/json/html/customer-user-products.ftl --stdin
\ No newline at end of file
+```text
+cat examples/data/json/github-users.json | ./bin/freemarker-cli -t examples/templates/json/md/github-users.ftl --stdin; echo
+```
diff --git a/freemarker-generator-cli/site/sample/accesslog/combined-access.log b/freemarker-generator-cli/examples/data/accesslog/combined-access.log
similarity index 100%
rename from freemarker-generator-cli/site/sample/accesslog/combined-access.log
rename to freemarker-generator-cli/examples/data/accesslog/combined-access.log
diff --git a/freemarker-generator-cli/site/sample/csv/contract.csv b/freemarker-generator-cli/examples/data/csv/contract.csv
similarity index 100%
rename from freemarker-generator-cli/site/sample/csv/contract.csv
rename to freemarker-generator-cli/examples/data/csv/contract.csv
diff --git a/freemarker-generator-cli/site/sample/csv/dataframe.csv b/freemarker-generator-cli/examples/data/csv/dataframe.csv
similarity index 100%
rename from freemarker-generator-cli/site/sample/csv/dataframe.csv
rename to freemarker-generator-cli/examples/data/csv/dataframe.csv
diff --git a/freemarker-generator-cli/site/sample/csv/excel-export-utf8.csv b/freemarker-generator-cli/examples/data/csv/excel-export-utf8.csv
similarity index 100%
rename from freemarker-generator-cli/site/sample/csv/excel-export-utf8.csv
rename to freemarker-generator-cli/examples/data/csv/excel-export-utf8.csv
diff --git a/freemarker-generator-cli/site/sample/csv/locker-test-users.csv b/freemarker-generator-cli/examples/data/csv/locker-test-users.csv
similarity index 100%
rename from freemarker-generator-cli/site/sample/csv/locker-test-users.csv
rename to freemarker-generator-cli/examples/data/csv/locker-test-users.csv
diff --git a/freemarker-generator-cli/site/sample/csv/sales-records.csv b/freemarker-generator-cli/examples/data/csv/sales-records.csv
similarity index 100%
rename from freemarker-generator-cli/site/sample/csv/sales-records.csv
rename to freemarker-generator-cli/examples/data/csv/sales-records.csv
diff --git a/freemarker-generator-cli/site/sample/csv/transactions.csv b/freemarker-generator-cli/examples/data/csv/transactions.csv
similarity index 100%
rename from freemarker-generator-cli/site/sample/csv/transactions.csv
rename to freemarker-generator-cli/examples/data/csv/transactions.csv
diff --git a/freemarker-generator-cli/site/sample/csv/user.csv b/freemarker-generator-cli/examples/data/csv/user.csv
similarity index 100%
rename from freemarker-generator-cli/site/sample/csv/user.csv
rename to freemarker-generator-cli/examples/data/csv/user.csv
diff --git a/freemarker-generator-cli/site/sample/excel/test-multiple-sheets.xlsx b/freemarker-generator-cli/examples/data/excel/test-multiple-sheets.xlsx
similarity index 100%
rename from freemarker-generator-cli/site/sample/excel/test-multiple-sheets.xlsx
rename to freemarker-generator-cli/examples/data/excel/test-multiple-sheets.xlsx
diff --git a/freemarker-generator-cli/site/sample/excel/test.xls b/freemarker-generator-cli/examples/data/excel/test.xls
similarity index 100%
rename from freemarker-generator-cli/site/sample/excel/test.xls
rename to freemarker-generator-cli/examples/data/excel/test.xls
diff --git a/freemarker-generator-cli/site/sample/excel/test.xlsx b/freemarker-generator-cli/examples/data/excel/test.xlsx
similarity index 100%
rename from freemarker-generator-cli/site/sample/excel/test.xlsx
rename to freemarker-generator-cli/examples/data/excel/test.xlsx
diff --git a/freemarker-generator-cli/site/sample/ftl/nginx/nginx.conf.ftl b/freemarker-generator-cli/examples/data/ftl/nginx/nginx.conf.ftl
similarity index 100%
rename from freemarker-generator-cli/site/sample/ftl/nginx/nginx.conf.ftl
rename to freemarker-generator-cli/examples/data/ftl/nginx/nginx.conf.ftl
diff --git a/freemarker-generator-cli/site/sample/ftl/nginx/nginx.env b/freemarker-generator-cli/examples/data/ftl/nginx/nginx.env
similarity index 100%
rename from freemarker-generator-cli/site/sample/ftl/nginx/nginx.env
rename to freemarker-generator-cli/examples/data/ftl/nginx/nginx.env
diff --git a/freemarker-generator-cli/site/sample/html/dependencies.html b/freemarker-generator-cli/examples/data/html/dependencies.html
similarity index 100%
rename from freemarker-generator-cli/site/sample/html/dependencies.html
rename to freemarker-generator-cli/examples/data/html/dependencies.html
diff --git a/freemarker-generator-cli/site/sample/json/github-users.json b/freemarker-generator-cli/examples/data/json/github-users.json
similarity index 100%
rename from freemarker-generator-cli/site/sample/json/github-users.json
rename to freemarker-generator-cli/examples/data/json/github-users.json
diff --git a/freemarker-generator-cli/site/sample/json/swagger-spec.json b/freemarker-generator-cli/examples/data/json/swagger-spec.json
similarity index 100%
rename from freemarker-generator-cli/site/sample/json/swagger-spec.json
rename to freemarker-generator-cli/examples/data/json/swagger-spec.json
diff --git a/freemarker-generator-cli/site/sample/properties/user_0001/user.properties b/freemarker-generator-cli/examples/data/properties/user_0001/user.properties
similarity index 100%
rename from freemarker-generator-cli/site/sample/properties/user_0001/user.properties
rename to freemarker-generator-cli/examples/data/properties/user_0001/user.properties
diff --git a/freemarker-generator-cli/site/sample/properties/user_0002/user.properties b/freemarker-generator-cli/examples/data/properties/user_0002/user.properties
similarity index 100%
rename from freemarker-generator-cli/site/sample/properties/user_0002/user.properties
rename to freemarker-generator-cli/examples/data/properties/user_0002/user.properties
diff --git a/freemarker-generator-cli/site/sample/properties/user_0003/user.properties b/freemarker-generator-cli/examples/data/properties/user_0003/user.properties
similarity index 100%
rename from freemarker-generator-cli/site/sample/properties/user_0003/user.properties
rename to freemarker-generator-cli/examples/data/properties/user_0003/user.properties
diff --git a/freemarker-generator-cli/site/sample/properties/user_0004/user.properties b/freemarker-generator-cli/examples/data/properties/user_0004/user.properties
similarity index 100%
rename from freemarker-generator-cli/site/sample/properties/user_0004/user.properties
rename to freemarker-generator-cli/examples/data/properties/user_0004/user.properties
diff --git a/freemarker-generator-cli/site/template/application.properties b/freemarker-generator-cli/examples/data/template/application.properties
similarity index 100%
rename from freemarker-generator-cli/site/template/application.properties
rename to freemarker-generator-cli/examples/data/template/application.properties
diff --git a/freemarker-generator-cli/site/template/nginx/nginx.conf.ftl b/freemarker-generator-cli/examples/data/template/nginx/nginx.conf.ftl
similarity index 100%
rename from freemarker-generator-cli/site/template/nginx/nginx.conf.ftl
rename to freemarker-generator-cli/examples/data/template/nginx/nginx.conf.ftl
diff --git a/freemarker-generator-cli/site/sample/xml/recipients.xml b/freemarker-generator-cli/examples/data/xml/recipients.xml
similarity index 100%
rename from freemarker-generator-cli/site/sample/xml/recipients.xml
rename to freemarker-generator-cli/examples/data/xml/recipients.xml
diff --git a/freemarker-generator-cli/site/sample/yaml/customer.yaml b/freemarker-generator-cli/examples/data/yaml/customer.yaml
similarity index 100%
rename from freemarker-generator-cli/site/sample/yaml/customer.yaml
rename to freemarker-generator-cli/examples/data/yaml/customer.yaml
diff --git a/freemarker-generator-cli/site/sample/yaml/swagger-spec.yaml b/freemarker-generator-cli/examples/data/yaml/swagger-spec.yaml
similarity index 100%
rename from freemarker-generator-cli/site/sample/yaml/swagger-spec.yaml
rename to freemarker-generator-cli/examples/data/yaml/swagger-spec.yaml
diff --git a/freemarker-generator-cli/templates/accesslog/combined-access.ftl b/freemarker-generator-cli/examples/templates/accesslog/combined-access.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/accesslog/combined-access.ftl
rename to freemarker-generator-cli/examples/templates/accesslog/combined-access.ftl
diff --git a/freemarker-generator-cli/templates/cat.ftl b/freemarker-generator-cli/examples/templates/cat.ftl
similarity index 100%
copy from freemarker-generator-cli/templates/cat.ftl
copy to freemarker-generator-cli/examples/templates/cat.ftl
diff --git a/freemarker-generator-cli/templates/csv/csv/gatling-user-credentials.ftl b/freemarker-generator-cli/examples/templates/csv/csv/gatling-user-credentials.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/csv/csv/gatling-user-credentials.ftl
rename to freemarker-generator-cli/examples/templates/csv/csv/gatling-user-credentials.ftl
diff --git a/freemarker-generator-cli/templates/csv/fo/transactions.ftl b/freemarker-generator-cli/examples/templates/csv/fo/transactions.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/csv/fo/transactions.ftl
rename to freemarker-generator-cli/examples/templates/csv/fo/transactions.ftl
diff --git a/freemarker-generator-cli/templates/csv/fo/transform.ftl b/freemarker-generator-cli/examples/templates/csv/fo/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/csv/fo/transform.ftl
rename to freemarker-generator-cli/examples/templates/csv/fo/transform.ftl
diff --git a/freemarker-generator-cli/templates/csv/html/transactions.ftl b/freemarker-generator-cli/examples/templates/csv/html/transactions.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/csv/html/transactions.ftl
rename to freemarker-generator-cli/examples/templates/csv/html/transactions.ftl
diff --git a/freemarker-generator-cli/templates/csv/md/filter.ftl b/freemarker-generator-cli/examples/templates/csv/md/filter.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/csv/md/filter.ftl
rename to freemarker-generator-cli/examples/templates/csv/md/filter.ftl
diff --git a/freemarker-generator-cli/templates/csv/shell/curl.ftl b/freemarker-generator-cli/examples/templates/csv/shell/curl.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/csv/shell/curl.ftl
rename to freemarker-generator-cli/examples/templates/csv/shell/curl.ftl
diff --git a/freemarker-generator-cli/templates/dataframe/example.ftl b/freemarker-generator-cli/examples/templates/dataframe/example.ftl
similarity index 76%
rename from freemarker-generator-cli/templates/dataframe/example.ftl
rename to freemarker-generator-cli/examples/templates/dataframe/example.ftl
index 54d0ac2..d1eef7b 100644
--- a/freemarker-generator-cli/templates/dataframe/example.ftl
+++ b/freemarker-generator-cli/examples/templates/dataframe/example.ftl
@@ -15,7 +15,8 @@
specific language governing permissions and limitations
under the License.
-->
-<#assign csvParser = CSVTool.parse(DataSources.get(0))>
+<#assign dataSource = DataSources.get(0)>
+<#assign csvParser = CSVTool.parse(dataSource, csvInFormat())>
<#assign users = DataFrameTool.fromCSVParser(csvParser)>
Original Data
@@ -44,5 +45,14 @@ ${DataFrameTool.print(users.getColumn("country").transform(DataFrameTool.transfo
Group By Age & Country
=============================================================================
${DataFrameTool.print(users.groupBy("country", "age").sort("country"))}
-
-
+<#--------------------------------------------------------------------------->
+<#function csvInFormat>
+ <#assign format = CSVTool.formats[CSV_SOURCE_FORMAT!"DEFAULT"]>
+ <#assign delimiter = CSVTool.toDelimiter(CSV_SOURCE_DELIMITER!format.getDelimiter())>
+ <#assign withHeader = CSV_SOURCE_WITH_HEADER!"false">
+ <#assign format = format.withDelimiter(delimiter)>
+ <#if withHeader?boolean>
+ <#assign format = format.withHeader()>
+ </#if>
+ <#return format>
+</#function>
diff --git a/freemarker-generator-cli/templates/dataframe/html/print.ftl b/freemarker-generator-cli/examples/templates/dataframe/html/print.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/dataframe/html/print.ftl
rename to freemarker-generator-cli/examples/templates/dataframe/html/print.ftl
diff --git a/freemarker-generator-cli/templates/demo.ftl b/freemarker-generator-cli/examples/templates/demo.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/demo.ftl
rename to freemarker-generator-cli/examples/templates/demo.ftl
diff --git a/freemarker-generator-cli/templates/excel/csv/custom.ftl b/freemarker-generator-cli/examples/templates/excel/csv/custom.ftl
similarity index 95%
rename from freemarker-generator-cli/templates/excel/csv/custom.ftl
rename to freemarker-generator-cli/examples/templates/excel/csv/custom.ftl
index a045bd3..ac4b4be 100644
--- a/freemarker-generator-cli/templates/excel/csv/custom.ftl
+++ b/freemarker-generator-cli/examples/templates/excel/csv/custom.ftl
@@ -15,7 +15,7 @@
specific language governing permissions and limitations
under the License.
-->
-<#assign format = CVS_FORMAT!"DEFAULT">
+<#assign format = CSV_TARGET_FORMAT!"DEFAULT">
<#assign salt = SystemTool.parameters["salt"]!"salt">
<#-- Parse the first data source & sheet of the Excel document -->
<#assign workbook = ExcelTool.parse(DataSources.get(0))>
@@ -23,7 +23,7 @@
<#assign records = ExcelTool.toTable(sheet)>
<#-- Setup CSVPrinter -->
<#assign cvsFormat = CSVTool.formats[format]>
-<#assign csvPrinter = CSVTool.printer(cvsFormat, SystemTool.writer)>
+<#assign csvPrinter = CSVTool.printer(cvsFormat)>
<#--
Transform an arbitrary Excel file and add addition columns using Commons CSV
We are using an instance of CSVPrinter directly have proper quoting of the output
diff --git a/freemarker-generator-cli/templates/excel/dataframe/transform.ftl b/freemarker-generator-cli/examples/templates/excel/dataframe/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/excel/dataframe/transform.ftl
rename to freemarker-generator-cli/examples/templates/excel/dataframe/transform.ftl
diff --git a/freemarker-generator-cli/templates/html/csv/dependencies.ftl b/freemarker-generator-cli/examples/templates/html/csv/dependencies.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/html/csv/dependencies.ftl
rename to freemarker-generator-cli/examples/templates/html/csv/dependencies.ftl
diff --git a/freemarker-generator-cli/templates/info.ftl b/freemarker-generator-cli/examples/templates/info.ftl
similarity index 100%
copy from freemarker-generator-cli/templates/info.ftl
copy to freemarker-generator-cli/examples/templates/info.ftl
diff --git a/freemarker-generator-cli/templates/json/csv/swagger-endpoints.ftl b/freemarker-generator-cli/examples/templates/json/csv/swagger-endpoints.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/json/csv/swagger-endpoints.ftl
rename to freemarker-generator-cli/examples/templates/json/csv/swagger-endpoints.ftl
diff --git a/freemarker-generator-cli/templates/json/md/github-users.ftl b/freemarker-generator-cli/examples/templates/json/md/github-users.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/json/md/github-users.ftl
rename to freemarker-generator-cli/examples/templates/json/md/github-users.ftl
diff --git a/freemarker-generator-cli/templates/properties/csv/locker-test-users.ftl b/freemarker-generator-cli/examples/templates/properties/csv/locker-test-users.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/properties/csv/locker-test-users.ftl
rename to freemarker-generator-cli/examples/templates/properties/csv/locker-test-users.ftl
diff --git a/freemarker-generator-cli/templates/tsv/fo/transactions.ftl b/freemarker-generator-cli/examples/templates/tsv/fo/transactions.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/tsv/fo/transactions.ftl
rename to freemarker-generator-cli/examples/templates/tsv/fo/transactions.ftl
diff --git a/freemarker-generator-cli/templates/xml/txt/recipients.ftl b/freemarker-generator-cli/examples/templates/xml/txt/recipients.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/xml/txt/recipients.ftl
rename to freemarker-generator-cli/examples/templates/xml/txt/recipients.ftl
diff --git a/freemarker-generator-cli/templates/yaml/txt/transform.ftl b/freemarker-generator-cli/examples/templates/yaml/txt/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/templates/yaml/txt/transform.ftl
rename to freemarker-generator-cli/examples/templates/yaml/txt/transform.ftl
diff --git a/freemarker-generator-cli/pom.xml b/freemarker-generator-cli/pom.xml
index 892473d..47756a9 100644
--- a/freemarker-generator-cli/pom.xml
+++ b/freemarker-generator-cli/pom.xml
@@ -71,14 +71,17 @@
<configuration>
<target>
<copy file="README.md" todir="./target/appassembler" />
- <copy file="./src/main/scripts/run-samples.sh" todir="./target/appassembler" />
+ <copy file="./src/main/scripts/run-examples.sh" todir="./target/appassembler" />
<copy todir="./target/appassembler/site">
<fileset dir="site" />
</copy>
<copy todir="./target/appassembler/templates">
<fileset dir="templates" />
</copy>
- <chmod file="./target/appassembler/run-samples.sh" perm="a+x" />
+ <copy todir="./target/appassembler/examples">
+ <fileset dir="examples" />
+ </copy>
+ <chmod file="./target/appassembler/run-examples.sh" perm="a+x" />
</target>
</configuration>
<goals>
@@ -144,7 +147,7 @@
<exclude>src/site/markdown/**/*.md</exclude>
<exclude>.travis.yml</exclude>
<exclude>src/main/resources/patterns/*</exclude>
- <exclude>site/sample/*/**</exclude>
+ <exclude>examples/data/*/**</exclude>
<exclude>src/test/data/encoding/utf8.txt</exclude>
<exclude>src/test/data/json/*/**</exclude>
<exclude>src/test/data/yaml/environments.yaml</exclude>
diff --git a/freemarker-generator-cli/run-examples.sh b/freemarker-generator-cli/run-examples.sh
new file mode 100755
index 0000000..f1ad546
--- /dev/null
+++ b/freemarker-generator-cli/run-examples.sh
@@ -0,0 +1,193 @@
+#!/bin/sh
+#
+# 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.
+
+# Check that java is on the path
+
+hash java 2>/dev/null || { echo >&2 "I require JDK but it's not installed. Aborting."; exit 1; }
+hash mvn 2>/dev/null || { echo >&2 "I require Maven but it's not installed. Aborting."; exit 1; }
+
+# Run all the samples being documented
+
+mkdir target 2>/dev/null
+mkdir target/out 2>/dev/null
+
+FREEMARKER_CMD="target/appassembler/bin/freemarker-cli"
+# FREEMARKER_CMD="java -jar target/freemarker-cli-2.0.0-BETA-4-SNAPSHOT-jar-with-dependencies.jar"
+
+#############################################################################
+# Info
+#############################################################################
+
+echo "templates/info.ftl"
+$FREEMARKER_CMD -t templates/info.ftl README.md > target/out/info.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Demo
+#############################################################################
+
+echo "examples/templates/demo.ftl"
+$FREEMARKER_CMD -t examples/templates/demo.ftl README.md > target/out/demo.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Interactive Mode
+#############################################################################
+
+$FREEMARKER_CMD -i '${JsonPathTool.parse(DataSources.first).read("$.info.title")}' examples/data/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"]}' examples/data/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]}' examples/data/html/dependencies.html > target/out/interactive-html.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -i '${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}' examples/data/yaml/swagger-spec.yaml > target/out/interactive-swagger.json || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -i '${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))}' examples/data/json/swagger-spec.json > target/out/interactive-swagger.yaml || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))}' examples/data/json/github-users.json > target/out/interactive-dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# CSV
+#############################################################################
+
+echo "templates/csv/html/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/html/transform.ftl examples/data/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+echo "templates/csv/md/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/md/transform.ftl examples/data/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# CSV To XML-FO & PDF
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+if hash fop 2>/dev/null; then
+ echo "fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf"
+ fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+if hash fop 2>/dev/null; then
+ echo "fop -fo target/out/transactions.fo target/out/transactions-fo.pdf"
+ fop -fo target/out/transactions.fo target/out/transactions-fo.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+#############################################################################
+# CSV to HTML & PDF
+#############################################################################
+
+echo "templates/csv/html/transform.ftl"
+$FREEMARKER_CMD -t examples/templates/csv/html/transactions.ftl examples/data/csv/transactions.csv > target/out/transactions.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+if hash wkhtmltopdf 2>/dev/null; then
+ echo "wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf"
+ wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+#############################################################################
+# DataFrame
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Grok
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Excel
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+echo "templates/excel/html/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# HTML
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# JSON
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+#############################################################################
+# Properties
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Template Directory
+#############################################################################
+
+echo "examples/data/template"
+$FREEMARKER_CMD -t examples/data/template -PNGINX_HOSTNAME=localhost -o target/out/template || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# YAML
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# XML
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+echo "Created the following sample files in ./target/out"
+ls -l ./target/out
\ No newline at end of file
diff --git a/freemarker-generator-cli/run-samples.sh b/freemarker-generator-cli/run-samples.sh
deleted file mode 100755
index ec2733a..0000000
--- a/freemarker-generator-cli/run-samples.sh
+++ /dev/null
@@ -1,193 +0,0 @@
-#!/bin/sh
-#
-# 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.
-
-# Check that java is on the path
-
-hash java 2>/dev/null || { echo >&2 "I require JDK but it's not installed. Aborting."; exit 1; }
-hash mvn 2>/dev/null || { echo >&2 "I require Maven but it's not installed. Aborting."; exit 1; }
-
-# Run all the samples being documented
-
-mkdir target 2>/dev/null
-mkdir target/out 2>/dev/null
-
-FREEMARKER_CMD="target/appassembler/bin/freemarker-cli"
-# FREEMARKER_CMD="java -jar target/freemarker-cli-2.0.0-BETA-4-SNAPSHOT-jar-with-dependencies.jar"
-
-#############################################################################
-# Info
-#############################################################################
-
-echo "templates/info.ftl"
-$FREEMARKER_CMD -t templates/info.ftl README.md > target/out/info.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Demo
-#############################################################################
-
-echo "templates/demo.ftl"
-$FREEMARKER_CMD -t templates/demo.ftl README.md > target/out/demo.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Interactive Mode
-#############################################################################
-
-$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; }
-$FREEMARKER_CMD -i '${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}' site/sample/yaml/swagger-spec.yaml > target/out/interactive-swagger.json || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -i '${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))}' site/sample/json/swagger-spec.json > target/out/interactive-swagger.yaml || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))}' site/sample/json/github-users.json > target/out/interactive-dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# CSV
-#############################################################################
-
-echo "templates/csv/html/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/html/transform.ftl site/sample/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/csv/md/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/md/transform.ftl site/sample/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/csv/shell/curl.ftl"
-$FREEMARKER_CMD -t ./templates/csv/shell/curl.ftl site/sample/csv/user.csv > target/out/curl.sh || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/csv/md/filter.ftl"
-$FREEMARKER_CMD -e UTF-8 -l de_AT -Pcolumn="Order ID" -Pvalues=226939189,957081544 -Pformat=DEFAULT -Pdelimiter=COMMA -t templates/csv/md/filter.ftl site/sample/csv/sales-records.csv > target/out/sales-records.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# CSV To XML-FO & PDF
-#############################################################################
-
-echo "templates/csv/fo/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/fo/transform.ftl site/sample/csv/locker-test-users.csv > target/out/locker-test-users.fo || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash fop 2>/dev/null; then
- echo "fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf"
- fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-echo "templates/csv/fo/transactions.ftl"
-$FREEMARKER_CMD -t templates/csv/fo/transactions.ftl site/sample/csv/transactions.csv > target/out/transactions.fo || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash fop 2>/dev/null; then
- echo "fop -fo target/out/transactions.fo target/out/transactions-fo.pdf"
- fop -fo target/out/transactions.fo target/out/transactions-fo.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-#############################################################################
-# CSV to HTML & PDF
-#############################################################################
-
-echo "templates/csv/html/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/html/transactions.ftl site/sample/csv/transactions.csv > target/out/transactions.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash wkhtmltopdf 2>/dev/null; then
- echo "wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf"
- wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-#############################################################################
-# DataFrame
-#############################################################################
-
-echo "templates/dataframe/example.ftl"
-$FREEMARKER_CMD -DCSV_TOOL_DELIMITER=SEMICOLON -DCSV_TOOL_HEADERS=true -t templates/dataframe/example.ftl site/sample/csv/dataframe.csv > target/out/dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Grok
-#############################################################################
-
-echo "templates/accesslog/combined-access.ftl"
-$FREEMARKER_CMD -t templates/accesslog/combined-access.ftl site/sample/accesslog/combined-access.log > target/out/combined-access.log.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Excel
-#############################################################################
-
-echo "templates/excel/dataframe/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/dataframe/transform.ftl site/sample/excel/test.xls > target/out/test.xls.dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/html/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/html/transform.ftl site/sample/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -t templates/excel/html/transform.ftl site/sample/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -t templates/excel/html/transform.ftl site/sample/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/md/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/md/transform.ftl site/sample/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/csv/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/csv/transform.ftl site/sample/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/csv/custom.ftl"
-$FREEMARKER_CMD -t templates/excel/csv/custom.ftl -Pcsv.format=MYSQL site/sample/excel/test.xls > target/out/test-transform-xls.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# HTML
-#############################################################################
-
-echo "templates/html/csv/dependencies.ftl"
-$FREEMARKER_CMD -t templates/html/csv/dependencies.ftl site/sample/html/dependencies.html > target/out/dependencies.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# JSON
-#############################################################################
-
-echo "templates/json/csv/swagger-endpoints.ftl"
-$FREEMARKER_CMD -t templates/json/csv/swagger-endpoints.ftl site/sample/json/swagger-spec.json > target/out/swagger-spec.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/json/yaml/transform.ftl"
-$FREEMARKER_CMD -t templates/json/yaml/transform.ftl site/sample/json/swagger-spec.json > target/out/swagger-spec.yaml || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash curl 2>/dev/null; then
-echo "templates/json/md/github-users.ftl"
-$FREEMARKER_CMD -t templates/json/md/github-users.ftl site/sample/json/github-users.json > target/out/github-users-curl.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-#############################################################################
-# Properties
-#############################################################################
-
-echo "templates/properties/csv/locker-test-users.ftl"
-$FREEMARKER_CMD -t templates/properties/csv/locker-test-users.ftl site/sample/properties > target/out/locker-test-users.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Template Directory
-#############################################################################
-
-echo "site/template"
-$FREEMARKER_CMD -t site/template -PNGINX_HOSTNAME=localhost -o target/out/template || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# YAML
-#############################################################################
-
-echo "templates/yaml/txt/transform.ftl"
-$FREEMARKER_CMD -t templates/yaml/txt/transform.ftl site/sample/yaml/customer.yaml > target/out/customer.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/yaml/json/transform.ftl"
-$FREEMARKER_CMD -t templates/yaml/json/transform.ftl site/sample/yaml/swagger-spec.yaml > target/out/swagger-spec.json || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# XML
-#############################################################################
-
-echo "templates/xml/txt/recipients.ftl"
-$FREEMARKER_CMD -t ./templates/xml/txt/recipients.ftl site/sample/xml/recipients.xml > target/out/recipients.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "Created the following sample files in ./target/out"
-ls -l ./target/out
\ No newline at end of file
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java
index 89e48bf..16dc76f 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/Settings.java
@@ -96,10 +96,10 @@ public class Settings {
private final List<String> dataModels;
/** User-supplied parameters */
- private final Map<String, Object> parameters;
+ private final Map<String, Object> userParameters;
/** User-supplied system properties */
- private final Properties systemProperties;
+ private final Properties userSystemProperties;
/** The writer used for rendering templates, e.g. stdout or a file writer */
private final Writer writer;
@@ -122,8 +122,8 @@ public class Settings {
boolean isReadFromStdin,
List<String> dataSources,
List<String> dataModels,
- Map<String, Object> parameters,
- Properties systemProperties,
+ Map<String, Object> userParameters,
+ Properties userSystemProperties,
Writer writer) {
if ((templates == null || templates.isEmpty()) && isEmpty(interactiveTemplate)) {
throw new IllegalArgumentException("Either 'template' or 'interactiveTemplate' must be provided");
@@ -145,8 +145,8 @@ public class Settings {
this.isReadFromStdin = isReadFromStdin;
this.dataSources = requireNonNull(dataSources);
this.dataModels = requireNonNull(dataModels);
- this.parameters = requireNonNull(parameters);
- this.systemProperties = requireNonNull(systemProperties);
+ this.userParameters = requireNonNull(userParameters);
+ this.userSystemProperties = requireNonNull(userSystemProperties);
this.configuration = requireNonNull(configuration);
this.writer = writer != null ? new NonClosableWriterWrapper(writer) : null;
}
@@ -170,7 +170,7 @@ public class Settings {
public List<String> getTemplates() {
return templates;
}
-
+
public String getInteractiveTemplate() {
return interactiveTemplate;
}
@@ -227,12 +227,12 @@ public class Settings {
return dataModels;
}
- public Map<String, Object> getParameters() {
- return parameters;
+ public Map<String, Object> getUserParameters() {
+ return userParameters;
}
- public Properties getSystemProperties() {
- return systemProperties;
+ public Properties getUserSystemProperties() {
+ return userSystemProperties;
}
public boolean hasOutputFile() {
@@ -254,8 +254,8 @@ public class Settings {
result.put(Model.FREEMARKER_CLI_ARGS, getArgs());
result.put(Model.FREEMARKER_LOCALE, getLocale());
result.put(Model.FREEMARKER_TEMPLATE_DIRECTORIES, getTemplateDirectories());
- result.put(Model.FREEMARKER_USER_PARAMETERS, getParameters());
- result.put(Model.FREEMARKER_USER_SYSTEM_PROPERTIES, getSystemProperties());
+ result.put(Model.FREEMARKER_USER_PARAMETERS, getUserParameters());
+ result.put(Model.FREEMARKER_USER_SYSTEM_PROPERTIES, getUserSystemProperties());
result.put(Model.FREEMARKER_WRITER, getWriter());
return result;
}
@@ -283,8 +283,8 @@ public class Settings {
", locale=" + locale +
", isReadFromStdin=" + isReadFromStdin +
", dataSources=" + dataSources +
- ", properties=" + parameters +
- ", systemProperties=" + systemProperties +
+ ", userParameters=" + userParameters +
+ ", userSystemProperties=" + userSystemProperties +
'}';
}
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 7151600..54e0758 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
@@ -64,7 +64,7 @@ public class Suppliers {
}
public static Supplier<Map<String, Object>> parameterSupplier(Settings settings) {
- return settings::getParameters;
+ return settings::getUserParameters;
}
public static TemplateTransformationsSupplier templateTransformationsSupplier(Settings settings) {
diff --git a/freemarker-generator-cli/src/main/scripts/run-examples.sh b/freemarker-generator-cli/src/main/scripts/run-examples.sh
new file mode 100755
index 0000000..53f4dcd
--- /dev/null
+++ b/freemarker-generator-cli/src/main/scripts/run-examples.sh
@@ -0,0 +1,193 @@
+#!/bin/sh
+
+#
+# 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.
+#
+
+# Check that java is on the path
+
+hash java 2>/dev/null || { echo >&2 "I require JDK but it's not installed. Aborting."; exit 1; }
+
+# Run all the samples being documented
+
+mkdir target 2>/dev/null
+mkdir target/out 2>/dev/null
+
+FREEMARKER_CMD=./bin/freemarker-cli
+
+#############################################################################
+# Info
+#############################################################################
+
+echo "templates/info.ftl"
+$FREEMARKER_CMD -t templates/info.ftl README.md > target/out/info.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Demo
+#############################################################################
+
+echo "examples/templates/demo.ftl"
+$FREEMARKER_CMD -t examples/templates/demo.ftl README.md > target/out/demo.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Interactive Mode
+#############################################################################
+
+$FREEMARKER_CMD -i '${JsonPathTool.parse(DataSources.first).read("$.info.title")}' examples/data/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"]}' examples/data/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]}' examples/data/html/dependencies.html > target/out/interactive-html.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -i '${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}' examples/data/yaml/swagger-spec.yaml > target/out/interactive-swagger.json || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -i '${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))}' examples/data/json/swagger-spec.json > target/out/interactive-swagger.yaml || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))}' examples/data/json/github-users.json > target/out/interactive-dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# CSV
+#############################################################################
+
+echo "templates/csv/html/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/html/transform.ftl examples/data/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+echo "templates/csv/md/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/md/transform.ftl examples/data/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# CSV To XML-FO & PDF
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+if hash fop 2>/dev/null; then
+ echo "fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf"
+ fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+if hash fop 2>/dev/null; then
+ echo "fop -fo target/out/transactions.fo target/out/transactions-fo.pdf"
+ fop -fo target/out/transactions.fo target/out/transactions-fo.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+#############################################################################
+# CSV to HTML & PDF
+#############################################################################
+
+echo "templates/csv/html/transform.ftl"
+$FREEMARKER_CMD -t examples/templates/csv/html/transactions.ftl examples/data/csv/transactions.csv > target/out/transactions.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+if hash wkhtmltopdf 2>/dev/null; then
+ echo "wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf"
+ wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+#############################################################################
+# DataFrame
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Grok
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Excel
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+echo "templates/excel/html/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# HTML
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# JSON
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+fi
+
+#############################################################################
+# Properties
+#############################################################################
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# Template Directory
+#############################################################################
+
+echo "examples/data/template"
+$FREEMARKER_CMD -t examples/data/template -PNGINX_HOSTNAME=localhost -o target/out/template || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# YAML
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+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 || { echo >&2 "Test failed. Aborting."; exit 1; }
+
+#############################################################################
+# XML
+#############################################################################
+
+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 >&2 "Test failed. Aborting."; exit 1; }
+
+echo "Created the following sample files in ./target/out"
+ls -l ./target/out
\ No newline at end of file
diff --git a/freemarker-generator-cli/src/main/scripts/run-samples.sh b/freemarker-generator-cli/src/main/scripts/run-samples.sh
deleted file mode 100755
index 780a702..0000000
--- a/freemarker-generator-cli/src/main/scripts/run-samples.sh
+++ /dev/null
@@ -1,193 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-# Check that java is on the path
-
-hash java 2>/dev/null || { echo >&2 "I require JDK but it's not installed. Aborting."; exit 1; }
-
-# Run all the samples being documented
-
-mkdir target 2>/dev/null
-mkdir target/out 2>/dev/null
-
-FREEMARKER_CMD=./bin/freemarker-cli
-
-#############################################################################
-# Info
-#############################################################################
-
-echo "templates/info.ftl"
-$FREEMARKER_CMD -t templates/info.ftl README.md > target/out/info.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Demo
-#############################################################################
-
-echo "templates/demo.ftl"
-$FREEMARKER_CMD -t templates/demo.ftl README.md > target/out/demo.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Interactive Mode
-#############################################################################
-
-$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; }
-$FREEMARKER_CMD -i '${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}' site/sample/yaml/swagger-spec.yaml > target/out/interactive-swagger.json || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -i '${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))}' site/sample/json/swagger-spec.json > target/out/interactive-swagger.yaml || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))}' site/sample/json/github-users.json > target/out/interactive-dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# CSV
-#############################################################################
-
-echo "templates/csv/html/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/html/transform.ftl site/sample/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/csv/md/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/md/transform.ftl site/sample/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/csv/shell/curl.ftl"
-$FREEMARKER_CMD -t ./templates/csv/shell/curl.ftl site/sample/csv/user.csv > target/out/curl.sh || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/csv/md/filter.ftl"
-$FREEMARKER_CMD -e UTF-8 -l de_AT -Pcolumn="Order ID" -Pvalues=226939189,957081544 -Pformat=DEFAULT -Pdelimiter=COMMA -t templates/csv/md/filter.ftl site/sample/csv/sales-records.csv > target/out/sales-records.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# CSV To XML-FO & PDF
-#############################################################################
-
-echo "templates/csv/fo/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/fo/transform.ftl site/sample/csv/locker-test-users.csv > target/out/locker-test-users.fo || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash fop 2>/dev/null; then
- echo "fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf"
- fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-echo "templates/csv/fo/transactions.ftl"
-$FREEMARKER_CMD -t templates/csv/fo/transactions.ftl site/sample/csv/transactions.csv > target/out/transactions.fo || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash fop 2>/dev/null; then
- echo "fop -fo target/out/transactions.fo target/out/transactions-fo.pdf"
- fop -fo target/out/transactions.fo target/out/transactions-fo.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-#############################################################################
-# CSV to HTML & PDF
-#############################################################################
-
-echo "templates/csv/html/transform.ftl"
-$FREEMARKER_CMD -t templates/csv/html/transactions.ftl site/sample/csv/transactions.csv > target/out/transactions.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash wkhtmltopdf 2>/dev/null; then
- echo "wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf"
- wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf 2>/dev/null || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-#############################################################################
-# DataFrame
-#############################################################################
-
-echo "templates/dataframe/example.ftl"
-$FREEMARKER_CMD -DCSV_TOOL_DELIMITER=SEMICOLON -DCSV_TOOL_HEADERS=true -t templates/dataframe/example.ftl site/sample/csv/dataframe.csv > target/out/dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Grok
-#############################################################################
-
-echo "templates/accesslog/combined-access.ftl"
-$FREEMARKER_CMD -t templates/accesslog/combined-access.ftl site/sample/accesslog/combined-access.log > target/out/combined-access.log.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Excel
-#############################################################################
-
-echo "templates/excel/dataframe/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/dataframe/transform.ftl site/sample/excel/test.xls > target/out/test.xls.dataframe.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/html/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/html/transform.ftl site/sample/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -t templates/excel/html/transform.ftl site/sample/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-$FREEMARKER_CMD -t templates/excel/html/transform.ftl site/sample/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/md/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/md/transform.ftl site/sample/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/csv/transform.ftl"
-$FREEMARKER_CMD -t templates/excel/csv/transform.ftl site/sample/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/excel/csv/custom.ftl"
-$FREEMARKER_CMD -t templates/excel/csv/custom.ftl -Pcsv.format=MYSQL site/sample/excel/test.xls > target/out/test-transform-xls.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# HTML
-#############################################################################
-
-echo "templates/html/csv/dependencies.ftl"
-$FREEMARKER_CMD -t templates/html/csv/dependencies.ftl site/sample/html/dependencies.html > target/out/dependencies.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# JSON
-#############################################################################
-
-echo "templates/json/csv/swagger-endpoints.ftl"
-$FREEMARKER_CMD -t templates/json/csv/swagger-endpoints.ftl site/sample/json/swagger-spec.json > target/out/swagger-spec.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/json/yaml/transform.ftl"
-$FREEMARKER_CMD -t templates/json/yaml/transform.ftl site/sample/json/swagger-spec.json > target/out/swagger-spec.yaml || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-if hash curl 2>/dev/null; then
-echo "templates/json/md/github-users.ftl"
-$FREEMARKER_CMD -t templates/json/md/github-users.ftl site/sample/json/github-users.json > target/out/github-users-curl.md || { echo >&2 "Test failed. Aborting."; exit 1; }
-fi
-
-#############################################################################
-# Properties
-#############################################################################
-
-echo "templates/properties/csv/locker-test-users.ftl"
-$FREEMARKER_CMD -t templates/properties/csv/locker-test-users.ftl site/sample/properties > target/out/locker-test-users.csv || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# Template Directory
-#############################################################################
-
-echo "site/template"
-$FREEMARKER_CMD -t site/template -PNGINX_HOSTNAME=localhost -o target/out/template || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# YAML
-#############################################################################
-
-echo "templates/yaml/txt/transform.ftl"
-$FREEMARKER_CMD -t templates/yaml/txt/transform.ftl site/sample/yaml/customer.yaml > target/out/customer.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "templates/yaml/json/transform.ftl"
-$FREEMARKER_CMD -t templates/yaml/json/transform.ftl site/sample/yaml/swagger-spec.yaml > target/out/swagger-spec.json || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-#############################################################################
-# XML
-#############################################################################
-
-echo "templates/xml/txt/recipients.ftl"
-$FREEMARKER_CMD -t ./templates/xml/txt/recipients.ftl site/sample/xml/recipients.xml > target/out/recipients.txt || { echo >&2 "Test failed. Aborting."; exit 1; }
-
-echo "Created the following sample files in ./target/out"
-ls -l ./target/out
\ No newline at end of file
diff --git a/freemarker-generator-cli/src/site/markdown/cli/concepts/data-sources.md b/freemarker-generator-cli/src/site/markdown/cli/concepts/data-sources.md
index 84647e0..548a65b 100644
--- a/freemarker-generator-cli/src/site/markdown/cli/concepts/data-sources.md
+++ b/freemarker-generator-cli/src/site/markdown/cli/concepts/data-sources.md
@@ -60,27 +60,27 @@ FreeMarker CLI DataSources
or load them from a directory
```
-bin/freemarker-cli -t templates/info.ftl -s site/sample/
+bin/freemarker-cli -t templates/info.ftl -s examples/data/
FreeMarker CLI DataSources
------------------------------------------------------------------------------
[#1], name=combined-access.log, group=default, contentType=text/plain, charset=UTF-8, length=2,068 Bytes
- URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/site/sample/accesslog/combined-access.log
+ URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/examples/data/accesslog/combined-access.log
...
[#22], name=swagger-spec.yaml, group=default, contentType=text/yaml, charset=UTF-8, length=17,555 Bytes
- URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/site/sample/yaml/swagger-spec.yaml
+ URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/examples/data/yaml/swagger-spec.yaml
```
which can be combined with `include` and `exclude` filters
```
-bin/freemarker-cli -t templates/info.ftl -s site/sample --data-source-include=*.json
+bin/freemarker-cli -t templates/info.ftl -s examples/data --data-source-include=*.json
FreeMarker CLI DataSources
------------------------------------------------------------------------------
[#1], name=github-users.json, group=default, contentType=application/json, charset=UTF-8, length=7,168 Bytes
- URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/site/sample/json/github-users.json
+ URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/examples/data/json/github-users.json
[#2], name=swagger-spec.json, group=default, contentType=application/json, charset=UTF-8, length=24,948 Bytes
- URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/site/sample/json/swagger-spec.json
+ URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/examples/data/json/swagger-spec.json
```
diff --git a/freemarker-generator-cli/src/site/markdown/cli/concepts/named-uris.md b/freemarker-generator-cli/src/site/markdown/cli/concepts/named-uris.md
index 7ab78e8..1c99b27 100644
--- a/freemarker-generator-cli/src/site/markdown/cli/concepts/named-uris.md
+++ b/freemarker-generator-cli/src/site/markdown/cli/concepts/named-uris.md
@@ -29,17 +29,17 @@ For our purposes, the scheme and the path components are especially important, t
The following Named URI loads a "user.csv" and the data source is available as `my_users`
```
-bin/freemarker-cli -t templates/info.ftl my_users=site/sample/csv/user.csv
+bin/freemarker-cli -t templates/info.ftl my_users=examples/data/csv/user.csv
[#1], name=my_users, group=default, contentType=text/csv, charset=UTF-8, length=376 Bytes
-URI : file:site/sample/csv/user.csv
+URI : file:examples/data/csv/user.csv
```
A Named URI allows to pass additional information as part of the fragment, e.g. the charset of the text file
```
-bin/freemarker-cli -t templates/info.ftl my_users=site/sample/csv/user.csv#charset=UTF-16
+bin/freemarker-cli -t templates/info.ftl my_users=examples/data/csv/user.csv#charset=UTF-16
[#1], name=my_users, group=default, contentType=text/csv, charset=UTF-16, length=376 Bytes
-URI : file:site/sample/csv/user.csv
+URI : file:examples/data/csv/user.csv
```
In addition to the simplified file syntax full URIs can be used
diff --git a/freemarker-generator-cli/src/site/markdown/cli/tools/dataframe.md b/freemarker-generator-cli/src/site/markdown/cli/tools/dataframe.md
index 3523294..83809ed 100644
--- a/freemarker-generator-cli/src/site/markdown/cli/tools/dataframe.md
+++ b/freemarker-generator-cli/src/site/markdown/cli/tools/dataframe.md
@@ -15,27 +15,16 @@ Currently the following sources are supported
[nRo/DataFrame]("https://raw.githubusercontent.com/nRo/DataFrame/master/src/test/resources/users.csv") provides the following CSV file
```
-┌────────────┬────────────┬────────────┐
-│#name │#age │#country │
-├────────────┼────────────┼────────────┤
-│Schmitt │24 │Germany │
-├────────────┼────────────┼────────────┤
-│Parker │45 │USA │
-├────────────┼────────────┼────────────┤
-│Meier │20 │Germany │
-├────────────┼────────────┼────────────┤
-│Schmitt │30 │France │
-├────────────┼────────────┼────────────┤
-│Peter │44 │Germany │
-├────────────┼────────────┼────────────┤
-│Meier │24 │Germany │
-├────────────┼────────────┼────────────┤
-│Green │33 │UK │
-├────────────┼────────────┼────────────┤
-│Schmitt │30 │Germany │
-├────────────┼────────────┼────────────┤
-│Meier │30 │Germany │
-└────────────┴────────────┴────────────┘
+name;age;country
+Schmitt;24;Germany
+Parker;45;USA
+Meier;20;Germany
+Schmitt;30;France
+Peter;44;Germany
+Meier;24;Germany
+Green;33;UK
+Schmitt;30;Germany
+Meier;30;Germany
```
and create a `DateFrame` using the following code
@@ -149,13 +138,13 @@ which results in
## JSON Examples
-Here we load a `site/samples/json/github-users.json` which represents a tabular data be
+Here we load a `examples/data/json/github-users.json` which represents a tabular data be
being parsed as a list of maps and print the JSOB as dataframe
```
./bin/freemarker-cli \
-i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))}' \
- site/sample/json/github-users.json
+ examples/data/json/github-users.json
┌────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┐
│#login │#id │#avatar_ur │#gravatar_ │#url │#html_url │#followers │#following │#gists_url │#starred_u │#subscript │#organizat │#repos_url │#events_ur │#received_ │#type │#site_admi │
@@ -193,7 +182,7 @@ Let's transform an Excel Sheet to a `DataFrame` being printed using the followin
which is rendered by the following command line invocation
```
-./bin/freemarker-cli -t templates/excel/dataframe/transform.ftl site/sample/excel/test.xls
+./bin/freemarker-cli -t examples/templates/excel/dataframe/transform.ftl examples/data/excel/test.xls
┌────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┐
│#Text │#Date │#Number │#Currency │#Time │#Percentag │#Forumula │
diff --git a/freemarker-generator-cli/src/site/markdown/cli/usage/transforming-directories.md b/freemarker-generator-cli/src/site/markdown/cli/usage/transforming-directories.md
index 7a65dc0..9f6a36f 100644
--- a/freemarker-generator-cli/src/site/markdown/cli/usage/transforming-directories.md
+++ b/freemarker-generator-cli/src/site/markdown/cli/usage/transforming-directories.md
@@ -13,8 +13,8 @@ The following sample files are used
* template/nginx/nginx.conf.ftl
```
-appassembler> tree site/template/
-site/template/
+appassembler> tree examples/data/template/
+examples/data/template/
|-- application.properties
`-- nginx
`-- nginx.conf.ftl
@@ -39,7 +39,7 @@ server {
If no output directory is provided all output is written to `stdout`
```
-bin/freemarker-cli -t site/template/
+bin/freemarker-cli -t examples/data/template/
# == application.properties ==================================================
server.name=localhost
server.logs=/var/log/nginx
@@ -60,7 +60,7 @@ The transformed templates are written to an `out` directory
* `nginx.conf.ftl` was changed to `nginx.conf" during the transformation
```
-bin/freemarker-cli -t site/template/ -o out; tree out
+bin/freemarker-cli -t examples/data/template/ -o out; tree out
out
|-- application.properties
`-- nginx
@@ -74,7 +74,7 @@ out
A user-supplied parameter `NGINX_HOSTNAME` is used to render the templates
```
-bin/freemarker-cli -t site/template/ -P NGINX_HOSTNAME=localhost
+bin/freemarker-cli -t examples/data/template/ -P NGINX_HOSTNAME=localhost
# == application.properties ==================================================
server.name=localhost
server.logs=/var/log/nginx
@@ -97,7 +97,7 @@ All environment variables can be copied to the top-level data model by providing
```
export NGINX_PORT=8080
-bin/freemarker-cli -t site/template/ -m env:///
+bin/freemarker-cli -t examples/data/template/ -m env:///
# == application.properties ==================================================
server.name=localhost
server.logs=/var/log/nginx
@@ -117,7 +117,7 @@ Instead of environment variables an environment file (aka properties file) can b
```
echo "NGINX_PORT=8080" > nginx.env
-bin/freemarker-cli -t site/template/ -m nginx.env
+bin/freemarker-cli -t examples/data/template/ -m nginx.env
# == application.properties ==================================================
server.name=localhost
server.logs=/var/log/nginx
@@ -137,7 +137,7 @@ Another option is passing the information as JSON file
```
echo '{"NGINX_PORT":"8443","NGINX_HOSTNAME":"localhost"}' > nginx.json
-bin/freemarker-cli -t site/template/ -m nginx.json
+bin/freemarker-cli -t examples/data/template/ -m nginx.json
# == application.properties ==================================================
server.name=localhost
server.logs=/var/log/nginx
@@ -157,7 +157,7 @@ Yet another option is using a YAML file
```
echo -e "- NGINX_PORT": "\"8443\"\n- NGINX_HOSTNAME": "localhost" > nginx.yaml
-bin/freemarker-cli -t site/template/ -m nginx.yaml
+bin/freemarker-cli -t examples/data/template/ -m nginx.yaml
# == application.properties ==================================================
server.name=localhost
server.logs=/var/log/nginx
@@ -180,7 +180,7 @@ In the cloud it is common to pass JSON configuration as environment variable
```
export NGINX_CONF='{"NGINX_PORT":"8443","NGINX_HOSTNAME":"localhost"}'
-bin/freemarker-cli -t site/template/ -m env:///NGINX_CONF#mimetype=application/json
+bin/freemarker-cli -t examples/data/template/ -m env:///NGINX_CONF#mimetype=application/json
# == application.properties ==================================================
server.name=localhost
server.logs=/var/log/nginx
@@ -200,7 +200,7 @@ For testing purpose it is useful to override certain settings
```
export NGINX_CONF='{"NGINX_PORT":"8443","NGINX_HOSTNAME":"localhost"}'
-bin/freemarker-cli -t site/template/ -PNGINX_HOSTNAME=www.mydomain.com -m env:///NGINX_CONF#mimetype=application/json
+bin/freemarker-cli -t examples/data/template/ -PNGINX_HOSTNAME=www.mydomain.com -m env:///NGINX_CONF#mimetype=application/json
# == application.properties ==================================================
server.name=www.mydomain.com
server.logs=/var/log/nginx
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 95c7241..0c3820c 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
@@ -40,90 +40,90 @@ public class ExamplesTest extends AbstractMainTest {
@Test
public void shouldRunDemoExamples() throws IOException {
- assertValid(execute("-t templates/demo.ftl README.md"));
+ assertValid(execute("-t examples/templates/demo.ftl README.md"));
}
@Test
public void shouldRunCsvExamples() throws IOException {
- assertValid(execute("-t templates/csv/html/transform.ftl site/sample/csv/contract.csv"));
- assertValid(execute("-t templates/csv/md/transform.ftl site/sample/csv/contract.csv"));
- assertValid(execute("-t templates/csv/shell/curl.ftl site/sample/csv/user.csv"));
- assertValid(execute("-t templates/csv/fo/transform.ftl site/sample/csv/locker-test-users.csv"));
- assertValid(execute("-t templates/csv/fo/transactions.ftl site/sample/csv/transactions.csv"));
- assertValid(execute("-t templates/csv/html/transactions.ftl site/sample/csv/transactions.csv"));
- assertValid(execute("-t templates/csv/transform.ftl site/sample/csv/contract.csv"));
+ assertValid(execute("-t templates/csv/html/transform.ftl examples/data/csv/contract.csv"));
+ assertValid(execute("-t templates/csv/md/transform.ftl examples/data/csv/contract.csv"));
+ assertValid(execute("-t examples/templates/csv/shell/curl.ftl examples/data/csv/user.csv"));
+ assertValid(execute("-t examples/templates/csv/fo/transform.ftl examples/data/csv/locker-test-users.csv"));
+ assertValid(execute("-t examples/templates/csv/fo/transactions.ftl examples/data/csv/transactions.csv"));
+ assertValid(execute("-t examples/templates/csv/html/transactions.ftl examples/data/csv/transactions.csv"));
+ assertValid(execute("-t templates/csv/csv/transform.ftl examples/data/csv/contract.csv"));
}
@Test
public void shouldRunExcelExamples() throws IOException {
- assertValid(execute("-t templates/excel/html/transform.ftl site/sample/excel/test.xls"));
- assertValid(execute("-t templates/excel/html/transform.ftl site/sample/excel/test.xlsx"));
- assertValid(execute("-t templates/excel/html/transform.ftl site/sample/excel/test-multiple-sheets.xlsx"));
- assertValid(execute("-t templates/excel/md/transform.ftl site/sample/excel/test-multiple-sheets.xlsx"));
- assertValid(execute("-t templates/excel/csv/transform.ftl site/sample/excel/test-multiple-sheets.xlsx"));
- assertValid(execute("-t templates/excel/csv/custom.ftl -Pcsv.format=MYSQL site/sample/excel/test.xls"));
- assertValid(execute("-t templates/excel/dataframe/transform.ftl site/sample/excel/test.xls"));
+ assertValid(execute("-t templates/excel/html/transform.ftl examples/data/excel/test.xls"));
+ assertValid(execute("-t templates/excel/html/transform.ftl examples/data/excel/test.xlsx"));
+ assertValid(execute("-t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
+ assertValid(execute("-t templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
+ assertValid(execute("-t templates/excel/csv/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
+ assertValid(execute("-t examples/templates/excel/csv/custom.ftl -Pcsv.format=MYSQL examples/data/excel/test.xls"));
+ assertValid(execute("-t examples/templates/excel/dataframe/transform.ftl examples/data/excel/test.xls"));
}
@Test
public void shouldRunHtmlExamples() throws IOException {
- assertValid(execute("-t templates/html/csv/dependencies.ftl site/sample/html/dependencies.html"));
+ assertValid(execute("-t examples/templates/html/csv/dependencies.ftl examples/data/html/dependencies.html"));
}
@Test
public void shouldRunJsonExamples() throws IOException {
- assertValid(execute("-t templates/json/csv/swagger-endpoints.ftl site/sample/json/swagger-spec.json"));
- assertValid(execute("-t templates/json/md/github-users.ftl site/sample/json/github-users.json"));
- assertValid(execute("-t templates/json/yaml/transform.ftl site/sample/json/swagger-spec.json"));
+ assertValid(execute("-t examples/templates/json/csv/swagger-endpoints.ftl examples/data/json/swagger-spec.json"));
+ assertValid(execute("-t examples/templates/json/md/github-users.ftl examples/data/json/github-users.json"));
+ assertValid(execute("-t templates/json/yaml/transform.ftl examples/data/json/swagger-spec.json"));
}
@Test
public void shouldRunPropertiesExamples() throws IOException {
- assertValid(execute("-t templates/properties/csv/locker-test-users.ftl site/sample/properties"));
+ assertValid(execute("-t examples/templates/properties/csv/locker-test-users.ftl examples/data/properties"));
}
@Test
public void shouldRunYamlExamples() throws IOException {
- assertValid(execute("-t templates/yaml/txt/transform.ftl site/sample/yaml/customer.yaml"));
- assertValid(execute("-t templates/yaml/json/transform.ftl site/sample/yaml/swagger-spec.yaml"));
+ assertValid(execute("-t examples/templates/yaml/txt/transform.ftl examples/data/yaml/customer.yaml"));
+ assertValid(execute("-t templates/yaml/json/transform.ftl examples/data/yaml/swagger-spec.yaml"));
}
@Test
public void shouldRunXmlExamples() throws IOException {
- assertValid(execute("-t templates/xml/txt/recipients.ftl site/sample/xml/recipients.xml"));
+ assertValid(execute("-t examples/templates/xml/txt/recipients.ftl examples/data/xml/recipients.xml"));
}
@Test
public void shouldRunGrokExamples() throws IOException {
- assertValid(execute("-t templates/accesslog/combined-access.ftl site/sample/accesslog/combined-access.log"));
+ assertValid(execute("-t examples/templates/accesslog/combined-access.ftl examples/data/accesslog/combined-access.log"));
}
@Test
public void shouldRunWithExposedEnvironmentVariableExamples() throws IOException {
- assertValid(execute("-b ./src/test -m env:/// -t templates/environment.ftl"));
+ assertValid(execute("-m env:/// -t ./src/test/templates/environment.ftl"));
}
@Test
public void shouldRunDataFrameExamples() throws IOException {
- assertValid(execute("-DCSV_TOOL_DELIMITER=SEMICOLON -DCSV_TOOL_HEADERS=true -t templates/dataframe/example.ftl site/sample/csv/dataframe.csv"));
+ assertValid(execute("-PCSV_SOURCE_DELIMITER=SEMICOLON -PCSV_SOURCE_WITH_HEADER=true -t examples/templates/dataframe/example.ftl examples/data/csv/dataframe.csv"));
}
@Test
public void shouldRunInteractiveTemplateExamples() throws IOException {
- 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"));
- assertValid(execute("-i ${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))} site/sample/yaml/swagger-spec.yaml"));
- assertValid(execute("-i ${GsonTool.toJson(yaml)} -m yaml=site/sample/yaml/swagger-spec.yaml"));
- assertValid(execute("-i ${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))} site/sample/json/swagger-spec.json"));
- assertValid(execute("-i ${YamlTool.toYaml(json)} -m json=site/sample/json/swagger-spec.json"));
- assertValid(execute("-i ${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))} site/sample/json/github-users.json"));
+ assertValid(execute("-i ${JsonPathTool.parse(DataSources.first).read(\"$.info.title\")} examples/data/json/swagger-spec.json"));
+ assertValid(execute("-i ${XmlTool.parse(DataSources.first)[\"recipients/person[1]/name\"]} examples/data/xml/recipients.xml"));
+ assertValid(execute("-i ${JsoupTool.parse(DataSources.first).select(\"a\")[0]} examples/data/html/dependencies.html"));
+ assertValid(execute("-i ${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))} examples/data/yaml/swagger-spec.yaml"));
+ assertValid(execute("-i ${GsonTool.toJson(yaml)} -m yaml=examples/data/yaml/swagger-spec.yaml"));
+ assertValid(execute("-i ${YamlTool.toYaml(GsonTool.parse(DataSources.get(0)))} examples/data/json/swagger-spec.json"));
+ assertValid(execute("-i ${YamlTool.toYaml(json)} -m json=examples/data/json/swagger-spec.json"));
+ assertValid(execute("-i ${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(DataSources.get(0))))} examples/data/json/github-users.json"));
}
@Test
public void shouldTransformTemplateDirectory() throws IOException {
- assertTrue(execute("-t site/template").contains("server.name=127.0.0.1"));
- assertTrue(execute("-t site/template -PNGINX_HOSTNAME=my.domain.com").contains("server.name=my.domain.com"));
+ assertTrue(execute("-t examples/data/template").contains("server.name=127.0.0.1"));
+ assertTrue(execute("-t examples/data/template -PNGINX_HOSTNAME=my.domain.com").contains("server.name=my.domain.com"));
}
@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 fd2c11c..faa6080 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
@@ -24,32 +24,8 @@ import java.util.Arrays;
public class ManualTest {
private static final String SPACE = " ";
- // private static final String CMD = "-b ./src/test -t templates/csv/html/transactions.ftl site/sample/csv/transactions.csv";
- // private static final String CMD = "-b ./src/test -l de_AT -DFOO=foo -DBAR=bar -t templates/info.ftl site/sample/csv/transactions.csv";
- // private static final String CMD = "-b ./src/test -DFOO=foo -PBAR=bar -l de -t templates/demo.ftl site/sample/csv/transactions.csv";
- // 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 -PCSV_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(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";
- // private static final String CMD = "-b ./src/test -l de_AT -DFOO=foo -DBAR=bar -t templates/info.ftl -d user:admin=site/sample/csv/contract.csv#charset=UTF-16 google:www=https://www.google.com?foo=bar#contenttype=application/json";
- // private static final String CMD = "-b ./src/test -t templates/info.ftl -d :user=site/sample/properties -d contract=site/sample/csv/contract.csv";
- // private static final String CMD = "-b ./src/test -t site/sample/ftl/nginx/nginx.conf.ftl -d env=site/sample/ftl/nginx/nginx.env";
- // private static final String CMD = "-b ./src/test -t templates/info.ftl -d env=site/sample/ftl/nginx/nginx.env";
- // private static final String CMD = "-b ./src/test -t templates/json/yaml/transform.ftl site/sample/json/swagger-spec.json";
- // private static final String CMD = "-b ./src/test -t templates/yaml/json/transform.ftl site/sample/yaml/swagger-spec.yaml";
- // private static final String CMD = "-b ./src/test -t templates/demo.ftl -m env=env:///";
- // private static final String CMD = "-b ./src/test -t templates/demo.ftl -m api=https://httpbin.org/get";
- // private static final String CMD = "-b ./src/test -t templates/demo.ftl -m env:///HOME";
- // private static final String CMD = "-b ./src/test -t templates/demo.ftl -m env=./site/sample/properties/user_0001/user.properties";
- // private static final String CMD = "-b ./src/test -t templates/demo.ftl -m ./site/sample/properties/user_0001/user.properties";
- // private static final String CMD = "-b ./src/test --data-model post=https://jsonplaceholder.typicode.com/posts/2 -t templates/info.ftl";
- private static final String CMD = "-DCSV_TOOL_DELIMITER=SEMICOLON -DCSV_TOOL_HEADERS=true -b ./src/test -t templates/dataframe/example.ftl https://raw.githubusercontent.com/nRo/DataFrame/master/src/test/resources/users.csv";
-
+ // private static final String CMD = "-PCSV_SOURCE_FORMAT=DATAFRAME -t examples/templates/dataframe/example.ftl https://raw.githubusercontent.com/nRo/DataFrame/master/src/test/resources/users.csv";
+ private static final String CMD = "-PCSV_SOURCE_WITH_HEADER=true -PCSV_SOURCE_FORMAT=DEFAULT -PCSV_TARGET_FORMAT=EXCEL -t templates/csv/md/transform.ftl examples/data/csv/contract.csv";
public static void main(String[] args) {
Main.execute(toArgs(CMD));
diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SecurityRelatedTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SecurityRelatedTest.java
index e3c5d9d..4cf264b 100644
--- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SecurityRelatedTest.java
+++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SecurityRelatedTest.java
@@ -26,11 +26,11 @@ public class SecurityRelatedTest extends AbstractMainTest {
@Test(expected = RuntimeException.class)
public void shouldDisallowFreeMarkerNewBuiltIn() throws IOException {
- execute("-b ./src/test -t templates/security/new.ftl");
+ execute("-t ./src/test/templates/security/new.ftl");
}
@Test(expected = RuntimeException.class)
public void shouldDisallowFreeMarkerApiBuiltIn() throws IOException {
- execute("-b ./src/test -t templates/security/api.ftl");
+ execute("-t ./src/test/templates/security/api.ftl");
}
}
diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SourceEncodingTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SourceEncodingTest.java
index 8f6e762..d5e7e89 100644
--- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SourceEncodingTest.java
+++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/SourceEncodingTest.java
@@ -28,13 +28,13 @@ public class SourceEncodingTest extends AbstractMainTest {
@Test
public void shouldLoadUtf8Text() throws IOException {
- final String output = execute("-b ./src/test -e UTF-8 -t templates/echo.ftl ./src/test/data/encoding/utf8.txt");
+ final String output = execute("-e UTF-8 -t ./src/test/templates/echo.ftl ./src/test/data/encoding/utf8.txt");
assertTrue("Unable to find expected cyrillic term", output.contains(CYRILLIC_TERM));
}
@Test
public void shouldLoadUtf16Text() throws IOException {
- final String output = execute("-b ./src/test -e UTF-16 -t templates/echo.ftl ./src/test/data/encoding/utf16.txt");
+ final String output = execute("-e UTF-16 -t ./src/test/templates/echo.ftl ./src/test/data/encoding/utf16.txt");
assertTrue("Unable to find expected cyrillic term", output.contains(CYRILLIC_TERM));
}
}
diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/UserSuppliedLocaleTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/UserSuppliedLocaleTest.java
index 2a3e76c..f867460 100644
--- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/UserSuppliedLocaleTest.java
+++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/UserSuppliedLocaleTest.java
@@ -26,7 +26,7 @@ public class UserSuppliedLocaleTest extends AbstractMainTest {
@Test
public void shouldUserGermanLocalForRenderingTemplate() throws IOException {
- final String output = execute("-b ./src/test -l de -t templates/locale.ftl README.md");
+ final String output = execute("-l de -t ./src/test/templates/locale.ftl README.md");
assertTrue(output.contains("3,142"));
assertTrue(output.contains("99.999,99"));
@@ -34,7 +34,7 @@ public class UserSuppliedLocaleTest extends AbstractMainTest {
@Test
public void shouldUserEnglishLocalForRenderingTemplate() throws IOException {
- final String output = execute("-b ./src/test -l en -t templates/locale.ftl README.md");
+ final String output = execute("-l en -t ./src/test/templates/locale.ftl README.md");
assertTrue(output.contains("3.142"));
assertTrue(output.contains("99,999.99"));
diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/SettingsTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/SettingsTest.java
index 5aa6681..90c7696 100644
--- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/SettingsTest.java
+++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/SettingsTest.java
@@ -57,8 +57,8 @@ public class SettingsTest {
assertEquals(ANY_OUTPUT_FILE, settings.getOutput().getName());
assertEquals(ANY_TEMPLATE_NAME, settings.getTemplates().get(0));
assertNotNull(settings.getDataSources());
- assertNotNull(settings.getParameters());
- assertNotNull(settings.getSystemProperties());
+ assertNotNull(settings.getUserParameters());
+ assertNotNull(settings.getUserSystemProperties());
assertTrue(settings.isReadFromStdin());
assertTrue(settings.isInteractiveTemplate());
assertTrue(settings.isVerbose());
diff --git a/freemarker-generator-cli/templates/cat.ftl b/freemarker-generator-cli/templates/csv/csv/transform.ftl
similarity index 73%
rename from freemarker-generator-cli/templates/cat.ftl
rename to freemarker-generator-cli/templates/csv/csv/transform.ftl
index a878261..656131d 100644
--- a/freemarker-generator-cli/templates/cat.ftl
+++ b/freemarker-generator-cli/templates/csv/csv/transform.ftl
@@ -15,8 +15,10 @@
specific language governing permissions and limitations
under the License.
-->
-<#list DataSources.list as dataSource>
-<#list dataSource.lineIterator as line>
-${line}
-</#list>
-</#list>
+<#import "/templates/lib/commons-csv.ftl" as csv />
+<#assign dataSource = DataSources.get(0)>
+<#assign csvParser = CSVTool.parse(dataSource, csv.sourceFormat())>
+<#assign csvPrinter = CSVTool.printer(csv.targetFormat())>
+<#list csvParser.iterator() as record>
+ ${csvPrinter.printRecord(record)}<#t>
+</#list>
\ No newline at end of file
diff --git a/freemarker-generator-cli/templates/csv/html/transform.ftl b/freemarker-generator-cli/templates/csv/html/transform.ftl
index 65eb4f1..cda4cd6 100644
--- a/freemarker-generator-cli/templates/csv/html/transform.ftl
+++ b/freemarker-generator-cli/templates/csv/html/transform.ftl
@@ -1,4 +1,4 @@
-<#ftl output_format="HTML" >
+<#ftl output_format="HTML" strip_whitespace=true>
<#--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -15,16 +15,15 @@
specific language governing permissions and limitations
under the License.
-->
+<#import "/templates/lib/commons-csv.ftl" as csv />
<#assign dataSource = DataSources.get(0)>
-<#assign name = dataSource.name>
-<#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader()>
-<#assign csvParser = CSVTool.parse(dataSource, cvsFormat)>
+<#assign csvParser = CSVTool.parse(dataSource, csv.sourceFormat())>
<#assign csvHeaders = csvParser.getHeaderNames()>
<#--------------------------------------------------------------------------->
<!DOCTYPE html>
<html>
<head>
- <title>${name}</title>
+ <title>${dataSource.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">
@@ -40,17 +39,21 @@
</html>
<#--------------------------------------------------------------------------->
<#macro writeHeaders headers>
- <tr>
- <#list headers as header>
- <th>${header}</th>
- </#list>
- </tr>
+ <#if headers?has_content>
+ <tr>
+ <#list headers as header>
+ <th>${header}</th>
+ </#list>
+ </tr>
+ </#if>
</#macro>
<#--------------------------------------------------------------------------->
<#macro writeColumns record>
- <tr>
- <#list record.iterator() as field>
- <th>${field}</th>
- </#list>
- </tr>
+ <#if record?has_content>
+ <tr>
+ <#list record.iterator() as field>
+ <td>${field}</td>
+ </#list>
+ </tr>
+ </#if>
</#macro>
\ No newline at end of file
diff --git a/freemarker-generator-cli/templates/csv/md/transform.ftl b/freemarker-generator-cli/templates/csv/md/transform.ftl
index fca0bc5..2766125 100644
--- a/freemarker-generator-cli/templates/csv/md/transform.ftl
+++ b/freemarker-generator-cli/templates/csv/md/transform.ftl
@@ -1,4 +1,3 @@
-<#ftl output_format="plainText">
<#--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -15,23 +14,28 @@
specific language governing permissions and limitations
under the License.
-->
-<#assign cvsFormat = CSVTool.formats["DEFAULT"].withHeader()>
-<#assign csvParser = CSVTool.parse(DataSources.get(0), cvsFormat)>
-<#assign csvHeaders = csvParser.getHeaderMap()?keys>
-<#assign csvRecords = csvParser.records>
+<#import "/templates/lib/commons-csv.ftl" as csv />
+<#assign dataSource = DataSources.get(0)>
+<#assign csvParser = CSVTool.parse(dataSource, csv.sourceFormat())>
+<#assign headers = (csvParser.getHeaderMap()!{})?keys>
+<#assign records = csvParser.records>
<#--------------------------------------------------------------------------->
<#compress>
-<@writeHeaders headers=csvHeaders/>
-<@writeColums columns=csvRecords/>
+ <@writeHeaders headers/>
+ <@writeColums records/>
</#compress>
<#--------------------------------------------------------------------------->
<#macro writeHeaders headers>
-| ${csvHeaders?join(" | ", "")} |
- <#list csvHeaders as csvHeader>| --------</#list>|
+ <#if headers?has_content>
+ | ${headers?join(" | ", "")} |
+ <#list headers as header>| --------</#list>|
+ </#if>
</#macro>
<#--------------------------------------------------------------------------->
<#macro writeColums columns>
- <#list columns as column>
- | ${column.iterator()?join(" | ", "")} |
- </#list>
+ <#if columns?has_content>
+ <#list columns as column>
+ | ${column.iterator()?join(" | ", "")} |
+ </#list>
+ </#if>
</#macro>
diff --git a/freemarker-generator-cli/templates/csv/transform.ftl b/freemarker-generator-cli/templates/csv/transform.ftl
deleted file mode 100644
index af091ec..0000000
--- a/freemarker-generator-cli/templates/csv/transform.ftl
+++ /dev/null
@@ -1,39 +0,0 @@
-<#ftl output_format="plainText" strip_text="true">
-<#--
- 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.
--->
-<#assign csvParser = createCsvParser(DataSources.get(0))>
-<#assign csvPrinter = createCsvPrinter()>
-<#-- Print each line without materializing the CSV in memory -->
-<#compress>
- <#list csvParser.iterator() as record>
- ${csvPrinter.printRecord(record)}
- </#list>
-</#compress>
-
-<#function createCsvParser dataSource>
- <#assign initialCvsInFormat = CSVTool.formats[CSV_IN_FORMAT!"DEFAULT"]>
- <#assign csvInDelimiter = CSVTool.toDelimiter(CSV_IN_DELIMITER!initialCvsInFormat.getDelimiter())>
- <#assign cvsInFormat = initialCvsInFormat.withDelimiter(csvInDelimiter)>
- <#return CSVTool.parse(dataSource, cvsInFormat)>
-</#function>
-
-<#function createCsvPrinter>
- <#assign initialCvsOutFormat = CSVTool.formats[CSV_OUT_FORMAT!"DEFAULT"]>
- <#assign csvOutDelimiter = CSVTool.toDelimiter(CSV_OUT_DELIMITER!initialCvsOutFormat.getDelimiter())>
- <#assign cvsOutFormat = initialCvsOutFormat.withDelimiter(csvOutDelimiter)>
- <#return CSVTool.printer(cvsOutFormat, SystemTool.writer)>
-</#function>
\ No newline at end of file
diff --git a/freemarker-generator-cli/templates/excel/csv/transform.ftl b/freemarker-generator-cli/templates/excel/csv/transform.ftl
index 2455c49..794e942 100644
--- a/freemarker-generator-cli/templates/excel/csv/transform.ftl
+++ b/freemarker-generator-cli/templates/excel/csv/transform.ftl
@@ -15,17 +15,28 @@
specific language governing permissions and limitations
under the License.
-->
-<#assign format = CVS_IN_FORMAT!"DEFAULT">
<#-- Parse the first data source & sheet of the Excel document -->
+<#import "/templates/lib/commons-csv.ftl" as csv />
<#assign workbook = ExcelTool.parse(DataSources.get(0))>
<#assign sheet = ExcelTool.getSheets(workbook)[0]>
<#assign records = ExcelTool.toTable(sheet)>
<#-- Setup CSVPrinter -->
-<#assign cvsFormat = CSVTool.formats[format]>
-<#assign csvPrinter = CSVTool.printer(cvsFormat, SystemTool.writer)>
+<#assign csvPrinter = CSVTool.printer(csv.targetFormat())>
<#-- Print each line of the Excel as CSV record -->
<#compress>
<#list records as record>
${csvPrinter.printRecord(record)}
</#list>
</#compress>
+<#--------------------------------------------------------------------------->
+<#function csvOutFormat>
+ <#assign format = CSVTool.formats[CSV_TARGET_FORMAT!"DEFAULT"]>
+ <#assign delimiter = CSVTool.toDelimiter(CSV_TARGET_DELIMITER!format.getDelimiter())>
+ <#assign withHeader = CSV_TARGET_WITH_HEADER!"false">
+ <#assign format = format.withDelimiter(delimiter)>
+ <#if withHeader?boolean>
+ <#assign format = format.withHeader>
+ </#if>
+ <#return format>
+</#function>
+
diff --git a/freemarker-generator-cli/templates/excel/html/transform.ftl b/freemarker-generator-cli/templates/excel/html/transform.ftl
index 68ccc42..58ace89 100644
--- a/freemarker-generator-cli/templates/excel/html/transform.ftl
+++ b/freemarker-generator-cli/templates/excel/html/transform.ftl
@@ -81,3 +81,4 @@
</#list>
</table>
</#macro>
+
diff --git a/freemarker-generator-cli/templates/info.ftl b/freemarker-generator-cli/templates/info.ftl
index 565e2ec..838ac29 100644
--- a/freemarker-generator-cli/templates/info.ftl
+++ b/freemarker-generator-cli/templates/info.ftl
@@ -49,8 +49,8 @@ FreeMarker CLI Data Model
FreeMarker CLI DataSources
------------------------------------------------------------------------------
<#list DataSources.list as dataSource>
- [#${dataSource?counter}], name=${dataSource.name}, group=${dataSource.group}, contentType=${dataSource.contentType}, charset=${dataSource.charset}, length=${dataSource.length} Bytes
- URI : ${dataSource.uri}
+[#${dataSource?counter}], name=${dataSource.name}, group=${dataSource.group}, contentType=${dataSource.contentType}, charset=${dataSource.charset}, length=${dataSource.length} Bytes
+URI : ${dataSource.uri}
</#list>
</#if>
diff --git a/freemarker-generator-cli/templates/lib/commons-csv.ftl b/freemarker-generator-cli/templates/lib/commons-csv.ftl
new file mode 100644
index 0000000..4082fa8
--- /dev/null
+++ b/freemarker-generator-cli/templates/lib/commons-csv.ftl
@@ -0,0 +1,55 @@
+<#ftl output_format="plainText" strip_text="true">
+<#--
+ 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.
+-->
+
+<#---
+ Detemine the CSV format for reading a CSV files using user-supplied
+ parameters from the data model.
+
+ * CSV_SOURCE_FORMAT - see https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVFormat.html
+ * CSV_SOURCE_DELIMITER - symbolic name of delimiter, e.g. "COLON" or "SEMICOLON"
+ * CSV_SOURCE_WITH_HEADER - whether the first rows are headers
+-->
+<#function sourceFormat>
+ <#assign format = CSVTool.formats[CSV_SOURCE_FORMAT!"DEFAULT"]>
+ <#assign delimiter = CSVTool.toDelimiter(CSV_SOURCE_DELIMITER!format.getDelimiter())>
+ <#assign withHeader = CSV_SOURCE_WITH_HEADER!"false">
+ <#assign format = format.withDelimiter(delimiter)>
+ <#if withHeader?boolean>
+ <#assign format = format.withHeader()>
+ </#if>
+ <#return format>
+</#function>
+
+<#---
+ Detemine the CSV format for printing a CSV files using user-supplied
+ parameters from the data model.
+
+ * CSV_TARGET_FORMAT - see https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVFormat.html
+ * CSV_TARGET_DELIMITER - symbolic name of delimiter, e.g. "COLON" or "SEMICOLON"
+ * CSV_TARGET_WITH_HEADER - whether the first rows are headers
+-->
+<#function targetFormat>
+ <#assign format = CSVTool.formats[CSV_TARGET_FORMAT!"DEFAULT"]>
+ <#assign delimiter = CSVTool.toDelimiter(CSV_TARGET_DELIMITER!format.getDelimiter())>
+ <#assign withHeader = CSV_TARGET_WITH_HEADER!"false">
+ <#assign format = format.withDelimiter(delimiter)>
+ <#if withHeader?boolean>
+ <#assign format = format.withHeader>
+ </#if>
+ <#return format>
+</#function>
diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVPrinterFacade.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVPrinterFacade.java
new file mode 100644
index 0000000..b8c0574
--- /dev/null
+++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVPrinterFacade.java
@@ -0,0 +1,84 @@
+package org.apache.freemarker.generator.tools.commonscsv;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+
+import java.io.Closeable;
+import java.io.Flushable;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Wrap <code>CSVPrinter</code> so each print method returns
+ * a string to be rendered by FreeMarker instead of writing to an
+ * internal writer.
+ */
+public class CommonsCSVPrinterFacade implements Flushable, Closeable {
+
+ private final StringWriter writer;
+ private final CSVPrinter csvPrinter;
+
+ public CommonsCSVPrinterFacade(CSVFormat format) throws IOException {
+ this.writer = new StringWriter();
+ this.csvPrinter = new CSVPrinter(writer, format);
+ }
+
+ @Override
+ public void close() throws IOException {
+ csvPrinter.close();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ csvPrinter.flush();
+ }
+
+ public String print(Object value) throws IOException {
+ csvPrinter.print(value);
+ return getOutput();
+ }
+
+ public String printComment(String comment) throws IOException {
+ csvPrinter.printComment(comment);
+ return getOutput();
+ }
+
+ public String println() throws IOException {
+ csvPrinter.println();
+ return getOutput();
+ }
+
+ public String printRecord(Iterable<?> values) throws IOException {
+ csvPrinter.printRecord(values);
+ return getOutput();
+ }
+
+ public String printRecord(Object... values) throws IOException {
+ csvPrinter.printRecord(values);
+ return getOutput();
+ }
+
+ public String printRecords(Iterable<?> values) throws IOException {
+ csvPrinter.printRecords(values);
+ return getOutput();
+ }
+
+ public String printRecords(Object... values) throws IOException {
+ csvPrinter.printRecords(values);
+ return getOutput();
+ }
+
+ public String printRecords(ResultSet resultSet) throws SQLException, IOException {
+ csvPrinter.printRecords(resultSet);
+ return getOutput();
+ }
+
+ private String getOutput() {
+ writer.flush();
+ final String output = writer.getBuffer().toString();
+ writer.getBuffer().setLength(0);
+ return output;
+ }
+}
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 296f903..7d2eab6 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
@@ -18,7 +18,6 @@ package org.apache.freemarker.generator.tools.commonscsv;
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.commons.io.input.BOMInputStream;
import org.apache.freemarker.generator.base.datasource.DataSource;
@@ -26,7 +25,6 @@ import org.apache.freemarker.generator.base.util.StringUtils;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Writer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
@@ -37,7 +35,6 @@ import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
-import static java.lang.Boolean.parseBoolean;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
@@ -45,10 +42,8 @@ import static org.apache.commons.io.IOUtils.toInputStream;
public class CommonsCSVTool {
- private final CSVFormat defaulCSVFormat = csvFormat();
-
public CSVParser parse(DataSource dataSource) {
- return parse(dataSource, defaulCSVFormat);
+ return parse(dataSource, defaultCSVInputFormat());
}
public CSVParser parse(DataSource dataSource, CSVFormat format) {
@@ -68,7 +63,7 @@ public class CommonsCSVTool {
}
public CSVParser parse(String csv) {
- return parse(csv, defaulCSVFormat);
+ return parse(csv, defaultCSVInputFormat());
}
public CSVParser parse(String csv, CSVFormat format) {
@@ -88,17 +83,12 @@ public class CommonsCSVTool {
return createCSVFormats();
}
- /**
- * Get a CSVPrinter using the FreeMarker's writer instance.
- *
- * @param csvFormat CSV format to use for writing records
- * @param writer Writer to receive the CSV output
- * @return CSVPrinter instance
- * @throws IOException thrown if the parameters of the format are inconsistent or if either out or format are null.
- */
- public CSVPrinter printer(CSVFormat csvFormat, Writer writer) throws IOException {
- // We do not close the CSVPrinter but the underlying writer at the of processing
- return new CSVPrinter(writer, csvFormat);
+ public CommonsCSVPrinterFacade printer() throws IOException {
+ return printer(defaultCSVOutputFormat());
+ }
+
+ public CommonsCSVPrinterFacade printer(CSVFormat csvFormat) throws IOException {
+ return new CommonsCSVPrinterFacade(csvFormat);
}
/**
@@ -248,6 +238,7 @@ public class CommonsCSVTool {
private static Map<String, CSVFormat> createCSVFormats() {
final Map<String, CSVFormat> result = new HashMap<>();
result.put("DEFAULT", CSVFormat.DEFAULT);
+ result.put("DATAFRAME", CSVFormat.DEFAULT.withDelimiter(';').withFirstRecordAsHeader());
result.put("EXCEL", CSVFormat.EXCEL);
result.put("INFORMIX_UNLOAD", CSVFormat.INFORMIX_UNLOAD);
result.put("INFORMIX_UNLOAD_CSV", CSVFormat.INFORMIX_UNLOAD_CSV);
@@ -262,21 +253,22 @@ public class CommonsCSVTool {
return result;
}
- private CSVFormat csvFormat() {
-
- CSVFormat csvFormat = CSVFormat.valueOf(System.getProperty("CSV_TOOL_FORMAT", "Default"));
-
- final String delimiter = System.getProperty("CSV_TOOL_DELIMITER");
- if (StringUtils.isNotEmpty(delimiter)) {
- csvFormat = csvFormat.withDelimiter(toDelimiter(delimiter));
- }
-
- final boolean withHeader = parseBoolean(System.getProperty("CSV_TOOL_HEADERS", Boolean.toString(!csvFormat.getSkipHeaderRecord())));
- if (withHeader) {
- csvFormat = csvFormat.withHeader();
- }
+ /**
+ * Provides a CSV default input format.
+ *
+ * @return CSV format
+ */
+ private static CSVFormat defaultCSVInputFormat() {
+ return CSVFormat.DEFAULT;
+ }
- return csvFormat;
+ /**
+ * Provides a CSV default output format.
+ *
+ * @return CSV format
+ */
+ private static CSVFormat defaultCSVOutputFormat() {
+ return CSVFormat.DEFAULT;
}
private static final class ValueResolver implements Function<CSVRecord, String> {
diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/DataFrameTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/DataFrameTool.java
index 5441861..bef1b7a 100644
--- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/DataFrameTool.java
+++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/DataFrameTool.java
@@ -18,6 +18,7 @@ package org.apache.freemarker.generator.tools.dataframe;
import de.unknownreality.dataframe.DataFrame;
import de.unknownreality.dataframe.DataFrameWriter;
+import de.unknownreality.dataframe.DefaultDataFrame;
import de.unknownreality.dataframe.sort.SortColumn.Direction;
import de.unknownreality.dataframe.transform.ColumnDataFrameTransform;
import de.unknownreality.dataframe.transform.CountTransformer;
@@ -42,6 +43,13 @@ import static de.unknownreality.dataframe.DataFrameWriter.DEFAULT_PRINT_FORMAT;
public class DataFrameTool {
/**
+ * Create a default data frame.
+ */
+ public DataFrame create() {
+ return new DefaultDataFrame();
+ }
+
+ /**
* Create a data frame from Apache Commons CSVParser.
*
* @param csvParser CSV Parser
@@ -108,7 +116,7 @@ public class DataFrameTool {
@Override
public String toString() {
- return "Bridge to nRo/DataFrame (see https://github.com/nRo/DataFrame)";
+ return "Bridge to [nRo/DataFrame](https://github.com/nRo/DataFrame)";
}
private static CountTransformer countTransformer(boolean ignoreNA) {
diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/converter/MapConverter.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/converter/MapConverter.java
index f6800ce..d8906c1 100644
--- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/converter/MapConverter.java
+++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/converter/MapConverter.java
@@ -30,17 +30,6 @@ public class MapConverter {
* Create a data frame from a list of maps. It is assumed
* that the map represent tabular data.
*
- * @param map map to build the data frame
- * @return <code>DataFrame</code>
- */
- public static DataFrame toDataFrame(Map<String, Object> map) {
- return toDataFrame(singletonList(map));
- }
-
- /**
- * Create a data frame from a list of maps. It is assumed
- * that the map represent tabular data.
- *
* @param maps list of map to build the data frame
* @return <code>DataFrame</code>
*/
diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/freemarker/FreeMarkerTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/freemarker/FreeMarkerTool.java
index 1150ccb..45b43e6 100644
--- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/freemarker/FreeMarkerTool.java
+++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/freemarker/FreeMarkerTool.java
@@ -36,7 +36,7 @@ public class FreeMarkerTool {
public synchronized BeansWrapper getBeansWrapper() {
if (beansWrapper == null) {
- beansWrapper = new BeansWrapperBuilder(Configuration.VERSION_2_3_29).build();
+ beansWrapper = new BeansWrapperBuilder(Configuration.VERSION_2_3_30).build();
}
return beansWrapper;
}
diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/system/SystemTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/system/SystemTool.java
index ae5b66a..3f038f7 100644
--- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/system/SystemTool.java
+++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/system/SystemTool.java
@@ -1,3 +1,4 @@
+
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -16,6 +17,8 @@
*/
package org.apache.freemarker.generator.tools.system;
+import org.apache.freemarker.generator.base.util.StringUtils;
+
import java.io.File;
import java.io.Writer;
import java.net.InetAddress;
@@ -35,7 +38,7 @@ import static org.apache.freemarker.generator.base.FreeMarkerConstants.Model.FRE
/**
* Provides system related functionality, e.g. accessing environment variables,
- * system properties, commandl-line arguments, hostname, FreeMarker writer, etc.
+ * system properties, command-line arguments, hostname, FreeMarker writer, etc.
*/
@SuppressWarnings("unchecked")
public class SystemTool {
@@ -121,6 +124,34 @@ public class SystemTool {
return env != null ? env : def;
}
+ /**
+ * Convinience lookup of a configuration value based on
+ * user-supplied parameters, system properties and
+ * environment variables.
+ *
+ * @param name name of the configuration parameter
+ * @return value of null
+ */
+ public String getString(String name) {
+ return StringUtils.firstNonEmpty(
+ getParameter(name),
+ System.getProperty(name),
+ getEnv(name));
+ }
+
+ /**
+ * Convinience lookup of a configuration value based on
+ * user-supplied parameters, system properties and
+ * environment variables.
+ *
+ * @param name name of the configuration parameter
+ * @param def default value
+ * @return value of null
+ */
+ public String getString(String name, String def) {
+ return StringUtils.firstNonEmpty(getString(name), def);
+ }
+
public String getHostName() {
try {
return InetAddress.getLocalHost().getHostName();
@@ -129,6 +160,13 @@ public class SystemTool {
}
}
+ /**
+ * The <code>Writer</code> passed to FreeMarker for rendering the output. Please
+ * note that FreeMarker does some magic on top of the writer so output generated
+ * by using the writer and FreeMarker templates are scrambled.
+ *
+ * @return writer
+ */
public Writer getWriter() {
return writer;
}
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 d8e4b6a..29f8e0e 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
@@ -18,7 +18,6 @@ package org.apache.freemarker.generator.tools.commonscsv;
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.datasource.DataSource;
import org.apache.freemarker.generator.base.datasource.DataSourceFactory;
@@ -26,8 +25,6 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
import java.util.List;
import java.util.Map;
@@ -113,15 +110,12 @@ public class CommonsCSVToolTest {
public void shallPrintCsvRecords() throws IOException {
final CommonsCSVTool commonsCsvTool = commonsCsvTool();
final CSVFormat cvsFormat = DEFAULT.withHeader();
- final Writer writer = new StringWriter();
try (CSVParser parser = commonsCsvTool.parse(dataSource(), cvsFormat)) {
- try (CSVPrinter printer = commonsCsvTool.printer(cvsFormat, writer)) {
- printer.printRecord(parser.getHeaderMap());
+ try (final CommonsCSVPrinterFacade printer = commonsCsvTool.printer(cvsFormat)) {
+ assertTrue(printer.printRecord(parser.getHeaderMap()).contains(CONTRACT_ID));
}
}
-
- assertTrue(writer.toString().contains(CONTRACT_ID));
}
@Test
diff --git a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/system/SystemToolTest.java b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/system/SystemToolTest.java
index 46323be..23d90ee 100644
--- a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/system/SystemToolTest.java
+++ b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/system/SystemToolTest.java
@@ -18,22 +18,35 @@ package org.apache.freemarker.generator.tools.system;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
public class SystemToolTest {
+ private static final String USER = System.getenv("USER");
+
@Test
- public void shallGetProperties() {
+ public void shouldGetProperties() {
assertFalse(systemTool().getSystemProperties().isEmpty());
}
@Test
- public void shallGetEnvs() {
+ public void shouldGetEnvs() {
assertFalse(systemTool().getEnvs().isEmpty());
}
@Test
- public void shallGetHostName() {
+ public void shouldGetString() {
+ assertEquals(USER, systemTool().getString("USER"));
+ }
+
+ @Test
+ public void shouldGetStringWithDefault() {
+ assertEquals("foo", systemTool().getString("_DOES_NOT_EXIST_", "foo"));
+ }
+
+ @Test
+ public void shouldGetHostName() {
assertFalse(systemTool().getHostName().isEmpty());
}
diff --git a/travis.sh b/travis.sh
index 912d3d7..f76ae9d 100755
--- a/travis.sh
+++ b/travis.sh
@@ -1,6 +1,6 @@
#!/bin/sh
mvn clean install
cd ./freemarker-generator-cli
-sh ./run-samples.sh
+sh ./run-examples.sh
cd ../freemarker-generator-maven-plugin-sample
-mvn clean package
\ No newline at end of file
+mvn clean package