This is an automated email from the ASF dual-hosted git repository.

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

commit 9ee2bbc094aa980ece39a223f9c679be522fa049
Author: ddekany <[email protected]>
AuthorDate: Sun Oct 11 20:28:15 2020 +0200

    FREEMARKER-154: Added option to demo.ftl to deduct potentially sensitive 
information, that we don't want to include in the documentation (the output is 
inserted into it).
---
 .../src/app/examples/templates/demo.ftl              | 20 +++++++++++++++++++-
 .../src/app/scripts/run-examples.bat                 |  2 +-
 .../src/app/scripts/run-examples.sh                  |  2 +-
 .../freemarker/generator/cli/ExamplesTest.java       |  2 +-
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/freemarker-generator-cli/src/app/examples/templates/demo.ftl 
b/freemarker-generator-cli/src/app/examples/templates/demo.ftl
index 8ec3ac4..e35e2a9 100644
--- a/freemarker-generator-cli/src/app/examples/templates/demo.ftl
+++ b/freemarker-generator-cli/src/app/examples/templates/demo.ftl
@@ -15,6 +15,7 @@
   specific language governing permissions and limitations
   under the License.
 -->
+<#assign deductSensitiveInformation = 
(tools.system.parameters.deductSensitiveInformation!'false') != 'false'>
 1) FreeMarker Special Variables
 ---------------------------------------------------------------------------
 FreeMarker version     : ${.version}
@@ -74,14 +75,31 @@ user.home    : 
${tools.system.systemProperties["user.home"]!""}
 9) List Environment Variables
 ---------------------------------------------------------------------------
 <#list tools.system.envs as name,value>
+<#if !deductSensitiveInformation
+    || ['BASEDIR', 'USERNAME', 'CLASSPATH', 'TEMP', 
'JAVA_HOME']?seq_contains(name?upper_case)
+>
 - ${name} ==> ${value}<#lt>
+</#if>
 </#list>
+<#if deductSensitiveInformation>
+[...]
+Some items were deducted!
+</#if>
 
 10) List System Properties
 ---------------------------------------------------------------------------
-<#list tools.system.systemProperties as name,value>
+<#list tools.system.systemProperties as name, value>
+<#if !deductSensitiveInformation
+    || ['app.dir', 'app.home', 'app.pid', 'basedir', 'java.version', 
'user.home', 'user.dir', 'user.name', 'user.timezone'
+        'file.separator', 'java.class.path', 'java.home']?seq_contains(name)
+>
 - ${name} ==> ${value}<#lt>
+</#if>
 </#list>
+<#if deductSensitiveInformation>
+[...]
+Some items were deducted!
+</#if>
 
 11) Access DataSources
 ---------------------------------------------------------------------------
diff --git a/freemarker-generator-cli/src/app/scripts/run-examples.bat 
b/freemarker-generator-cli/src/app/scripts/run-examples.bat
index c472333..7d92ef5 100644
--- a/freemarker-generator-cli/src/app/scripts/run-examples.bat
+++ b/freemarker-generator-cli/src/app/scripts/run-examples.bat
@@ -35,7 +35,7 @@ REM Demo
 REM =========================================================================
 
 echo "examples\templates\demo.ftl"
-%FREEMARKER_CMD% -t examples\templates\demo.ftl README.md --output-encoding 
CP1252 > target\out\demo.txt
+%FREEMARKER_CMD% -t examples\templates\demo.ftl --output-encoding CP1252 
-PdeductSensitiveInformation=true  README.md > target\out\demo.txt
 
 REM =========================================================================
 REM Interactive Mode
diff --git a/freemarker-generator-cli/src/app/scripts/run-examples.sh 
b/freemarker-generator-cli/src/app/scripts/run-examples.sh
index 89f86e7..5063fe9 100755
--- a/freemarker-generator-cli/src/app/scripts/run-examples.sh
+++ b/freemarker-generator-cli/src/app/scripts/run-examples.sh
@@ -40,7 +40,7 @@ $FREEMARKER_CMD -t freemarker-generator/info.ftl README.md > 
target/out/info.txt
 #############################################################################
 
 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; }
+$FREEMARKER_CMD -t examples/templates/demo.ftl 
-PdeductSensitiveInformation=true README.md > target/out/demo.txt || { echo >&2 
"Test failed.  Aborting."; exit 1; }
 
 #############################################################################
 # Interactive Mode
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 a2e7c79..9c7f2e0 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
@@ -44,7 +44,7 @@ public class ExamplesTest extends AbstractMainTest {
 
     @Test
     public void shouldRunDemoExamples() throws IOException {
-        assertValid(execute("-t src/app/examples/templates/demo.ftl 
README.md"));
+        assertValid(execute("-t src/app/examples/templates/demo.ftl 
-PdeductSensitiveInformation=true README.md"));
     }
 
     @Test

Reply via email to