This repository has been archived by the owner on Feb 12, 2018. It is now read-only.
forked from dtrott/maven-protoc-plugin
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-added integration test
- Loading branch information
Showing
9 changed files
with
222 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# An optional description for this build job to be included in the build reports. | ||
invoker.description = Verifies that javanano generation works | ||
|
||
# A comma or space separated list of goals/phases to execute, may | ||
# specify an empty list to execute the default goal of the IT project | ||
invoker.goals = clean generate-sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.google.protobuf.tools.maven-protoc-plugin.its</groupId> | ||
<artifactId>it-parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>TEST-26</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<name>Integration Test 26</name> | ||
|
||
<build> | ||
<extensions> | ||
<extension> | ||
<groupId>kr.motd.maven</groupId> | ||
<artifactId>os-maven-plugin</artifactId> | ||
<version>1.3.0.Final</version> | ||
</extension> | ||
</extensions> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>com.google.protobuf.tools</groupId> | ||
<artifactId>maven-protoc-plugin</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile-javanano</goal> | ||
</goals> | ||
<configuration> | ||
<protocArtifact>com.google.protobuf:protoc:2.6.1:exe:${os.detected.classifier} | ||
</protocArtifact> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package integration_test; | ||
|
||
option java_package = "test"; | ||
option java_outer_classname = "TestProtos"; | ||
option parcelable_messages = true; | ||
|
||
message TestMessage { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
outputDirectory = new File(basedir, 'target/generated-sources/protobuf/javanano'); | ||
assert outputDirectory.exists(); | ||
assert outputDirectory.isDirectory(); | ||
|
||
generatedJavaFile = new File(outputDirectory, 'test/TestProtos.java'); | ||
assert generatedJavaFile.exists(); | ||
assert generatedJavaFile.isFile(); | ||
|
||
content = generatedJavaFile.text; | ||
assert content.contains('package test'); | ||
assert content.contains('class Test'); | ||
assert content.contains('class TestMessage'); | ||
|
||
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/google/protobuf/maven/ProtocCompileJavaNanoMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.google.protobuf.maven; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.plugins.annotations.ResolutionScope; | ||
|
||
/** | ||
* This mojo executes the {@code protoc} compiler for generating main Java sources | ||
* from protocol buffer definitions. It also searches dependency artifacts for | ||
* {@code .proto} files and includes them in the {@code proto_path} so that they can be | ||
* referenced. Finally, it adds the {@code .proto} files to the project as resources so | ||
* that they are included in the final artifact. | ||
* | ||
* @since 0.4.3 | ||
*/ | ||
@Mojo( | ||
name = "compile-javanano", | ||
defaultPhase = LifecyclePhase.GENERATE_SOURCES, | ||
requiresDependencyResolution = ResolutionScope.COMPILE, | ||
threadSafe = true | ||
) | ||
public final class ProtocCompileJavaNanoMojo extends AbstractProtocCompileMojo { | ||
|
||
/** | ||
* This is the directory into which the {@code .java} will be created. | ||
*/ | ||
@Parameter( | ||
required = true, | ||
defaultValue = "${project.build.directory}/generated-sources/protobuf/javanano" | ||
) | ||
private File outputDirectory; | ||
|
||
@Override | ||
protected void addProtocBuilderParameters(final Protoc.Builder protocBuilder) throws MojoExecutionException { | ||
super.addProtocBuilderParameters(protocBuilder); | ||
protocBuilder.setJavaNanoOutputDirectory(getOutputDirectory()); | ||
} | ||
|
||
@Override | ||
protected File getOutputDirectory() { | ||
return outputDirectory; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/google/protobuf/maven/ProtocTestCompileJavaNanoMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.google.protobuf.maven; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.plugins.annotations.ResolutionScope; | ||
|
||
/** | ||
* This mojo executes the {@code protoc} compiler for generating test Java sources | ||
* from protocol buffer definitions. It also searches dependency artifacts in the test scope for | ||
* {@code .proto} files and includes them in the {@code proto_path} so that they can be | ||
* referenced. Finally, it adds the {@code .proto} files to the project as test resources so | ||
* that they can be included in the test-jar artifact. | ||
* | ||
* @since 0.4.3 | ||
*/ | ||
@Mojo( | ||
name = "test-compile-javanano", | ||
defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, | ||
requiresDependencyResolution = ResolutionScope.TEST, | ||
threadSafe = true | ||
) | ||
public class ProtocTestCompileJavaNanoMojo extends AbstractProtocTestCompileMojo { | ||
|
||
/** | ||
* This is the directory into which the {@code .java} test sources will be created. | ||
*/ | ||
@Parameter( | ||
required = true, | ||
defaultValue = "${project.build.directory}/generated-test-sources/protobuf/javanano" | ||
) | ||
private File outputDirectory; | ||
|
||
@Override | ||
protected void addProtocBuilderParameters(final Protoc.Builder protocBuilder) throws MojoExecutionException { | ||
super.addProtocBuilderParameters(protocBuilder); | ||
protocBuilder.setJavaNanoOutputDirectory(getOutputDirectory()); | ||
// We need to add project output directory to the protobuf import paths, | ||
// in case test protobuf definitions extend or depend on production ones | ||
final File buildOutputDirectory = new File(project.getBuild().getOutputDirectory()); | ||
if (buildOutputDirectory.exists()) { | ||
protocBuilder.addProtoPathElement(buildOutputDirectory); | ||
} | ||
} | ||
|
||
@Override | ||
protected File getOutputDirectory() { | ||
return outputDirectory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters