Skip to content

Commit 5d24ee1

Browse files
authored
Merge pull request #67 from ZenWave360/feature/avro-schema-generator
Feature/avro schema generator
2 parents 81d6e26 + b999047 commit 5d24ee1

File tree

20 files changed

+750
-3
lines changed

20 files changed

+750
-3
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
generate-summary: true
4040
jacoco-csv-file: >
4141
./plugins/asyncapi-spring-cloud-streams3/target/site/jacoco/jacoco.csv
42+
./plugins/avro-schema-compiler/target/site/jacoco/jacoco.csv
4243
./plugins/java-to-jdl/target/site/jacoco/jacoco.csv
4344
./plugins/java-to-asyncapi/target/site/jacoco/jacoco.csv
4445
./plugins/backend-application-default/target/site/jacoco/jacoco.csv

.github/workflows/publish-maven-central.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
generate-summary: true
5252
jacoco-csv-file: >
5353
./plugins/asyncapi-spring-cloud-streams3/target/site/jacoco/jacoco.csv
54+
./plugins/avro-schema-compiler/target/site/jacoco/jacoco.csv
5455
./plugins/java-to-jdl/target/site/jacoco/jacoco.csv
5556
./plugins/java-to-asyncapi/target/site/jacoco/jacoco.csv
5657
./plugins/backend-application-default/target/site/jacoco/jacoco.csv

.github/workflows/publish-maven-snapshots.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
generate-summary: true
4545
jacoco-csv-file: >
4646
./plugins/asyncapi-spring-cloud-streams3/target/site/jacoco/jacoco.csv
47+
./plugins/avro-schema-compiler/target/site/jacoco/jacoco.csv
4748
./plugins/java-to-jdl/target/site/jacoco/jacoco.csv
4849
./plugins/java-to-asyncapi/target/site/jacoco/jacoco.csv
4950
./plugins/backend-application-default/target/site/jacoco/jacoco.csv
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Avro Schema Generator
2+
> 👉 ZenWave360 Helps You Create Software Easy to Understand
3+
4+
[![Maven Central](https://img.shields.io/maven-central/v/io.zenwave360.sdk/zenwave-sdk.svg?label=Maven%20Central&logo=apachemaven)](https://search.maven.org/artifact/io.zenwave360.sdk/zenwave-sdk)
5+
[![GitHub](https://img.shields.io/github/license/ZenWave360/zenwave-sdk)](https://github.com/ZenWave360/zenwave-sdk/blob/main/LICENSE)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>io.zenwave360.sdk</groupId>
6+
<artifactId>plugins-parent</artifactId>
7+
<version>2.1.0-SNAPSHOT</version>
8+
</parent>
9+
<name>${project.groupId}:${project.artifactId}</name>
10+
<groupId>io.zenwave360.sdk.plugins</groupId>
11+
<artifactId>avro-schema-compiler</artifactId>
12+
<packaging>jar</packaging>
13+
14+
<properties>
15+
<avro-compiler.version>1.12.0</avro-compiler.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.apache.avro</groupId>
21+
<artifactId>avro-compiler</artifactId>
22+
<version>${avro-compiler.version}</version>
23+
<scope>provided</scope>
24+
</dependency>
25+
</dependencies>
26+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package io.zenwave360.sdk.plugins;
2+
3+
import io.zenwave360.sdk.doc.DocumentedOption;
4+
import org.apache.avro.Conversion;
5+
import org.apache.avro.LogicalTypes;
6+
7+
import java.io.File;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
public class AvroCompilerProperties {
12+
13+
@DocumentedOption(description = "Avro schema file or folder containing avro schemas")
14+
public File sourceDirectory;
15+
16+
@DocumentedOption(description = "Avro schema files or folders containing avro schemas")
17+
public List<String> imports;
18+
19+
@DocumentedOption(description = "A set of Ant-like inclusion patterns used to select files from the source tree that are to be processed. By default, the pattern **\\/*.avsc is used to include all avro schema files.")
20+
public List<String> includes = List.of("**/*.avsc");
21+
22+
@DocumentedOption(description = "A set of Ant-like exclusion patterns used to prevent certain files from being processed. By default, this set is empty such that no files are excluded.")
23+
public List<String> excludes;
24+
25+
public String templateDirectory = "/org/apache/avro/compiler/specific/templates/java/classic/";
26+
public String stringType = "CharSequence";
27+
public String fieldVisibility = "PRIVATE";
28+
public boolean createOptionalGetters = false;
29+
public boolean gettersReturnOptional = false;
30+
public boolean optionalGettersForNullableFieldsOnly = false;
31+
public boolean createSetters = true;
32+
public boolean createNullSafeAnnotations = false;
33+
public String nullSafeAnnotationNullable = "org.jetbrains.annotations.Nullable";
34+
public String nullSafeAnnotationNotNull = "org.jetbrains.annotations.NotNull";
35+
public boolean enableDecimalLogicalType = false;
36+
public String outputCharacterEncoding = "UTF-8";
37+
public List<String> velocityToolsClassesNames = new ArrayList<>();
38+
public String recordSpecificClass = "org.apache.avro.specific.SpecificRecordBase";
39+
public String errorSpecificClass = "org.apache.avro.specific.SpecificExceptionBase";
40+
41+
@DocumentedOption(description = "Custom Logical Type Factories")
42+
public List<Class<? extends LogicalTypes.LogicalTypeFactory>> customLogicalTypeFactories;
43+
44+
@DocumentedOption(description = "Custom Conversions")
45+
public List<Class<? extends Conversion<?>>> customConversions;
46+
47+
public List<Object> instantiateAdditionalVelocityTools() {
48+
final List<Object> velocityTools = new ArrayList<>(velocityToolsClassesNames.size());
49+
for (String velocityToolClassName : velocityToolsClassesNames) {
50+
try {
51+
Class<?> klass = Class.forName(velocityToolClassName);
52+
velocityTools.add(klass.getDeclaredConstructor().newInstance());
53+
} catch (Exception e) {
54+
throw new RuntimeException(e);
55+
}
56+
}
57+
return velocityTools;
58+
}
59+
}

0 commit comments

Comments
 (0)