-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomatic.sh
executable file
·281 lines (276 loc) · 6.49 KB
/
automatic.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
#!/bin/sh
#
# * Matricola Cognome Nome
# * 754530 Galimberti Riccardo
# * 755152 Paredi Giacomo
# * 753252 Radice Lorenzo
# * Sede: Como
#
# 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 3 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. If not, see <http://www.gnu.org/licenses/>.
# Shell automatic compiler for ClimateMonitor program
# Paths
bin="bin/"
doc="doc/javadoc/"
src="src/"
lib="lib/"
obj=$bin
robj="../"
# ClassPath
cp="-cp "$bin""
# Include
inc="LICENSE.txt README.md readme.txt autori.txt"
# Javac Arguments
args="-encoding UTF-8 $cp -d"
srca="$src*/*.java"
# Manifest file
manifest="META-INF/MANIFEST.MF"
# Executable
jar="ClimateMonitor.jar"
# Do not remove
description=".description.txt"
# Function Result
result() {
if [ $1 -eq 0 ]; then
success "$2"
else
failed "$2"
fi
}
# Positive result
success() {
echo ""
echo "$1: succeeded"
echo ""
}
# Negative Result
failed() {
echo ""
echo "$1: failed"
echo ""
return 1
}
# Compile to Objects
compile() {
# Make dir
mkdir $obj 2> /dev/null
if extract_jar; then
# Compile java
d="javac $args $obj $srca"
echo "$d" && eval $d
res=$?
else
res=1
fi
result $res "Compilation"
}
# Remove Objects files
rmobj() {
if cd $obj; then
# Delete all files except description
d1="find . ! -name "$description" ! -name "$jar" -type f -delete"
# Delete all directories
d2="find . -type d -empty -delete"
echo "$d1" && eval $d1
echo "$d2" && eval $d2
res=$?
cd $robj
else
echo ""
echo "No bin found"
echo ""
res=1
fi
result $res "Object removal"
}
# Extract libraries
extract_jar() {
# Make dir
mkdir $obj 2> /dev/null
# Go to bin directory
if cd $obj; then
d="jar -xf ../"$lib"commons-lang3-3.1.jar && jar -xf ../"$lib"opencsv-5.5.2.jar"
echo "$d" && eval $d
res=$?
cd $robj
else
echo ""
echo "ERROR: no bin found"
echo ""
res=1
fi
result $res "JAR extraction"
}
# Change Manifest
change_manifest() {
# Make dir
mkdir $obj 2> /dev/null
# Go to bin directory
if cd $obj; then
# Made the MANIFEST.MF file
echo "echo "Main-Class: src.climatemonitoring.ClimateMonitor" > "$manifest""
echo "Main-Class: src.climatemonitoring.ClimateMonitor" > "$manifest"
res=$?
# Exit up
cd $robj
else
echo ""
echo "ERROR: no bin found"
echo ""
res=1
fi
result $res "Manifest file changing"
}
# Copy files
copy() {
# Copy files
d="cp "$inc" "$bin""
echo "$d" && eval $d
result $? "Files copy"
}
# JAR
compile_jar() {
# Make dir
mkdir $bin 2> /dev/null
# Compile java
if compile && change_manifest && copy && cd $obj; then
# Make an executable JAR
d="jar cfm $robj$bin$jar $manifest * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/* */*/*/*/*/*/*"
echo "$d" && eval $d
res=$?
cd $robj
if result $res "JAR creation"
then
# Remove Compiled files
rmobj
fi
fi
}
# Remove JAR
rmjar() {
d="rm $bin$jar"
echo "$d" && $d
result $? "JAR removing"
}
# Document
document() {
if extract_jar; then
# Compile java
d="javadoc -quiet -locale it_IT -doctitle \"Climate Monitor\" -author -version -package -use $args $doc -sourcepath $srca"
echo "$d" && eval $d
res=$?
echo ""
rmobj
else
res=1
fi
result $? "Documentation creation"
}
# Remove Documetation
rmdoc() {
if cd $doc; then
# Delete all files except description
d1="find . ! -name $description -type f -delete"
# Delete all directories
d2="find . -type d -empty -delete"
echo "$d1" && eval $d1
echo "$d2" && eval $d2
res=$?
result $res "Documentation removal"
cd ../..
return $res
else
echo ""
echo "No doc found"
echo ""
fi
}
# Compile and Document
comp_doc() {
# Compile Java and Make JAR
compile_jar
# Make JavaDoc
document
}
# Remove all
rmall() {
# Remove JAR
rmjar
# Remove Object files
rmobj
# Remove Documentation
rmdoc
}
# Help menu
help() {
echo "Help Menu"
echo " -h print this menu"
echo " -c compile with javac"
echo " -j make executable JAR file and delete object files"
echo " -d make Documentation with javadoc"
echo " -r remove"
echo " o object files"
echo " j JAR file"
echo " d Documentation"
echo " * all"
echo " * build JAR and make Documentation without making garbage"
}
# Move in a directory different from src
# Check the Path
if [ -n "$(echo $PWD | grep 'Climate_Monitoring')" ]; then
case $1 in
# Help
"h" | "-h" | "help" | "-help" | "--help")
help
;;
# Compile
"c" | "-c" | "compile" | "javac" | "-compile" | "--javac" | "--compile")
compile
;;
# JAR
"j" | "-j" | "-jar" | "jar" | "--jar")
compile_jar
;;
# Doument
"d" | "-d" | "document" | "javadoc" | "-document" | "--document" | "--javadoc")
document
;;
# Remove
"r" | "-r" | "rm" | "-rm" | "remove" | "-remove" | "--remove")
case $2 in
# Remove Object files
"o" | "obj" | "object" | "javac")
rmobj
;;
# Remove JAR
"j" | "jar" | "javac")
rmjar
;;
# Remove Documentation
"d" |"doc" | "documentation")
rmdoc
;;
# Remove all
*)
rmall
;;
esac
;;
*)
# Do all
comp_doc
;;
esac
else
echo "Error: Wrong Path"
fi