Skip to content

Commit

Permalink
Add support of build.java using the JEP 330
Browse files Browse the repository at this point in the history
  • Loading branch information
forax committed Jun 18, 2018
1 parent a374f86 commit 01acf01
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com.github.forax.pro.main/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

2 comments on commit 01acf01

@sormuras
Copy link
Collaborator

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.

@forax
Copy link
Owner Author

@forax forax commented on 01acf01 Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.