Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ProtoPlugin to specify an executable artifact that does not need to be run by Java #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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