This is an automated email from the ASF dual-hosted git repository.
opwvhk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/main by this push:
new 70d6e7c348 AVRO-4098: [maven-plugin]: make protocol-idl mojo support
all compiler options [AVRO-4098] (#3261)
70d6e7c348 is described below
commit 70d6e7c34820cc2babf6c43f0b3a155835740c02
Author: Alex Riedler <[email protected]>
AuthorDate: Tue Jun 10 12:19:31 2025 -0400
AVRO-4098: [maven-plugin]: make protocol-idl mojo support all compiler
options [AVRO-4098] (#3261)
* AVRO-40980: [maven-plugin] make mojos support all compiler options
Keep compiler settings DRY, in particular make idl-protocol support
for createNullSafeAnnotations flag
* AVRO-4098: Add test case
---------
Co-authored-by: Oscar Westra van Holthe - Kind <[email protected]>
---
.../main/java/org/apache/avro/mojo/AbstractAvroMojo.java | 16 ++++++++++------
.../src/main/java/org/apache/avro/mojo/IDLMojo.java | 12 +-----------
.../src/test/java/org/apache/avro/mojo/TestIDLMojo.java | 3 ++-
.../maven-plugin/src/test/resources/unit/idl/pom.xml | 1 +
4 files changed, 14 insertions(+), 18 deletions(-)
diff --git
a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
index 282801cbbf..5615df36e3 100644
---
a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
+++
b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
@@ -422,8 +422,7 @@ public abstract class AbstractAvroMojo extends AbstractMojo
{
doCompile(sourceFileForModificationDetection, new
SpecificCompiler(protocol), outputDirectory);
}
- private void doCompile(File sourceFileForModificationDetection,
SpecificCompiler compiler, File outputDirectory)
- throws IOException {
+ protected void setCompilerProperties(SpecificCompiler compiler) {
compiler.setTemplateDir(templateDirectory);
compiler.setStringType(GenericData.StringType.valueOf(stringType));
compiler.setFieldVisibility(getFieldVisibility());
@@ -435,6 +434,15 @@ public abstract class AbstractAvroMojo extends
AbstractMojo {
compiler.setNullSafeAnnotationNullable(nullSafeAnnotationNullable);
compiler.setNullSafeAnnotationNotNull(nullSafeAnnotationNotNull);
compiler.setEnableDecimalLogicalType(enableDecimalLogicalType);
+
compiler.setOutputCharacterEncoding(project.getProperties().getProperty("project.build.sourceEncoding"));
+ compiler.setAdditionalVelocityTools(instantiateAdditionalVelocityTools());
+ compiler.setRecordSpecificClass(this.recordSpecificClass);
+ compiler.setErrorSpecificClass(this.errorSpecificClass);
+ }
+
+ private void doCompile(File sourceFileForModificationDetection,
SpecificCompiler compiler, File outputDirectory)
+ throws IOException {
+ setCompilerProperties(compiler);
try {
for (String customConversion : customConversions) {
compiler.addCustomConversion(Thread.currentThread().getContextClassLoader().loadClass(customConversion));
@@ -442,10 +450,6 @@ public abstract class AbstractAvroMojo extends
AbstractMojo {
} catch (ClassNotFoundException e) {
throw new IOException(e);
}
-
compiler.setOutputCharacterEncoding(project.getProperties().getProperty("project.build.sourceEncoding"));
- compiler.setAdditionalVelocityTools(instantiateAdditionalVelocityTools());
- compiler.setRecordSpecificClass(this.recordSpecificClass);
- compiler.setErrorSpecificClass(this.errorSpecificClass);
compiler.compileToDestination(sourceFileForModificationDetection,
outputDirectory);
}
diff --git
a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLMojo.java
b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLMojo.java
index 632ce7f955..f2a379a5fb 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLMojo.java
@@ -20,7 +20,6 @@ package org.apache.avro.mojo;
import org.apache.avro.Protocol;
import org.apache.avro.compiler.specific.SpecificCompiler;
-import org.apache.avro.generic.GenericData;
import org.apache.avro.idl.IdlFile;
import org.apache.avro.idl.IdlReader;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -97,19 +96,10 @@ public class IDLMojo extends AbstractAvroMojo {
} else {
compiler = new SpecificCompiler(idlFile.getNamedSchemas().values());
}
- compiler.setStringType(GenericData.StringType.valueOf(stringType));
- compiler.setTemplateDir(templateDirectory);
- compiler.setFieldVisibility(getFieldVisibility());
- compiler.setCreateOptionalGetters(createOptionalGetters);
- compiler.setGettersReturnOptional(gettersReturnOptional);
-
compiler.setOptionalGettersForNullableFieldsOnly(optionalGettersForNullableFieldsOnly);
- compiler.setCreateSetters(createSetters);
-
compiler.setAdditionalVelocityTools(instantiateAdditionalVelocityTools());
- compiler.setEnableDecimalLogicalType(enableDecimalLogicalType);
+ setCompilerProperties(compiler);
for (String customConversion : customConversions) {
compiler.addCustomConversion(projPathLoader.loadClass(customConversion));
}
-
compiler.setOutputCharacterEncoding(project.getProperties().getProperty("project.build.sourceEncoding"));
compiler.compileToDestination(sourceFilePath.toFile(),
outputDirectory);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
diff --git
a/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLMojo.java
b/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLMojo.java
index ab6cd7c966..59819ae4de 100644
--- a/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLMojo.java
+++ b/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLMojo.java
@@ -61,7 +61,8 @@ public class TestIDLMojo extends AbstractAvroMojoTest {
assertFilesExist(outputDir, generatedFiles);
final String idlUserContent = FileUtils.fileRead(new File(outputDir,
"IdlUser.java"));
- assertTrue(idlUserContent.contains("java.time.Instant"));
+ assertTrue(idlUserContent.contains("@org.jetbrains.annotations.Nullable\n
public java.lang.String getId"));
+ assertTrue(idlUserContent.contains("@org.jetbrains.annotations.NotNull\n
public java.time.Instant getModifiedOn"));
assertEquals(Collections.singletonList("[WARN] Line 22, char 1: Ignoring
out-of-place documentation comment.\n"
+ "Did you mean to use a multiline comment ( /* ... */ ) instead?"),
log.getLogEntries());
diff --git a/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml
b/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml
index aae65a9792..aa53c4babd 100644
--- a/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml
+++ b/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml
@@ -47,6 +47,7 @@
<sourceDirectory>${basedir}/src/test</sourceDirectory>
<outputDirectory>${basedir}/target/test-harness/idl</outputDirectory>
<stringType>String</stringType>
+ <createNullSafeAnnotations>true</createNullSafeAnnotations>
<project
implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub"/>
</configuration>
</plugin>