diff --git a/src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/JavaConfigRunner.java b/src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/JavaConfigRunner.java new file mode 100644 index 0000000..8488750 --- /dev/null +++ b/src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/JavaConfigRunner.java @@ -0,0 +1,46 @@ +package com.github.forax.pro.main; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Optional; +import java.util.stream.Stream; + +import com.github.forax.pro.helper.Platform; +import com.github.forax.pro.main.runner.ConfigRunner; + +public class JavaConfigRunner implements ConfigRunner { + @Override + public Optional accept(Path configFile, String[] arguments) { + return Optional.of(() -> run(configFile, arguments)) + .filter(__ -> configFile.toString().endsWith(".java")); + } + + private static void run(Path configFile, String... arguments) { + //System.out.println("run with java " + configFile); + + Path javaHome = Paths.get(System.getProperty("java.home")); + var args = + Stream.of( + Stream.of(javaHome.resolve("bin").resolve(Platform.current().javaExecutableName()).toString()), + Stream.of("-Dpro.exitOnError=true"), + Stream.of(arguments).filter(a -> a.length() != 0).map(a -> "-Dpro.arguments=" + String.join(",", a)), + Stream.of(configFile.toString()) + ) + .flatMap(s -> s) + .toArray(String[]::new); + + //System.out.println("cmd " + java.util.Arrays.toString(args)); + + var exitCode = 1; + try { + var process = new ProcessBuilder(args) + .inheritIO() + .start(); + exitCode = process.waitFor(); + } catch (InterruptedException|IOException e) { + System.err.println("i/o error " + e.getMessage()); + } + System.exit(exitCode); + } +} diff --git a/src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/Main.java b/src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/Main.java index 7f17259..66b0149 100644 --- a/src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/Main.java +++ b/src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/Main.java @@ -47,6 +47,7 @@ static class Configuration { enum InputFile { ARGUMENT(args -> (args.length >= 1)? Optional.of(new Configuration(Paths.get(args[0]), Main::shift)): Optional.empty()), + DEFAULT_JAVA(args -> Optional.of(new Configuration(Paths.get("build.java"), identity()))), DEFAULT_PRO(args -> Optional.of(new Configuration(Paths.get("build.pro"), identity()))), DEFAULT_JSON(args -> Optional.of(new Configuration(Paths.get("build.json"), identity()))) ; diff --git a/src/main/java/com.github.forax.pro.main/module-info.java b/src/main/java/com.github.forax.pro.main/module-info.java index c1831b4..d67be6e 100644 --- a/src/main/java/com.github.forax.pro.main/module-info.java +++ b/src/main/java/com.github.forax.pro.main/module-info.java @@ -14,6 +14,7 @@ uses javax.tools.Tool; provides com.github.forax.pro.main.runner.ConfigRunner - with com.github.forax.pro.main.JSONConfigRunner, + with com.github.forax.pro.main.JavaConfigRunner, + com.github.forax.pro.main.JSONConfigRunner, com.github.forax.pro.main.JShellConfigRunner; } \ No newline at end of file