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/08/27 20:02:07 UTC

[freemarker-generator] branch master updated: FREEMARKER-155 Migrate the FTL code to terser dotter form (#22)

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 0ead56f  FREEMARKER-155 Migrate the FTL code to terser dotter form (#22)
0ead56f is described below

commit 0ead56f26f1a80abf95bbbd0d9db52223668ce23
Author: Siegfried Goeschl <si...@gmail.com>
AuthorDate: Thu Aug 27 22:01:58 2020 +0200

    FREEMARKER-155 Migrate the FTL code to terser dotter form (#22)
---
 freemarker-generator-cli/CHANGELOG.md              |  4 +++-
 .../templates/accesslog/combined-access.ftl        |  8 +++----
 .../templates/csv/csv/gatling-user-credentials.ftl |  2 +-
 .../examples/templates/csv/html/transactions.ftl   |  2 +-
 .../src/app/examples/templates/csv/shell/curl.ftl  |  2 +-
 .../app/examples/templates/dataframe/example.ftl   |  6 ++---
 .../examples/templates/dataframe/html/print.ftl    |  2 +-
 .../src/app/examples/templates/demo.ftl            |  2 +-
 .../app/examples/templates/excel/csv/custom.ftl    |  2 +-
 .../templates/json/csv/swagger-endpoints.ftl       | 10 ++++----
 .../templates/properties/csv/locker-test-users.ftl | 14 +++++------
 .../app/examples/templates/tsv/fo/transactions.ftl |  2 +-
 .../freemarker/generator/cli/ManualTest.java       | 27 +++++++++++-----------
 13 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/freemarker-generator-cli/CHANGELOG.md b/freemarker-generator-cli/CHANGELOG.md
index 6fca548..d095c1c 100644
--- a/freemarker-generator-cli/CHANGELOG.md
+++ b/freemarker-generator-cli/CHANGELOG.md
@@ -17,6 +17,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-155] Migrate the FTL code to terser dotter form 
 * [FREEMARKER-153] Packaged templates are now prefixed with `freemarker-generator`, e.g. `freemarker-generator/info.ftl`
 * [FREEMARKER-153] Renamed `--basedir` command line option to `--template-dir`
 * [FREEMARKER-153] Renamed `freemarker-cli` to `freemarker-generator`
@@ -54,4 +55,5 @@ All notable changes to this project will be documented in this file. We try to a
 [FREEMARKER-148]: https://issues.apache.org/jira/browse/FREEMARKER-148
 [FREEMARKER-149]: https://issues.apache.org/jira/browse/FREEMARKER-149
 [FREEMARKER-151]: https://issues.apache.org/jira/browse/FREEMARKER-151
-[FREEMARKER-153]: https://issues.apache.org/jira/browse/FREEMARKER-151
\ No newline at end of file
+[FREEMARKER-153]: https://issues.apache.org/jira/browse/FREEMARKER-153
+[FREEMARKER-155]: https://issues.apache.org/jira/browse/FREEMARKER-155
\ No newline at end of file
diff --git a/freemarker-generator-cli/src/app/examples/templates/accesslog/combined-access.ftl b/freemarker-generator-cli/src/app/examples/templates/accesslog/combined-access.ftl
index 56d7f21..af78768 100644
--- a/freemarker-generator-cli/src/app/examples/templates/accesslog/combined-access.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/accesslog/combined-access.ftl
@@ -23,10 +23,10 @@
     TIMESTAMP;VERB;REQUEST;HTTPVERSION
     <#list lines as line>
         <#assign parts = grok.match(line)>
-        <#assign timestamp = parts["timestamp"]>
-        <#assign verb = parts["verb"]>
-        <#assign request = parts["request"]>
-        <#assign httpversion = parts["httpversion"]>
+        <#assign timestamp = parts.timestamp>
+        <#assign verb = parts.verb>
+        <#assign request = parts.request>
+        <#assign httpversion = parts.httpversion>
         ${timestamp};${verb};${request};${httpversion}
     </#list>
 </#compress>
\ No newline at end of file
diff --git a/freemarker-generator-cli/src/app/examples/templates/csv/csv/gatling-user-credentials.ftl b/freemarker-generator-cli/src/app/examples/templates/csv/csv/gatling-user-credentials.ftl
index 3bf2f68..aae83f4 100644
--- a/freemarker-generator-cli/src/app/examples/templates/csv/csv/gatling-user-credentials.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/csv/csv/gatling-user-credentials.ftl
@@ -16,7 +16,7 @@
   under the License.
 -->
 <#assign dataSource = dataSources?values[0]>
-<#assign cvsFormat = tools.csv.formats["DEFAULT"].withDelimiter(';')>
+<#assign cvsFormat = tools.csv.formats.DEFAULT.withDelimiter(';')>
 <#assign csvParser = tools.csv.parse(dataSource, cvsFormat)>
 <#assign csvRecords = csvParser.records>
 
diff --git a/freemarker-generator-cli/src/app/examples/templates/csv/html/transactions.ftl b/freemarker-generator-cli/src/app/examples/templates/csv/html/transactions.ftl
index ef2dc5c..030cd82 100644
--- a/freemarker-generator-cli/src/app/examples/templates/csv/html/transactions.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/csv/html/transactions.ftl
@@ -17,7 +17,7 @@
 -->
 <#assign dataSource = dataSources?values[0]>
 <#assign name = dataSource.name>
-<#assign cvsFormat = tools.csv.formats["DEFAULT"].withDelimiter('\t').withHeader()>
+<#assign cvsFormat = tools.csv.formats.DEFAULT.withDelimiter('\t').withHeader()>
 <#assign csvParser = tools.csv.parse(dataSource, cvsFormat)>
 <#assign csvHeaders = csvParser.getHeaderMap()?keys>
 <#assign csvRecords = csvParser.records>
diff --git a/freemarker-generator-cli/src/app/examples/templates/csv/shell/curl.ftl b/freemarker-generator-cli/src/app/examples/templates/csv/shell/curl.ftl
index aaae7a6..114dd4f 100644
--- a/freemarker-generator-cli/src/app/examples/templates/csv/shell/curl.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/csv/shell/curl.ftl
@@ -15,7 +15,7 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<#assign cvsFormat = tools.csv.formats["DEFAULT"].withHeader()>
+<#assign cvsFormat = tools.csv.formats.DEFAULT.withHeader()>
 <#assign csvParser = tools.csv.parse(dataSources?values[0], cvsFormat)>
 <#assign records = csvParser.records>
 <#assign csvMap = tools.csv.toMap(records, "disposer")>
diff --git a/freemarker-generator-cli/src/app/examples/templates/dataframe/example.ftl b/freemarker-generator-cli/src/app/examples/templates/dataframe/example.ftl
index da26004..3b154ea 100644
--- a/freemarker-generator-cli/src/app/examples/templates/dataframe/example.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/dataframe/example.ftl
@@ -15,7 +15,7 @@
   under the License.
 -->
 <#assign dataSource = dataSources?values[0]>
-<#assign csvParser = tools.csv.parse(dataSource, tools.csv.formats["DATAFRAME"])>
+<#assign csvParser = tools.csv.parse(dataSource, tools.csv.formats.DATAFRAME)>
 <#assign users = tools.dataframe.fromCSVParser(csvParser)>
 
 Original Data
@@ -31,7 +31,7 @@ Select By Name & Country
 <#assign country = "Germany">
 ${tools.dataframe.print(users
 .select("(name == 'Schmitt' || name == 'Meier') && country == '${country}'")
-.sort("name", tools.dataframe.sortOrder["ASCENDING"]))}
+.sort("name", tools.dataframe.sortOrder.ASCENDING))}
 
 Head of Users
 =============================================================================
@@ -39,7 +39,7 @@ ${tools.dataframe.print(users.head(2))}
 
 Count Column Values
 =============================================================================
-${tools.dataframe.print(users.getColumn("country").transform(tools.dataframe.transformer["COUNT"]))}
+${tools.dataframe.print(users.getColumn("country").transform(tools.dataframe.transformer.COUNT))}
 
 Group By Age & Country
 =============================================================================
diff --git a/freemarker-generator-cli/src/app/examples/templates/dataframe/html/print.ftl b/freemarker-generator-cli/src/app/examples/templates/dataframe/html/print.ftl
index e542b1c..3ae73c8 100644
--- a/freemarker-generator-cli/src/app/examples/templates/dataframe/html/print.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/dataframe/html/print.ftl
@@ -15,7 +15,7 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<#assign cvsFormat = tools.csv.formats["DEFAULT"].withHeader().withDelimiter(';')>
+<#assign cvsFormat = tools.csv.formats.DEFAULT.withHeader().withDelimiter(';')>
 <#assign csvParser = tools.csv.parse(dataSources?values[0], cvsFormat)>
 <#assign dataFrame = tools.dataframe.toDataFrame(csvParser)>
 <#--------------------------------------------------------------------------->
diff --git a/freemarker-generator-cli/src/app/examples/templates/demo.ftl b/freemarker-generator-cli/src/app/examples/templates/demo.ftl
index f6d52af..8ec3ac4 100644
--- a/freemarker-generator-cli/src/app/examples/templates/demo.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/demo.ftl
@@ -58,7 +58,7 @@ Host name       : ${tools.system.getHostName()}
 Command line    : ${tools.system.getCommandLineArgs()?join(", ")}
 System property : ${tools.system.getSystemProperty("user.name", "N.A.")}
 Timestamp       : ${tools.system.currentTimeMillis?c}
-Environment     : ${tools.system.envs["USER"]!"N.A."}
+Environment     : ${tools.system.envs.USER!"N.A."}
 
 8) Access System Properties
 ---------------------------------------------------------------------------
diff --git a/freemarker-generator-cli/src/app/examples/templates/excel/csv/custom.ftl b/freemarker-generator-cli/src/app/examples/templates/excel/csv/custom.ftl
index feda79a..1e2bd06 100644
--- a/freemarker-generator-cli/src/app/examples/templates/excel/csv/custom.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/excel/csv/custom.ftl
@@ -16,7 +16,7 @@
   under the License.
 -->
 <#assign format = CSV_TARGET_FORMAT!"DEFAULT">
-<#assign salt = tools.system.parameters["salt"]!"salt">
+<#assign salt = tools.system.parameters.salt!"salt">
 <#-- Parse the first data source & sheet of the Excel document -->
 <#assign workbook = tools.excel.parse(dataSources?values[0])>
 <#assign sheet = tools.excel.getSheets(workbook)[0]>
diff --git a/freemarker-generator-cli/src/app/examples/templates/json/csv/swagger-endpoints.ftl b/freemarker-generator-cli/src/app/examples/templates/json/csv/swagger-endpoints.ftl
index 474fd5a..6ab4ce2 100644
--- a/freemarker-generator-cli/src/app/examples/templates/json/csv/swagger-endpoints.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/json/csv/swagger-endpoints.ftl
@@ -26,11 +26,11 @@
         <#assign names = metadata?keys?sort>
         <#list names as name>
             <#assign method = paths[endpoint][name]>
-            <#assign summary = sanitize(method["summary"]!"")>
-            <#assign description = sanitize(method["description"]!"")>
-            <#assign consumes = join(method["consumes"]![])>
-            <#assign produces = join(method["produces"]![])>
-            <#assign parameters = method["parameters"]>
+            <#assign summary = sanitize(method.summary!"")>
+            <#assign description = sanitize(method.description!"")>
+            <#assign consumes = join(method.consumes![])>
+            <#assign produces = join(method.produces![])>
+            <#assign parameters = method.parameters>
             ${url};${name?upper_case};${consumes};${produces};${parameters?size};${summary};${description}
         </#list>
     </#list>
diff --git a/freemarker-generator-cli/src/app/examples/templates/properties/csv/locker-test-users.ftl b/freemarker-generator-cli/src/app/examples/templates/properties/csv/locker-test-users.ftl
index 1d2d21f..8e01dac 100644
--- a/freemarker-generator-cli/src/app/examples/templates/properties/csv/locker-test-users.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/properties/csv/locker-test-users.ftl
@@ -19,15 +19,15 @@
     TENANT,SITE,USER_ID,DISPOSER_ID,PASSWORD,SMS_OTP,NAME,DESCRIPTION
     <#list dataSources?values as dataSource>
         <#assign properties = tools.properties.parse(dataSource)>
-        <#assign environments = properties["ENVIRONMENTS"]!"">
+        <#assign environments = properties.ENVIRONMENTS!"">
         <#assign tenant = extractTenant(environments)>
         <#assign site = extractSite(environments)>
-        <#assign userId = properties["USER_ID"]!"">
-        <#assign disposerId = properties["USER_ID"]!"">
-        <#assign password = properties["PASSWORD"]!"">
-        <#assign smsOtp = properties["SMS_OTP"]!"">
-        <#assign name = properties["NAME"]!"">
-        <#assign description = properties["DESCRIPTION"]!"">
+        <#assign userId = properties.USER_ID!"">
+        <#assign disposerId = properties.USER_ID!"">
+        <#assign password = properties.PASSWORD!"">
+        <#assign smsOtp = properties.SMS_OTP!"">
+        <#assign name = properties.NAME!"">
+        <#assign description = properties.DESCRIPTION!"">
         ${tenant},${site},${userId},${disposerId},${password},${smsOtp},${name},${description}
     </#list>
 </#compress>
diff --git a/freemarker-generator-cli/src/app/examples/templates/tsv/fo/transactions.ftl b/freemarker-generator-cli/src/app/examples/templates/tsv/fo/transactions.ftl
index 51c2be4..5beefc3 100644
--- a/freemarker-generator-cli/src/app/examples/templates/tsv/fo/transactions.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/tsv/fo/transactions.ftl
@@ -15,7 +15,7 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<#assign cvsFormat = tools.csv.formats["TDF"].withHeader()>
+<#assign cvsFormat = tools.csv.formats.TDF.withHeader()>
 <#assign csvParser = tools.csv.parse(dataSources?values[0], cvsFormat)>
 <#assign csvHeaders = csvParser.getHeaderMap()?keys>
 <#assign csvRecords = csvParser.records>
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 06f8714..7d12754 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
@@ -16,28 +16,27 @@
  */
 package org.apache.freemarker.generator.cli;
 
-import java.util.Arrays;
+import java.io.IOException;
 
 /**
  * Invoke freemarker-cli and dump the output for ad-hoc manual testing.
  */
-public class ManualTest {
+public class ManualTest extends AbstractMainTest {
 
-    private static final String SPACE = " ";
     // private static final String CMD = "-V";
-    // 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=false -PCSV_SOURCE_FORMAT=DEFAULT -PCSV_TARGET_FORMAT=EXCEL -PCSV_TARGET_WITH_HEADER=true -t templates/csv/csv/transform.ftl examples/data/csv/contract.csv";
-    // private static final String CMD = "-t examples/templates/json/dataframe/github-users.ftl examples/data/json/github-users.json";
-    // private static final String CMD = "-t templates/csv/md/transform.ftl -o target/contract.md -t templates/csv/html/transform.ftl examples/data/csv/contract.csv";
-    private static final String CMD = "-t examples/templates/demo.ftl src/test/data";
+    private static final String CMD = "-t src/app/examples/templates/demo.ftl src/test/data";
 
-
-    public static void main(String[] args) {
-        Main.execute(toArgs(CMD));
+    @Override
+    public String execute(String commandLine) throws IOException {
+        return super.execute(commandLine);
     }
 
-    private static String[] toArgs(String line) {
-        // map a "%20" to space to protect system property values containing a space
-        return Arrays.stream(line.split(SPACE)).map(s -> s.replace("%20", " ")).toArray(String[]::new);
+    public static void main(String[] args) {
+        try {
+            final String output = new ManualTest().execute(CMD);
+            System.out.println(output);
+        } catch (IOException e) {
+            throw new RuntimeException("Executing the manual test failed: " + CMD, e);
+        }
     }
 }