-
Notifications
You must be signed in to change notification settings - Fork 15
/
run-samples.sh
executable file
·165 lines (122 loc) · 9.01 KB
/
run-samples.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/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(Documents.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(Documents.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(Documents.first).select("a")[0]}' site/sample/html/dependencies.html > target/out/interactive-html.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; }
#############################################################################
# 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
#############################################################################
# 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/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 -Dcsv.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; }
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; }
#############################################################################
# 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; }
#############################################################################
# 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