This repository has been archived by the owner on Nov 30, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
build_archetype.sh
executable file
·349 lines (329 loc) · 11.5 KB
/
build_archetype.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/bin/bash
# * $Header: build_archetype.sh $
# * $Revision: 0.1 $
# * $Date: 14/giu/2011 18.16.47 $
# *
# * ====================================================================
# *
# * Copyright (C) 2007-2011 GeoSolutions S.A.S.
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program.
# *
# * ====================================================================
# *
# * This software consists of voluntary contributions made by developers
# * of GeoSolutions. For more information on GeoSolutions, please see
# * <http://www.geo-solutions.it/>.
###################################################
# usage
function usage {
echo -e "
USAGE:\n\
$0 -s GEOBATCH_SOURCE_DIR ... [OPTION VALUE]...\n\
\n\
OPTIONS\n\
[-s] where to get the geobatch sources\n\
ACCEPTED VALUE: [default: './src/']\n\
Any valid path pointing to the GB you want to use as source dir\n\
\n\
[-d] where to put the project\n\
ACCEPTED VALUE: [default: './out/']\n\
\n\
Any valid path pointing to a directory\n\
[-b] The version of GeoBatch to use \n\
ACCEPTED VALUE: [default: '1.0']\n\
1.0 or 1.2-SNAPSHOT\n\
\n\
[-n] The application name\n\
ACCEPTED VALUE: [default: 'my_application']
Any valid mvn project name (lowercase '_' or '-' separed)\n\
\n\
[-a] The name of the action to prepare\n\
ACCEPTED VALUE: [default: 'MyAction']\n\
Any valid java class name (CamelCase format)\n";
return;
}
###################################################
# Variables
# where to get the geobatch sources [-s]
GB_DIR="./src/";
# Version of GeoBatch to use
# 1.0 or 1.1-SNAPSHOT [-b]
GB_VER="1.0"; #"1.1-SNAPSHOT"
# where to put the project [-d]
DEST_DIR="./out/"
# The application name [-n]
NAME_APP="my_application"
# The name of the action to prepare [-a]
NAME_ACT="MyAction"
# used for folder and pom.xml stuff
NAME_ACT_LOWER=$(echo $NAME_ACT | tr "[:upper:]" "[:lower:]")
###################################################
###################################################
# checking arguments
args=("${@}");
#for arg in $@; do
for ((i=0; i<$#; i++)){
arg=${args[$i]};
case $arg in
"-s")
echo "Setting Geobatch Source dir (-s)"
i=$((++i));
GB_DIR=${args[$i]};
if [ -d "$GB_DIR" ]; then
echo "GeoBatch source dir set to-> $GB_DIR"
else
echo -e "ERROR:\n Bad GeoBatch source directory! ($GB_DIR)"
usage;
exit -1;
fi
;;
"-b")
echo "Setting Geobatch Source version (-b)"
i=$((++i));
GB_VER=${args[$i]};
case $GB_VER in
"1.0")
;;
"1.2-SNAPSHOT")
;;
*)
echo -e "ERROR:\n Bad GeoBatch source variable! ($GB_VER)"
usage;
exit -1;
esac
echo "GeoBatch source dir set to-> $GB_VER"
;;
"-d")
echo "Setting Application destination dir (-d)"
i=$((++i));
DEST_DIR=${args[$i]};
if [ -d "$DEST_DIR" ]; then
echo "Application destination directory set to-> $DEST_DIR"
else
echo -e "ERROR:\n Bad Application destination directory! ($DEST_DIR)"
usage;
exit -1;
fi
;;
"-n")
echo "Setting Application name (-n)"
i=$((++i));
# set name application to lowercase
NAME_APP=$(echo ${args[$i]} | tr "[:upper:]" "[:lower:]")
case $NAME_APP in
-*)
echo -e "ERROR:\n Bad application name! ($NAME_APP)"
usage;
exit -1;
;;
*)
echo "Application name set to-> $NAME_APP"
esac
;;
"-a")
echo "Setting Action name (-a)"
i=$((++i));
# set name first character to Uppercase (to respect CamelCase format)
NAME_ACT="${args[$i]^}"
case $NAME_ACT in
-*)
echo -e "ERROR:\n Bad action name! ($NAME_ACT)"
usage;
exit -1;
;;
*)
echo "Action name set to-> $NAME_ACT"
esac
# used for folder and pom.xml stuff
NAME_ACT_LOWER=$(echo $NAME_ACT | tr "[:upper:]" "[:lower:]")
;;
"--help")
usage;
exit -1;
;;
"-h")
usage;
exit -1;
;;
*)
echo "Default: calling usage ($arg)"
usage;
exit -1;
;;
esac
}
##############################################################################
# REPLACE pom FUNCTION
##################
#KEYS (do not modify)
GB_VER_KEY="##GB_VER##"
NAME_APP_KEY="##NAME_APP##"
# will be set to $GB_VER
PROJ_VER_KEY="##PROJ_VER##"
NAME_ACT_KEY="##NAME_ACT##"
function replace_pom {
cat "$1" | \
awk '{if ($0 ~ /.*'"$GB_VER_KEY"'.*/) { gsub(/'"$GB_VER_KEY"'/,"'"$GB_VER"'",$0);} \
if ($0 ~ /.*'"$NAME_APP_KEY"'.*/) { gsub(/'"$NAME_APP_KEY"'/,"'"$NAME_APP"'",$0);} \
if ($0 ~ /.*'"$PROJ_VER_KEY"'.*/){ gsub(/'"$PROJ_VER_KEY"'/,"'"$GB_VER"'",$0);} \
if ($0 ~ /.*'"$NAME_ACT_KEY"'.*/){ gsub(/'"$NAME_ACT_KEY"'/,"'"$NAME_ACT_LOWER"'",$0);} \
{ print $0}}' > "$2"
}
##############################################################################
# REPLACE replace_application_pom FUNCTION
##################
#VARIABLEs (do not modify)
APP_START_DELIM="<!-- START APPLICATION DESCRIPTION -->"
APPLICATION_DES="\
<parent>\n\
<groupId>it.geosolutions.geobatch.$NAME_APP</groupId>\n\
<artifactId>$NAME_APP</artifactId>\n\
<version>$GB_VER</version>\n\
</parent>\n\
<!-- =========================================================== -->\n\
<!-- Module Description -->\n\
<!-- =========================================================== -->\n\
<groupId>it.geosolutions.geobatch.$NAME_APP</groupId>\n\
<artifactId>application-$NAME_APP</artifactId>\n\
<packaging>war</packaging>\n"
APP_STOP_DELIM="<!-- STOP APPLICATION DESCRIPTION -->"
ACTION_PROFILE="\
<!--<profile>\n\
<id>$NAME_ACT_LOWER</id>\n\
<activation>\n\
<property>\n\
<name>all</name>\n\
<value>true</value>\n\
</property>\n\
</activation>\n\
<dependencies>\n\
<dependency>\n\
<groupId>it.geosolutions.geobatch.$NAME_APP</groupId>\n\
<artifactId>action-$NAME_APP-$NAME_ACT_LOWER</artifactId>\n\
</dependency>\n\
</dependencies>\n\
<build>\n\
<plugins>\n\
<plugin>\n\
<groupId>org.apache.maven.plugins</groupId>\n\
<artifactId>maven-dependency-plugin</artifactId>\n\
<executions>\n\
<execution>\n\
<id>unpack_$NAME_ACT_LOWER</id>\n\
<phase>package</phase>\n\
<goals>\n\
<goal>unpack</goal>\n\
</goals>\n\
<configuration>\n\
<artifactItems>\n\
<artifactItem>\n\
<groupId>it.geosolutions.geobatch.$NAME_APP</groupId>\n\
<artifactId>action-$NAME_APP-$NAME_ACT_LOWER</artifactId>\n\
<classifier>flowdata</classifier>\n\
<type>jar</type>\n\
<overWrite>false</overWrite>\n\
<outputDirectory>\${project.build.directory}/\${flow.dir}</outputDirectory>\n\
<includes>data/**</includes>\n\
</artifactItem>\n\
</artifactItems>\n\
<overWriteReleases>true</overWriteReleases>\n\
<overWriteSnapshots>true</overWriteSnapshots>\n\
</configuration>\n\
</execution>\n\
</executions>\n\
</plugin>\n\
</plugins>\n\
</build>\n\
</profile>-->\n"
function replace_application_pom {
cat "$1" | awk 'BEGIN{appl_des=0;profile=0;}\
/'"$APP_START_DELIM"'/,/'"$APP_STOP_DELIM"'/{if (appl_des==0){appl_des=1;}; next}\
{if (appl_des==1){print "'"$APPLICATION_DES"'"; appl_des=0;} else {print $0}}\
/<profiles>/,/<\/profiles>/{if (profile==0){print "'"$ACTION_PROFILE"'"; profile=1; }}' > "$2"
}
################
# PROJECT FOLDER(s) STRUCTURE
################
mkdir -p "$DEST_DIR/src"
replace_pom ".build/src-pom.xml" "$DEST_DIR/src/pom.xml" -p
cp ".build/build.sh" "$DEST_DIR/src/build.sh" -p
# copy webapp
cp "$GB_DIR/application" "$DEST_DIR/src/application-$NAME_APP" -Rp
#cp ".build/application-pom.xml" "$DEST_DIR/src/application-$NAME_APP/pom.xml" -p
replace_application_pom "$GB_DIR/application/pom.xml" "$DEST_DIR/src/application-$NAME_APP/pom.xml"
#################################################################################################
# ACTION(s) FOLDER STRUCTURE
################
mkdir "$DEST_DIR/src/actions-$NAME_APP" -p
replace_pom ".build/actions-pom.xml" "$DEST_DIR/src/actions-$NAME_APP/pom.xml"
#################################################################################################
# function replace_java
# replace all the KEYS into java sources
function replace_java {
cat "$1" | \
awk '{if ($0 ~ /.*package.*/) { gsub(/'"$NAME_ACT_KEY"'/,"'"$NAME_ACT_LOWER"'",$0);} \
if ($0 ~ /.*'"$NAME_APP_KEY"'.*/) { gsub(/'"$NAME_APP_KEY"'/,"'"$NAME_APP"'",$0);} \
if ($0 ~ /.*'"$NAME_ACT_KEY"'.*/){ gsub(/'"$NAME_ACT_KEY"'/,"'"$NAME_ACT"'",$0);} \
{ print $0}}' > "$2"
}
#################################################################################################
# ACTION SOURCES
################
#remove double slash
ACTION_DIR="$DEST_DIR/src/actions-$NAME_APP/$NAME_ACT_LOWER/"
mkdir -p "$ACTION_DIR"
#place pom replacing keys
replace_pom ".build/action/pom.xml" "$ACTION_DIR/pom.xml"
# build package structure
ACTION_SOURCE_DIR="$ACTION_DIR/src/main/java/it/geosolutions/geobatch/$NAME_APP/$NAME_ACT_LOWER/"
mkdir -p "$ACTION_SOURCE_DIR"
# copy all file templates replacing keys
for java in `ls .build/action/src/main/java/`; do
replace_java ".build/action/src/main/java/$java" "$ACTION_SOURCE_DIR/$NAME_ACT$java"
done
#################################################################################################
# function replace_configuration
# replace all the KEYS into the flow configuration
NAME_ACT_LOWER_KEY="##NAME_ACT_LOWER##"
function replace_resources {
cat "$1" | \
awk '{if ($0 ~ /.*'"$NAME_ACT_LOWER_KEY"'.*/) { gsub(/'"$NAME_ACT_LOWER_KEY"'/,"'"$NAME_ACT_LOWER"'",$0);} \
if ($0 ~ /.*'"$NAME_APP_KEY"'.*/) { gsub(/'"$NAME_APP_KEY"'/,"'"$NAME_APP"'",$0);} \
if ($0 ~ /.*'"$NAME_ACT_KEY"'.*/){ gsub(/'"$NAME_ACT_KEY"'/,"'"$NAME_ACT"'",$0);} \
{ print $0}}' > "$2"
}
################
# ACTION RESOURCES
################
ACTION_RESOURCE_DIR="$ACTION_DIR/src/main/resources/"
mkdir -p "$ACTION_RESOURCE_DIR"
# copy and filter application context
replace_resources ".build/action/src/main/resources/applicationContext.xml" "$ACTION_RESOURCE_DIR""applicationContext.xml"
mkdir -p "$ACTION_RESOURCE_DIR/data/$NAME_ACT_LOWER/in/"
touch "$ACTION_RESOURCE_DIR/data/$NAME_ACT_LOWER/in/.placeholder"
# copy and filter configuration
replace_resources ".build/action/src/main/resources/data/Flow.xml" "$ACTION_RESOURCE_DIR/data/$NAME_ACT_LOWER.xml"
################
# ACTION TESTS
################
mkdir -p "$ACTION_DIR/src/test/java/it/geosolutions/geobatch/$NAME_ACT_LOWER/test"
#build
#mvn eclipse:clean eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true -Declipse.addVersionToProjectName=true -Pdao.xstream,netcdf2geotiff -Dall -Dmaven.test.skip=true -e -o
echo -e "\
\nApplication $NAME_APP SUCCESFULLY build!!!\n\
\nIf you want to activate the action ($NAME_ACT) you still have to uncomment:\n\
\t- Action dependency version into the dependency management of the $DEST_DIR/src/pom.xml\n\
\t- Action profile into the profiles node of the $DEST_DIR/src/actions-$NAME_APP/pom.xml\n\
\t- Action profile into the profiles node of the $DEST_DIR/src/application-$NAME_APP/pom.xml\n"