-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ions/avro/deployment/src/main/java/io/quarkus/avro/deployment/AvroIDLCodeGenProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.avro.deployment; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import org.apache.avro.Protocol; | ||
import org.apache.avro.compiler.idl.Idl; | ||
import org.apache.avro.compiler.idl.ParseException; | ||
import org.apache.avro.compiler.specific.SpecificCompiler; | ||
|
||
import io.quarkus.bootstrap.prebuild.CodeGenException; | ||
import io.quarkus.deployment.CodeGenProvider; | ||
|
||
public class AvroIDLCodeGenProvider extends AvroCodeGenProviderBase implements CodeGenProvider { | ||
@Override | ||
public String providerId() { | ||
return "avdl"; | ||
} | ||
|
||
@Override | ||
public String inputExtension() { | ||
return "avdl"; | ||
} | ||
|
||
@Override | ||
void init() { | ||
|
||
} | ||
|
||
@Override | ||
void compileSingleFile(Path filePath, Path outputDir, AvroOptions options) throws CodeGenException { | ||
try (Idl parser = new Idl(filePath.toFile())) { | ||
Protocol idlProtocol = parser.CompilationUnit(); | ||
String json = idlProtocol.toString(false); | ||
Protocol protocol = Protocol.parse(json); | ||
final SpecificCompiler compiler = new SpecificCompiler(protocol); | ||
compiler.setTemplateDir(templateDirectory); | ||
compiler.setStringType(options.stringType); | ||
compiler.setFieldVisibility(SpecificCompiler.FieldVisibility.PRIVATE); | ||
compiler.setCreateOptionalGetters(options.createOptionalGetters); | ||
compiler.setGettersReturnOptional(options.gettersReturnOptional); | ||
compiler.setOptionalGettersForNullableFieldsOnly(options.optionalGettersForNullableFieldsOnly); | ||
compiler.setCreateSetters(options.createSetters); | ||
compiler.setEnableDecimalLogicalType(options.enableDecimalLogicalType); | ||
|
||
compiler.setOutputCharacterEncoding("UTF-8"); | ||
compiler.compileToDestination(filePath.toFile(), outputDir.toFile()); | ||
} catch (IOException | ParseException e) { | ||
throw new CodeGenException("Failed to compile avro IDL file: " + filePath.toString() + " to Java", e); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...vro/deployment/src/main/resources/META-INF/services/io.quarkus.deployment.CodeGenProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
io.quarkus.avro.deployment.AvroIDLCodeGenProvider | ||
io.quarkus.avro.deployment.AvroSchemaCodeGenProvider | ||
io.quarkus.avro.deployment.AvroProtocolCodeGenProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@namespace("test") | ||
protocol Hello { | ||
|
||
enum Level{ | ||
LOW, MEDIUM, HIGH | ||
} | ||
|
||
record Message { | ||
string name; | ||
string desc; | ||
Level priority; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters