Skip to content

Commit

Permalink
separate release version into source and test release version
Browse files Browse the repository at this point in the history
  • Loading branch information
forax committed May 30, 2018
1 parent afbff68 commit 1c933fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void main(String[] args) throws IOException {
set("pro.exitOnError", true);

set("compiler.lint", "all,-varargs,-overloads");
set("compiler.release", jdkVersion());
set("compiler.sourceRelease", jdkVersion());

var version = "0." + jdkVersion();
set("packager.modules", list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ public interface CompilerBuilder {
java.util.Optional<java.util.List<java.lang.String>> rawArguments();
CompilerBuilder rawArguments(java.lang.String... rawArguments);
CompilerBuilder rawArguments(java.util.List<java.lang.String> rawArguments);
@Deprecated
int release();
@Deprecated
CompilerBuilder release(int release);
java.util.Optional<java.util.List<java.lang.String>> rootModules();
CompilerBuilder rootModules(java.lang.String... rootModules);
CompilerBuilder rootModules(java.util.List<java.lang.String> rootModules);
java.util.Optional<java.lang.Integer> sourceRelease();
CompilerBuilder sourceRelease(int sourceRelease);
java.util.Optional<java.lang.Integer> testRelease();
CompilerBuilder testRelease(int testRelease);
java.util.Optional<java.util.List<java.nio.file.Path>> upgradeModulePath();
CompilerBuilder upgradeModulePath(java.nio.file.Path... upgradeModulePath);
CompilerBuilder upgradeModulePath(java.util.List<java.nio.file.Path> upgradeModulePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@

@TypeCheckedConfig
public interface CompilerConf {
@Deprecated
int release();
@Deprecated
void release(int release);

Optional<Integer> sourceRelease();
void sourceRelease(int release);

Optional<Integer> testRelease();
void testRelease(int testRelease);

Optional<Boolean> verbose();
void verbose(boolean verbose);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public String name() {
}

@Override
@SuppressWarnings("deprecation")
public void init(MutableConfig config) {
var compilerConf = config.getOrUpdate(name(), CompilerConf.class);
compilerConf.release(9);
Expand Down Expand Up @@ -118,13 +119,15 @@ public int execute(Config config) throws IOException {
.orElseThrow(() -> new IllegalStateException("can not find javac"));
var compiler = config.getOrThrow(name(), CompilerConf.class);


@SuppressWarnings("deprecation")
var sourceRelease = compiler.sourceRelease().orElse(compiler.release());
var moduleSourceFinder = ModuleHelper.sourceModuleFinders(compiler.moduleSourcePath());
var errorCode = compile(log, javacTool, compiler,
compiler.moduleSourcePath(),
moduleSourceFinder,
List.of(),
compiler.moduleSourceResourcesPath(),
sourceRelease,
compiler.moduleExplodedSourcePath(),
"source:");
if (errorCode != 0) {
Expand Down Expand Up @@ -155,11 +158,12 @@ public int execute(Config config) throws IOException {
moduleMergedTestFinder,
List.of(compiler.moduleExplodedSourcePath()),
StableList.<Path>of().appendAll(compiler.moduleSourceResourcesPath()).appendAll(compiler.moduleTestResourcesPath()),
compiler.testRelease().orElse(sourceRelease),
compiler.moduleExplodedTestPath(),
"test:");
}

private static int compile(Log log, ToolProvider javacTool, CompilerConf compiler, List<Path> moduleSourcePath, ModuleFinder moduleFinder, List<Path> additionalSourcePath, List<Path> resourcesPath, Path destination, String pass) throws IOException {
private static int compile(Log log, ToolProvider javacTool, CompilerConf compiler, List<Path> moduleSourcePath, ModuleFinder moduleFinder, List<Path> additionalSourcePath, List<Path> resourcesPath, int release, Path destination, String pass) throws IOException {
Optional<List<Path>> modulePath = modulePathOrDependencyPath(compiler.modulePath(),
compiler.moduleDependencyPath(), additionalSourcePath);

Expand Down Expand Up @@ -207,21 +211,21 @@ public void dependencyNotFound(String moduleName, String dependencyChain) {
deleteAllFiles(destination, false);


var javac = new Javac(compiler.release());
var javac = new Javac(release);
compiler.verbose().ifPresent(javac::verbose);
compiler.lint().ifPresent(javac::lint);
compiler.rawArguments().ifPresent(javac::rawArguments);
compiler.upgradeModulePath().ifPresent(javac::upgradeModulePath);
compiler.rootModules().ifPresent(javac::rootModules);

var compatibilityMode = compiler.release() <= 8;
var compatibilityMode = release <= 8;
if (!compatibilityMode) {
// module mode, compile all java files at once using moduleSourcePath
javac.moduleSourcePath(moduleSourcePath);
modulePath.ifPresent(javac::modulePath);
javac.destination(destination);

var errorCode = compileAllFiles(log, javacTool, compiler, moduleSourcePath, rootSourceNames, javac, compiler.release(), __ -> true);
var errorCode = compileAllFiles(log, javacTool, compiler, moduleSourcePath, rootSourceNames, javac, release, __ -> true);
if (errorCode != 0) {
return errorCode;
}
Expand All @@ -236,7 +240,7 @@ public void dependencyNotFound(String moduleName, String dependencyChain) {
javac.destination(destination.resolve(moduleName));

var moduleInfoFilter = pathFilenameEquals("module-info.java");
var errorCode = compileAllFiles(log, javacTool, compiler, moduleSourcePath, List.of(moduleName), javac, compiler.release(), moduleInfoFilter.negate());
var errorCode = compileAllFiles(log, javacTool, compiler, moduleSourcePath, List.of(moduleName), javac, release, moduleInfoFilter.negate());
if (errorCode != 0) {
return errorCode;
}
Expand Down

0 comments on commit 1c933fd

Please sign in to comment.