From aca7aa41a946ec06ada1d5cc4477965552be0728 Mon Sep 17 00:00:00 2001 From: Geert Bevin Date: Thu, 23 May 2024 07:53:16 -0400 Subject: [PATCH] Added support for setting the bld build file java and javac options through bld-wrapper.properties. Fixes #33. --- lib/bld/bld-wrapper.properties | 6 ++-- src/main/java/rife/bld/wrapper/Wrapper.java | 37 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index 31dfcb2..1976594 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,9 +1,11 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true +bld.downloadLocation= bld.extension-antlr=com.uwyn.rife2:bld-antlr4:1.2.8 bld.extension-archive=com.uwyn.rife2:bld-archive:0.4.8 bld.extension-tests=com.uwyn.rife2:bld-tests-badge:1.4.8 +bld.javaOptions= +bld.javacOptions= bld.repositories=MAVEN_CENTRAL,RIFE2_RELEASES -bld.downloadLocation= bld.sourceDirectories=core/src/bld/java -bld.version=1.9.1 \ No newline at end of file +bld.version=1.9.2-SNAPSHOT \ No newline at end of file diff --git a/src/main/java/rife/bld/wrapper/Wrapper.java b/src/main/java/rife/bld/wrapper/Wrapper.java index 4779312..41c42fd 100644 --- a/src/main/java/rife/bld/wrapper/Wrapper.java +++ b/src/main/java/rife/bld/wrapper/Wrapper.java @@ -18,6 +18,7 @@ import java.security.NoSuchAlgorithmException; import java.util.*; import java.util.jar.*; +import java.util.regex.MatchResult; import java.util.regex.Pattern; import static rife.tools.FileUtils.JAR_FILE_PATTERN; @@ -52,9 +53,13 @@ public class Wrapper { static final String PROPERTY_DOWNLOAD_EXTENSION_SOURCES = "bld.downloadExtensionSources"; static final String PROPERTY_DOWNLOAD_EXTENSION_JAVADOC = "bld.downloadExtensionJavadoc"; static final String PROPERTY_SOURCE_DIRECTORIES = "bld.sourceDirectories"; + static final String PROPERTY_JAVAC_OPTIONS = "bld.javacOptions"; + static final String PROPERTY_JAVA_OPTIONS = "bld.javaOptions"; static final File BLD_USER_DIR = new File(System.getProperty("user.home"), ".bld"); static final File DISTRIBUTIONS_DIR = new File(BLD_USER_DIR, "dist"); static final Pattern META_DATA_SNAPSHOT_VERSION = Pattern.compile(".*?([^<]+)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); + static final Pattern OPTIONS_PATTERN = Pattern.compile("\"[^\"]+\"|\\S+"); + private File currentDir_ = new File(System.getProperty("user.dir")); @@ -164,9 +169,11 @@ private void createWrapperProperties(File destinationDirectory, String version) var properties_blueprint = """ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true + bld.downloadLocation= bld.extensions= + bld.javaOptions= + bld.javacOptions= bld.repositories=MAVEN_CENTRAL,RIFE2_RELEASES - bld.downloadLocation= bld.sourceDirectories= bld.version=${version} """ @@ -514,6 +521,7 @@ private int launchMainCli(File jarFile, List arguments) args.add("-jar"); args.add(jarFile.getAbsolutePath()); + args.addAll(bldJavaOptions()); args.addAll(arguments); var process_builder = new ProcessBuilder(args); @@ -545,6 +553,7 @@ private int launchMainBuild(File jarFile, List arguments) var compilation_units = file_manager.getJavaFileObjectsFromFiles(bldSourceFiles()); var diagnostics = new DiagnosticCollector(); var options = new ArrayList<>(List.of("-d", buildBldDirectory().getAbsolutePath(), "-cp", classpath)); + options.addAll(bldJavacOptions()); var compilation_task = compiler.getTask(null, file_manager, diagnostics, options, null, compilation_units); if (!compilation_task.call()) { if (!diagnostics.getDiagnostics().isEmpty()) { @@ -560,9 +569,13 @@ private int launchMainBuild(File jarFile, List arguments) var java_args = new ArrayList(); java_args.add("java"); includeJvmParameters(arguments, java_args); + java_args.add("-cp"); java_args.add(classpath); + + java_args.addAll(bldJavaOptions()); java_args.addAll(arguments); + var process_builder = new ProcessBuilder(java_args); process_builder.directory(currentDir_); process_builder.inheritIO(); @@ -615,6 +628,28 @@ public List bldSourceFiles() { return source_files; } + public List bldJavacOptions() { + if (!wrapperProperties_.containsKey(PROPERTY_JAVAC_OPTIONS)) { + return Collections.emptyList(); + } + + return OPTIONS_PATTERN.matcher(wrapperProperties_.get(PROPERTY_JAVAC_OPTIONS).toString()) + .results() + .map(MatchResult::group) + .toList(); + } + + public List bldJavaOptions() { + if (!wrapperProperties_.containsKey(PROPERTY_JAVA_OPTIONS)) { + return Collections.emptyList(); + } + + return OPTIONS_PATTERN.matcher(wrapperProperties_.get(PROPERTY_JAVA_OPTIONS).toString()) + .results() + .map(MatchResult::group) + .toList(); + } + private String readString(String version, URL url) throws IOException { var connection = url.openConnection();