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

Support passing option to Java compiler (fix #64) #70

Merged
merged 2 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions src/it/TEST-36/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2016 Maven Protocol Buffers Plugin Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# An optional description for this build job to be included in the build reports.
invoker.description = Verifies that Java generation works for lite runtime, using additional generator options

# 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 compile
65 changes: 65 additions & 0 deletions src/it/TEST-36/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright (c) 2016 Maven Protocol Buffers Plugin Authors. All rights reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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>org.xolstice.maven.plugins.protobuf.its</groupId>
<artifactId>it-parent</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>test-36</artifactId>
<version>1.0.0</version>

<name>Integration Test 36</name>

<properties>
<protobufJavaArtifact>protobuf-javalite</protobufJavaArtifact>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>@project.version@</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<javaOptions>lite</javaOptions>
</configuration>
</execution>
</executions>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:${protobufVersion}:exe:${os.detected.classifier}
</protocArtifact>
</configuration>
</plugin>
</plugins>
</build>
</project>
36 changes: 36 additions & 0 deletions src/it/TEST-36/src/main/proto/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright (c) 2016 Maven Protocol Buffers Plugin Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

syntax = "proto3";

option java_package = "test";
option java_outer_classname = "TestProtos";
option optimize_for = SPEED;

message TestMessage {
message NestedMessage {
int32 bb = 1;
}

enum NestedEnum {
FOO = 0;
BAR = 1;
BAZ = 2;
}

// Singular
int32 optional_int32 = 1;
}
31 changes: 31 additions & 0 deletions src/it/TEST-36/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2016 Maven Protocol Buffers Plugin Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

outputDirectory = new File(basedir, 'target/generated-sources/protobuf/java');
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');
assert content.contains('com.google.protobuf.GeneratedMessageLite');

return true;
5 changes: 3 additions & 2 deletions src/it/setup-it-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

<mavenVersion>3.3.9</mavenVersion>

<protobufVersion>3.6.1</protobufVersion>
<protobufVersion>3.9.1</protobufVersion>
sergei-ivanov marked this conversation as resolved.
Show resolved Hide resolved
<protobufJavaArtifact>protobuf-java</protobufJavaArtifact>
</properties>

<build>
Expand Down Expand Up @@ -163,7 +164,7 @@
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<artifactId>${protobufJavaArtifact}</artifactId>
<version>${protobufVersion}</version>
</dependency>
<!-- Test dependencies -->
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/xolstice/maven/plugin/protobuf/Protoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ public List<String> buildProtocCommand() {
command.add("--proto_path=" + protoPathElement);
}
if (javaOutputDirectory != null) {
command.add("--java_out=" + javaOutputDirectory);
String outputOption = "--java_out=";
if (nativePluginParameter != null) {
outputOption += nativePluginParameter + ':';
}
outputOption += javaOutputDirectory;
command.add(outputOption);

// For now we assume all custom plugins produce Java output
for (final ProtocPlugin plugin : plugins) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,27 @@ public final class ProtocCompileMojo extends AbstractProtocCompileMojo {
defaultValue = "${project.build.directory}/generated-sources/protobuf/java"
)
private File outputDirectory;


/**
* Additional comma-separated options to be passed to the Java generator.
* <b>Cannot</b> contain colon (<tt>:</tt>) symbols.
*/
sergei-ivanov marked this conversation as resolved.
Show resolved Hide resolved
@Parameter(
required = false,
property = "javaOptions"
)
private String javaOptions;
sergei-ivanov marked this conversation as resolved.
Show resolved Hide resolved

@Override
protected void addProtocBuilderParameters(final Protoc.Builder protocBuilder) {
super.addProtocBuilderParameters(protocBuilder);
if (javaOptions != null) {
protocBuilder.setNativePluginParameter(javaOptions);
}
protocBuilder.setJavaOutputDirectory(getOutputDirectory());
}

@Override
protected File getOutputDirectory() {
return outputDirectory;
Expand Down