forked from zkoss/atlantic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·231 lines (199 loc) · 7.42 KB
/
init.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
#!/bin/bash
echo ""
echo "This script will assist you in setting up your custom ZK theme maven project."
echo ""
# 1. gather information
while true; do
while true; do
read -p "Enter the [GROUP ID] for your theme project and press [ENTER]: " groupId
case $groupId in
"" ) echo "[GROUP ID] cannot be empty, try again.";;
* ) break;;
esac
done
while true; do
read -p "Enter the [ARTIFACT ID] (will also be your theme name) for your theme project and press [ENTER]: " artifactId
case $artifactId in
"" ) echo "[ARTIFACT ID] cannot be empty, try again.";;
# need to check with regex, because this string will be used in folder path
*[[:space:]]* ) echo "[ARTIFACT ID] cannot contain whitespace(s), try again.";;
* ) break;;
esac
done
themeName=$artifactId
themeNameCap=$(echo $themeName | cut -c 1 | tr [a-z] [A-Z])$(echo $themeName | cut -c 2-)
while true; do
read -p "Enter the [VERSION] for your theme project and press [ENTER]: " version
case $version in
"" ) echo "[VERSION] cannot be empty, try again.";;
* ) break;;
esac
done
while true; do
read -p "Enter the [DISPLAY NAME] for your theme and press [ENTER]: " displayName
case $displayName in
"" ) echo "[DISPLAY NAME] cannot be empty, try again.";;
* ) break;;
esac
done
echo ""
echo "GROUP ID : $groupId"
echo "ARTIFACT ID : $artifactId"
echo "VERSION : $version"
echo "DISPLAY NAME : $displayName"
echo ""
read -p "Is the above information correct? [Y/n] " confirm
case $confirm in
"") break;;
[Yy]*) break;;
*) echo "Let's start again then."; echo "";;
esac
done
# 2. done gathering information, update the files now
# need to update
# 1. pom.xml
# 2. version
# 3. folder path
# 4. Version.java
# 5. webAppInit.java
# 6. config.xml
# 7. lang-addon.xml
# first, check if files to be modified are present
if [ ! -e pom.xml ]; then
echo "[pom.xml] not found, unable to proceed, abort."
exit 2
fi
if [ ! -e version ]; then
echo "[version] not found, unable to proceed, abort."
exit 2
fi
fileCount=$(find . -name "Version.java" | wc -l)
if [ ! $fileCount -eq "1" ]; then
echo "more than one [Version.java], or file not found, unable to proceed, abort."
exit 2
fi
versionFilePath=$(find . -name "Version.java") # we now have the path to the file
oldThemePath=${versionFilePath%/Version.java} # trim the file name
oldThemeName=$(echo ${oldThemePath} | rev | cut -d / -f 1 | rev) # substring the theme name
themeWebAppInitFileCount=$(find ${oldThemePath} -name "*ThemeWebAppInit.java" | wc -l)
if [ ! $themeWebAppInitFileCount -eq "1" ]; then
echo "more than one [ThemeWebAppInit.java], or file not found, unable to proceed, abort."
exit 2
fi
themeWebAppInitFilePath=$(find ${oldThemePath} -name "*ThemeWebAppInit.java")
if [ ! -e src/archive/metainfo/zk/config.xml ]; then
echo "[config.xml] not found, unable to proceed, abort."
exit 2
fi
if [ ! -e src/archive/metainfo/zk/lang-addon.xml ]; then
echo "[lang-addon.xml] not found, unable to proceed, abort."
exit 2
fi
if [ ! -e readme.txt ]; then
echo "[readme.txt] not found, proceed anyway..."
fi
# all files found, start updating
echo -n "updating pom.xml..."
sed -i.zktmp "0,/<groupId>.*<\/groupId>/s//<groupId>${groupId}<\/groupId>/" pom.xml
echo -n "...."
sed -i.zktmp "0,/<artifactId>.*<\/artifactId>/s//<artifactId>${artifactId}<\/artifactId>/" pom.xml
echo -n "...."
sed -i.zktmp "0,/<version>.*<\/version>/s//<version>${version}<\/version>/" pom.xml
echo -n "...."
sed -i.zktmp "0,/<name>.*<\/name>/s//<name>${artifactId}<\/name>/" pom.xml
echo -n "...."
sed -i.zktmp "0,/<description>.*<\/description>/s//<description>${displayName}<\/description>/" pom.xml
echo -n "..."
echo -n "done."
echo ""
echo -n "updating version..."
sed -i.zktmp "2 s/.*/${version}/" version
echo -n "..................."
echo -n "done."
echo ""
echo -n "updating Version.java..."
sed -i.zktmp "0,/package org\.zkoss\.theme\..*;/s//package org\.zkoss\.theme\.${themeName};/" ${versionFilePath}
echo -n "......."
sed -i.zktmp "0,/public static final String UID = \".*\";/s//public static final String UID = \"${version}\";/" ${versionFilePath}
echo -n "......."
echo -n "done."
echo ""
echo -n "updating ThemeWebAppInit.java..."
sed -i.zktmp "0,/\/\* .*ThemeWebAppInit\.java/s//\/\* ${themeNameCap}ThemeWebAppInit\.java/" ${themeWebAppInitFilePath}
echo -n "."
sed -i.zktmp "0,/package org\.zkoss\.theme\..*;/s//package org\.zkoss\.theme\.${themeName};/" ${themeWebAppInitFilePath}
echo -n "."
sed -i.zktmp "0,/public class .*ThemeWebAppInit implements WebAppInit {/s//public class ${themeNameCap}ThemeWebAppInit implements WebAppInit {/" ${themeWebAppInitFilePath}
echo -n "."
sed -i.zktmp "0,/private final static String THEME_NAME = \".*\";/s//private final static String THEME_NAME = \"${themeName}\";/" ${themeWebAppInitFilePath}
echo -n "."
sed -i.zktmp "0,/private final static String THEME_DISPLAY = \".*\";/s//private final static String THEME_DISPLAY = \"${displayName}\";/" ${themeWebAppInitFilePath}
echo -n "."
mv ${themeWebAppInitFilePath} ${oldThemePath}/${themeNameCap}ThemeWebAppInit.java
echo -n "."
echo -n "done."
echo ""
echo -n "updating theme path..."
mv ${oldThemePath} ${oldThemePath/${oldThemeName}/${themeName}}
echo -n "................"
echo -n "done."
echo ""
echo -n "updating config.xml..."
configXmlFile=src/archive/metainfo/zk/config.xml
sed -i.zktmp "0,/<config-name>.*<\/config-name>/s//<config-name>${themeName}<\/config-name>/" ${configXmlFile}
echo -n "...."
sed -i.zktmp "0,/<version-class>org\.zkoss\.theme\..*\.Version<\/version-class>/s//<version-class>org\.zkoss\.theme\.${themeName}\.Version<\/version-class>/" ${configXmlFile}
echo -n "...."
sed -i.zktmp "0,/<version-uid>.*<\/version-uid>/s//<version-uid>${version}<\/version-uid>/" ${configXmlFile}
echo -n "...."
sed -i.zktmp "0,/<listener-class>org\.zkoss\.theme\..*\..*ThemeWebAppInit<\/listener-class>/s//<listener-class>org\.zkoss\.theme\.${themeName}\.${themeNameCap}ThemeWebAppInit<\/listener-class>/" ${configXmlFile}
echo -n "...."
echo -n "done."
echo ""
echo -n "updating lang-addon.xml..."
langAddonXmlFile=src/archive/metainfo/zk/lang-addon.xml
sed -i.zktmp "0,/<addon-name>.*<\/addon-name>/s//<addon-name>${themeName}<\/addon-name>/g" ${langAddonXmlFile}
echo -n "...."
sed -i.zktmp "0,/<version-class>org\.zkoss\.theme\..*\.Version<\/version-class>/s//<version-class>org\.zkoss\.theme\.${themeName}\.Version<\/version-class>/" ${langAddonXmlFile}
echo -n "...."
sed -i.zktmp "0,/<version-uid>.*<\/version-uid>/s//<version-uid>${version}<\/version-uid>/" ${langAddonXmlFile}
echo -n "...."
echo -n "done."
echo ""
echo -n "updating readme.txt..."
sed -i.zktmp "0,/How to use .*\.jar:/s//How to use ${themeName}\.jar:/" readme.txt
echo -n "...."
sed -i.zktmp "0,/Put .*\.jar in WEB-INF\/lib, then .* will become/s//Put ${themeName}\.jar in WEB-INF\/lib, then ${themeName} will become/" readme.txt
echo -n "...."
sed -i.zktmp "0,/<value>.*<\/value>/s//<value>${themeName}<\/value>/" readme.txt
echo -n "...."
sed -i.zktmp "0,/zktheme=.*/s//zktheme=${themeName}/" readme.txt
echo -n "...."
echo -n "done."
echo ""
echo -n "removing zktmp files..."
find . -name "*.zktmp" | xargs rm -f
echo -n "..............."
echo -n "done."
echo ""
echo "All done."
exit 1
if [ "$OS" = "Windows_NT" ]; then # to avoid tons of if/else with uname -s in Windows
OS_detected="Windows"
else
OS_detected=$(uname -s 2>/dev/null || echo not)
fi
case "$OS_detected" in
Darwin)
echo 'mac'
;;
Linux)
echo 'linux'
;;
Windows)
echo 'windows'
;;
*)
echo 'other OS'
;;
esac