提交 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 @@
<module name="ParenPad"/>
<module name="WhitespaceAfter"/>
<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 name="ModifierOrder"/>
<module name="RedundantModifier"/>
......
......@@ -18,6 +18,11 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
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.InvocationTargetException;
import java.lang.reflect.Method;
......@@ -36,6 +41,7 @@ import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* This class is a complete pure Java build tool. It allows to build this
* project without any external dependencies except a JDK.
......@@ -44,6 +50,16 @@ import java.util.zip.ZipOutputStream;
*/
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.
*/
......@@ -158,6 +174,18 @@ public class BuildBase {
*/
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.
*
......@@ -283,11 +311,17 @@ public class BuildBase {
}
});
sysOut.println("Targets:");
String description;
for (Method m : methods) {
int mod = m.getModifiers();
if (!Modifier.isStatic(mod) && Modifier.isPublic(mod)
&& 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();
......@@ -320,6 +354,16 @@ public class BuildBase {
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.
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论