Debian Codegraph @

src/tools/org/h2/build/Build.java

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.build;
7
8 import java.io.File;
9 import java.io.IOException;
10 import java.lang.reflect.Method;
11 import java.net.InetAddress;
12 import java.net.InetSocketAddress;
13 import java.net.ServerSocket;
14 import java.net.Socket;
15 import java.net.URI;
16 import java.nio.charset.StandardCharsets;
17 import java.nio.file.FileSystem;
18 import java.nio.file.FileSystems;
19 import java.nio.file.Files;
20 import java.nio.file.Path;
21 import java.nio.file.Paths;
22 import java.nio.file.StandardCopyOption;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Map.Entry;
26 import java.util.TreeMap;
27 import java.util.concurrent.TimeUnit;
28
29 import org.h2.build.doc.XMLParser;
30
31 /**
32 * The build definition.
33 */
34 public class Build extends BuildBase {
35
36 private static final String ASM_VERSION = "9.4";
37
38 private static final String ARGS4J_VERSION = "2.33";
39
40 private static final String DERBY_VERSION = "10.14.2.0";
41
42 private static final String HSQLDB_VERSION = "2.5.1";
43
44 private static final String JACOCO_VERSION = "0.8.5";
45
46 private static final String JTS_VERSION = "1.17.0";
47
48 private static final String JUNIT_VERSION = "5.6.2";
49
50 private static final String LUCENE_VERSION = "8.5.2";
51
52 private static final String MYSQL_CONNECTOR_VERSION = "8.0.27";
53
54 private static final String OSGI_VERSION = "5.0.0";
55
56 private static final String OSGI_JDBC_VERSION = "1.1.0";
57
58 private static final String PGJDBC_VERSION = "42.4.0";
59
60 private static final String PGJDBC_HASH = "21ff952426bbfe4a041c175407333d4a07c70931";
61
62 private static final String JAVAX_SERVLET_VERSION = "4.0.1";
63
64 private static final String JAKARTA_SERVLET_VERSION = "5.0.0";
65
66 private static final String SLF4J_VERSION = "1.7.30";
67
68 private static final String APIGUARDIAN_VERSION = "1.1.0";
69
70 private static final String SQLITE_VERSION = "3.36.0.3";
71
72 private static final String NASHORN_VERSION = "15.4";
73
74 private boolean filesMissing;
75
76 /**
77 * Run the build.
78 *
79 * @param args the command line arguments
80 */
81 public static void main(String... args) {
82 new Build().run(args);
83 }
84
85 /**
86 * Run the benchmarks.
87 */
88 @Description(summary = "Run the benchmarks.")
89 public void benchmark() {
90 downloadUsingMaven("ext/hsqldb-" + HSQLDB_VERSION + ".jar",
91 "org.hsqldb", "hsqldb", HSQLDB_VERSION,
92 "b1f720a63a8756867895cc22dd74b51fb70e90ac");
93 downloadUsingMaven("ext/derby-" + DERBY_VERSION + ".jar",
94 "org.apache.derby", "derby", DERBY_VERSION,
95 "7efad40ef52fbb1f08142f07a83b42d29e47d8ce");
96 downloadUsingMaven("ext/derbyclient-" + DERBY_VERSION + ".jar",
97 "org.apache.derby", "derbyclient", DERBY_VERSION,
98 "fdd338d43e09bf7cd16f5523a0f717e5ef79a1a8");
99 downloadUsingMaven("ext/derbynet-" + DERBY_VERSION + ".jar",
100 "org.apache.derby", "derbynet", DERBY_VERSION,
101 "d03edf879317c7102884c4689e03a4d1a5f84126");
102 // downloadUsingMaven("ext/derbyshared-" + DERBY_VERSION + ".jar",
103 // "org.apache.derby", "derbyshared", DERBY_VERSION,
104 // "ff2dfb3e2a92d593cf111baad242d156947abbc1");
105 downloadUsingMaven("ext/postgresql-" + PGJDBC_VERSION + ".jar",
106 "org.postgresql", "postgresql", PGJDBC_VERSION, PGJDBC_HASH);
107 downloadUsingMaven("ext/mysql-connector-java-" + MYSQL_CONNECTOR_VERSION + ".jar",
108 "mysql", "mysql-connector-java", MYSQL_CONNECTOR_VERSION,
109 "f1da9f10a3de6348725a413304aab6d0aa04f923");
110 downloadUsingMaven("ext/sqlite-" + SQLITE_VERSION + ".jar",
111 "org.xerial", "sqlite-jdbc", SQLITE_VERSION, "7fa71c4dfab806490cb909714fb41373ec552c29");
112 compile();
113
114 String cp = "temp" +
115 File.pathSeparator + "bin/h2" + getJarSuffix() +
116 File.pathSeparator + "ext/hsqldb-" + HSQLDB_VERSION + ".jar" +
117 File.pathSeparator + "ext/derby-" + DERBY_VERSION + ".jar" +
118 File.pathSeparator + "ext/derbyclient-" + DERBY_VERSION + ".jar" +
119 File.pathSeparator + "ext/derbynet-" + DERBY_VERSION + ".jar" +
120 // File.pathSeparator + "ext/derbyshared-" + DERBY_VERSION + ".jar" +
121 File.pathSeparator + "ext/postgresql-" + PGJDBC_VERSION + ".jar" +
122 File.pathSeparator + "ext/mysql-connector-java-" + MYSQL_CONNECTOR_VERSION + ".jar" +
123 File.pathSeparator + "ext/sqlite-" + SQLITE_VERSION + ".jar";
124 StringList args = args("-Xmx128m",
125 "-cp", cp, "-Dderby.system.durability=test", "org.h2.test.bench.TestPerformance");
126 execJava(args.plus("-init", "-db", "1"));
127 execJava(args.plus("-db", "2"));
128 execJava(args.plus("-db", "3", "-out", "pe.html"));
129 execJava(args.plus("-init", "-db", "4"));
130 execJava(args.plus("-db", "5", "-exit"));
131 execJava(args.plus("-db", "6"));
132 execJava(args.plus("-db", "7"));
133 execJava(args.plus("-db", "8", "-out", "ps.html"));
134 // Disable SQLite because it doesn't work with multi-threaded benchmark, BenchB
135 // execJava(args.plus("-db", "9"));
136 }
137
138 /**
139 * Clean all jar files, classes, and generated documentation.
140 */
141 @Description(summary = "Clean all jar files, classes, and generated documentation.")
142 public void clean() {
143 delete("temp");
144 delete("docs");
145 mkdir("docs");
146 mkdir("bin");
147 delete(files(".").keep("*/Thumbs.db"));
148 }
149
150 /**
151 * Compile all classes.
152 */
153 @Description(summary = "Compile all classes.")
154 public void compile() {
155 clean();
156 mkdir("temp");
157 download();
158 String classpath = "temp" +
159 File.pathSeparator + "ext/javax.servlet-api-" + JAVAX_SERVLET_VERSION + ".jar" +
160 File.pathSeparator + "ext/jakarta.servlet-api-" + JAKARTA_SERVLET_VERSION + ".jar" +
161 File.pathSeparator + "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
162 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
163 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
164 File.pathSeparator + "ext/slf4j-api-" + SLF4J_VERSION + ".jar" +
165 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
166 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
167 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar" +
168 File.pathSeparator + "ext/asm-" + ASM_VERSION + ".jar" +
169 File.pathSeparator + javaToolsJar;
170 FileList files = files("src/main");
171 StringList args = args("-Xlint:unchecked", "-d", "temp", "-sourcepath", "src/main", "-classpath", classpath);
172 String version = getTargetJavaVersion();
173 if (version != null) {
174 args = args.plus("-target", version, "-source", version);
175 }
176 javac(args, files);
177
178 files = files("src/main/META-INF/native-image");
179 files.addAll(files("src/main/META-INF/services"));
180 copy("temp", files, "src/main");
181
182 files = files("src/test");
183 files.addAll(files("src/tools"));
184 // we don't use Junit for this test framework
185 files = files.exclude("src/test/org/h2/test/TestAllJunit.java");
186 args = args("-Xlint:unchecked", "-Xlint:deprecation",
187 "-d", "temp", "-sourcepath", "src/test" + File.pathSeparator + "src/tools",
188 "-classpath", classpath);
189 if (version != null) {
190 args = args.plus("-target", version, "-source", version);
191 }
192 javac(args, files);
193
194 files = files("src/test").
195 exclude("*.java").
196 exclude("*/package.html");
197 copy("temp", files, "src/test");
198
199 javadoc("-sourcepath", "src/main",
200 "-d", "docs/javadoc",
201 "org.h2.tools", "org.h2.jmx",
202 "-classpath",
203 "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
204 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
205 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
206 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
207 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
208 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar");
209
210 files = files("src/main").
211 exclude("*.MF").
212 exclude("*.java").
213 exclude("*/package.html").
214 exclude("*/java.sql.Driver").
215 exclude("*.DS_Store");
216 zip("temp/org/h2/util/data.zip", files, "src/main", true, false);
217 }
218
219 private void compileTools() {
220 mkdir("temp");
221 FileList files = files("src/tools").keep("src/tools/org/h2/build/*");
222 StringList args = args("-d", "temp", "-sourcepath", "src/tools" +
223 File.pathSeparator + "src/test" +
224 File.pathSeparator + "src/main");
225 String version = getTargetJavaVersion();
226 if (version != null) {
227 args = args.plus("-target", version, "-source", version);
228 }
229 javac(args, files);
230 }
231
232 /**
233 * Run the JaCoco code coverage.
234 */
235 @Description(summary = "Run the JaCoco code coverage.")
236 public void coverage() {
237 compile();
238 downloadTest();
239 downloadUsingMaven("ext/org.jacoco.agent-" + JACOCO_VERSION + ".jar",
240 "org.jacoco", "org.jacoco.agent", JACOCO_VERSION,
241 "0fd03a8ab78af3dd03b27647067efa72690d4922");
242 URI uri = URI.create("jar:"
243 + Paths.get("ext/org.jacoco.agent-" + JACOCO_VERSION + ".jar").toAbsolutePath().toUri());
244 try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
245 Files.copy(fs.getPath("jacocoagent.jar"), Paths.get("ext/jacocoagent.jar"),
246 StandardCopyOption.REPLACE_EXISTING);
247 } catch (IOException ex) {
248 throw new RuntimeException(ex);
249 }
250 downloadUsingMaven("ext/org.jacoco.cli-" + JACOCO_VERSION + ".jar",
251 "org.jacoco", "org.jacoco.cli", JACOCO_VERSION,
252 "30155fcd37821879264365693055290dbfe984bb");
253 downloadUsingMaven("ext/org.jacoco.core-" + JACOCO_VERSION + ".jar",
254 "org.jacoco", "org.jacoco.core", JACOCO_VERSION,
255 "1ac96769aa83e5492d1a1a694774f6baec4eb704");
256 downloadUsingMaven("ext/org.jacoco.report-" + JACOCO_VERSION + ".jar",
257 "org.jacoco", "org.jacoco.report", JACOCO_VERSION,
258 "421e4aab2aaa809d1e66a96feb11f61ea698da19");
259 downloadUsingMaven("ext/args4j-" + ARGS4J_VERSION + ".jar",
260 "args4j", "args4j", ARGS4J_VERSION,
261 "bd87a75374a6d6523de82fef51fc3cfe9baf9fc9");
262
263 delete(files("coverage"));
264 // Use own copy
265 copy("coverage/bin", files("temp"), "temp");
266 // JaCoCo does not support multiple versions of the same classes
267 delete(files("coverage/bin/META-INF/versions"));
268 String cp = "coverage/bin" +
269 File.pathSeparator + "ext/postgresql-" + PGJDBC_VERSION + ".jar" +
270 File.pathSeparator + "ext/javax.servlet-api-" + JAVAX_SERVLET_VERSION + ".jar" +
271 File.pathSeparator + "ext/jakarta.servlet-api-" + JAKARTA_SERVLET_VERSION + ".jar" +
272 File.pathSeparator + "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
273 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
274 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
275 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
276 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
277 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar" +
278 File.pathSeparator + "ext/slf4j-api-" + SLF4J_VERSION + ".jar" +
279 File.pathSeparator + "ext/slf4j-nop-" + SLF4J_VERSION + ".jar" +
280 File.pathSeparator + javaToolsJar;
281 cp = addNashornJavaScriptEngineIfNecessary(cp);
282 // Run tests
283 execJava(args(
284 "-Xmx128m",
285 "-javaagent:ext/jacocoagent.jar=destfile=coverage/jacoco.exec,"
286 + "excludes=org.h2.test.*:org.h2.tools.*:org.h2.sample.*",
287 "-cp", cp,
288 "org.h2.test.TestAll", "codeCoverage"));
289 // Remove classes that we don't want to include in report
290 delete(files("coverage/bin/org/h2/test"));
291 delete(files("coverage/bin/org/h2/tools"));
292 delete(files("coverage/bin/org/h2/sample"));
293 // Generate report
294 execJava(args("-cp",
295 "ext/org.jacoco.cli-" + JACOCO_VERSION + ".jar" + File.pathSeparator
296 + "ext/org.jacoco.core-" + JACOCO_VERSION + ".jar" + File.pathSeparator
297 + "ext/org.jacoco.report-" + JACOCO_VERSION + ".jar" + File.pathSeparator
298 + "ext/asm-" + ASM_VERSION + ".jar" + File.pathSeparator
299 + "ext/asm-commons-" + ASM_VERSION + ".jar" + File.pathSeparator
300 + "ext/asm-tree-" + ASM_VERSION + ".jar" + File.pathSeparator
301 + "ext/args4j-" + ARGS4J_VERSION + ".jar",
302 "org.jacoco.cli.internal.Main", "report", "coverage/jacoco.exec",
303 "--classfiles", "coverage/bin",
304 "--html", "coverage/report", "--sourcefiles", "h2/src/main"));
305 try {
306 tryOpenCoverageInBrowser();
307 } catch (Throwable e) {
308 e.printStackTrace();
309 }
310 }
311
312 private static void tryOpenCoverageInBrowser() throws Exception {
313 Class<?> desktop = Class.forName("java.awt.Desktop");
314 Method m = desktop.getMethod("getDesktop");
315 Object d = m.invoke(null);
316 m = d.getClass().getMethod("open", File.class);
317 m.invoke(d, new File("coverage/report/index.html"));
318 }
319
320 private static String getTargetJavaVersion() {
321 return System.getProperty("version");
322 }
323
324 private void compileMVStore(boolean debugInfo) {
325 clean();
326 mkdir("temp");
327 String classpath = "temp" +
328 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar";
329 FileList files = files("src/main/org/h2/mvstore").
330 exclude("src/main/org/h2/mvstore/db/*");
331 StringList args = args();
332 if (debugInfo) {
333 args = args.plus("-Xlint:unchecked", "-d", "temp", "-sourcepath",
334 "src/main", "-classpath", classpath);
335 } else {
336 args = args.plus("-Xlint:unchecked", "-g:none", "-d", "temp",
337 "-sourcepath", "src/main", "-classpath", classpath);
338 }
339 String version = getTargetJavaVersion();
340 if (version != null) {
341 args = args.plus("-target", version, "-source", version);
342 }
343 javac(args, files);
344 }
345
346 private static void filter(String source, String target, String old,
347 String replacement) {
348 String text = new String(readFile(Paths.get(source)));
349 text = replaceAll(text, old, replacement);
350 writeFile(Paths.get(target), text.getBytes());
351 }
352
353 /**
354 * Create the documentation from the documentation sources. API Javadocs are
355 * created as well.
356 */
357 @Description(summary = "Create the documentation from sources (incl. API Javadocs).")
358 public void docs() {
359 javadoc();
360 copy("docs", files("src/docsrc/index.html"), "src/docsrc");
361 java("org.h2.build.doc.XMLChecker", null);
362 java("org.h2.build.code.CheckJavadoc", null);
363 java("org.h2.build.code.CheckTextFiles", null);
364 java("org.h2.build.doc.GenerateDoc", null);
365 java("org.h2.build.indexer.Indexer", null);
366 java("org.h2.build.doc.MergeDocs", null);
367 java("org.h2.build.doc.WebSite", null);
368 java("org.h2.build.doc.LinkChecker", null);
369 java("org.h2.build.doc.XMLChecker", null);
370 java("org.h2.build.doc.SpellChecker", null);
371 java("org.h2.build.code.CheckTextFiles", null);
372 beep();
373 }
374
375 /**
376 * Download all required jar files. Actually those are only compile time
377 * dependencies. The database can be used without any dependencies.
378 */
379 @Description(summary = "Download all required jar files.")
380 public void download() {
381 downloadOrVerify(false);
382 }
383
384 private void downloadOrVerify(boolean offline) {
385 downloadOrVerify("ext/javax.servlet-api-" + JAVAX_SERVLET_VERSION + ".jar",
386 "javax/servlet", "javax.servlet-api", JAVAX_SERVLET_VERSION,
387 "a27082684a2ff0bf397666c3943496c44541d1ca", offline);
388 downloadOrVerify("ext/jakarta.servlet-api-" + JAKARTA_SERVLET_VERSION + ".jar",
389 "jakarta/servlet", "jakarta.servlet-api", JAKARTA_SERVLET_VERSION,
390 "2e6b8ccde55522c879434ddec3714683ccae6867", offline);
391 downloadOrVerify("ext/lucene-core-" + LUCENE_VERSION + ".jar",
392 "org/apache/lucene", "lucene-core", LUCENE_VERSION,
393 "b275ca5f39b6dd45d5a7ecb49da65205ad2732ca", offline);
394 downloadOrVerify("ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar",
395 "org/apache/lucene", "lucene-analyzers-common", LUCENE_VERSION,
396 "2c4a7e8583e2061aa35db85705393b8b6e67a679", offline);
397 downloadOrVerify("ext/lucene-queryparser-" + LUCENE_VERSION + ".jar",
398 "org/apache/lucene", "lucene-queryparser", LUCENE_VERSION,
399 "96a104be314d0adaac163635610da8dfc5e4166e", offline);
400 downloadOrVerify("ext/slf4j-api-" + SLF4J_VERSION + ".jar",
401 "org/slf4j", "slf4j-api", SLF4J_VERSION,
402 "b5a4b6d16ab13e34a88fae84c35cd5d68cac922c", offline);
403 downloadOrVerify("ext/org.osgi.core-" + OSGI_VERSION + ".jar",
404 "org/osgi", "org.osgi.core", OSGI_VERSION,
405 "6e5e8cd3c9059c08e1085540442a490b59a7783c", offline);
406 downloadOrVerify("ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar",
407 "org/osgi", "org.osgi.service.jdbc", OSGI_JDBC_VERSION,
408 "07673601d60c98d876b82530ff4363ed9e428c1e", offline);
409 downloadOrVerify("ext/jts-core-" + JTS_VERSION + ".jar",
410 "org/locationtech/jts", "jts-core", JTS_VERSION,
411 "7e1973b5babdd98734b1ab903fc1155714402eec", offline);
412 downloadOrVerify("ext/junit-jupiter-api-" + JUNIT_VERSION + ".jar",
413 "org.junit.jupiter", "junit-jupiter-api", JUNIT_VERSION,
414 "c9ba885abfe975cda123bf6f8f0a69a1b46956d0", offline);
415 downloadUsingMaven("ext/asm-" + ASM_VERSION + ".jar",
416 "org.ow2.asm", "asm", ASM_VERSION,
417 "b4e0e2d2e023aa317b7cfcfc916377ea348e07d1");
418 downloadUsingMaven("ext/apiguardian-" + APIGUARDIAN_VERSION + ".jar",
419 "org.apiguardian", "apiguardian-api", APIGUARDIAN_VERSION,
420 "fc9dff4bb36d627bdc553de77e1f17efd790876c");
421 }
422
423 private void downloadOrVerify(String target, String group, String artifact,
424 String version, String sha1Checksum, boolean offline) {
425 if (offline) {
426 Path targetFile = Paths.get(target);
427 if (Files.exists(targetFile)) {
428 return;
429 }
430 println("Missing file: " + target);
431 filesMissing = true;
432 } else {
433 downloadUsingMaven(target, group, artifact, version, sha1Checksum);
434 }
435 }
436
437 private void downloadTest() {
438 // for TestOldVersion
439 downloadUsingMaven("ext/h2-1.2.127.jar",
440 "com/h2database", "h2", "1.2.127",
441 "056e784c7cf009483366ab9cd8d21d02fe47031a");
442 // for TestPgServer
443 downloadUsingMaven("ext/postgresql-" + PGJDBC_VERSION + ".jar",
444 "org.postgresql", "postgresql", PGJDBC_VERSION, PGJDBC_HASH);
445 // for TestTraceSystem
446 downloadUsingMaven("ext/slf4j-nop-" + SLF4J_VERSION + ".jar",
447 "org/slf4j", "slf4j-nop", SLF4J_VERSION,
448 "55d4c73dd343efebd236abfeb367c9ef41d55063");
449 // for TestTriggersConstraints
450 if (requiresNashornJavaScriptEngine()) {
451 downloadUsingMaven("ext/nashorn-core-" + NASHORN_VERSION + ".jar",
452 "org/openjdk/nashorn", "nashorn-core", NASHORN_VERSION,
453 "f67f5ffaa5f5130cf6fb9b133da00c7df3b532a5");
454 downloadUsingMaven("ext/asm-util-" + ASM_VERSION + ".jar",
455 "org.ow2.asm", "asm-util", ASM_VERSION,
456 "ab1e0a84b72561dbaf1ee260321e72148ebf4b19");
457 }
458 downloadUsingMaven("ext/asm-commons-" + ASM_VERSION + ".jar",
459 "org.ow2.asm", "asm-commons", ASM_VERSION,
460 "8fc2810ddbcbbec0a8bbccb3f8eda58321839912");
461 downloadUsingMaven("ext/asm-tree-" + ASM_VERSION + ".jar",
462 "org.ow2.asm", "asm-tree", ASM_VERSION,
463 "a99175a17d7fdc18cbcbd0e8ea6a5d276844190a");
464 }
465
466 private static String getVersion() {
467 return getStaticField("org.h2.engine.Constants", "VERSION");
468 }
469
470 private static String getJarSuffix() {
471 return "-" + getVersion() + ".jar";
472 }
473
474 /**
475 * Create the h2.zip file and the Windows installer.
476 */
477 @Description(summary = "Create the h2.zip file and the Windows installer.")
478 public void installer() {
479 delete(files("bin").keep("*.jar"));
480 jar();
481 docs();
482 try {
483 exec("soffice", args("--invisible", "macro:///Standard.Module1.H2Pdf"));
484 copy("docs", files("../h2web/h2.pdf"), "../h2web");
485 } catch (Exception e) {
486 println("OpenOffice / LibreOffice is not available or macros H2Pdf is not installed:");
487 println(e.toString());
488 println("********************************************************************************");
489 println("Install and run LibreOffice or OpenOffice.");
490 println("Open Tools - Macros - Organize Macros - LibreOffice Basic...");
491 println("Navigate to My Macros / Standard / Module1 and press Edit button.");
492 println("Put content of h2/src/installer/openoffice.txt here.");
493 println("Edit BaseDir variable value:");
494
495 println(" BaseDir = \"" + Paths.get(System.getProperty("user.dir")).getParent().toUri() + '"');
496 println("Close office application and try to build installer again.");
497 println("********************************************************************************");
498 }
499 delete("docs/html/onePage.html");
500 FileList files = files("../h2").keep("../h2/build.*");
501 files.addAll(files("../h2/bin").keep("../h2/bin/h2*"));
502 files.addAll(files("../h2/docs").exclude("*.jar"));
503 files.addAll(files("../h2/service"));
504 files.addAll(files("../h2/src"));
505 zip("../h2web/h2.zip", files, "../", false, false);
506 boolean installer = false;
507 try {
508 exec("makensis", args(isWindows() ? "/V2" : "-V2", "src/installer/h2.nsi"));
509 installer = true;
510 } catch (Exception e) {
511 println("NSIS is not available: " + e);
512 }
513 String buildDate = getStaticField("org.h2.engine.Constants", "BUILD_DATE");
514 byte[] data = readFile(Paths.get("../h2web/h2.zip"));
515 String sha1Zip = getSHA1(data), sha1Exe = null;
516 writeFile(Paths.get("../h2web/h2-" + buildDate + ".zip"), data);
517 if (installer) {
518 data = readFile(Paths.get("../h2web/h2-setup.exe"));
519 sha1Exe = getSHA1(data);
520 writeFile(Paths.get("../h2web/h2-setup-" + buildDate + ".exe"), data);
521 }
522 updateChecksum("../h2web/html/download.html", sha1Zip, sha1Exe);
523 }
524
525 private static void updateChecksum(String fileName, String sha1Zip, String sha1Exe) {
526 Path file = Paths.get(fileName);
527 String checksums = new String(readFile(file));
528 checksums = replaceAll(checksums, "<!-- sha1Zip -->",
529 "(SHA1 checksum: " + sha1Zip + ")");
530 if (sha1Exe != null) {
531 checksums = replaceAll(checksums, "<!-- sha1Exe -->",
532 "(SHA1 checksum: " + sha1Exe + ")");
533 }
534 writeFile(file, checksums.getBytes());
535 }
536
537 private static String canonicalPath(Path file) {
538 try {
539 return file.toRealPath().toString();
540 } catch (IOException e) {
541 throw new RuntimeException(e);
542 }
543 }
544
545 private FileList excludeTestMetaInfFiles(FileList files) {
546 FileList testMetaInfFiles = files("src/test/META-INF");
547 int basePathLength = canonicalPath(Paths.get("src/test")).length();
548 for (Path file : testMetaInfFiles) {
549 files = files.exclude(canonicalPath(file).substring(basePathLength + 1));
550 }
551 return files;
552 }
553
554 /**
555 * Add META-INF/versions for Java 9+.
556 */
557 private void addVersions() {
558 copy("temp/META-INF/versions/9", files("src/java9/precompiled"), "src/java9/precompiled");
559 copy("temp/META-INF/versions/10", files("src/java10/precompiled"), "src/java10/precompiled");
560 }
561
562 /**
563 * Create the regular h2.jar file.
564 */
565 @Description(summary = "Create the regular h2.jar file.")
566 public void jar() {
567 compile();
568 addVersions();
569 manifest("src/main/META-INF/MANIFEST.MF");
570 FileList files = files("temp").
571 exclude("temp/org/h2/build/*").
572 exclude("temp/org/h2/dev/*").
573 exclude("temp/org/h2/jcr/*").
574 exclude("temp/org/h2/java/*").
575 exclude("temp/org/h2/jcr/*").
576 exclude("temp/org/h2/samples/*").
577 exclude("temp/org/h2/server/ftp/*").
578 exclude("temp/org/h2/test/*").
579 exclude("*.bat").
580 exclude("*.sh").
581 exclude("*.txt").
582 exclude("*.DS_Store");
583 files = excludeTestMetaInfFiles(files);
584 jar("bin/h2" + getJarSuffix(), files, "temp");
585 filter("src/installer/h2.sh", "bin/h2.sh", "h2.jar", "h2" + getJarSuffix());
586 filter("src/installer/h2.bat", "bin/h2.bat", "h2.jar", "h2" + getJarSuffix());
587 filter("src/installer/h2w.bat", "bin/h2w.bat", "h2.jar", "h2" + getJarSuffix());
588 }
589
590 /**
591 * Create the file h2mvstore.jar. This only contains the MVStore.
592 */
593 @Description(summary = "Create h2mvstore.jar containing only the MVStore.")
594 public void jarMVStore() {
595 compileMVStore(true);
596 addVersions();
597 manifest("src/installer/mvstore/MANIFEST.MF");
598 FileList files = files("temp");
599 files.exclude("*.DS_Store");
600 files = excludeTestMetaInfFiles(files);
601 jar("bin/h2-mvstore" + getJarSuffix(), files, "temp");
602 }
603
604 /**
605 * Create the Javadocs of the API (incl. the JDBC API) and tools.
606 */
607 @Description(summary = "Create the API Javadocs (incl. JDBC API and tools).")
608 public void javadoc() {
609 compileTools();
610 delete("docs");
611 mkdir("docs/javadoc");
612 javadoc("-sourcepath", "src/main",
613 "-d", "docs/javadoc",
614 "org.h2.jdbc", "org.h2.jdbcx",
615 "org.h2.tools", "org.h2.api", "org.h2.engine", "org.h2.fulltext",
616 "-classpath",
617 "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
618 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
619 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
620 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
621 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
622 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar");
623 }
624
625 /**
626 * Create the Javadocs of the implementation.
627 */
628 @Description(summary = "Create the Javadocs of the implementation.")
629 public void javadocImpl() {
630 compileTools();
631 mkdir("docs/javadocImpl2");
632 javadoc("-sourcepath", "src/main" +
633 // need to be disabled if not enough memory
634 File.pathSeparator + "src/test" +
635 File.pathSeparator + "src/tools",
636 "-noindex",
637 "-d", "docs/javadocImpl2",
638 "-classpath", javaToolsJar +
639 File.pathSeparator + "ext/slf4j-api-" + SLF4J_VERSION + ".jar" +
640 File.pathSeparator + "ext/javax.servlet-api-" + JAVAX_SERVLET_VERSION + ".jar" +
641 File.pathSeparator + "ext/jakarta.servlet-api-" + JAKARTA_SERVLET_VERSION + ".jar" +
642 File.pathSeparator + "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
643 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
644 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
645 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
646 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
647 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar" +
648 File.pathSeparator + "ext/asm-" + ASM_VERSION + ".jar" +
649 File.pathSeparator + "ext/junit-jupiter-api-" + JUNIT_VERSION + ".jar" +
650 File.pathSeparator + "ext/apiguardian-api-" + APIGUARDIAN_VERSION + ".jar",
651 "-subpackages", "org.h2",
652 "-exclude", "org.h2.dev:org.h2.java:org.h2.test:org.h2.build.code:org.h2.build.doc");
653
654 mkdir("docs/javadocImpl3");
655 javadoc("-sourcepath", "src/main",
656 "-noindex",
657 "-d", "docs/javadocImpl3",
658 "-classpath", javaToolsJar +
659 File.pathSeparator + "ext/slf4j-api-" + SLF4J_VERSION + ".jar" +
660 File.pathSeparator + "ext/javax.servlet-api-" + JAVAX_SERVLET_VERSION + ".jar" +
661 File.pathSeparator + "ext/jakarta.servlet-api-" + JAKARTA_SERVLET_VERSION + ".jar" +
662 File.pathSeparator + "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
663 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
664 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
665 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
666 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
667 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar",
668 "-subpackages", "org.h2.mvstore",
669 "-exclude", "org.h2.mvstore.db");
670
671 System.setProperty("h2.interfacesOnly", "false");
672 System.setProperty("h2.javadocDestDir", "docs/javadocImpl");
673 javadoc("-sourcepath", "src/main" +
674 File.pathSeparator + "src/test" +
675 File.pathSeparator + "src/tools",
676 "-Xdoclint:all,-missing",
677 "-d", "docs/javadoc",
678 "-classpath", javaToolsJar +
679 File.pathSeparator + "ext/slf4j-api-" + SLF4J_VERSION + ".jar" +
680 File.pathSeparator + "ext/javax.servlet-api-" + JAVAX_SERVLET_VERSION + ".jar" +
681 File.pathSeparator + "ext/jakarta.servlet-api-" + JAKARTA_SERVLET_VERSION + ".jar" +
682 File.pathSeparator + "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
683 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
684 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
685 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
686 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
687 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar" +
688 File.pathSeparator + "ext/asm-" + ASM_VERSION + ".jar" +
689 File.pathSeparator + "ext/junit-jupiter-api-" + JUNIT_VERSION + ".jar" +
690 File.pathSeparator + "ext/apiguardian-api-" + APIGUARDIAN_VERSION + ".jar",
691 "-subpackages", "org.h2",
692 "-package");
693 }
694
695 private static void manifest(String path) {
696 String manifest = new String(readFile(Paths.get(path)), StandardCharsets.UTF_8);
697 manifest = replaceAll(manifest, "${version}", getVersion());
698 manifest = replaceAll(manifest, "${buildJdk}", getJavaSpecVersion());
699 String createdBy = System.getProperty("java.runtime.version") +
700 " (" + System.getProperty("java.vm.vendor") + ")";
701 manifest = replaceAll(manifest, "${createdBy}", createdBy);
702 mkdir("temp/META-INF");
703 writeFile(Paths.get("temp/META-INF/MANIFEST.MF"), manifest.getBytes());
704 }
705
706 /**
707 * This will build a release of the H2 .jar files and upload it to
708 * file:///data/h2database/m2-repo. This is only required when
709 * a new H2 version is made.
710 */
711 @Description(summary = "Build H2 release jars and upload to file:///data/h2database/m2-repo.")
712 public void mavenDeployCentral() {
713 // generate and deploy h2*-sources.jar file
714 FileList files = files("src/main");
715 copy("docs", files, "src/main");
716 files = files("docs").keep("docs/org/*").keep("*.java");
717 files.addAll(files("docs").keep("docs/META-INF/*"));
718 String manifest = new String(readFile(Paths.get("src/installer/source-manifest.mf")));
719 manifest = replaceAll(manifest, "${version}", getVersion());
720 writeFile(Paths.get("docs/META-INF/MANIFEST.MF"), manifest.getBytes());
721 jar("docs/h2-" + getVersion() + "-sources.jar", files, "docs");
722 delete("docs/org");
723 delete("docs/META-INF");
724 // the option -DgeneratePom=false doesn't work with some versions of
725 // Maven because of bug http://jira.codehaus.org/browse/MDEPLOY-84
726 // as a workaround we generate the pom, but overwrite it later on
727 // (that's why the regular jar is created at the very end)
728 execScript("mvn", args(
729 "deploy:deploy-file",
730 "-Dfile=docs/h2-" + getVersion() + "-sources.jar",
731 "-Durl=file:///data/h2database/m2-repo",
732 "-Dpackaging=jar",
733 "-Dclassifier=sources",
734 "-Dversion=" + getVersion(),
735 "-DartifactId=h2",
736 "-DgroupId=com.h2database"
737 // ,"-DgeneratePom=false"
738 ));
739
740 // generate and deploy the h2*-javadoc.jar file
741 javadocImpl();
742 files = files("docs/javadocImpl2");
743 jar("docs/h2-" + getVersion() + "-javadoc.jar", files, "docs/javadocImpl2");
744 execScript("mvn", args(
745 "deploy:deploy-file",
746 "-Dfile=docs/h2-" + getVersion() + "-javadoc.jar",
747 "-Durl=file:///data/h2database/m2-repo",
748 "-Dpackaging=jar",
749 "-Dclassifier=javadoc",
750 "-Dversion=" + getVersion(),
751 "-DartifactId=h2",
752 "-DgroupId=com.h2database"
753 // ,"-DgeneratePom=false"
754 ));
755
756 // generate and deploy the h2*.jar file
757 jar();
758 String pom = new String(readFile(Paths.get("src/installer/pom-template.xml")));
759 pom = replaceAll(pom, "@version@", getVersion());
760 writeFile(Paths.get("bin/pom.xml"), pom.getBytes());
761 execScript("mvn", args(
762 "deploy:deploy-file",
763 "-Dfile=bin/h2" + getJarSuffix(),
764 "-Durl=file:///data/h2database/m2-repo",
765 "-Dpackaging=jar",
766 "-Dversion=" + getVersion(),
767 "-DpomFile=bin/pom.xml",
768 "-DartifactId=h2",
769 "-DgroupId=com.h2database"));
770
771 // generate the h2-mvstore-*-sources.jar file
772 files = files("src/main");
773 copy("docs", files, "src/main");
774 files = files("docs").keep("docs/org/h2/mvstore/*").
775 exclude("docs/org/h2/mvstore/db/*").
776 keep("*.java");
777 files.addAll(files("docs").keep("docs/META-INF/*"));
778 manifest = new String(readFile(Paths.get("src/installer/source-mvstore-manifest.mf")));
779 manifest = replaceAll(manifest, "${version}", getVersion());
780 writeFile(Paths.get("docs/META-INF/MANIFEST.MF"), manifest.getBytes());
781 jar("docs/h2-mvstore-" + getVersion() + "-sources.jar", files, "docs");
782 delete("docs/org");
783 delete("docs/META-INF");
784
785 // deploy the h2-mvstore-*-source.jar file
786 execScript("mvn", args(
787 "deploy:deploy-file",
788 "-Dfile=docs/h2-mvstore-" + getVersion() + "-sources.jar",
789 "-Durl=file:///data/h2database/m2-repo",
790 "-Dpackaging=jar",
791 "-Dclassifier=sources",
792 "-Dversion=" + getVersion(),
793 "-DartifactId=h2-mvstore",
794 "-DgroupId=com.h2database"
795 // ,"-DgeneratePom=false"
796 ));
797
798 // generate and deploy the h2-mvstore-*-javadoc.jar file
799 javadocImpl();
800 files = files("docs/javadocImpl3");
801 jar("docs/h2-mvstore-" + getVersion() + "-javadoc.jar", files, "docs/javadocImpl3");
802 execScript("mvn", args(
803 "deploy:deploy-file",
804 "-Dfile=docs/h2-mvstore-" + getVersion() + "-javadoc.jar",
805 "-Durl=file:///data/h2database/m2-repo",
806 "-Dpackaging=jar",
807 "-Dclassifier=javadoc",
808 "-Dversion=" + getVersion(),
809 "-DartifactId=h2-mvstore",
810 "-DgroupId=com.h2database"
811 // ,"-DgeneratePom=false"
812 ));
813
814 // generate and deploy the h2-mvstore-*.jar file
815 jarMVStore();
816 pom = new String(readFile(Paths.get("src/installer/pom-mvstore-template.xml")));
817 pom = replaceAll(pom, "@version@", getVersion());
818 writeFile(Paths.get("bin/pom.xml"), pom.getBytes());
819 execScript("mvn", args(
820 "deploy:deploy-file",
821 "-Dfile=bin/h2-mvstore" + getJarSuffix(),
822 "-Durl=file:///data/h2database/m2-repo",
823 "-Dpackaging=jar",
824 "-Dversion=" + getVersion(),
825 "-DpomFile=bin/pom.xml",
826 "-DartifactId=h2-mvstore",
827 "-DgroupId=com.h2database"));
828 }
829
830 /**
831 * This will build a 'snapshot' H2 .jar file and upload it to the local
832 * Maven 2 repository.
833 */
834 @Description(summary = "Build a snapshot H2 jar and upload to local Maven 2 repo.")
835 public void mavenInstallLocal() {
836 // MVStore
837 jarMVStore();
838 String pom = new String(readFile(Paths.get("src/installer/pom-mvstore-template.xml")));
839 pom = replaceAll(pom, "@version@", getVersion());
840 writeFile(Paths.get("bin/pom.xml"), pom.getBytes());
841 execScript("mvn", args(
842 "install:install-file",
843 "-Dversion=" + getVersion(),
844 "-Dfile=bin/h2-mvstore" + getJarSuffix(),
845 "-Dpackaging=jar",
846 "-DpomFile=bin/pom.xml",
847 "-DartifactId=h2-mvstore",
848 "-DgroupId=com.h2database"));
849 // database
850 jar();
851 pom = new String(readFile(Paths.get("src/installer/pom-template.xml")));
852 pom = replaceAll(pom, "@version@", getVersion());
853 writeFile(Paths.get("bin/pom.xml"), pom.getBytes());
854 execScript("mvn", args(
855 "install:install-file",
856 "-Dversion=" + getVersion(),
857 "-Dfile=bin/h2" + getJarSuffix(),
858 "-Dpackaging=jar",
859 "-DpomFile=bin/pom.xml",
860 "-DartifactId=h2",
861 "-DgroupId=com.h2database"));
862 }
863
864 /**
865 * Build the jar file without downloading any files over the network. If the
866 * required files are missing, they are listed, and the jar file is not
867 * built.
868 */
869 @Description(summary = "Build H2 jar avoiding downloads (list missing files).")
870 public void offline() {
871 downloadOrVerify(true);
872 if (filesMissing) {
873 println("Required files are missing");
874 } else {
875 jar();
876 }
877 }
878
879 /**
880 * Just run the spellchecker.
881 */
882 @Description(summary = "Run the spellchecker.")
883 public void spellcheck() {
884 java("org.h2.build.doc.SpellChecker", null);
885 }
886
887 /**
888 * Compile and run all tests. This does not include the compile step.
889 */
890 @Description(summary = "Compile and run all tests (excluding the compile step).")
891 public void test() {
892 test(false);
893 }
894
895 /**
896 * Compile and run all fast tests. This does not include the compile step.
897 */
898 @Description(summary = "Compile and run all tests for CI (excl. the compile step).")
899 public void testCI() {
900 test(true);
901 }
902
903 private void test(boolean ci) {
904 downloadTest();
905 String cp = "temp" + File.pathSeparator + "bin" +
906 File.pathSeparator + "ext/postgresql-" + PGJDBC_VERSION + ".jar" +
907 File.pathSeparator + "ext/javax.servlet-api-" + JAVAX_SERVLET_VERSION + ".jar" +
908 File.pathSeparator + "ext/jakarta.servlet-api-" + JAKARTA_SERVLET_VERSION + ".jar" +
909 File.pathSeparator + "ext/lucene-core-" + LUCENE_VERSION + ".jar" +
910 File.pathSeparator + "ext/lucene-analyzers-common-" + LUCENE_VERSION + ".jar" +
911 File.pathSeparator + "ext/lucene-queryparser-" + LUCENE_VERSION + ".jar" +
912 File.pathSeparator + "ext/org.osgi.core-" + OSGI_VERSION + ".jar" +
913 File.pathSeparator + "ext/org.osgi.service.jdbc-" + OSGI_JDBC_VERSION + ".jar" +
914 File.pathSeparator + "ext/jts-core-" + JTS_VERSION + ".jar" +
915 File.pathSeparator + "ext/slf4j-api-" + SLF4J_VERSION + ".jar" +
916 File.pathSeparator + "ext/slf4j-nop-" + SLF4J_VERSION + ".jar" +
917 File.pathSeparator + "ext/asm-" + ASM_VERSION + ".jar" +
918 File.pathSeparator + javaToolsJar;
919 cp = addNashornJavaScriptEngineIfNecessary(cp);
920 int version = getJavaVersion();
921 if (version >= 9) {
922 cp = "src/java9/precompiled" + File.pathSeparator + cp;
923 if (version >= 10) {
924 cp = "src/java10/precompiled" + File.pathSeparator + cp;
925 }
926 }
927 int ret;
928 if (ci) {
929 ret = execJava(args(
930 "-ea",
931 "-Xmx128m",
932 "-XX:MaxDirectMemorySize=2g",
933 "-cp", cp,
934 "org.h2.test.TestAll", "ci"));
935 } else {
936 ret = execJava(args(
937 "-ea",
938 "-Xmx128m",
939 "-cp", cp,
940 "org.h2.test.TestAll"));
941 }
942 // return a failure code for CI builds
943 if (ret != 0) {
944 System.exit(ret);
945 }
946 }
947
948 /**
949 * Print the system properties.
950 */
951 @Description(summary = "Print the system properties.")
952 public void testSysProperties() {
953 System.out.println("environment settings:");
954 for (Entry<Object, Object> e : new TreeMap<>(
955 System.getProperties()).entrySet()) {
956 System.out.println(e);
957 }
958 }
959
960 /**
961 * Test the local network of this machine.
962 */
963 @Description(summary = "Test the local network of this machine.")
964 public void testNetwork() {
965 try {
966 long start = System.nanoTime();
967 System.out.println("localhost:");
968 System.out.println(" " + InetAddress.getByName("localhost"));
969 for (InetAddress address : InetAddress.getAllByName("localhost")) {
970 System.out.println(" " + address);
971 }
972 InetAddress localhost = InetAddress.getLocalHost();
973 System.out.println("getLocalHost:" + localhost);
974 for (InetAddress address : InetAddress.getAllByName(localhost
975 .getHostAddress())) {
976 System.out.println(" " + address);
977 }
978 InetAddress address = InetAddress.getByName(localhost.getHostAddress());
979 System.out.println("byName:" + address);
980 ServerSocket serverSocket;
981 try {
982 serverSocket = new ServerSocket(0);
983 } catch (Exception e) {
984 e.printStackTrace();
985 serverSocket = new ServerSocket(0);
986 }
987 System.out.println(serverSocket);
988 int port = serverSocket.getLocalPort();
989 final ServerSocket accept = serverSocket;
990 start = System.nanoTime();
991 Thread thread = new Thread() {
992 @Override
993 public void run() {
994 try {
995 System.out.println("server accepting");
996 Socket s = accept.accept();
997 Thread.sleep(100);
998 System.out.println("server accepted:" + s);
999 System.out.println("server read:" + s.getInputStream().read());
1000 Thread.sleep(200);
1001 s.getOutputStream().write(234);
1002 Thread.sleep(100);
1003 System.out.println("server closing");
1004 s.close();
1005 System.out.println("server done");
1006 } catch (Throwable t) {
1007 t.printStackTrace();
1008 }
1009 }
1010 };
1011 thread.start();
1012 System.out.println("time: " +
1013 TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
1014 Thread.sleep(1000);
1015 start = System.nanoTime();
1016 final Socket socket = new Socket();
1017 socket.setSoTimeout(2000);
1018 final InetSocketAddress socketAddress = new InetSocketAddress(address, port);
1019 System.out.println("client:" + socketAddress);
1020 try {
1021 Thread t = new Thread() {
1022 @Override
1023 public void run() {
1024 try {
1025 socket.connect(socketAddress, 2000);
1026 } catch (IOException e) {
1027 e.printStackTrace();
1028 }
1029 }
1030 };
1031 t.start();
1032 t.join(5000);
1033 if (!socket.isConnected()) {
1034 final InetSocketAddress localhostAddress = new InetSocketAddress(
1035 "localhost", port);
1036 System.out.println("not connected, trying localhost:"
1037 + socketAddress);
1038 socket.connect(localhostAddress, 2000);
1039 }
1040 System.out.println("time: " +
1041 TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
1042 Thread.sleep(200);
1043 start = System.nanoTime();
1044 System.out.println("client:" + socket.toString());
1045 socket.getOutputStream().write(123);
1046 System.out.println("time: " +
1047 TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
1048 Thread.sleep(100);
1049 start = System.nanoTime();
1050 System.out.println("client read:" + socket.getInputStream().read());
1051 socket.close();
1052 } catch (Throwable t) {
1053 t.printStackTrace();
1054 }
1055 thread.join(5000);
1056 System.out.println("time: " +
1057 TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
1058 if (thread.isAlive()) {
1059 System.out.println("thread is still alive, interrupting");
1060 thread.interrupt();
1061 }
1062 Thread.sleep(100);
1063 System.out.println("done");
1064 } catch (Exception e) {
1065 e.printStackTrace();
1066 }
1067 }
1068
1069 /**
1070 * This build target is used for the automated build. It copies the result
1071 * of the automated build (including test results, newsfeed, code coverage)
1072 * to the public web site.
1073 */
1074 @Description(summary = "Upload all build results to the public website.")
1075 public void uploadBuild() {
1076 String password = System.getProperty("h2.ftpPassword");
1077 if (password == null) {
1078 throw new RuntimeException("h2.ftpPassword not set");
1079 }
1080 downloadTest();
1081 mkdir("temp");
1082 FileList files = files("src/tools").keep("*/UploadBuild.java");
1083 StringList args = args("-d", "temp", "-sourcepath", "src/tools" +
1084 File.pathSeparator + "src/test" + File.pathSeparator + "src/main");
1085 String version = getTargetJavaVersion();
1086 if (version != null) {
1087 args = args.plus("-target", version, "-source", version);
1088 }
1089 javac(args, files);
1090 String cp = "bin" + File.pathSeparator + "temp";
1091 execJava(args("-Xmx512m", "-cp", cp,
1092 "-Dh2.ftpPassword=" + password,
1093 "org.h2.build.doc.UploadBuild"));
1094 }
1095
1096 /**
1097 * Build the h2console.war file.
1098 */
1099 @Description(summary = "Build the h2console.war file.")
1100 public void warConsole() {
1101 jar();
1102 copy("temp/WEB-INF", files("src/tools/WEB-INF/web.xml"), "src/tools/WEB-INF");
1103 copy("temp", files("src/tools/WEB-INF/console.html"), "src/tools/WEB-INF");
1104 copy("temp/WEB-INF/lib", files("bin/h2" + getJarSuffix()), "bin");
1105 FileList files = files("temp").exclude("temp/org*").exclude("temp/META-INF*");
1106 files.exclude("*.DS_Store");
1107 jar("bin/h2console.war", files, "temp");
1108 }
1109
1110 @Override
1111 protected String getLocalMavenDir() {
1112 String userHome = System.getProperty("user.home", "");
1113 Path file = Paths.get(userHome, ".m2/settings.xml");
1114 if (!Files.exists(file)) {
1115 return super.getLocalMavenDir();
1116 }
1117 XMLParser p = new XMLParser(new String(BuildBase.readFile(file)));
1118 HashMap<String, String> prop = new HashMap<>();
1119 for (String name = ""; p.hasNext();) {
1120 int event = p.next();
1121 if (event == XMLParser.START_ELEMENT) {
1122 name += "/" + p.getName();
1123 } else if (event == XMLParser.END_ELEMENT) {
1124 name = name.substring(0, name.lastIndexOf('/'));
1125 } else if (event == XMLParser.CHARACTERS) {
1126 String text = p.getText().trim();
1127 if (text.length() > 0) {
1128 prop.put(name, text);
1129 }
1130 }
1131 }
1132 String local = prop.get("/settings/localRepository");
1133 if (local == null) {
1134 local = "${user.home}/.m2/repository";
1135 }
1136 local = replaceAll(local, "${user.home}", userHome);
1137 return local;
1138 }
1139
1140 private String addNashornJavaScriptEngineIfNecessary(String cp) {
1141 if (requiresNashornJavaScriptEngine()) {
1142 return cp +
1143 File.pathSeparator + "ext/nashorn-core-" + NASHORN_VERSION + ".jar" +
1144 File.pathSeparator + "ext/asm-commons-" + ASM_VERSION + ".jar" +
1145 File.pathSeparator + "ext/asm-tree-" + ASM_VERSION + ".jar" +
1146 File.pathSeparator + "ext/asm-util-" + ASM_VERSION + ".jar";
1147 }
1148 return cp;
1149 }
1150
1151 private boolean requiresNashornJavaScriptEngine() {
1152 return getJavaVersion() >= 15; // Nashorn was removed in Java 15
1153 }
1154
1155 }