File tree Expand file tree Collapse file tree 6 files changed +47
-2
lines changed
pbj-compiler/src/main/java/com/hedera/pbj/compiler Expand file tree Collapse file tree 6 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ public abstract class PbjCompilerPlugin implements Plugin<Project> {
2929 */
3030 @ Override
3131 public void apply (Project project ) {
32+ // Register the PbjExtension to fetch optional parameters from Gradle files
33+ final PbjExtension pbj = project .getExtensions ().create ("pbj" , PbjExtension .class );
34+
3235 // get reference to java plugin
3336 final var javaPlugin = project .getExtensions ().getByType (JavaPluginExtension .class );
3437 // get java src sets
@@ -61,6 +64,7 @@ public void apply(Project project) {
6164 pbjTask .setSource (pbjSourceSet );
6265 pbjTask .getJavaMainOutputDirectory ().set (outputDirectoryMain );
6366 pbjTask .getJavaTestOutputDirectory ().set (outputDirectoryTest );
67+ pbjTask .getJavaPackageSuffix ().set (pbj .getJavaPackageSuffix ());
6468 });
6569
6670 // 5) register fact that pbj should be run before compiling by informing the 'java' part
Original file line number Diff line number Diff line change 44import javax .inject .Inject ;
55import org .gradle .api .file .DirectoryProperty ;
66import org .gradle .api .internal .file .FileOperations ;
7+ import org .gradle .api .provider .Property ;
8+ import org .gradle .api .tasks .Input ;
9+ import org .gradle .api .tasks .Optional ;
710import org .gradle .api .tasks .OutputDirectory ;
811import org .gradle .api .tasks .SourceTask ;
912import org .gradle .api .tasks .TaskAction ;
@@ -33,6 +36,11 @@ public abstract class PbjCompilerTask extends SourceTask {
3336 @ Inject
3437 protected abstract FileOperations getFileOperations ();
3538
39+ /** An optional Java package suffix for PBJ-generated classes when `pbj.java_package` is missing. */
40+ @ Optional
41+ @ Input
42+ public abstract Property <String > getJavaPackageSuffix ();
43+
3644 /**
3745 * Perform task action - Generates all the PBJ java source files
3846 *
@@ -46,6 +54,6 @@ public void perform() throws Exception {
4654 getSource (),
4755 getJavaMainOutputDirectory ().get ().getAsFile (),
4856 getJavaTestOutputDirectory ().get ().getAsFile (),
49- null );
57+ getJavaPackageSuffix (). getOrNull () );
5058 }
5159}
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+ package com .hedera .pbj .compiler ;
3+
4+ import org .gradle .api .provider .Property ;
5+
6+ /** A Gradle extension to pass parameters to the PbjCompilerPlugin. */
7+ public interface PbjExtension {
8+ /**
9+ * An optional suffix to append to Java package names of PBJ-generated classes
10+ * when the Protobuf model is missing an explicit `pbj.java_package` option and PBJ has to
11+ * derive the Java package name from the standard `java_package` option or otherwise.
12+ * @return the suffix property
13+ */
14+ Property <String > getJavaPackageSuffix ();
15+ }
Original file line number Diff line number Diff line change 1- 0.10.0 -SNAPSHOT
1+ 0.10.1 -SNAPSHOT
Original file line number Diff line number Diff line change @@ -61,6 +61,9 @@ dependencyAnalysis { issues { all { onAny { exclude("com.hedera.pbj:pbj-compiler
6161// IMPROVE: JMH code should not depend on test code
6262jmh { includeTests = true }
6363
64+ // Avoid a clash with Google protoc models when .proto files don't specify `pbj.java_package`:
65+ pbj { javaPackageSuffix = " .pbj.integration.tests" }
66+
6467// Add downloaded HAPI repo protobuf files into build directory and add to sources to build them
6568val cloneHederaProtobufs =
6669 tasks.register<GitClone >(" cloneHederaProtobufs" ) {
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+ syntax = "proto3" ;
3+
4+ package proto ;
5+
6+ // Test when only the java_package is specified. Do not specify the pbj.java_package option.
7+ option java_package = "com.hedera.pbj.test.proto" ;
8+ option java_multiple_files = true ;
9+
10+ /**
11+ * Sample protobuf.
12+ */
13+ message MessageInAPackage {
14+ bytes bytesField = 1 ;
15+ }
You can’t perform that action at this time.
0 commit comments