提交 86792ec9 authored 作者: Noel Grandin's avatar Noel Grandin

Merge pull request #237 from tomasp8/better-build

Improve build script: fork the same JRE, show target descriptions
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<module name="ParenPad"/> <module name="ParenPad"/>
<module name="WhitespaceAfter"/> <module name="WhitespaceAfter"/>
<module name="WhitespaceAround"> <module name="WhitespaceAround">
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,DIV_ASSIGN,EQUAL,GE,GT,LAND,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS_ASSIGN,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND,WILDCARD_TYPE"/> <property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,DIV_ASSIGN,EQUAL,GE,GT,LAND,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS_ASSIGN,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
</module> </module>
<module name="ModifierOrder"/> <module name="ModifierOrder"/>
<module name="RedundantModifier"/> <module name="RedundantModifier"/>
......
...@@ -12,8 +12,9 @@ import java.net.InetSocketAddress; ...@@ -12,8 +12,9 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap;
import org.h2.build.code.SwitchSource; import org.h2.build.code.SwitchSource;
import org.h2.build.doc.XMLParser; import org.h2.build.doc.XMLParser;
...@@ -36,6 +37,7 @@ public class Build extends BuildBase { ...@@ -36,6 +37,7 @@ public class Build extends BuildBase {
/** /**
* Run the benchmarks. * Run the benchmarks.
*/ */
@Description(summary = "Run the benchmarks.")
public void benchmark() { public void benchmark() {
downloadUsingMaven("ext/hsqldb-2.3.2.jar", downloadUsingMaven("ext/hsqldb-2.3.2.jar",
"org/hsqldb", "hsqldb", "2.3.2", "org/hsqldb", "hsqldb", "2.3.2",
...@@ -68,19 +70,20 @@ public class Build extends BuildBase { ...@@ -68,19 +70,20 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/mysql-connector-java-5.1.6.jar"; File.pathSeparator + "ext/mysql-connector-java-5.1.6.jar";
StringList args = args("-Xmx128m", StringList args = args("-Xmx128m",
"-cp", cp, "org.h2.test.bench.TestPerformance"); "-cp", cp, "org.h2.test.bench.TestPerformance");
exec("java", args.plus("-init", "-db", "1")); execJava(args.plus("-init", "-db", "1"));
exec("java", args.plus("-db", "2")); execJava(args.plus("-db", "2"));
exec("java", args.plus("-db", "3", "-out", "pe.html")); execJava(args.plus("-db", "3", "-out", "pe.html"));
exec("java", args.plus("-init", "-db", "4")); execJava(args.plus("-init", "-db", "4"));
exec("java", args.plus("-db", "5", "-exit")); execJava(args.plus("-db", "5", "-exit"));
exec("java", args.plus("-db", "6")); execJava(args.plus("-db", "6"));
exec("java", args.plus("-db", "7")); execJava(args.plus("-db", "7"));
exec("java", args.plus("-db", "8", "-out", "ps.html")); execJava(args.plus("-db", "8", "-out", "ps.html"));
} }
/** /**
* Clean all jar files, classes, and generated documentation. * Clean all jar files, classes, and generated documentation.
*/ */
@Description(summary = "Clean all jar files, classes, and generated documentation.")
public void clean() { public void clean() {
delete("temp"); delete("temp");
delete("docs"); delete("docs");
...@@ -90,8 +93,9 @@ public class Build extends BuildBase { ...@@ -90,8 +93,9 @@ public class Build extends BuildBase {
} }
/** /**
* Compile all classes * Compile all classes.
*/ */
@Description(summary = "Compile all classes.")
public void compile() { public void compile() {
compile(true, false, false); compile(true, false, false);
} }
...@@ -112,6 +116,7 @@ public class Build extends BuildBase { ...@@ -112,6 +116,7 @@ public class Build extends BuildBase {
/** /**
* Run the Emma code coverage. * Run the Emma code coverage.
*/ */
@Description(summary = "Run the Emma code coverage.")
public void coverage() { public void coverage() {
downloadTest(); downloadTest();
downloadUsingMaven("ext/emma-2.0.5312.jar", downloadUsingMaven("ext/emma-2.0.5312.jar",
...@@ -128,10 +133,9 @@ public class Build extends BuildBase { ...@@ -128,10 +133,9 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/jts-core-1.14.0.jar" + File.pathSeparator + "ext/jts-core-1.14.0.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/slf4j-nop-1.6.0.jar" + File.pathSeparator + "ext/slf4j-nop-1.6.0.jar" +
File.pathSeparator + System.getProperty("java.home") + File.pathSeparator + javaToolsJar;
"/../lib/tools.jar";
// -XX:-UseSplitVerifier is for Java 7 compatibility // -XX:-UseSplitVerifier is for Java 7 compatibility
exec("java", args( execJava(args(
"-Xmx128m", "-Xmx128m",
"-XX:-UseSplitVerifier", "-XX:-UseSplitVerifier",
"-cp", cp, "emma", "run", "-cp", cp, "emma", "run",
...@@ -146,6 +150,7 @@ public class Build extends BuildBase { ...@@ -146,6 +150,7 @@ public class Build extends BuildBase {
/** /**
* Switch the source code to the current JDK. * Switch the source code to the current JDK.
*/ */
@Description(summary = "Switch the source code to match the current JDK.")
public void switchSource() { public void switchSource() {
switchSource(true); switchSource(true);
} }
...@@ -204,7 +209,7 @@ public class Build extends BuildBase { ...@@ -204,7 +209,7 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
File.pathSeparator + "ext/jts-core-1.14.0.jar" + File.pathSeparator + "ext/jts-core-1.14.0.jar" +
File.pathSeparator + System.getProperty("java.home") + "/../lib/tools.jar"; File.pathSeparator + javaToolsJar;
FileList files; FileList files;
if (clientOnly) { if (clientOnly) {
files = files("src/main/org/h2/Driver.java"); files = files("src/main/org/h2/Driver.java");
...@@ -259,6 +264,7 @@ public class Build extends BuildBase { ...@@ -259,6 +264,7 @@ public class Build extends BuildBase {
* Create the documentation from the documentation sources. API Javadocs are * Create the documentation from the documentation sources. API Javadocs are
* created as well. * created as well.
*/ */
@Description(summary = "Create the documentation from sources (incl. API Javadocs).")
public void docs() { public void docs() {
javadoc(); javadoc();
copy("docs", files("src/docsrc/index.html"), "src/docsrc"); copy("docs", files("src/docsrc/index.html"), "src/docsrc");
...@@ -282,6 +288,7 @@ public class Build extends BuildBase { ...@@ -282,6 +288,7 @@ public class Build extends BuildBase {
* Download all required jar files. Actually those are only compile time * Download all required jar files. Actually those are only compile time
* dependencies. The database can be used without any dependencies. * dependencies. The database can be used without any dependencies.
*/ */
@Description(summary = "Download all required jar files.")
public void download() { public void download() {
downloadOrVerify(false); downloadOrVerify(false);
} }
...@@ -352,6 +359,7 @@ public class Build extends BuildBase { ...@@ -352,6 +359,7 @@ public class Build extends BuildBase {
/** /**
* Create the h2.zip file and the Windows installer. * Create the h2.zip file and the Windows installer.
*/ */
@Description(summary = "Create the h2.zip file and the Windows installer.")
public void installer() { public void installer() {
delete(files("bin").keep("*.jar")); delete(files("bin").keep("*.jar"));
jar(); jar();
...@@ -420,6 +428,7 @@ public class Build extends BuildBase { ...@@ -420,6 +428,7 @@ public class Build extends BuildBase {
/** /**
* Create the regular h2.jar file. * Create the regular h2.jar file.
*/ */
@Description(summary = "Create the regular h2.jar file.")
public void jar() { public void jar() {
compile(); compile();
manifest("H2 Database Engine", "org.h2.tools.Console"); manifest("H2 Database Engine", "org.h2.tools.Console");
...@@ -451,6 +460,7 @@ public class Build extends BuildBase { ...@@ -451,6 +460,7 @@ public class Build extends BuildBase {
* Create the file h2android.jar. This only contains the embedded database, * Create the file h2android.jar. This only contains the embedded database,
* plus the H2 Android API. Debug information is disabled. * plus the H2 Android API. Debug information is disabled.
*/ */
@Description(summary = "Create h2android.jar with only the embedded DB and H2 Android API.")
public void jarAndroid() { public void jarAndroid() {
compile(false, false, true); compile(false, false, true);
FileList files = files("temp"). FileList files = files("temp").
...@@ -482,6 +492,7 @@ public class Build extends BuildBase { ...@@ -482,6 +492,7 @@ public class Build extends BuildBase {
* Create the h2client.jar. This only contains the remote JDBC * Create the h2client.jar. This only contains the remote JDBC
* implementation. * implementation.
*/ */
@Description(summary = "Create h2client.jar with only the remote JDBC implementation.")
public void jarClient() { public void jarClient() {
compile(true, true, false); compile(true, true, false);
FileList files = files("temp"). FileList files = files("temp").
...@@ -507,6 +518,7 @@ public class Build extends BuildBase { ...@@ -507,6 +518,7 @@ public class Build extends BuildBase {
/** /**
* Create the file h2mvstore.jar. This only contains the MVStore. * Create the file h2mvstore.jar. This only contains the MVStore.
*/ */
@Description(summary = "Create h2mvstore.jar containing only the MVStore.")
public void jarMVStore() { public void jarMVStore() {
compileMVStore(true); compileMVStore(true);
manifestMVStore(); manifestMVStore();
...@@ -520,6 +532,7 @@ public class Build extends BuildBase { ...@@ -520,6 +532,7 @@ public class Build extends BuildBase {
* Create the file h2small.jar. This only contains the embedded database. * Create the file h2small.jar. This only contains the embedded database.
* Debug information is disabled. * Debug information is disabled.
*/ */
@Description(summary = "Create h2small.jar containing only the embedded database.")
public void jarSmall() { public void jarSmall() {
compile(false, false, true); compile(false, false, true);
FileList files = files("temp"). FileList files = files("temp").
...@@ -555,6 +568,7 @@ public class Build extends BuildBase { ...@@ -555,6 +568,7 @@ public class Build extends BuildBase {
* Create the file h2jaqu.jar. This only contains the JaQu (Java Query) * Create the file h2jaqu.jar. This only contains the JaQu (Java Query)
* implementation. All other jar files do not include JaQu. * implementation. All other jar files do not include JaQu.
*/ */
@Description(summary = "Create jaqu.jar with only the Java Query implementation.")
public void jarJaqu() { public void jarJaqu() {
compile(true, false, true); compile(true, false, true);
manifest("H2 JaQu", ""); manifest("H2 JaQu", "");
...@@ -566,8 +580,9 @@ public class Build extends BuildBase { ...@@ -566,8 +580,9 @@ public class Build extends BuildBase {
} }
/** /**
* Create the Javadocs of the API (including the JDBC API) and tools. * Create the Javadocs of the API (incl. the JDBC API) and tools.
*/ */
@Description(summary = "Create the API Javadocs (incl. JDBC API and tools).")
public void javadoc() { public void javadoc() {
compileTools(); compileTools();
delete("docs"); delete("docs");
...@@ -585,17 +600,17 @@ public class Build extends BuildBase { ...@@ -585,17 +600,17 @@ public class Build extends BuildBase {
/** /**
* Create the Javadocs of the implementation. * Create the Javadocs of the implementation.
*/ */
@Description(summary = "Create the Javadocs of the implementation.")
public void javadocImpl() { public void javadocImpl() {
compileTools(); compileTools();
mkdir("docs/javadocImpl2"); mkdir("docs/javadocImpl2");
javadoc("-sourcepath", "src/main" + javadoc("-sourcepath", "src/main" +
File.pathSeparator + "src/test" + File.pathSeparator + "src/test" +
File.pathSeparator + "src/tools" , File.pathSeparator + "src/tools",
"-noindex", "-noindex",
"-tag", "h2.resource", "-tag", "h2.resource",
"-d", "docs/javadocImpl2", "-d", "docs/javadocImpl2",
"-classpath", System.getProperty("java.home") + "-classpath", javaToolsJar +
"/../lib/tools.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/servlet-api-3.0.1.jar" + File.pathSeparator + "ext/servlet-api-3.0.1.jar" +
File.pathSeparator + "ext/lucene-core-3.6.2.jar" + File.pathSeparator + "ext/lucene-core-3.6.2.jar" +
...@@ -610,8 +625,7 @@ public class Build extends BuildBase { ...@@ -610,8 +625,7 @@ public class Build extends BuildBase {
"-noindex", "-noindex",
"-tag", "h2.resource", "-tag", "h2.resource",
"-d", "docs/javadocImpl3", "-d", "docs/javadocImpl3",
"-classpath", System.getProperty("java.home") + "-classpath", javaToolsJar +
"/../lib/tools.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/servlet-api-3.0.1.jar" + File.pathSeparator + "ext/servlet-api-3.0.1.jar" +
File.pathSeparator + "ext/lucene-core-3.6.2.jar" + File.pathSeparator + "ext/lucene-core-3.6.2.jar" +
...@@ -626,8 +640,7 @@ public class Build extends BuildBase { ...@@ -626,8 +640,7 @@ public class Build extends BuildBase {
javadoc("-sourcepath", "src/main" + javadoc("-sourcepath", "src/main" +
File.pathSeparator + "src/test" + File.pathSeparator + "src/test" +
File.pathSeparator + "src/tools", File.pathSeparator + "src/tools",
"-classpath", "-classpath", javaToolsJar +
System.getProperty("java.home") + "/../lib/tools.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/servlet-api-3.0.1.jar" + File.pathSeparator + "ext/servlet-api-3.0.1.jar" +
File.pathSeparator + "ext/lucene-core-3.6.2.jar" + File.pathSeparator + "ext/lucene-core-3.6.2.jar" +
...@@ -673,6 +686,7 @@ public class Build extends BuildBase { ...@@ -673,6 +686,7 @@ public class Build extends BuildBase {
* file:///data/h2database/m2-repo. This is only required when * file:///data/h2database/m2-repo. This is only required when
* a new H2 version is made. * a new H2 version is made.
*/ */
@Description(summary = "Build H2 release jars and upload to file:///data/h2database/m2-repo.")
public void mavenDeployCentral() { public void mavenDeployCentral() {
// generate and deploy h2*-sources.jar file // generate and deploy h2*-sources.jar file
FileList files = files("src/main"); FileList files = files("src/main");
...@@ -794,9 +808,10 @@ public class Build extends BuildBase { ...@@ -794,9 +808,10 @@ public class Build extends BuildBase {
} }
/** /**
* This will build a 'snapshot' H2 .jar file and upload it the to the local * This will build a 'snapshot' H2 .jar file and upload it to the local
* Maven 2 repository. * Maven 2 repository.
*/ */
@Description(summary = "Build a snapshot H2 jar and upload to local Maven 2 repo.")
public void mavenInstallLocal() { public void mavenInstallLocal() {
// MVStore // MVStore
jarMVStore(); jarMVStore();
...@@ -831,6 +846,7 @@ public class Build extends BuildBase { ...@@ -831,6 +846,7 @@ public class Build extends BuildBase {
* required files are missing, they are are listed, and the jar file is not * required files are missing, they are are listed, and the jar file is not
* built. * built.
*/ */
@Description(summary = "Build H2 jar avoiding downloads (list missing files).")
public void offline() { public void offline() {
downloadOrVerify(true); downloadOrVerify(true);
if (filesMissing) { if (filesMissing) {
...@@ -870,6 +886,7 @@ public class Build extends BuildBase { ...@@ -870,6 +886,7 @@ public class Build extends BuildBase {
/** /**
* Just run the spellchecker. * Just run the spellchecker.
*/ */
@Description(summary = "Run the spellchecker.")
public void spellcheck() { public void spellcheck() {
java("org.h2.build.doc.SpellChecker", null); java("org.h2.build.doc.SpellChecker", null);
} }
...@@ -877,6 +894,7 @@ public class Build extends BuildBase { ...@@ -877,6 +894,7 @@ public class Build extends BuildBase {
/** /**
* Compile and run all tests. This does not include the compile step. * Compile and run all tests. This does not include the compile step.
*/ */
@Description(summary = "Compile and run all tests (excluding the compile step).")
public void test() { public void test() {
test(false); test(false);
} }
...@@ -884,6 +902,7 @@ public class Build extends BuildBase { ...@@ -884,6 +902,7 @@ public class Build extends BuildBase {
/** /**
* Compile and run all fast tests. This does not include the compile step. * Compile and run all fast tests. This does not include the compile step.
*/ */
@Description(summary = "Compile and run all fast tests (excl. the compile step).")
public void testFast() { public void testFast() {
test(true); test(true);
} }
...@@ -900,15 +919,14 @@ public class Build extends BuildBase { ...@@ -900,15 +919,14 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/jts-core-1.14.0.jar" + File.pathSeparator + "ext/jts-core-1.14.0.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/slf4j-nop-1.6.0.jar" + File.pathSeparator + "ext/slf4j-nop-1.6.0.jar" +
File.pathSeparator + System.getProperty("java.home") + File.pathSeparator + javaToolsJar;
"/../lib/tools.jar";
if (fast) { if (fast) {
exec("java", args( execJava(args(
"-Xmx128m", "-Xmx128m",
"-cp", cp, "-cp", cp,
"org.h2.test.TestAll", "fast")); "org.h2.test.TestAll", "fast"));
} else { } else {
exec("java", args( execJava(args(
"-Xmx128m", "-Xmx128m",
"-cp", cp, "-cp", cp,
"org.h2.test.TestAll")); "org.h2.test.TestAll"));
...@@ -916,8 +934,9 @@ public class Build extends BuildBase { ...@@ -916,8 +934,9 @@ public class Build extends BuildBase {
} }
/** /**
* Print the system properties * Print the system properties.
*/ */
@Description(summary = "Print the system properties.")
public void testSysProperties() { public void testSysProperties() {
System.out.println("environment settings:"); System.out.println("environment settings:");
for (Entry<Object, Object> e : new TreeMap<Object, Object>( for (Entry<Object, Object> e : new TreeMap<Object, Object>(
...@@ -929,6 +948,7 @@ public class Build extends BuildBase { ...@@ -929,6 +948,7 @@ public class Build extends BuildBase {
/** /**
* Test the local network of this machine. * Test the local network of this machine.
*/ */
@Description(summary = "Test the local network of this machine.")
public void testNetwork() { public void testNetwork() {
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
...@@ -1035,6 +1055,7 @@ public class Build extends BuildBase { ...@@ -1035,6 +1055,7 @@ public class Build extends BuildBase {
* of the automated build (including test results, newsfeed, code coverage) * of the automated build (including test results, newsfeed, code coverage)
* to the public web site. * to the public web site.
*/ */
@Description(summary = "Upload all build results to the public website.")
public void uploadBuild() { public void uploadBuild() {
String password = System.getProperty("h2.ftpPassword"); String password = System.getProperty("h2.ftpPassword");
if (password == null) { if (password == null) {
...@@ -1052,7 +1073,7 @@ public class Build extends BuildBase { ...@@ -1052,7 +1073,7 @@ public class Build extends BuildBase {
javac(args, files); javac(args, files);
String cp = "bin" + File.pathSeparator + "temp" + String cp = "bin" + File.pathSeparator + "temp" +
File.pathSeparator + "ext/h2mig_pagestore_addon.jar"; File.pathSeparator + "ext/h2mig_pagestore_addon.jar";
exec("java", args("-Xmx512m", "-cp", cp, execJava(args("-Xmx512m", "-cp", cp,
"-Dh2.ftpPassword=" + password, "-Dh2.ftpPassword=" + password,
"org.h2.build.doc.UploadBuild")); "org.h2.build.doc.UploadBuild"));
} }
...@@ -1060,6 +1081,7 @@ public class Build extends BuildBase { ...@@ -1060,6 +1081,7 @@ public class Build extends BuildBase {
/** /**
* Build the h2console.war file. * Build the h2console.war file.
*/ */
@Description(summary = "Build the h2console.war file.")
public void warConsole() { public void warConsole() {
jar(); jar();
copy("temp/WEB-INF", files("src/tools/WEB-INF/web.xml"), "src/tools/WEB-INF"); copy("temp/WEB-INF", files("src/tools/WEB-INF/web.xml"), "src/tools/WEB-INF");
......
...@@ -18,6 +18,11 @@ import java.io.InputStreamReader; ...@@ -18,6 +18,11 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
...@@ -36,6 +41,7 @@ import java.util.zip.Deflater; ...@@ -36,6 +41,7 @@ import java.util.zip.Deflater;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
/** /**
* This class is a complete pure Java build tool. It allows to build this * This class is a complete pure Java build tool. It allows to build this
* project without any external dependencies except a JDK. * project without any external dependencies except a JDK.
...@@ -44,6 +50,16 @@ import java.util.zip.ZipOutputStream; ...@@ -44,6 +50,16 @@ import java.util.zip.ZipOutputStream;
*/ */
public class BuildBase { public class BuildBase {
/**
* Stores descriptions for methods which can be invoked as build targets.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
public static @interface Description {
String summary() default "";
}
/** /**
* A list of strings. * A list of strings.
*/ */
...@@ -158,6 +174,18 @@ public class BuildBase { ...@@ -158,6 +174,18 @@ public class BuildBase {
*/ */
protected boolean quiet; protected boolean quiet;
/**
* The full path to the executable of the current JRE.
*/
protected String javaExecutable = System.getProperty("java.home") +
File.separator + "bin" + File.separator + "java";
/**
* The full path to the tools jar of the current JDK.
*/
protected String javaToolsJar = System.getProperty("java.home") + File.separator + ".." +
File.separator + "lib" + File.separator + "tools.jar";
/** /**
* This method should be called by the main method. * This method should be called by the main method.
* *
...@@ -283,11 +311,17 @@ public class BuildBase { ...@@ -283,11 +311,17 @@ public class BuildBase {
} }
}); });
sysOut.println("Targets:"); sysOut.println("Targets:");
String description;
for (Method m : methods) { for (Method m : methods) {
int mod = m.getModifiers(); int mod = m.getModifiers();
if (!Modifier.isStatic(mod) && Modifier.isPublic(mod) if (!Modifier.isStatic(mod) && Modifier.isPublic(mod)
&& m.getParameterTypes().length == 0) { && m.getParameterTypes().length == 0) {
sysOut.println(m.getName()); if (m.isAnnotationPresent(Description.class)) {
description = String.format("%1$-20s %2$s", m.getName(), m.getAnnotation(Description.class).summary());
} else {
description = m.getName();
}
sysOut.println(description);
} }
} }
sysOut.println(); sysOut.println();
...@@ -320,6 +354,16 @@ public class BuildBase { ...@@ -320,6 +354,16 @@ public class BuildBase {
return exec(script, args); return exec(script, args);
} }
/**
* Execute java in a separate process, but using the java executable of the current JRE.
*
* @param args the command line parameters for the java command
* @return the exit value
*/
protected int execJava(StringList args) {
return exec(javaExecutable, args);
}
/** /**
* Execute a program in a separate process. * Execute a program in a separate process.
* *
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论