diff --git a/src/it/TEST-16/pom.xml b/src/it/TEST-16/pom.xml index 65bbe9c3..0f9406a2 100644 --- a/src/it/TEST-16/pom.xml +++ b/src/it/TEST-16/pom.xml @@ -39,6 +39,13 @@ + + + kr.motd.maven + os-maven-plugin + 1.5.0.Final + + org.xolstice.maven.plugins @@ -70,6 +77,14 @@ prefix- + + grpc-java + io.grpc + protoc-gen-grpc-java + 1.12.0 + exe + ${os.detected.classifier} + diff --git a/src/main/java/org/xolstice/maven/plugin/protobuf/AbstractProtocMojo.java b/src/main/java/org/xolstice/maven/plugin/protobuf/AbstractProtocMojo.java index 1d20aeed..0c01782d 100644 --- a/src/main/java/org/xolstice/maven/plugin/protobuf/AbstractProtocMojo.java +++ b/src/main/java/org/xolstice/maven/plugin/protobuf/AbstractProtocMojo.java @@ -540,16 +540,23 @@ protected void createProtocPlugins() { final String javaHome = detectJavaHome(); for (final ProtocPlugin plugin : protocPlugins) { + getLog().info("Building protoc plugin: " + plugin.getId()); - if (plugin.getJavaHome() != null) { - getLog().debug("Using javaHome defined in plugin definition: " + plugin.getJavaHome()); + if (plugin.getMainClass() == null) { + final Artifact pluginArtifact = createDependencyArtifact(plugin.getGroupId(), plugin.getArtifactId(), + plugin.getVersion(), plugin.getType(), plugin.getClassifier()); + final File file = resolveBinaryArtifact(pluginArtifact); + getLog().debug("Setting executableFile for plugin: " + file.getAbsolutePath()); + plugin.setExecutableFile(file); } else { - getLog().debug("Setting javaHome for plugin: " + javaHome); - plugin.setJavaHome(javaHome); - } + if (plugin.getJavaHome() != null) { + getLog().debug("Using javaHome defined in plugin definition: " + plugin.getJavaHome()); + } else { + getLog().debug("Setting javaHome for plugin: " + javaHome); + plugin.setJavaHome(javaHome); + } - getLog().info("Building protoc plugin: " + plugin.getId()); - final ProtocPluginAssembler assembler = new ProtocPluginAssembler( + final ProtocPluginAssembler assembler = new ProtocPluginAssembler( plugin, session, project.getArtifact(), @@ -560,7 +567,8 @@ protected void createProtocPlugins() { remoteRepositories, protocPluginDirectory, getLog()); - assembler.execute(); + assembler.execute(); + } } } diff --git a/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPlugin.java b/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPlugin.java index fab66814..22c24076 100644 --- a/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPlugin.java +++ b/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPlugin.java @@ -48,6 +48,8 @@ public class ProtocPlugin { private String version; + private String type; + private String classifier; private String mainClass; @@ -63,6 +65,8 @@ public class ProtocPlugin { private List jvmArgs; + private File executableFile; + /** * Returns the unique id for this plugin. * @@ -100,6 +104,15 @@ public String getVersion() { return version; } + /** + * Returns an optional type of the plugin's artifact for dependency resolution. + * + * @return the plugin's artifact type. + */ + public String getType() { + return type; + } + /** * Returns an optional classifier of the plugin's artifact for dependency resolution. * @@ -152,6 +165,10 @@ public String getPluginName() { return "protoc-gen-" + id; } + public void setExecutableFile(final File executableFile) { + this.executableFile = executableFile; + } + /** * Validate the state of this plugin specification. * @@ -170,9 +187,6 @@ public void validate(final Log log) { if (version == null) { throw new MojoConfigurationException("version must be set in protocPlugin definition"); } - if (mainClass == null) { - throw new MojoConfigurationException("mainClass must be set in protocPlugin definition"); - } if (javaHome == null || !new File(javaHome).isDirectory()) { throw new MojoConfigurationException("javaHome is invalid: " + javaHome); } @@ -223,10 +237,14 @@ private boolean archDirectoryExists(String arch) { * @return file handle for the plugin executable. */ public File getPluginExecutableFile(final File pluginDirectory) { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - return new File(pluginDirectory, getPluginName() + ".exe"); + if (executableFile != null) { + return executableFile; } else { - return new File(pluginDirectory, getPluginName()); + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + return new File(pluginDirectory, getPluginName() + ".exe"); + } else { + return new File(pluginDirectory, getPluginName()); + } } } @@ -237,12 +255,14 @@ public String toString() { ", groupId='" + groupId + '\'' + ", artifactId='" + artifactId + '\'' + ", version='" + version + '\'' + + ", type='" + type + '\'' + ", classifier='" + classifier + '\'' + ", mainClass='" + mainClass + '\'' + ", javaHome='" + javaHome + '\'' + ", winJvmDataModel='" + winJvmDataModel + '\'' + ", args=" + args + ", jvmArgs=" + jvmArgs + + ", executableFile=" + executableFile + '}'; } } diff --git a/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPluginAssembler.java b/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPluginAssembler.java index aded96db..a59a5d8b 100644 --- a/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPluginAssembler.java +++ b/src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPluginAssembler.java @@ -258,7 +258,7 @@ private void resolvePluginDependencies() { pluginDefinition.getGroupId(), pluginDefinition.getArtifactId(), versionSpec, - "jar", + pluginDefinition.getType() != null ? pluginDefinition.getType() : "jar", pluginDefinition.getClassifier(), Artifact.SCOPE_RUNTIME);