opwvhk commented on code in PR #3614: URL: https://github.com/apache/avro/pull/3614#discussion_r2740280118
########## lang/java/gradle-plugin/src/test/resources/templates/protocol.vm: ########## @@ -0,0 +1,19 @@ +## +## Licensed to the Apache Software Foundation (ASF) under one +## or more contributor license agreements. See the NOTICE file +## distributed with this work for additional information +## regarding copyright ownership. The ASF licenses this file +## to you under the Apache License, Version 2.0 (the +## "License"); you may not use this file except in compliance +## with the License. You may obtain a copy of the License at +## +## https://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +## No need to place anything here by now. File must exist, though. Review Comment: I'm missing something here... It's great to compile the data classes for protocols (arguably the largest use case). But the protocol interface is the key to the Avro RPC option. ########## lang/java/gradle-plugin/pom.xml: ########## @@ -0,0 +1,187 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>avro-parent</artifactId> + <groupId>org.apache.avro</groupId> + <version>1.13.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>gradle-plugin</artifactId> + <packaging>pom</packaging> + + <name>Apache Avro Gradle Plugin</name> + <description>Gradle plugin for Avro IDL and Specific API Compilers</description> + + <properties> + <main.basedir>${project.parent.parent.basedir}</main.basedir> + <pluginTestingVersion>3.3.0</pluginTestingVersion> + <!-- No Spotless for Kotlin--> + <spotless.skip>true</spotless.skip> + </properties> + + <!-- Relocation https://maven.apache.org/guides/mini/guide-relocation.html --> + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>3.1.0</version> + + <executions> + <execution> + <id>run-gradle-task-assemble</id> + <phase>compile</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <executable>./gradlew</executable> + <arguments> + <argument>assemble</argument> + <argument>-i</argument> Review Comment: Can we pass the Maven log level here? I doubt it, but it would be convenient. ########## lang/java/gradle-plugin/build.gradle.kts: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + kotlin("jvm") version "2.2.10" + `java-gradle-plugin` + id("com.gradle.plugin-publish") version "2.0.0" +} + +group = "eu.eventloopsoftware" +version = "0.1.0" + +repositories { + mavenCentral() + mavenLocal() +} + +dependencies { + // TODO: for release use ${version} + implementation("org.apache.avro:avro-compiler:1.12.1") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.3.0") + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} +kotlin { + jvmToolchain(21) +} + + Review Comment: Do we want a double newline here? #nitpick ########## lang/java/gradle-plugin/src/main/kotlin/eu/eventloopsoftware/avro/gradle/plugin/AvroGradlePlugin.kt: ########## @@ -0,0 +1,170 @@ +package eu.eventloopsoftware.avro.gradle.plugin + +import eu.eventloopsoftware.avro.gradle.plugin.extension.AvroGradlePluginExtension +import eu.eventloopsoftware.avro.gradle.plugin.tasks.AbstractCompileTask +import eu.eventloopsoftware.avro.gradle.plugin.tasks.CompileAvroSchemaTask +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.provider.Property +import org.gradle.api.tasks.TaskProvider +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmExtension + +abstract class AvroGradlePlugin : Plugin<Project> { + + override fun apply(project: Project) { + project.logger.info("Running Avro Gradle plugin for project: ${project.name}") + + val extension = project.extensions.create("avro", AvroGradlePluginExtension::class.java) + + // Required so that we can get the sourceSets from the java extension below. + project.pluginManager.apply("java") + + val compileAvroSchemaTask = registerSchemaTask(extension, project) + val compileTestAvroSchemaTask = registerSchemaTestTask(extension, project) + addGeneratedSourcesHook(project, compileAvroSchemaTask, compileTestAvroSchemaTask) + + } + + private fun addGeneratedSourcesHook( + project: Project, + compileAvroSchemaTask: TaskProvider<CompileAvroSchemaTask>, + compileTestAvroSchemaTask: TaskProvider<CompileAvroSchemaTask> + ) { + project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + addGeneratedSourcesToKotlinProject(project, compileAvroSchemaTask, compileTestAvroSchemaTask) + } + + project.plugins.withType(JavaPlugin::class.java) { + addGeneratedSourcesToJavaProject(project, compileAvroSchemaTask, compileTestAvroSchemaTask) + } + } + + private fun registerSchemaTask(extension: AvroGradlePluginExtension, project: Project) = + project.tasks.register("avroGenerateJavaClasses", CompileAvroSchemaTask::class.java) { compileSchemaTask -> + + val includesAvsc: Set<String> = extension.includedSchemaFiles.get() + val includesProtocol: Set<String> = extension.includedProtocolFiles.get() + + addProperties( + compileSchemaTask, + extension, + project, + extension.outputDirectory + ) + + addSchemaFiles(compileSchemaTask, project, extension, includesAvsc, extension.sourceDirectory) + addProtocolFiles(compileSchemaTask, project, extension, includesProtocol, extension.testSourceDirectory) Review Comment: Do we also generate the interface for protocols? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
