Skip to content

Commit

Permalink
Added support for setting the bld build file java and javac options t…
Browse files Browse the repository at this point in the history
…hrough bld-wrapper.properties. Fixes #33.
  • Loading branch information
gbevin committed May 23, 2024
1 parent 57c4b20 commit aca7aa4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
bld.version=1.9.2-SNAPSHOT
37 changes: 36 additions & 1 deletion src/main/java/rife/bld/wrapper/Wrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("<snapshotVersion>.*?<value>([^<]+)</value>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
static final Pattern OPTIONS_PATTERN = Pattern.compile("\"[^\"]+\"|\\S+");


private File currentDir_ = new File(System.getProperty("user.dir"));

Expand Down Expand Up @@ -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}
"""
Expand Down Expand Up @@ -514,6 +521,7 @@ private int launchMainCli(File jarFile, List<String> arguments)
args.add("-jar");
args.add(jarFile.getAbsolutePath());

args.addAll(bldJavaOptions());
args.addAll(arguments);

var process_builder = new ProcessBuilder(args);
Expand Down Expand Up @@ -545,6 +553,7 @@ private int launchMainBuild(File jarFile, List<String> arguments)
var compilation_units = file_manager.getJavaFileObjectsFromFiles(bldSourceFiles());
var diagnostics = new DiagnosticCollector<JavaFileObject>();
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()) {
Expand All @@ -560,9 +569,13 @@ private int launchMainBuild(File jarFile, List<String> arguments)
var java_args = new ArrayList<String>();
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();
Expand Down Expand Up @@ -615,6 +628,28 @@ public List<File> bldSourceFiles() {
return source_files;
}

public List<String> 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<String> 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();
Expand Down

1 comment on commit aca7aa4

@hrstoyanov
Copy link

Choose a reason for hiding this comment

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

@gbevin would you make a release to make this official, please?

Please sign in to comment.