Skip to content

Commit

Permalink
Rework build logic
Browse files Browse the repository at this point in the history
This commit reworks how the model class is "shared" between the annotation
processor and the jazzer plugin. Instead of using a symlink, the code is
now generated by a common build plugin. In practice, the 2 modules use the
same record, but in a different package. It's also cleaner in the sense
that there's no dependency between the plugin and the annotation processor,
which would have led to too many classes on classpath.

Fixes #101
  • Loading branch information
melix committed Jan 7, 2025
1 parent 69d0ad2 commit b400264
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 55 deletions.
7 changes: 7 additions & 0 deletions build-logic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id 'groovy-gradle-plugin'
}

dependencies {
implementation(gradleApi())
}
1 change: 1 addition & 0 deletions build-logic/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "build-logic"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import io.micronaut.build.internal.tasks.GenerateModelClasses

def generateModel = tasks.register("generateModel", GenerateModelClasses) {
group = "build"
description = "Generate the model for the fuzzing module"
outputDirectory = layout.buildDirectory.dir("generated/sources/model")
}

sourceSets {
main {
java.srcDir(generateModel)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2003-2021 the original author or authors.
*
* Licensed 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.
*/
package io.micronaut.build.internal.tasks;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;

public abstract class GenerateModelClasses extends DefaultTask {
@OutputDirectory
public abstract DirectoryProperty getOutputDirectory();

@Input
public abstract Property<String> getPackageName();

@TaskAction
public void generateModelClasses() throws IOException {
var packageName = getPackageName().get();
var packageDir =
getOutputDirectory().get().getAsFile().toPath().resolve(packageName.replace('.', '/'));
Files.createDirectories(packageDir);
var model = packageDir.resolve("DefinedFuzzTarget.java");
try (var writer = new PrintWriter(Files.newBufferedWriter(model))) {
writer.println("package " + packageName + ";");
writer.println();
writer.println("""
import java.util.List;
public record DefinedFuzzTarget(
String targetClass,
List<String> dictionary,
List<String> dictionaryResources,
boolean enableImplicitly
) {
public static final String DIRECTORY = "io.micronaut.fuzzing.fuzz-targets";
}
""");
}
}
}
10 changes: 5 additions & 5 deletions build.gradle → build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
plugins {
id "io.micronaut.build.internal.docs"
id "io.micronaut.build.internal.quality-reporting"
id("io.micronaut.build.internal.docs")
id("io.micronaut.build.internal.quality-reporting")
}

// These tasks are used in the release workflow, but the jazzer plugin is an included build
["publishAllPublicationsToBuildRepository", "publishToSonatype", "closeAndReleaseSonatypeStagingRepository"].each {t ->
listOf("publishAllPublicationsToBuildRepository", "publishToSonatype", "closeAndReleaseSonatypeStagingRepository").forEach {t ->
if (tasks.names.find { it == t } == null) {
tasks.register(t) {
dependsOn(gradle.includedBuilds.find { it.name == "micronaut-jazzer-plugin" }.task(":$t"))
dependsOn(gradle.includedBuilds.find { it.name == "micronaut-jazzer-plugin" }?.task(":$t"))
}
} else {
tasks.named(t) {
dependsOn(gradle.includedBuilds.find { it.name == "micronaut-jazzer-plugin" }.task(":$t"))
dependsOn(gradle.includedBuilds.find { it.name == "micronaut-jazzer-plugin" }?.task(":$t"))
}
}
}
3 changes: 0 additions & 3 deletions buildSrc/build.gradle

This file was deleted.

9 changes: 9 additions & 0 deletions fuzzing-annotation-processor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import io.micronaut.build.internal.tasks.GenerateModelClasses

plugins {
id("io.micronaut.build.internal.fuzzing-module")
id("io.micronaut.build.internal.fuzzing-model")
}

dependencies {
Expand All @@ -9,3 +12,9 @@ dependencies {

testImplementation(mn.micronaut.inject.java.test)
}

tasks {
generateModel {
packageName = "io.micronaut.fuzzing.processor"
}
}

This file was deleted.

6 changes: 3 additions & 3 deletions fuzzing-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ dependencies {
implementation(mn.micronaut.jackson.databind)
implementation(mn.reactor)

implementation("ch.qos.logback:logback-classic:1.4.14")
implementation(mnLogging.logback.classic)

implementation(projects.micronautFuzzingApi)

annotationProcessor(mn.micronaut.inject.java)
annotationProcessor(projects.micronautFuzzingAnnotationProcessor)

testImplementation("org.junit.jupiter:junit-jupiter-engine:5.11.4")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.11.4")
testImplementation(mnTest.junit.jupiter.engine)
testImplementation(mnTest.junit.jupiter.params)
testImplementation(mn.micronaut.http.client)
testImplementation(mnTest.micronaut.test.junit5)
testAnnotationProcessor(mn.micronaut.inject.java)
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
[versions]
micronaut = "4.7.5"
micronaut-docs = "2.0.0"
micronaut-test = "4.1.0"
micronaut-test = "4.6.2"
micronaut-logging = "1.5.1"
groovy = "4.0.15"
spock = "2.3-groovy-4.0"

Expand All @@ -31,7 +32,7 @@ managed-jazzer = "0.23.0"
[libraries]
# Core
micronaut-core = { module = 'io.micronaut:micronaut-core-bom', version.ref = 'micronaut' }

micronaut-logging = { module = "io.micronaut.logging:micronaut-logging-bom", version.ref = "micronaut-logging" }
#
# Managed dependencies appear in the BOM
#
Expand Down
17 changes: 11 additions & 6 deletions jazzer-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
plugins {
id("java-gradle-plugin")
id("io.micronaut.build.internal.publishing")
id("io.micronaut.build.internal.fuzzing-model")
}

repositories {
mavenCentral()
}

dependencies {
// todo: bom dependencies
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
implementation(mn.jackson.databind)

testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.11.4")
testImplementation(mnTest.junit.jupiter.api)
testImplementation(mnTest.junit.jupiter.engine)
}

tasks.test {
useJUnitPlatform()
tasks{
test {
useJUnitPlatform()
}
generateModel {
packageName = "io.micronaut.fuzzing.model"
}
}

gradlePlugin {
Expand Down
2 changes: 2 additions & 0 deletions jazzer-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
projectDesc=A Gradle plugin integrating with Jazzer
micronautVersion=4.7.1
micronautTestVersion=4.6.2
8 changes: 6 additions & 2 deletions jazzer-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pluginManagement {
includeBuild("../build-logic")
}

rootProject.name = "micronaut-jazzer-plugin"

plugins {
Expand All @@ -6,7 +10,7 @@ plugins {

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

configure<io.micronaut.build.MicronautBuildSettingsExtension> {
useStandardizedProjectNames = false
micronautBuild {
useStandardizedProjectNames = true
importMicronautCatalog()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.micronaut.fuzzing.processor.DefinedFuzzTarget;
import io.micronaut.fuzzing.model.DefinedFuzzTarget;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.ListProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.micronaut.fuzzing.jazzer;

import io.micronaut.fuzzing.processor.DefinedFuzzTarget;
import io.micronaut.fuzzing.model.DefinedFuzzTarget;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.micronaut.fuzzing.jazzer;

import io.micronaut.fuzzing.processor.DefinedFuzzTarget;
import io.micronaut.fuzzing.model.DefinedFuzzTarget;
import org.gradle.api.Action;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.provider.SetProperty;
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pluginManagement {
gradlePluginPortal()
mavenCentral()
}
includeBuild("build-logic")
includeBuild("jazzer-plugin") {
name = "micronaut-jazzer-plugin"
}
Expand All @@ -20,10 +21,9 @@ include("fuzzing-tests")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

configure<io.micronaut.build.MicronautBuildSettingsExtension> {
micronautBuild {
useStandardizedProjectNames = true

importMicronautCatalog()

requiresDevelopmentVersion("micronaut-core", "4.8.x")
}

0 comments on commit b400264

Please sign in to comment.