|
30 | 30 | import io.github.ascopes.protobufmavenplugin.plugins.MavenProtocPluginBean; |
31 | 31 | import io.github.ascopes.protobufmavenplugin.plugins.PathProtocPluginBean; |
32 | 32 | import io.github.ascopes.protobufmavenplugin.plugins.UriProtocPluginBean; |
| 33 | +import io.github.ascopes.protobufmavenplugin.utils.Digest; |
33 | 34 | import java.nio.file.Files; |
34 | 35 | import java.nio.file.Path; |
35 | 36 | import java.util.Collection; |
@@ -60,11 +61,13 @@ public abstract class AbstractGenerateMojo extends AbstractMojo { |
60 | 61 | private static final String DEFAULT_TRUE = "true"; |
61 | 62 | private static final String DEFAULT_TRANSITIVE = "TRANSITIVE"; |
62 | 63 |
|
| 64 | + private static final String PROTOBUF_COMPILER_DIGEST = "protobuf.compiler.digest"; |
63 | 65 | private static final String PROTOBUF_COMPILER_EXCLUDES = "protobuf.compiler.excludes"; |
64 | 66 | private static final String PROTOBUF_COMPILER_INCLUDES = "protobuf.compiler.includes"; |
65 | 67 | private static final String PROTOBUF_COMPILER_INCREMENTAL = "protobuf.compiler.incremental"; |
66 | 68 | private static final String PROTOBUF_COMPILER_VERSION = "protobuf.compiler.version"; |
67 | 69 | private static final String PROTOBUF_SKIP = "protobuf.skip"; |
| 70 | + private static final String PROTOC_ALIAS = "protoc"; |
68 | 71 |
|
69 | 72 | private static final Logger log = LoggerFactory.getLogger(AbstractGenerateMojo.class); |
70 | 73 |
|
@@ -264,6 +267,10 @@ public AbstractGenerateMojo() { |
264 | 267 | * no effect, and the project-wide setting is used. If explicitly |
265 | 268 | * specified, then the project setting is ignored in favour of this |
266 | 269 | * value instead.</li> |
| 270 | + * <li>{@code digest} - an optional digest to verify the binary against. |
| 271 | + * If specified, this is a string in the format {@code sha512:1a2b3c4d...}, |
| 272 | + * using any supported message digest provided by your JDK (e.g. {@code md5}, |
| 273 | + * {@code sha1}, {@code sha256}, {@code sha512}, etc).</li> |
267 | 274 | * </ul> |
268 | 275 | * |
269 | 276 | * @since 2.0.0 |
@@ -731,6 +738,22 @@ public AbstractGenerateMojo() { |
731 | 738 | @Parameter(defaultValue = DEFAULT_FALSE) |
732 | 739 | boolean phpEnabled; |
733 | 740 |
|
| 741 | + /** |
| 742 | + * Optional digest to verify {@code protoc} against. |
| 743 | + * |
| 744 | + * <p>Generally, you will not need to provide this, as the Maven Central |
| 745 | + * {@code protoc} binaries will already be digest-verified as part of distribution. |
| 746 | + * You may wish to specify this if you are using a {@code PATH}-based binary, or |
| 747 | + * using a URL for {@code protoc}. |
| 748 | + * |
| 749 | + * <p>This is a string in the format {@code sha512:1a2b3c...}, using any |
| 750 | + * message digest algorithm supported by your JDK. |
| 751 | + * |
| 752 | + * @since 3.5.0 |
| 753 | + */ |
| 754 | + @Parameter(property = PROTOBUF_COMPILER_DIGEST) |
| 755 | + @Nullable Digest protocDigest; |
| 756 | + |
734 | 757 | /** |
735 | 758 | * Specifies where to find {@code protoc} or which version to download. |
736 | 759 | * |
@@ -768,7 +791,11 @@ public AbstractGenerateMojo() { |
768 | 791 | * |
769 | 792 | * @since 0.0.1 |
770 | 793 | */ |
771 | | - @Parameter(required = true, property = PROTOBUF_COMPILER_VERSION) |
| 794 | + @Parameter( |
| 795 | + alias = PROTOC_ALIAS, |
| 796 | + required = true, |
| 797 | + property = PROTOBUF_COMPILER_VERSION |
| 798 | + ) |
772 | 799 | String protocVersion; |
773 | 800 |
|
774 | 801 | /** |
@@ -912,7 +939,7 @@ public AbstractGenerateMojo() { |
912 | 939 | * Override the source directories to compile from. |
913 | 940 | * |
914 | 941 | * <p>Leave unspecified or explicitly null/empty to use the defaults. |
915 | | - * |
| 942 | + * |
916 | 943 | * <p><strong>Note that specifying custom directories will override the default |
917 | 944 | * directories rather than adding to them.</strong> |
918 | 945 | * |
@@ -1037,6 +1064,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { |
1037 | 1064 | .outputDescriptorIncludeSourceInfo(outputDescriptorIncludeSourceInfo) |
1038 | 1065 | .outputDescriptorRetainOptions(outputDescriptorRetainOptions) |
1039 | 1066 | .outputDirectory(outputDirectory()) |
| 1067 | + .protocDigest(protocDigest) |
1040 | 1068 | .protocVersion(protocVersion()) |
1041 | 1069 | .registerAsCompilationRoot(registerAsCompilationRoot) |
1042 | 1070 | .sourceDependencies(nonNullList(sourceDependencies)) |
|
0 commit comments