Skip to content

Commit

Permalink
AVRO-40980: [maven-plugin] make mojos support all compiler options
Browse files Browse the repository at this point in the history
Keep compiler settings DRY, in particular make idl-protocol support
for createNullSafeAnnotations flag
  • Loading branch information
AlexRiedler committed Dec 9, 2024
1 parent 0fd1e78 commit c225a84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ protected void doCompile(File sourceFileForModificationDetection, Protocol proto
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());
Expand All @@ -406,17 +405,22 @@ private void doCompile(File sourceFileForModificationDetection, SpecificCompiler
compiler.setCreateSetters(createSetters);
compiler.setCreateNullSafeAnnotations(createNullSafeAnnotations);
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));
}
} 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,10 @@ protected void doCompile(String filename, File sourceDirectory, File outputDirec
} 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);
Expand Down

0 comments on commit c225a84

Please sign in to comment.