Skip to content

Commit

Permalink
Merge pull request #4 from anilkulkarni87/feature/gradleVersionCatalog
Browse files Browse the repository at this point in the history
Added gradle version catalog features
  • Loading branch information
anilkulkarni87 authored Nov 22, 2023
2 parents 1211606 + baa45e3 commit 2459269
Show file tree
Hide file tree
Showing 24 changed files with 905 additions and 103 deletions.
56 changes: 23 additions & 33 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,63 +1,54 @@
plugins{
id'java'
id"com.github.davidmc24.gradle.plugin.avro" version"1.7.0"
id"com.github.node-gradle.node" version"3.5.1"
alias(libs.plugins.com.github.davidmc24.gradle.plugin.avro)
alias(libs.plugins.com.github.node.gradle.node)
id'checkstyle'
id("org.openrewrite.rewrite") version("6.5.4")
id"com.github.imflog.kafka-schema-registry-gradle-plugin" version"1.12.0"
alias(libs.plugins.org.openrewrite.rewrite)
alias(libs.plugins.com.github.imflog.kafka.schema.registry.gradle.plugin)
alias(libs.plugins.com.github.ben.manes.versions)
alias(libs.plugins.nl.littlerobots.version.catalog.update)
}

group'com.lavro'
version'1.0-SNAPSHOT'

repositories{
mavenCentral()
maven{
url"https://clojars.org/repo/"
}
maven{
url"https://packages.confluent.io/maven"
}
}

dependencies{
testImplementation'org.junit.jupiter:junit-jupiter-api:5.10.0'
testRuntimeOnly'org.junit.jupiter:junit-jupiter-engine:5.10.0'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
implementation'org.slf4j:slf4j-api:2.0.9'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
implementation'org.slf4j:slf4j-simple:2.0.9'
implementation"org.apache.avro:avro:1.11.1"
// https://mvnrepository.com/artifact/net.datafaker/datafaker
implementation'net.datafaker:datafaker:1.7.0'
testRuntimeOnly libs.org.junit.jupiter.junit.jupiter.engine
testImplementation libs.org.junit.jupiter.junit.jupiter.api

implementation libs.org.slf4j.slf4j.api
implementation libs.org.slf4j.slf4j.simple
implementation libs.org.apache.avro
implementation libs.net.datafaker

implementation(project(":schemas"))
implementation(project(":custom-conversions"))
implementation'org.apache.kafka:kafka-clients:3.5.1'
// https://mvnrepository.com/artifact/io.confluent/kafka-avro-serializer
implementation'io.confluent:kafka-avro-serializer:5.3.0'
rewrite("org.openrewrite.recipe:rewrite-static-analysis:1.1.0")

implementation libs.org.apache.kafka.kafka.clients
implementation libs.io.confluent.kafka.avro.serializer
// rewrite("org.openrewrite.recipe:rewrite-static-analysis:1.1.0")


}

def rewriteRunTask = tasks.named("rewriteRun")
//def rewriteRunTask = tasks.named("rewriteRun")

test{
useJUnitPlatform()
}

rewrite{
activeRecipe("org.openrewrite.staticanalysis.CodeCleanup")
}
//rewrite{
// activeRecipe("org.openrewrite.staticanalysis.CodeCleanup")
//}
checkstyle{
toolVersion'10.12.5'
toolVersion = libs.versions.checkstyle.get()
configFile(file("config/checkstyle/checkstyle.xml"))
}


tasks.withType(Checkstyle) {
dependsOn(rewriteRunTask)
// dependsOn(rewriteRunTask)
reports{
xml.required = true
html.required = true
Expand All @@ -81,4 +72,3 @@ schemaRegistry{
subject("customerrecord", "schemas/build/generated-main-avro-avsc/com/dataanada/customer/CustomerRecord.avsc", "AVRO")
}
}

19 changes: 6 additions & 13 deletions custom-conversions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ plugins {
group 'com.lavro'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
maven {
url "https://clojars.org/repo/"
}
}

dependencies {
implementation "org.apache.avro:avro:1.11.1"
implementation 'com.github.davidmc24.gradle.plugin:gradle-avro-plugin:1.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
// https://mvnrepository.com/artifact/clojure-interop/javax.crypto
implementation 'clojure-interop:javax.crypto:1.0.5'
testImplementation 'clojure-interop:javax.crypto:1.0.5'
implementation libs.org.apache.avro
implementation libs.com.github.davidmc24.gradle.plugin.gradle.avro.plugin
testRuntimeOnly libs.org.junit.jupiter.junit.jupiter.engine
testImplementation libs.org.junit.jupiter.junit.jupiter.api
implementation libs.clojure.interop.javax.crypto
testImplementation libs.clojure.interop.javax.crypto

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static String encrypt(String plaintext) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getIV());
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
int padding_len = cipher.getBlockSize() - (new_data.length % cipher.getBlockSize());
int padding_len = cipher.getBlockSize() - new_data.length % cipher.getBlockSize();
byte[] padding = new byte[padding_len];
for (int i = 0; i < padding_len; i++) {
padding[i] = (byte) padding_len;
Expand All @@ -62,12 +62,18 @@ public static String encrypt(String plaintext) throws Exception {
}

public static String decrypt(String encryptedData) throws Exception {
if(encryptedData == null){
return null;
}
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getEncoded(), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getIV());
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);

byte[] encrypted = Base64.getDecoder().decode(encryptedData);

byte[] decrypted = cipher.doFinal(encrypted);

int padding_len = decrypted[decrypted.length - 1];
byte[] unpadded_data = new byte[decrypted.length - padding_len];
System.arraycopy(decrypted, 0, unpadded_data, 0, unpadded_data.length);
Expand All @@ -76,7 +82,9 @@ public static String decrypt(String encryptedData) throws Exception {

public String toCharSequence(CharSequence value, Schema schema, LogicalType type) {
try {
// String plaintext = Base64.getEncoder().encodeToString(value.array());
System.out.println(value);
System.out.println(schema);
System.out.println(type);
String encrypted = encrypt(String.valueOf(value));
System.out.println("When writing to Avro ToByteBuffer is :" + encrypted.toString());
return encrypted;
Expand All @@ -88,7 +96,9 @@ public String toCharSequence(CharSequence value, Schema schema, LogicalType type
@Override
public CharSequence fromCharSequence(CharSequence bytes, Schema schema, LogicalType type) {
try {
// String encryptedText = Base64.getEncoder().encodeToString(bytes.array());
System.out.println(bytes);
System.out.println(schema);
System.out.println(type);
String decryptedText = decrypt((String.valueOf(bytes)));
System.out.println("When reading from the avro file FromByteBuffer is :" + decryptedText);
return decryptedText;
Expand Down
28 changes: 14 additions & 14 deletions docs/avrodoc/avrodoc.html

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[versions]
org-junit-jupiter = "5.10.0"
org-slf4j = "2.0.9"
javax-crypto="1.0.5"
davidmc24-gradle-plugin-gradle-avro-plugin="1.9.1"
checkstyle="10.12.5"
confluent-kafka-avro-serializer="5.3.0"
confluent-kafka-schema-registry="7.5.1"
datafaker="1.7.0"
apache-avro="1.11.2"
apache-kafka-kafka-clients="3.6.0"
logging-log4j-log4j-core="2.17.1"


ben-manes-versions="0.50.0"
kafka-schema-registry-gradle-plugin="1.12.0"
gradle-node="7.0.1"
littlerobots-version-catalog-update="0.8.1"
rewrite="6.5.4"

[libraries]
clojure-interop-javax-crypto = { module = "clojure-interop:javax.crypto", version.ref="javax-crypto" }
com-github-davidmc24-gradle-plugin-gradle-avro-plugin = {module="com.github.davidmc24.gradle.plugin:gradle-avro-plugin", version.ref="davidmc24-gradle-plugin-gradle-avro-plugin"}
com-puppycrawl-tools-checkstyle = {module="com.puppycrawl.tools:checkstyle", version.ref="checkstyle"}
io-confluent-kafka-avro-serializer = {module="io.confluent:kafka-avro-serializer", version.ref="confluent-kafka-avro-serializer"}
io-confluent-kafka-schema-registry = {module="io.confluent:kafka-schema-registry", version.ref="confluent-kafka-schema-registry"}
net-datafaker = {module="net.datafaker:datafaker", version.ref="datafaker"}
org-apache-avro = {module="org.apache.avro:avro", version.ref="apache-avro"}
org-apache-kafka-kafka-clients = {module="org.apache.kafka:kafka-clients", version.ref="apache-kafka-kafka-clients"}
org-apache-logging-log4j-log4j-core = {module="org.apache.logging.log4j:log4j-core", version.ref="logging-log4j-log4j-core"}
org-junit-jupiter-junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "org-junit-jupiter" }
org-junit-jupiter-junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "org-junit-jupiter" }
org-slf4j-slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "org-slf4j" }
org-slf4j-slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "org-slf4j" }

[plugins]
com-github-ben-manes-versions = {id="com.github.ben-manes.versions",version.ref="ben-manes-versions"}
com-github-davidmc24-gradle-plugin-avro = {id="com.github.davidmc24.gradle.plugin.avro",version.ref="davidmc24-gradle-plugin-gradle-avro-plugin"}
com-github-davidmc24-gradle-plugin-avro-base = {id="com.github.davidmc24.gradle.plugin.avro-base",version.ref="davidmc24-gradle-plugin-gradle-avro-plugin"}
com-github-imflog-kafka-schema-registry-gradle-plugin = {id="com.github.imflog.kafka-schema-registry-gradle-plugin",version.ref="kafka-schema-registry-gradle-plugin"}
com-github-node-gradle-node = {id="com.github.node-gradle.node",version.ref="gradle-node"}
nl-littlerobots-version-catalog-update = {id="nl.littlerobots.version-catalog-update",version.ref="littlerobots-version-catalog-update"}
org-openrewrite-rewrite = {id="org.openrewrite.rewrite",version.ref="rewrite"}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file modified query.avro
Binary file not shown.
65 changes: 27 additions & 38 deletions schemas/build.gradle
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
import com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask
import com.github.davidmc24.gradle.plugin.avro.GenerateAvroProtocolTask
import com.github.davidmc24.gradle.plugin.avro.GenerateAvroSchemaTask

import org.apache.avro.Schema
import org.apache.avro.SchemaCompatibility
import org.apache.avro.SchemaCompatibility.SchemaCompatibilityType

plugins {
id 'java'
id "com.github.davidmc24.gradle.plugin.avro" version "1.7.0"
id "com.github.node-gradle.node" version "3.5.1"
alias(libs.plugins.com.github.davidmc24.gradle.plugin.avro)
alias(libs.plugins.com.github.node.gradle.node)
}

apply plugin: "com.github.davidmc24.gradle.plugin.avro-base"

group 'com.lavro'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
maven {
url "https://clojars.org/repo/"
}
maven {
url "https://packages.confluent.io/maven"
}
}

configurations {
customConversions
}

dependencies {
customConversions(project(":custom-conversions"))
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'org.scala-lang:scala-library:2.13.10'
implementation "org.apache.avro:avro:1.11.1"
testRuntimeOnly libs.org.junit.jupiter.junit.jupiter.engine
testImplementation libs.org.junit.jupiter.junit.jupiter.api
implementation libs.org.apache.avro
// https://mvnrepository.com/artifact/io.confluent/kafka-schema-registry
implementation 'io.confluent:kafka-schema-registry:7.5.1'
implementation(project(":custom-conversions"))
implementation libs.io.confluent.kafka.schema.registry
implementation(project(":custom-conversions"))

}
Expand All @@ -44,15 +36,10 @@ test {
useJUnitPlatform()
}

//task generateProtocol(type: GenerateAvroProtocolTask) {
// shouldRunAfter "build"
// source file("src/main/avro")
// include("**/*.avdl")
// outputDir = file("build/generated-main-avro-avpr")
//}

def generateProtocol = tasks.register("generateProtocol", GenerateAvroProtocolTask) {
shouldRunAfter("build")
println "Running generateProtocol"
source file("src/main/avro")
include("**/*.avdl")
outputDir = file("build/generated-main-avro-avpr")
Expand All @@ -61,19 +48,27 @@ def generateProtocol = tasks.register("generateProtocol", GenerateAvroProtocolTa
def generateSchema=tasks.register("generateSchema", GenerateAvroSchemaTask) {
// shouldRunAfter("GenerateAvroProtocolTask")
dependsOn generateProtocol
println "Running generateSchema"
source file("src/main/avro")
source file("build/generated-main-avro-avpr")
include("**/*.avpr")
outputDir = file("build/generated-main-avro-avsc")
}

//task generateSchema(type: GenerateAvroSchemaTask){
// shouldRunAfter "build"
// shouldRunAfter "generateProtocol"
// source file("build/generated-main-avro-avpr")
// include("**/*.avpr")
// outputDir = file("build/generated-main-avro-avsc")
//}
tasks.register("copyAvroSchemas", Copy) {
dependsOn(generateSchema)
println "Running copyAvroSchemas"
def sourceDir = file('build/generated-main-avro-avsc') // Change this to your Avro schema source directory
def destinationDir = file('src/main/resources/schemas') // Change this to your desired destination directory

// Ensure the destination directory exists; if not, create it
destinationDir.mkdirs()

from sourceDir
into destinationDir
include '**/*.avsc'
}


avro {
enableDecimalLogicalType = false
Expand All @@ -99,11 +94,5 @@ tasks.register("generateAvrodoc", NpxTask) {
mustRunAfter tasks.withType(GenerateAvroJavaTask)
}

//task generateAvrodoc(type: NpxTask) {
// dependsOn(generateSchema)
// command = '@mikaello/avrodoc-plus'
// args = ['-i','build/generated-main-avro-avsc', '-o','../docs/avrodoc/avrodoc.html']
// mustRunAfter tasks.withType(GenerateAvroJavaTask)
//}

//tasks.named("generateProtocol") { finalizedBy("generateSchema") }
build.finalizedBy generateProtocol, generateSchema, generateAvrodoc, copyAvroSchemas
1 change: 1 addition & 0 deletions schemas/src/main/avro/query.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ protocol Example{
@logicalType("encrypted")
string secretName;
string queryEngine;
//union {null,@logicalType("encrypted") string} testField = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"type" : "record",
"name" : "CustomerRecord",
"namespace" : "com.dataanada.customer",
"fields" : [ {
"name" : "customerId",
"type" : "int"
}, {
"name" : "firstName",
"type" : {
"type" : "string",
"logicalType" : "encrypted"
}
}, {
"name" : "lastName",
"type" : {
"type" : "string",
"logicalType" : "encrypted"
}
}, {
"name" : "email",
"type" : {
"type" : "string",
"logicalType" : "encrypted"
}
}, {
"name" : "addressLine1",
"type" : "string"
}, {
"name" : "city",
"type" : "string"
}, {
"name" : "state",
"type" : "string"
}, {
"name" : "zip",
"type" : "int"
}, {
"name" : "country",
"type" : "string"
} ]
}
Loading

0 comments on commit 2459269

Please sign in to comment.