Skip to content

Commit af87715

Browse files
authored
GH-687: Add src/main/proto and src/test/proto as directory roots for migration purposes (#692)
Closes GH-687.
1 parent a333e2e commit af87715

File tree

18 files changed

+494
-16
lines changed

18 files changed

+494
-16
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<groupId>io.github.ascopes</groupId>
2323
<artifactId>protobuf-maven-plugin-parent</artifactId>
24-
<version>3.3.2-SNAPSHOT</version>
24+
<version>3.4.0-SNAPSHOT</version>
2525

2626
<name>Protobuf Maven Plugin Parent</name>
2727
<description>Parent POM for the Protobuf Maven Plugin.</description>

protobuf-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>io.github.ascopes</groupId>
2424
<artifactId>protobuf-maven-plugin-parent</artifactId>
25-
<version>3.3.2-SNAPSHOT</version>
25+
<version>3.4.0-SNAPSHOT</version>
2626
</parent>
2727

2828
<artifactId>protobuf-maven-plugin</artifactId>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (C) 2023 - 2025, Ashley Scopes.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
invoker.goals = clean package
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (C) 2023 - 2025, Ashley Scopes.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>@project.groupId@.it</groupId>
26+
<artifactId>integration-test-parent</artifactId>
27+
<version>@project.version@</version>
28+
<relativePath>../setup/pom.xml</relativePath>
29+
</parent>
30+
31+
<groupId>java-main-legacy-source-directory</groupId>
32+
<artifactId>java-main-legacy-source-directory</artifactId>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>com.google.protobuf</groupId>
37+
<artifactId>protobuf-java</artifactId>
38+
<scope>compile</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
</plugin>
54+
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-surefire-plugin</artifactId>
58+
</plugin>
59+
60+
<plugin>
61+
<groupId>@project.groupId@</groupId>
62+
<artifactId>@project.artifactId@</artifactId>
63+
64+
<executions>
65+
<execution>
66+
<goals>
67+
<goal>generate</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Copyright (C) 2023 - 2025, Ashley Scopes.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
syntax = "proto3";
18+
19+
option java_multiple_files = true;
20+
option java_package = "org.example.helloworld";
21+
22+
package org.example.helloworld;
23+
24+
message GreetingRequest {
25+
string name = 1;
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2023 - 2025, Ashley Scopes.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.example.helloworld;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.util.ArrayList;
24+
import org.junit.jupiter.api.Test;
25+
26+
class ProtobufTest {
27+
@Test
28+
void generatedProtobufSourcesAreFullMessages() throws Throwable {
29+
// When
30+
var superClasses = new ArrayList<String>();
31+
Class<?> superClass = GreetingRequest.class;
32+
33+
do {
34+
superClasses.add(superClass.getName());
35+
superClass = superClass.getSuperclass();
36+
} while (superClass != null);
37+
38+
// Then
39+
// GeneratedMessageV3 for protobuf-java 3.25.3 and older.
40+
// GeneratedMessage for protobuf-java 4.26.0 and newer.
41+
assertTrue(superClasses.contains("com.google.protobuf.GeneratedMessage"));
42+
}
43+
44+
@Test
45+
void generatedProtobufSourcesAreValid() throws Throwable {
46+
// Given
47+
var expectedGreetingRequest = GreetingRequest
48+
.newBuilder()
49+
.setName("Ashley")
50+
.build();
51+
52+
// When
53+
var baos = new ByteArrayOutputStream();
54+
expectedGreetingRequest.writeTo(baos);
55+
var actualGreetingRequest = GreetingRequest.parseFrom(baos.toByteArray());
56+
57+
assertNotEquals(0, baos.toByteArray().length);
58+
59+
// Then
60+
assertEquals(expectedGreetingRequest.getName(), actualGreetingRequest.getName());
61+
}
62+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2023 - 2025, Ashley Scopes.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.nio.file.Path
17+
18+
import static org.assertj.core.api.Assertions.assertThat
19+
20+
Path baseDirectory = basedir.toPath().toAbsolutePath()
21+
Path generatedSourcesDir = baseDirectory.resolve("target/generated-sources/protobuf")
22+
Path classesDir = baseDirectory.resolve("target/classes")
23+
List<String> expectedGeneratedFiles = [
24+
"org/example/helloworld/Helloworld",
25+
"org/example/helloworld/GreetingRequest",
26+
"org/example/helloworld/GreetingRequestOrBuilder",
27+
]
28+
29+
assertThat(generatedSourcesDir).isDirectory()
30+
31+
assertThat(classesDir).isDirectory()
32+
33+
expectedGeneratedFiles.forEach {
34+
assertThat(generatedSourcesDir.resolve("${it}.java"))
35+
.exists()
36+
.isNotEmptyFile()
37+
assertThat(classesDir.resolve("${it}.class"))
38+
.exists()
39+
.isNotEmptyFile()
40+
}
41+
42+
return true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (C) 2023 - 2025, Ashley Scopes.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
invoker.goals = clean package
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (C) 2023 - 2025, Ashley Scopes.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>@project.groupId@.it</groupId>
26+
<artifactId>integration-test-parent</artifactId>
27+
<version>@project.version@</version>
28+
<relativePath>../setup/pom.xml</relativePath>
29+
</parent>
30+
31+
<groupId>java-test-legacy-source-directory</groupId>
32+
<artifactId>java-test-legacy-source-directory</artifactId>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>com.google.protobuf</groupId>
37+
<artifactId>protobuf-java</artifactId>
38+
<scope>compile</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
</plugin>
54+
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-jar-plugin</artifactId>
58+
<configuration>
59+
<skip>true</skip>
60+
</configuration>
61+
</plugin>
62+
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-surefire-plugin</artifactId>
66+
</plugin>
67+
68+
<plugin>
69+
<groupId>@project.groupId@</groupId>
70+
<artifactId>@project.artifactId@</artifactId>
71+
72+
<executions>
73+
<execution>
74+
<goals>
75+
<goal>generate-test</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>

0 commit comments

Comments
 (0)