-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of build.java using the JEP 330
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/com.github.forax.pro.main/com/github/forax/pro/main/JavaConfigRunner.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Runnable> accept(Path configFile, String[] arguments) { | ||
return Optional.<Runnable>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); | ||
} | ||
} |
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
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
01acf01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was JSR 330 integrated in 11-ea+18? Didn't see it in the release notes.
01acf01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,
see https://bugs.openjdk.java.net/browse/JDK-8201274