Created
January 31, 2015 09:10
-
-
Save therne/e825a1e05e645bb5c1eb to your computer and use it in GitHub Desktop.
The super, gorgeous and compatible Entrypoint class for Vert.x Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileInputStream; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Properties; | |
/** | |
* Starter - Entry point of the Vert.x gradle module. | |
* @author vista | |
*/ | |
public class Starter { | |
private static Properties props = new Properties(); | |
private static List<String> getCommand() throws Exception { | |
String moduleName = props.getProperty("modowner", "") | |
+ "~" + props.getProperty("modname", "") | |
+ "~" + props.getProperty("version", ""); | |
if (moduleName.equals("~~")) { | |
throw new Exception("module information not found in gradle.properties"); | |
} | |
String runModArgs = props.getProperty("runModArgs", ""); | |
return Arrays.asList(vertxPath(), "runmod", moduleName, "-cp", "build/classes/main", runModArgs); | |
} | |
private static String vertxPath() throws Exception { | |
Process p = Runtime.getRuntime().exec("which vertx"); | |
String line, output=""; | |
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
while ((line = in.readLine()) != null) output += line; | |
return output; | |
} | |
public static void main(String[] args) { | |
try { | |
// load properties | |
props.load(new FileInputStream("gradle.properties")); | |
// launch process | |
ProcessBuilder pb = new ProcessBuilder(getCommand()); | |
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); | |
pb.redirectError(ProcessBuilder.Redirect.INHERIT); | |
final Process child = pb.start(); | |
// kill when me is killed | |
Runtime.getRuntime().addShutdownHook(new Thread(child::destroy)); | |
child.waitFor(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
윈도우가 안되서 별 0점 드리겠습니다 ^^