Skip to content

Commit

Permalink
Allow ProtoPlugin to specify an executable artifact that does not nee…
Browse files Browse the repository at this point in the history
…d to be run by Java
  • Loading branch information
cheister committed Apr 28, 2020
1 parent efd74cc commit ba3bd35
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
15 changes: 15 additions & 0 deletions src/it/TEST-16/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
</properties>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.5.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
Expand Down Expand Up @@ -70,6 +77,14 @@
<arg>prefix-</arg>
</args>
</protocPlugin>
<protocPlugin>
<id>grpc-java</id>
<groupId>io.grpc</groupId>
<artifactId>protoc-gen-grpc-java</artifactId>
<version>1.12.0</version>
<type>exe</type>
<classifier>${os.detected.classifier}</classifier>
</protocPlugin>
</protocPlugins>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -560,7 +567,8 @@ protected void createProtocPlugins() {
remoteRepositories,
protocPluginDirectory,
getLog());
assembler.execute();
assembler.execute();
}
}
}

Expand Down
32 changes: 26 additions & 6 deletions src/main/java/org/xolstice/maven/plugin/protobuf/ProtocPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ProtocPlugin {

private String version;

private String type;

private String classifier;

private String mainClass;
Expand All @@ -63,6 +65,8 @@ public class ProtocPlugin {

private List<String> jvmArgs;

private File executableFile;

/**
* Returns the unique id for this plugin.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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);
}
Expand Down Expand Up @@ -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());
}
}
}

Expand All @@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void resolvePluginDependencies() {
pluginDefinition.getGroupId(),
pluginDefinition.getArtifactId(),
versionSpec,
"jar",
pluginDefinition.getType() != null ? pluginDefinition.getType() : "jar",
pluginDefinition.getClassifier(),
Artifact.SCOPE_RUNTIME);

Expand Down

0 comments on commit ba3bd35

Please sign in to comment.