Skip to content

Commit

Permalink
[Simplify] Remove unused methods, add ListProperty<> values for `Te…
Browse files Browse the repository at this point in the history
…mplates`

This is extracted from #31

This removes unused methods that were knock ons from #30. This fixes issues with serialization of the `Templates` value when computing if the tasks should run.
  • Loading branch information
Nava2 committed Apr 22, 2023
1 parent c4b2567 commit 12357c9
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
package org.assertj.generator.gradle

import org.assertj.generator.gradle.internal.tasks.DefaultAssertJGeneratorSourceSet

import org.assertj.generator.gradle.tasks.AssertJGenerationTask
import org.assertj.generator.gradle.tasks.AssertJGeneratorSourceSet
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.internal.file.SourceDirectorySetFactory
import org.gradle.api.internal.plugins.DslObject
import org.gradle.api.logging.Logging
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.Convention
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginConvention
Expand All @@ -37,13 +36,13 @@ class AssertJGeneratorGradlePlugin implements Plugin<Project> {

static final ASSERTJ_GEN_CONFIGURATION_NAME = "assertJ"

private final SourceDirectorySetFactory sourceDirectorySetFactory
private final ObjectFactory objects

private static final logger = Logging.getLogger(AssertJGeneratorGradlePlugin)

@Inject
AssertJGeneratorGradlePlugin(SourceDirectorySetFactory sourceDirectorySetFactory) {
this.sourceDirectorySetFactory = sourceDirectorySetFactory
AssertJGeneratorGradlePlugin(ObjectFactory objects) {
this.objects = objects
}

@Override
Expand Down Expand Up @@ -79,8 +78,11 @@ class AssertJGeneratorGradlePlugin implements Plugin<Project> {
Convention sourceSetConvention = new DslObject(sourceSet).convention

// Create the assertJ closure within the source set, e.g. main { assertJ { } }
DefaultAssertJGeneratorSourceSet assertJSourceSet = new DefaultAssertJGeneratorSourceSet(
sourceSet, sourceDirectorySetFactory)
def assertJSourceSet = objects.newInstance(
DefaultAssertJGeneratorSourceSet,
objects,
sourceSet,
)
sourceSetConvention.plugins[AssertJGeneratorSourceSet.NAME] = assertJSourceSet
sourceSet.allSource.source(assertJSourceSet.assertJ)

Expand All @@ -104,17 +106,18 @@ class AssertJGeneratorGradlePlugin implements Plugin<Project> {
if (!generationTask) {
generationTask = project.tasks.create(generateTaskName, AssertJGenerationTask) {
description = "Generates AssertJ assertions for the ${sourceSet} sources."
generationClasspath = sourceSet.runtimeClasspath // Get the classes used when creating the ClassLoader for
// Generation
generationClasspath = sourceSet.runtimeClasspath
// Get the classes used when creating the ClassLoader for
// Generation

source = assertJSS.assertJ // Set up the conventional sources
assertJOptions = assertJSS // Set the config options, too
source = assertJSS.assertJ // Set up the conventional sources
assertJOptions = assertJSS // Set the config options, too
}

final def compileJavaTask = project.tasks.findByName(sourceSet.compileJavaTaskName)
generationTask.dependsOn compileJavaTask
}

project.afterEvaluate {
generationTask.configure {
outputDir = assertJSS.getOutputDir(sourceSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import org.assertj.generator.gradle.tasks.config.EntryPointGeneratorOptions
import org.assertj.generator.gradle.tasks.config.Templates
import org.gradle.api.Action
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.internal.file.SourceDirectorySetFactory
import org.gradle.api.internal.tasks.DefaultSourceSet
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.SourceSet
import org.gradle.util.ConfigureUtil

import javax.inject.Inject

/**
* Simple, default implementation of {@link AssertJGeneratorSourceSet}
*/
Expand All @@ -38,10 +39,14 @@ class DefaultAssertJGeneratorSourceSet extends DefaultAssertJGeneratorOptions im

private final SourceDirectorySet assertJDirectorySet

DefaultAssertJGeneratorSourceSet(SourceSet sourceSet, SourceDirectorySetFactory sourceDirectorySetFactory) {
super()
@Inject
DefaultAssertJGeneratorSourceSet(ObjectFactory objectFactory, SourceSet sourceSet) {
super(objectFactory)
this.name = sourceSet.name
this.assertJDirectorySet = sourceDirectorySetFactory.create("${((DefaultSourceSet) sourceSet).displayName} AssertJ Sources")
this.assertJDirectorySet = objectFactory.sourceDirectorySet(
"$sourceSet AssertJ Sources",
sourceSet.name,
)

// We default to the java directory
assertJ.setSrcDirs(["src/${this.name}/java"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import org.assertj.assertions.generator.AssertionsEntryPointType
import org.assertj.generator.gradle.tasks.config.AssertJGeneratorOptions
import org.assertj.generator.gradle.tasks.config.EntryPointGeneratorOptions
import org.assertj.generator.gradle.tasks.config.Templates
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.SourceSet
import org.gradle.util.ConfigureUtil

import javax.inject.Inject
import java.nio.file.Path
import java.nio.file.Paths

Expand All @@ -39,15 +41,16 @@ class DefaultAssertJGeneratorOptions implements AssertJGeneratorOptions, Seriali

protected String outputDir

DefaultAssertJGeneratorOptions() {
@Inject
DefaultAssertJGeneratorOptions(ObjectFactory objects) {
this.outputDir = "generated-src/${SOURCE_SET_NAME_TAG}-test/java"

skip = true
hierarchical = null
templates = new Templates()
templates = objects.newInstance(Templates)

// default entry points
this._entryPoints = new EntryPointGeneratorOptions()
this._entryPoints = objects.newInstance(EntryPointGeneratorOptions)
this._entryPoints.only(AssertionsEntryPointType.STANDARD)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.assertj.generator.gradle.internal.tasks.AssertionsGeneratorReport
import org.assertj.generator.gradle.tasks.config.AssertJGeneratorOptions
import org.gradle.api.file.*
import org.gradle.api.logging.Logging
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.*
import org.gradle.api.tasks.incremental.IncrementalTaskInputs

Expand All @@ -41,12 +42,18 @@ class AssertJGenerationTask extends SourceTask {
@Classpath
FileCollection generationClasspath

@Input
@Internal
AssertJGeneratorOptions assertJOptions

@InputFiles
List<File> getTemplateFiles() {
assertJOptions.templates.files
@Classpath
ListProperty<File> getTemplateFiles() {
assertJOptions.templates.templateFiles
}

@Input
ListProperty<String> getTemplateStrings() {
assertJOptions.templates.templateStrings
}

@OutputDirectory
Expand Down Expand Up @@ -81,7 +88,7 @@ class AssertJGenerationTask extends SourceTask {
} else if (sourceFiles.contains(change.file)) {
// source file changed
classesToGenerate += change.file
} else if (templateFiles.contains(change.file)) {
} else if (templateFiles.get().contains(change.file)) {
fullRegenRequired = true
}
}
Expand Down
Loading

0 comments on commit 12357c9

Please sign in to comment.