-
Notifications
You must be signed in to change notification settings - Fork 14
/
release.pl
274 lines (243 loc) · 6.83 KB
/
release.pl
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
# Creates all files for a new release.
#
# (C) BaseX Team, BSD License
use warnings;
use strict;
use File::Basename;
use File::Copy;
use File::Path;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use File::Copy::Recursive qw(rcopy);
# path to main class
my $main = "org.basex.BaseXGUI";
# home of nsis
my $nsis = "win/nsis/makensis.exe /V1";
# original version, as found in pom.xml
my $version = "";
# full version with four numbers
my $full = "";
# prepare release
prepare();
# create zip file
zip();
# create installer
exe();
# create war file
war();
# create pad file
pad();
# finish release
finish();
# prepares a new release
sub prepare {
print "* Prepare release\n";
# delete old release files
rmtree("release");
mkdir "release/";
# extract pom version
version();
# create artifacts
artifacts();
copy("../basex/basex-core/target/basex-$version.jar", "release/BaseX.jar");
copy("../basex/basex-api/target/basex-api-$version.jar", "release/basex-api-$version.jar");
# prepare start scripts
mkdir "release/bin/";
for my $f(
glob("../basex/basex-core/etc/*"),
glob("../basex/basex-api/etc/*")
) {
next if -d $f;
(my $n = $f) =~ s|.*/||;
open(my $in, $f);
binmode $in;
open(my $out, ">release/bin/$n");
binmode $out;
while(my $l = <$in>) {
# replace "target/classes"
next if $l =~ m|^CORE=|;
$l =~ s|target[/\\]classes|BaseX.jar|;
$l =~ s|;%MAIN%[/\\]\.\.[/\\]basex-core[/\\]lib[/\\]\*||;
$l =~ s|:\$CORE[/\\]lib[/\\]\*||;
print $out $l;
}
close($in);
close($out);
}
# assemble webapp files
rcopy("../basex/basex-api/src/main/webapp/", "release/webapp/");
unlink("release/webapp/.gitignore");
rmtree("release/webapp/WEB-INF/data");
rmtree("release/webapp/WEB-INF/repo");
# write version file
print "* Write version file\n";
open(my $out, ">release/version.txt");
print $out $version;
close($out);
}
# create artifacts
sub artifacts {
print "* Create BaseX artifacts\n";
rmtree("../basex/basex-core/lib/");
rmtree("../basex/basex-api/lib/");
system('cd ../basex && mvn install -q -DskipTests');
}
# gets version from pom file
sub version {
open(POM, "../basex/pom.xml") or die "pom.xml not found";
while(my $l = <POM>) {
next if $l !~ m|<version>(.*)</version>|;
$version = $1;
$full = $version;
if(length($full) > 5) {
$full =~ s/-.*//;
$full .= ".0" while $full !~ /\..*\./;
$full .= ".".time();
} else {
$full .= ".0" while $full !~ /\..*\..*\./;
}
last;
}
close(POM);
print "* Version: $version ($full)\n";
}
# creates the zip archive
sub zip {
print "* Create ZIP file\n";
my $source = "release/";
my $target = "release/basex";
mkdir "$source/basex/";
rcopy("$source/BaseX.jar", "$target/BaseX.jar");
rcopy("../basex/LICENSE", $target);
rcopy("../basex/CHANGELOG", $target);
rcopy("readme.txt", $target);
rcopy(".basexhome", $target);
mkdir "$target/bin/";
rcopy("$source/bin/", "$target/bin/");
mkdir "$target/data/";
mkdir "$target/data/.logs/";
mkdir "$target/etc/";
rcopy("etc/", "$target/etc/");
mkdir "$target/lib/";
foreach my $file(
glob("../basex/basex-core/lib/*"),
glob("../basex/basex-api/lib/*"),
glob("lib/*")
) {
rcopy($file, "$target/lib") if $file !~ m|/lib/basex-$version|;
}
mkdir "$target/lib/custom/";
rcopy("$source/basex-api-$version.jar", "$target/lib/basex-api-$version.jar");
mkdir "$target/repo/";
rcopy("repo/", "$target/repo/");
mkdir "$target/src/";
rcopy("src/", "$target/src/");
mkdir "$target/webapp/";
rcopy("$source/webapp/", "$target/webapp/");
my $zip = Archive::Zip->new();
zip_rec($zip, $target, "basex");
# save the zip file
$zip->writeToFileNamed("release/BaseX.zip") == AZ_OK or
die "Could not write ZIP file.";
}
# recursively add zip files
sub zip_rec {
my $zip = shift;
my $source = shift;
my $target = shift;
# Parse files
foreach my $file(glob("$source/.* $source/*")) {
next if $file =~ /\.$/;
my $trg = "$target/".basename($file);
if(-d $file) {
$zip->addDirectory($trg);
zip_rec($zip, $file, $trg);
} else {
my $f = $zip->addFile($file, $trg);
$f->unixFileAttributes($file =~ /\./ ? 0644 : 0755);
}
}
};
# creates the war file
sub war {
print "* Create WAR file\n";
# create WAR file
system("cd ../basex/basex-api && mvn war:war");
move("../basex/basex-api/target/basex-api-$version.war", "release/basex.war");
}
# creates the installer
sub exe {
print "* Create EXE file\n";
# prepare installer
open(my $in, "win/BaseX.nsi");
open(my $out, ">win/tmp.nsi");
foreach my $line (<$in>) {
$line =~ s/0\.0\.0\.0/$full/;
print $out $line;
}
close($in);
close($out);
# create installer
system("$nsis win/tmp.nsi");
#sign();
move("win/Setup.exe", "release/BaseX.exe");
unlink("win/tmp.nsi");
}
# signs the installer
sub sign {
print "* Sign EXE file\n";
system("signtool sign /a /tr http://time.certum.pl/ /td SHA256 /fd SHA256 win/Setup.exe");
if ($? == -1) {
# failed to execute the command
print "Failed to execute: $!\n";
exit 1;
} elsif ($? & 127) {
# command died with signal
printf "Command died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
exit 1;
} elsif ($? >> 8) {
# command exited with non-zero status
printf "Command exited with errorlevel %d\n", $? >> 8;
exit 1;
}
}
# write PAD file
sub pad {
print "* Update PAD file\n";
my ($sec,$min,$hou,$day,$month,$year,$etc) = localtime();
$year += 1900;
$month++;
$month = "0$month" if length($month) == 1;
$day = "0$day" if length($day) == 1;
my $bytes = -s "release/BaseX.zip";
my $kb = int($bytes / 102.4) / 10;
my $mb = int($kb / 102.4) / 10;
open(my $in, "BaseXPADFile.xml");
open(my $out, ">release/BaseXPADFile.xml");
while(my $l = <$in>) {
$l =~ s/\$version/$version/;
$l =~ s/\$month/$month/;
$l =~ s/\$day/$day/;
$l =~ s/\$year/$year/;
$l =~ s/\$bytes/$bytes/;
$l =~ s/\$mb/$mb/;
$l =~ s/\$kb/$kb/;
print $out $l;
}
close($in);
close($out);
}
# finishes the release files
sub finish {
print "* Finish release\n";
(my $v = $version) =~ s/\.//g;
move("release/BaseX.app.zip", "release/BaseX$v.app.zip");
move("release/BaseX.zip", "release/BaseX$v.zip");
move("release/BaseX.jar", "release/BaseX$v.jar");
move("release/basex.war", "release/BaseX$v.war");
move("release/BaseX.exe", "release/BaseX$v.exe");
unlink("release/basex-api-$version.jar");
rmtree("release/basex");
rmtree("release/bin");
rmtree("release/webapp");
}