Skip to content

Commit

Permalink
GH-397: Work around quirk in immutables defaults for unmodifiable col…
Browse files Browse the repository at this point in the history
…lections

Seems that immutables will not attempt to reconstruct mutable
variants of Lists from the default values, and Maven raises
no exceptions when this fails. Work-around for now is to use
null defaults.
  • Loading branch information
ascopes committed Sep 22, 2024
1 parent 804d59f commit db73ba2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.CREATE_NEW;
import static java.util.Objects.requireNonNullElse;

import io.github.ascopes.protobufmavenplugin.dependencies.DependencyResolutionDepth;
import io.github.ascopes.protobufmavenplugin.dependencies.MavenArtifactPathResolver;
Expand Down Expand Up @@ -71,6 +72,12 @@
public final class JvmPluginResolver {

private static final Set<String> ALLOWED_SCOPES = Set.of("compile", "runtime", "system");
private static final List<String> DEFAULT_JVM_ARGS = List.of();
private static final List<String> DEFAULT_JVM_CONFIG_ARGS = List.of(
"-Xshare:auto",
"-XX:+TieredCompilation",
"-XX:TieredStopAtLevel=1"
);
private static final Logger log = LoggerFactory.getLogger(JvmPluginResolver.class);

private final HostSystem hostSystem;
Expand Down Expand Up @@ -164,13 +171,15 @@ private ArgumentFileBuilder buildArgLine(MavenProtocPlugin plugin)
args.add(buildJavaPath(modules));
}

plugin.getJvmConfigArgs()
requireNonNullElse(plugin.getJvmConfigArgs(), DEFAULT_JVM_CONFIG_ARGS)
.stream()
.filter(checkValidJvmConfigArg(plugin))
.forEach(args::add);

args.add(determineMainClass(plugin, dependencies.get(0)));
plugin.getJvmArgs().forEach(args::add);

requireNonNullElse(plugin.getJvmArgs(), DEFAULT_JVM_ARGS)
.forEach(args::add);

return args;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public interface MavenProtocPlugin extends MavenArtifact, ProtocPlugin {
* @return the list of command line arguments to pass to the JVM.
* @since 2.6.0
*/
default List<String> getJvmArgs() {
return List.of();
}
@Nullable List<String> getJvmArgs();

/**
* The dependency resolution depth.
Expand All @@ -68,20 +66,10 @@ default List<String> getJvmArgs() {
* <p>Users can use this to control concerns such as heap memory controls,
* GC and JIT settings, and specifying additional JVM options.
*
* <p>This defaults to allowing shared JIT caches, and optimising the JIT
* for short-lived processes. Specifying this attribute overrides the default
* values.
*
* @return the list of command line arguments to pass to the JVM.
* @since 2.6.0
*/
default List<String> getJvmConfigArgs() {
return List.of(
"-Xshare:auto",
"-XX:+TieredCompilation",
"-XX:TieredStopAtLevel=1"
);
}
@Nullable List<String> getJvmConfigArgs();

/**
* The main class entrypoint to use if the plugin is not an assembled JAR.
Expand Down

0 comments on commit db73ba2

Please sign in to comment.