Class JvmPluginResolver
java.lang.Object
io.github.ascopes.protobufmavenplugin.plugins.JvmPluginResolver
@Description("Resolves and packages JVM protoc plugins from various remote and local locations")
@Named
final class JvmPluginResolver
extends Object
Component that takes a reference to a pure-Java
protoc
plugin and wraps it in a shell
script or batch file to invoke it as if it were a single executable binary.
The aim is to support enabling protoc to invoke executables without creating native binaries first, which is error-prone and increases the complexity of this Maven plugin significantly.
This implementation is a rewrite as of v2.6.0 that now uses Java argument files to deal with argument quoting in a platform-agnostic way, since the specification for batch files is very poorly documented and full of edge cases that could cause builds to fail.
- Since:
- 2.6.0
- Author:
- Ashley Scopes
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MavenArtifactPathResolver
private final HostSystem
private static final org.slf4j.Logger
private final SystemPathBinaryResolver
private final TemporarySpace
-
Constructor Summary
ConstructorsConstructorDescriptionJvmPluginResolver
(HostSystem hostSystem, MavenArtifactPathResolver artifactPathResolver, TemporarySpace temporarySpace, SystemPathBinaryResolver pathResolver) -
Method Summary
Modifier and TypeMethodDescriptionprivate ArgumentFileBuilder
buildArgLine
(MavenProtocPlugin plugin) private String
buildJavaPath
(Iterable<Path> iterable) private String
determineMainClass
(MavenProtocPlugin plugin, Path pluginPath) findJavaModules
(List<Path> paths) private String
hashPlugin
(MavenProtocPlugin plugin, int index) private void
quoteBatchArg
(Appendable appendable, String arg) private void
quoteShellArg
(Appendable appendable, String arg) private ResolvedProtocPlugin
resolveMavenPlugin
(MavenProtocPlugin pluginDescriptor, int index) (package private) Collection
<? extends ResolvedProtocPlugin> resolveMavenPlugins
(Collection<? extends MavenProtocPlugin> pluginDescriptors) private @Nullable String
tryToDetermineMainClassFromJarManifest
(Path pluginPath) private static void
writeAndPropagateExceptions
(Path file, Charset charset, boolean makeExecutable, JvmPluginResolver.WriteOperation writeOperation) private Path
writeArgumentFile
(Charset charset, Path scratchDir, ArgumentFileBuilder argumentFileBuilder) private Path
writePosixScripts
(Path javaExecutable, Path scratchDir, ArgumentFileBuilder argFileBuilder) private Path
writeWindowsScripts
(Path javaExecutable, Path scratchDir, ArgumentFileBuilder argFileBuilder)
-
Field Details
-
ALLOWED_SCOPES
-
DEFAULT_JVM_ARGS
-
DEFAULT_JVM_CONFIG_ARGS
-
log
private static final org.slf4j.Logger log -
hostSystem
-
artifactPathResolver
-
temporarySpace
-
pathResolver
-
-
Constructor Details
-
JvmPluginResolver
@Inject JvmPluginResolver(HostSystem hostSystem, MavenArtifactPathResolver artifactPathResolver, TemporarySpace temporarySpace, SystemPathBinaryResolver pathResolver)
-
-
Method Details
-
resolveMavenPlugins
Collection<? extends ResolvedProtocPlugin> resolveMavenPlugins(Collection<? extends MavenProtocPlugin> pluginDescriptors) throws ResolutionException - Throws:
ResolutionException
-
resolveMavenPlugin
private ResolvedProtocPlugin resolveMavenPlugin(MavenProtocPlugin pluginDescriptor, int index) throws ResolutionException - Throws:
ResolutionException
-
hashPlugin
-
buildArgLine
- Throws:
ResolutionException
-
determineMainClass
private String determineMainClass(MavenProtocPlugin plugin, Path pluginPath) throws ResolutionException - Throws:
ResolutionException
-
tryToDetermineMainClassFromJarManifest
private @Nullable String tryToDetermineMainClassFromJarManifest(Path pluginPath) throws ResolutionException - Throws:
ResolutionException
-
buildJavaPath
-
findJavaModules
-
checkValidJvmConfigArg
-
writePosixScripts
private Path writePosixScripts(Path javaExecutable, Path scratchDir, ArgumentFileBuilder argFileBuilder) throws ResolutionException - Throws:
ResolutionException
-
writeWindowsScripts
private Path writeWindowsScripts(Path javaExecutable, Path scratchDir, ArgumentFileBuilder argFileBuilder) throws ResolutionException - Throws:
ResolutionException
-
writeArgumentFile
private Path writeArgumentFile(Charset charset, Path scratchDir, ArgumentFileBuilder argumentFileBuilder) throws ResolutionException - Throws:
ResolutionException
-
quoteShellArg
- Throws:
IOException
-
quoteBatchArg
- Throws:
IOException
-
writeAndPropagateExceptions
private static void writeAndPropagateExceptions(Path file, Charset charset, boolean makeExecutable, JvmPluginResolver.WriteOperation writeOperation) throws ResolutionException - Throws:
ResolutionException
-