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