提交 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"/>
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论