Skip to content

Commit

Permalink
Added integration test for test sources generation with javalite
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-ivanov committed Jan 17, 2020
1 parent 6b6c1dd commit 70f78c2
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/it/TEST-36/invoker.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2016 Maven Protocol Buffers Plugin Authors. All rights reserved.
# Copyright (c) 2019 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.
Expand All @@ -15,8 +15,8 @@
#

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

<!--
~ Copyright (c) 2016 Maven Protocol Buffers Plugin Authors. All rights reserved.
~ Copyright (c) 2019 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.
Expand Down Expand Up @@ -32,9 +32,9 @@
<version>1.0.0</version>

<name>Integration Test 36</name>

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

<build>
Expand All @@ -43,7 +43,6 @@
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>@project.version@</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
Expand Down
22 changes: 22 additions & 0 deletions src/it/TEST-37/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2019 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 test protos and 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 test-compile
64 changes: 64 additions & 0 deletions src/it/TEST-37/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright (c) 2019 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-37</artifactId>
<version>1.0.0</version>

<name>Integration Test 37</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>
<executions>
<execution>
<goals>
<goal>test-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-37/src/test/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-37/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2019 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-test-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;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.xolstice.maven.plugin.protobuf;

/*
* Copyright (c) 2018 Maven Protocol Buffers Plugin Authors. All rights reserved.
* Copyright (c) 2019 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.
Expand Down Expand Up @@ -47,10 +47,11 @@ 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.
*
* @since 0.7.0
*/
@Parameter(
Expand All @@ -67,7 +68,7 @@ protected void addProtocBuilderParameters(final Protoc.Builder protocBuilder) {
}
protocBuilder.setJavaOutputDirectory(getOutputDirectory());
}

@Override
protected File getOutputDirectory() {
return outputDirectory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.xolstice.maven.plugin.protobuf;

/*
* Copyright (c) 2018 Maven Protocol Buffers Plugin Authors. All rights reserved.
* Copyright (c) 2019 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.
Expand Down Expand Up @@ -49,10 +49,11 @@ public final class ProtocTestCompileMojo extends AbstractProtocTestCompileMojo {
defaultValue = "${project.build.directory}/generated-test-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.
*
* @since 0.7.0
*/
@Parameter(
Expand All @@ -65,7 +66,7 @@ public final class ProtocTestCompileMojo extends AbstractProtocTestCompileMojo {
protected void addProtocBuilderParameters(final Protoc.Builder protocBuilder) {
super.addProtocBuilderParameters(protocBuilder);
if (javaOptions != null) {
protocBuilder.setNativePluginParameter(javaOptions);
protocBuilder.setNativePluginParameter(javaOptions);
}
protocBuilder.setJavaOutputDirectory(getOutputDirectory());
// We need to add project output directory to the protobuf import paths,
Expand Down

0 comments on commit 70f78c2

Please sign in to comment.