From 173a980baf0447956c7ffcba2742a9e7aba8477a Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Sun, 22 Sep 2024 10:28:14 +0100 Subject: [PATCH 1/2] GH-397: implement ability to specify JVM arguments to plugins --- .../invoker.properties | 17 +++++ .../pom.xml | 53 ++++++++++++++ .../protoc-plugin/pom.xml | 55 +++++++++++++++ .../example/protocplugin/ProtocPlugin.java | 38 ++++++++++ .../some-project/pom.xml | 68 ++++++++++++++++++ .../protobuf/org/example/helloworld.proto | 27 ++++++++ .../test.groovy | 38 ++++++++++ .../invoker.properties | 17 +++++ .../src/it/gh-397-jvm-plugin-jvm-args/pom.xml | 53 ++++++++++++++ .../protoc-plugin/pom.xml | 55 +++++++++++++++ .../example/protocplugin/ProtocPlugin.java | 42 +++++++++++ .../some-project/pom.xml | 69 +++++++++++++++++++ .../protobuf/org/example/helloworld.proto | 27 ++++++++ .../it/gh-397-jvm-plugin-jvm-args/test.groovy | 39 +++++++++++ .../mojo/AbstractGenerateMojo.java | 10 ++- .../plugins/JvmPluginResolver.java | 39 +++++++++-- .../plugins/MavenProtocPlugin.java | 29 ++++++++ 17 files changed, 670 insertions(+), 6 deletions(-) create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/invoker.properties create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/pom.xml create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/pom.xml create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/pom.xml create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/src/main/protobuf/org/example/helloworld.proto create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/test.groovy create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/invoker.properties create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/pom.xml create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/pom.xml create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/pom.xml create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/src/main/protobuf/org/example/helloworld.proto create mode 100644 protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/test.groovy diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/invoker.properties b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/invoker.properties new file mode 100644 index 00000000..71cb16da --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/invoker.properties @@ -0,0 +1,17 @@ +# +# Copyright (C) 2023 - 2024, Ashley Scopes. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +invoker.goals = clean package diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/pom.xml b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/pom.xml new file mode 100644 index 00000000..af27f960 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + + @project.groupId@ + protobuf-maven-plugin-parent + @project.version@ + ../../../../pom.xml + + + gh-397-jvm-plugin-commandline-args + parent + pom + + + protoc-plugin + some-project + + + + 4.28.2 + + + + + + com.google.protobuf + protobuf-java + ${protobuf.version} + + + + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/pom.xml b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/pom.xml new file mode 100644 index 00000000..bd0f8286 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/pom.xml @@ -0,0 +1,55 @@ + + + + 4.0.0 + + + gh-397-jvm-plugin-commandline-args + parent + @project.version@ + ../pom.xml + + + protoc-plugin + + + + com.google.protobuf + protobuf-java + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.example.protocplugin.ProtocPlugin + + + + + + + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java new file mode 100644 index 00000000..b20975b1 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 - 2024, Ashley Scopes. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.example.protocplugin; + +import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; +import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + +public class ProtocPlugin { + public static void main(String[] args) throws Throwable { + var request = CodeGeneratorRequest.parseFrom(System.in); + + var listingFile = CodeGeneratorResponse.File.newBuilder() + .setName("commandline-args.txt") + .setContent(String.join("\n", args)) + .build(); + + CodeGeneratorResponse.newBuilder() + .addFile(listingFile) + .build() + .writeTo(System.out); + } +} diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/pom.xml b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/pom.xml new file mode 100644 index 00000000..52cf1b2d --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + + gh-397-jvm-plugin-commandline-args + parent + @project.version@ + ../pom.xml + + + some-project + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + + ${project.groupId} + protoc-plugin + ${project.version} + + foo + bar + baz + + + + + false + ${protobuf.version} + + + + + + generate + + + + + + + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/src/main/protobuf/org/example/helloworld.proto b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/src/main/protobuf/org/example/helloworld.proto new file mode 100644 index 00000000..8d91946c --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/some-project/src/main/protobuf/org/example/helloworld.proto @@ -0,0 +1,27 @@ +// +// Copyright (C) 2023 - 2024, Ashley Scopes. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.example.helloworld"; + +package org.example.helloworld; + +message GreetingRequest { + string name = 1; +} + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/test.groovy b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/test.groovy new file mode 100644 index 00000000..6c1cf660 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-commandline-args/test.groovy @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 - 2024, Ashley Scopes. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.nio.file.Files +import java.nio.file.Path +import java.util.stream.Stream + +import static org.assertj.core.api.Assertions.assertThat + +Path baseProjectDir = basedir.toPath().toAbsolutePath() +Path protocPluginTargetDir = baseProjectDir.resolve("protoc-plugin") + .resolve("target") +Path expectedGeneratedFile = baseProjectDir.resolve("some-project") + .resolve("target") + .resolve("generated-sources") + .resolve("protobuf") + .resolve("commandline-args.txt") + +// Verify the JVM plugin produced the expected output file +assertThat(expectedGeneratedFile) + .exists() + .isRegularFile() + .hasContent("foo\nbar\nbaz") + +return true diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/invoker.properties b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/invoker.properties new file mode 100644 index 00000000..71cb16da --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/invoker.properties @@ -0,0 +1,17 @@ +# +# Copyright (C) 2023 - 2024, Ashley Scopes. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +invoker.goals = clean package diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/pom.xml b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/pom.xml new file mode 100644 index 00000000..6f4f9709 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + + @project.groupId@ + protobuf-maven-plugin-parent + @project.version@ + ../../../../pom.xml + + + gh-397-jvm-plugin-jvm-args + parent + pom + + + protoc-plugin + some-project + + + + 4.28.2 + + + + + + com.google.protobuf + protobuf-java + ${protobuf.version} + + + + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/pom.xml b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/pom.xml new file mode 100644 index 00000000..4ec49a19 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/pom.xml @@ -0,0 +1,55 @@ + + + + 4.0.0 + + + gh-397-jvm-plugin-jvm-args + parent + @project.version@ + ../pom.xml + + + protoc-plugin + + + + com.google.protobuf + protobuf-java + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.example.protocplugin.ProtocPlugin + + + + + + + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java new file mode 100644 index 00000000..945e0686 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/protoc-plugin/src/main/java/org/example/protocplugin/ProtocPlugin.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023 - 2024, Ashley Scopes. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.example.protocplugin; + +import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; +import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + +public class ProtocPlugin { + public static void main(String[] args) throws Throwable { + var request = CodeGeneratorRequest.parseFrom(System.in); + + var jvmArgs = new StringBuilder(); + System.getProperties() + .forEach((k, v) -> jvmArgs.append(k).append("=").append(v).append("\n")); + + var listingFile = CodeGeneratorResponse.File.newBuilder() + .setName("jvm-args.txt") + .setContent(jvmArgs.toString()) + .build(); + + CodeGeneratorResponse.newBuilder() + .addFile(listingFile) + .build() + .writeTo(System.out); + } +} diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/pom.xml b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/pom.xml new file mode 100644 index 00000000..a460891d --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/pom.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + + + gh-397-jvm-plugin-jvm-args + parent + @project.version@ + ../pom.xml + + + some-project + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + + ${project.groupId} + protoc-plugin + ${project.version} + + this-should-be-warned-as-invalid + -Xms100m + -Xmx128m + -Dthis.should.be.set=if it works + + + + + false + ${protobuf.version} + + + + + + generate + + + + + + + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/src/main/protobuf/org/example/helloworld.proto b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/src/main/protobuf/org/example/helloworld.proto new file mode 100644 index 00000000..8d91946c --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/some-project/src/main/protobuf/org/example/helloworld.proto @@ -0,0 +1,27 @@ +// +// Copyright (C) 2023 - 2024, Ashley Scopes. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.example.helloworld"; + +package org.example.helloworld; + +message GreetingRequest { + string name = 1; +} + diff --git a/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/test.groovy b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/test.groovy new file mode 100644 index 00000000..d378e414 --- /dev/null +++ b/protobuf-maven-plugin/src/it/gh-397-jvm-plugin-jvm-args/test.groovy @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2023 - 2024, Ashley Scopes. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.nio.file.Files +import java.nio.file.Path +import java.util.stream.Stream + +import static org.assertj.core.api.Assertions.assertThat + +Path baseProjectDir = basedir.toPath().toAbsolutePath() +Path protocPluginTargetDir = baseProjectDir.resolve("protoc-plugin") + .resolve("target") +Path expectedGeneratedFile = baseProjectDir.resolve("some-project") + .resolve("target") + .resolve("generated-sources") + .resolve("protobuf") + .resolve("jvm-args.txt") + +// Verify the JVM plugin produced the expected output file +assertThat(expectedGeneratedFile) + .exists() + .isRegularFile() + .content() + .containsOnlyOnce("this.should.be.set=if it works\n") + +return true diff --git a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java index 1d672d97..fcdfdea8 100644 --- a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java +++ b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java @@ -465,7 +465,8 @@ public AbstractGenerateMojo() { *
  • {@code version} - the version - required
  • *
  • {@code type} - the artifact type - optional
  • *
  • {@code classifier} - the artifact classifier - optional
  • - *
  • {@code options} - a string of options to pass to the plugin + *
  • {@code options} - a string of options to pass to the plugin. This + * uses the standard {@code protoc} interface for specifying options * - optional.
  • *
  • {@code order} - an integer order to run the plugins in. Defaults * to 100,000. Higher numbers run later than lower numbers.
  • @@ -479,6 +480,13 @@ public AbstractGenerateMojo() { * same project. If the plugin is an assembled JAR, then this option is * optional, the {@code Main-Class} manifest entry will be used when * present if this is not provided. + *
  • {@code jvmArgs} - a list of commandline arguments to pass to the + * plugin process - optional.
  • + *
  • {@code jvmConfigArgs} - a list of commandline arguments to configure + * the JVM itself. This is used to control factors such as JIT compilation, + * JVM properties, heap size, etc. Users should leave this as the default + * value (which optimises for short-lived processes) unless they know + * exactly what they are doing - optional. * * * @since 0.3.0 diff --git a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/JvmPluginResolver.java b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/JvmPluginResolver.java index 79c02ffd..d9696ad5 100644 --- a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/JvmPluginResolver.java +++ b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/JvmPluginResolver.java @@ -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; @@ -43,6 +44,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.function.Predicate; import java.util.jar.Manifest; import java.util.stream.Collectors; import javax.inject.Inject; @@ -70,6 +72,12 @@ public final class JvmPluginResolver { private static final Set ALLOWED_SCOPES = Set.of("compile", "runtime", "system"); + private static final List DEFAULT_JVM_ARGS = List.of(); + private static final List 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; @@ -150,11 +158,6 @@ private ArgumentFileBuilder buildArgLine(MavenProtocPlugin plugin) var args = new ArgumentFileBuilder(); - // JVM tuning flags to improve the performance of short-lived processes. - args.add("-Xshare:auto"); - args.add("-XX:+TieredCompilation"); - args.add("-XX:TieredStopAtLevel=1"); - // Caveat: we currently ignore the Class-Path JAR manifest entry. Not sure why we would want // to be using that here though, so I am leaving it unimplemented until such a time that someone // requests it. @@ -168,8 +171,16 @@ private ArgumentFileBuilder buildArgLine(MavenProtocPlugin plugin) args.add(buildJavaPath(modules)); } + requireNonNullElse(plugin.getJvmConfigArgs(), DEFAULT_JVM_CONFIG_ARGS) + .stream() + .filter(checkValidJvmConfigArg(plugin)) + .forEach(args::add); + args.add(determineMainClass(plugin, dependencies.get(0))); + requireNonNullElse(plugin.getJvmArgs(), DEFAULT_JVM_ARGS) + .forEach(args::add); + return args; } @@ -259,6 +270,24 @@ private List findJavaModules(List paths) { .collect(Collectors.toUnmodifiableList()); } + private Predicate checkValidJvmConfigArg(MavenProtocPlugin plugin) { + return arg -> { + // JVM args must begin with a hyphen, otherwise Java may interpret + // them as being the application entrypoint class and accidentally + // clobber the invocation. + if (arg.startsWith("-") && arg.length() > 1) { + return true; + } + + log.warn( + "Dropping illegal JVM argument '{}' for Maven plugin {}", + arg, + plugin.getArtifactId() + ); + return false; + }; + } + private Path writePosixScripts( String id, Path javaExecutable, diff --git a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/MavenProtocPlugin.java b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/MavenProtocPlugin.java index 35b17086..3d054ef9 100644 --- a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/MavenProtocPlugin.java +++ b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/MavenProtocPlugin.java @@ -18,6 +18,7 @@ import io.github.ascopes.protobufmavenplugin.dependencies.DependencyResolutionDepth; import io.github.ascopes.protobufmavenplugin.dependencies.MavenArtifact; +import java.util.List; import org.immutables.value.Value.Derived; import org.immutables.value.Value.Immutable; import org.immutables.value.Value.Modifiable; @@ -35,6 +36,23 @@ @Modifiable public interface MavenProtocPlugin extends MavenArtifact, ProtocPlugin { + /** + * Get the command line arguments to pass to the JVM. + * + *

    This defaults to an empty list. + * + * @return the list of command line arguments to pass to the JVM. + * @since 2.6.0 + */ + @Nullable List getJvmArgs(); + + /** + * The dependency resolution depth. + * + *

    This cannot be changed for this type of plugin. + * + * @return {@code null}, always. + */ @Derived @Override default @Nullable DependencyResolutionDepth getDependencyResolutionDepth() { @@ -42,6 +60,17 @@ public interface MavenProtocPlugin extends MavenArtifact, ProtocPlugin { return null; } + /** + * Get the arguments to pass to the JVM to configure it. + * + *

    Users can use this to control concerns such as heap memory controls, + * GC and JIT settings, and specifying additional JVM options. + * + * @return the list of command line arguments to pass to the JVM. + * @since 2.6.0 + */ + @Nullable List getJvmConfigArgs(); + /** * The main class entrypoint to use if the plugin is not an assembled JAR. * From ef91257aed7e0bcf4d8719f9290d964620fecab3 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Sun, 22 Sep 2024 10:47:01 +0100 Subject: [PATCH 2/2] GH-397: Bump version to 3.6.0 --- pom.xml | 2 +- protobuf-maven-plugin/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1fc6b26d..e186943b 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ io.github.ascopes protobuf-maven-plugin-parent - 2.5.1-SNAPSHOT + 2.6.0-SNAPSHOT Protobuf Maven Plugin Parent Parent POM for the Protobuf Maven Plugin. diff --git a/protobuf-maven-plugin/pom.xml b/protobuf-maven-plugin/pom.xml index e177a62a..08c0e93f 100644 --- a/protobuf-maven-plugin/pom.xml +++ b/protobuf-maven-plugin/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes protobuf-maven-plugin-parent - 2.5.1-SNAPSHOT + 2.6.0-SNAPSHOT protobuf-maven-plugin