mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 08:17:11 -07:00
Added support for automatically consolidating compile options that are named differently but serve the same purpose
This commit is contained in:
parent
3e9b252c51
commit
c6c9d32c35
2 changed files with 37 additions and 4 deletions
|
@ -23,6 +23,13 @@ import java.util.List;
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public class CompileOperation extends AbstractOperation<CompileOperation> {
|
public class CompileOperation extends AbstractOperation<CompileOperation> {
|
||||||
|
static final String COMPILE_OPTION_D = "-d";
|
||||||
|
static final String COMPILE_OPTION_CP = "-cp";
|
||||||
|
static final String COMPILE_OPTION_CLASS_PATH = "--class-path";
|
||||||
|
static final String COMPILE_OPTION_CLASSPATH = "--classpath";
|
||||||
|
static final String COMPILE_OPTION_P = "-p";
|
||||||
|
static final String COMPILE_OPTION_MODULE_PATH = "--module-path";
|
||||||
|
|
||||||
private File buildMainDirectory_;
|
private File buildMainDirectory_;
|
||||||
private File buildTestDirectory_;
|
private File buildTestDirectory_;
|
||||||
private final List<String> compileMainClasspath_ = new ArrayList<>();
|
private final List<String> compileMainClasspath_ = new ArrayList<>();
|
||||||
|
@ -124,19 +131,33 @@ public class CompileOperation extends AbstractOperation<CompileOperation> {
|
||||||
try (var file_manager = compiler.getStandardFileManager(null, null, null)) {
|
try (var file_manager = compiler.getStandardFileManager(null, null, null)) {
|
||||||
var compilation_units = file_manager.getJavaFileObjectsFromFiles(sources);
|
var compilation_units = file_manager.getJavaFileObjectsFromFiles(sources);
|
||||||
var diagnostics = new DiagnosticCollector<JavaFileObject>();
|
var diagnostics = new DiagnosticCollector<JavaFileObject>();
|
||||||
var options = new ArrayList<>(List.of("-d", destination.getAbsolutePath()));
|
var options = new ArrayList<>(List.of(COMPILE_OPTION_D, destination.getAbsolutePath()));
|
||||||
|
|
||||||
if (!classpath.isEmpty()) {
|
if (!classpath.isEmpty()) {
|
||||||
options.addAll(List.of("-cp", FileUtils.joinPaths(classpath)));
|
var class_path = FileUtils.joinPaths(classpath);
|
||||||
|
class_path = removeAndAppendCompileOptionPath(class_path, COMPILE_OPTION_CP);
|
||||||
|
class_path = removeAndAppendCompileOptionPath(class_path, COMPILE_OPTION_CLASS_PATH);
|
||||||
|
class_path = removeAndAppendCompileOptionPath(class_path, COMPILE_OPTION_CLASSPATH);
|
||||||
|
|
||||||
|
options.addAll(List.of(COMPILE_OPTION_CP, class_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modulePath.isEmpty()) {
|
if (!modulePath.isEmpty()) {
|
||||||
options.addAll(List.of("-p", FileUtils.joinPaths(modulePath)));
|
var module_path = FileUtils.joinPaths(modulePath);
|
||||||
|
module_path = removeAndAppendCompileOptionPath(module_path, COMPILE_OPTION_P);
|
||||||
|
module_path = removeAndAppendCompileOptionPath(module_path, COMPILE_OPTION_MODULE_PATH);
|
||||||
|
|
||||||
|
options.addAll(List.of(COMPILE_OPTION_P, module_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
options.addAll(compileOptions());
|
options.addAll(compileOptions());
|
||||||
|
|
||||||
var compilation_task = compiler.getTask(null, file_manager, diagnostics, options, null, compilation_units);
|
var compilation_task = compiler.getTask(null, file_manager, diagnostics, options, null, compilation_units);
|
||||||
if (!compilation_task.call()) {
|
if (!compilation_task.call()) {
|
||||||
diagnostics_.addAll(diagnostics.getDiagnostics());
|
diagnostics_.addAll(diagnostics.getDiagnostics());
|
||||||
executeProcessDiagnostics(diagnostics);
|
executeProcessDiagnostics(diagnostics);
|
||||||
}
|
}
|
||||||
|
|
||||||
var module_info_class = new File(destination, "module-info.class");
|
var module_info_class = new File(destination, "module-info.class");
|
||||||
if (module_info_class.exists() && moduleMainClass() != null) {
|
if (module_info_class.exists() && moduleMainClass() != null) {
|
||||||
var orig_bytes = FileUtils.readBytes(module_info_class);
|
var orig_bytes = FileUtils.readBytes(module_info_class);
|
||||||
|
@ -146,6 +167,16 @@ public class CompileOperation extends AbstractOperation<CompileOperation> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String removeAndAppendCompileOptionPath(String basePath, String option) {
|
||||||
|
var index = compileOptions_.indexOf(option);
|
||||||
|
if (index != -1 && index + 1 < compileOptions_.size() - 1) {
|
||||||
|
compileOptions_.remove(index);
|
||||||
|
return basePath + File.pathSeparator + compileOptions_.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return basePath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Part of the {@link #execute} operation, processes the compilation diagnostics.
|
* Part of the {@link #execute} operation, processes the compilation diagnostics.
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,6 +14,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static rife.bld.operations.CompileOperation.COMPILE_OPTION_MODULE_PATH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for the standard javac tool.
|
* Options for the standard javac tool.
|
||||||
*
|
*
|
||||||
|
@ -410,7 +412,7 @@ public class JavacOptions extends ArrayList<String> {
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
public JavacOptions modulePathStrings(List<String> paths) {
|
public JavacOptions modulePathStrings(List<String> paths) {
|
||||||
add("--module-path");
|
add(COMPILE_OPTION_MODULE_PATH);
|
||||||
add(FileUtils.joinPaths(paths));
|
add(FileUtils.joinPaths(paths));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue