Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Simplification] Remove global options in plugin in favour of source-… #30

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,69 @@ import com.gradle.publish.PublishTask.GRADLE_PUBLISH_KEY
import com.gradle.publish.PublishTask.GRADLE_PUBLISH_SECRET

plugins {
id("groovy")
id("com.gradle.plugin-publish") version "1.2.0"
id("java-gradle-plugin")
id("groovy")
id("com.gradle.plugin-publish") version "1.2.0"
id("java-gradle-plugin")
}

val setupPluginUpload by tasks.registering {
// TODO switch this to use github action
if ("CI" in System.getenv() && "TRAVIS" in System.getenv()) {
// Used for publishing from Travis
// TODO switch this to use github action
if ("CI" in System.getenv() && "TRAVIS" in System.getenv()) {
// Used for publishing from Travis

val key = System.getenv(GRADLE_PUBLISH_KEY) ?: System.getProperty(GRADLE_PUBLISH_KEY)
val secret = System.getenv(GRADLE_PUBLISH_SECRET) ?: System.getProperty(GRADLE_PUBLISH_SECRET)
val key = System.getenv(GRADLE_PUBLISH_KEY) ?: System.getProperty(GRADLE_PUBLISH_KEY)
val secret = System.getenv(GRADLE_PUBLISH_SECRET) ?: System.getProperty(GRADLE_PUBLISH_SECRET)

if (key == null || secret == null) {
error("GRADLE_PUBLISH_KEY and/or GRADLE_PUBLISH_SECRET are not defined environment variables")
}

System.setProperty(GRADLE_PUBLISH_KEY, key)
System.setProperty(GRADLE_PUBLISH_SECRET, secret)
if (key == null || secret == null) {
error("GRADLE_PUBLISH_KEY and/or GRADLE_PUBLISH_SECRET are not defined environment variables")
}

System.setProperty(GRADLE_PUBLISH_KEY, key)
System.setProperty(GRADLE_PUBLISH_SECRET, secret)
}
}

tasks.named("publishPlugins") {
dependsOn(setupPluginUpload)
dependsOn(setupPluginUpload)
}

group = "org.assertj"
version = "2.2.0-SNAPSHOT"

gradlePlugin {
website.set("https://github.com/assertj/assertj-generator-gradle-plugin")
vcsUrl.set("https://github.com/assertj/assertj-generator-gradle-plugin.git")
website.set("https://github.com/assertj/assertj-generator-gradle-plugin")
vcsUrl.set("https://github.com/assertj/assertj-generator-gradle-plugin.git")

plugins {
create("assertJGeneratorPlugin") {
id = "org.assertj.generator"
plugins {
create("assertJGeneratorPlugin") {
id = "org.assertj.generator"

displayName = "AssertJ Generator Gradle Plugin"
description = "Run the AssertJ generator against your source files to generate test sources."
displayName = "AssertJ Generator Gradle Plugin"
description = "Run the AssertJ generator against your source files to generate test sources."

tags.set(listOf("assertj", "testing", "generator"))
tags.set(listOf("assertj", "testing", "generator"))

implementationClass = "org.assertj.generator.gradle.AssertJGeneratorGradlePlugin"
}
implementationClass = "org.assertj.generator.gradle.AssertJGeneratorGradlePlugin"
}
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
api(gradleApi())
api(localGroovy())
api(gradleApi())
api(localGroovy())

api("org.assertj:assertj-core:3.24.2")
api("org.assertj:assertj-assertions-generator:2.2.1")

api("org.assertj:assertj-core:3.24.2")
api("org.assertj:assertj-assertions-generator:2.2.1")
implementation("com.google.guava:guava:31.1-jre")

implementation("com.google.guava:guava:31.1-jre")
testCompileOnly("org.jetbrains:annotations:24.0.1")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only change here was this


testImplementation(gradleTestKit())
testImplementation("junit:junit:4.13.2")
testImplementation(gradleTestKit())
testImplementation("junit:junit:4.13.2")
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package org.assertj.generator.gradle

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

import org.assertj.generator.gradle.tasks.AssertJGenerationTask
import org.assertj.generator.gradle.tasks.AssertJGeneratorSourceSet
import org.gradle.api.Plugin
Expand Down Expand Up @@ -69,8 +69,6 @@ class AssertJGeneratorGradlePlugin implements Plugin<Project> {
}
}

project.extensions.create("assertJ", GlobalAssertJGeneratorOptions)

def javaPlugin = project.getConvention().getPlugin(JavaPluginConvention)
// So now we have to go through and add the properties that we want
javaPlugin.sourceSets.all { sourceSet ->
Expand Down Expand Up @@ -118,9 +116,6 @@ class AssertJGeneratorGradlePlugin implements Plugin<Project> {
}

project.afterEvaluate {
// First, figure out global vs. locally scoped configurations
assertJSS.defaultFromGlobals(project)

generationTask.configure {
outputDir = assertJSS.getOutputDir(sourceSet)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class DefaultAssertJGeneratorSourceSet extends DefaultAssertJGeneratorOptions im
final String name
boolean skip
String entryPointClassPackage
EntryPointGeneratorOptions entryPoints
private File outputDir

private final SourceDirectorySet assertJDirectorySet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import groovy.transform.EqualsAndHashCode
import groovy.transform.PackageScope
import groovy.transform.ToString
import org.assertj.assertions.generator.AssertionsEntryPointType
import org.assertj.generator.gradle.AssertJGeneratorGradlePlugin
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.Project
import org.gradle.api.tasks.SourceSet
import org.gradle.util.ConfigureUtil

Expand All @@ -30,7 +28,8 @@ import java.nio.file.Paths
/**
* Simple, default implementation of {@link AssertJGeneratorOptions}
*/
@EqualsAndHashCode @ToString
@EqualsAndHashCode
@ToString
class DefaultAssertJGeneratorOptions implements AssertJGeneratorOptions, Serializable {

boolean skip
Expand All @@ -41,20 +40,21 @@ class DefaultAssertJGeneratorOptions implements AssertJGeneratorOptions, Seriali
protected String outputDir

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

skip = true
hierarchical = null
templates = new Templates()

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

Path getOutputDir(SourceSet sourceSet) {
if (!outputDir) return null

def path
if (sourceSet.name.contains("test")) {
path = this.outputDir.replace(SOURCE_SET_NAME_TAG, sourceSet.name)
} else {
path = this.outputDir.replace(SOURCE_SET_NAME_TAG, sourceSet.getTaskName('test', ''))
}
def path = this.outputDir.replace(SOURCE_SET_NAME_TAG, sourceSet.name)

Paths.get(path)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ class DefaultAssertJGeneratorOptions implements AssertJGeneratorOptions, Seriali
}

void setEntryPoints(EntryPointGeneratorOptions newValue) {
this.entryPoints = newValue
this._entryPoints = newValue
}

@Override
Expand All @@ -115,25 +115,6 @@ class DefaultAssertJGeneratorOptions implements AssertJGeneratorOptions, Seriali
ConfigureUtil.configure(closure, orCreateEntryPoints)
this
}



@Override
AssertJGeneratorOptions defaultFromGlobals(Project project) {
GlobalAssertJGeneratorOptions globalOpts =
project.extensions.findByName(AssertJGeneratorGradlePlugin.ASSERTJ_GEN_CONFIGURATION_NAME) as GlobalAssertJGeneratorOptions

if (!this.getOutputDirRaw()) {
this.outputDir = globalOpts.outputDir
}

if (!this.entryPoints) {
this.entryPoints = globalOpts.entryPoints
}

templates.defaults(globalOpts.templates)
this
}

private void writeObject(ObjectOutputStream s) throws IOException {
s.writeObject(outputDir)
Expand All @@ -143,11 +124,11 @@ class DefaultAssertJGeneratorOptions implements AssertJGeneratorOptions, Seriali
}

private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
this.outputDir = (String)s.readObject()
this.outputDir = (String) s.readObject()
this.skip = s.readBoolean()
this._entryPoints = (EntryPointGeneratorOptions)s.readObject()
this._entryPoints = (EntryPointGeneratorOptions) s.readObject()

Templates templatesFromIn = (Templates)s.readObject()
Templates templatesFromIn = (Templates) s.readObject()
if (templatesFromIn) {
if (this.templates) {
this.templates.copyFrom(templatesFromIn)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,4 @@ default void setEntryPoints(Collection<String> values) {
* @see #isSkip()
*/
void setSkip(boolean skip);

AssertJGeneratorOptions defaultFromGlobals(Project project);

}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class IncrementalBuild {

private def assertFiles(String sourceSet, boolean exists) {
final Path generatedPackagePath = testProjectDir.root.toPath()
.resolve("build/generated-src/test${sourceSet == "main" ? "" : sourceSet.capitalize()}/java")
.resolve("build/generated-src/${sourceSet}-test/java")
.resolve(packagePath)

def buildPath = testProjectDir.root.toPath().resolve("build")
Expand All @@ -207,7 +207,4 @@ class IncrementalBuild {
it
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,13 @@ class SimpleBuild {
sourceSets {
main {
assertJ {
exclude '**/org/example/OtherWorld*'
source.exclude '**/org/example/OtherWorld*'
}
}
}
""")

def result = GradleRunner.create()
.withGradleVersion("3.5")
.withProjectDir(testProjectDir.root)
.withDebug(true)
.withPluginClasspath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.junit.rules.TemporaryFolder
import java.nio.file.Path
import java.nio.file.Paths

import static org.assertj.core.api.Assertions.*
import static org.assertj.core.api.Assertions.assertThat

/**
* Checks the behaviour of overriding globals in a project
Expand All @@ -34,7 +34,7 @@ class SkipPackageInfo {

File buildFile
Path generatedPackagePath

@Before
void setup() {
buildFile = testProjectDir.newFile('build.gradle')
Expand Down Expand Up @@ -105,8 +105,8 @@ class SkipPackageInfo {
}
""".stripIndent()

generatedPackagePath = testProjectDir.newFolder('build', 'generated-src', 'test', 'java').toPath()
.resolve(packagePath)
generatedPackagePath = testProjectDir.newFolder('build', 'generated-src', 'main-test', 'java').toPath()
.resolve(packagePath)
}


Expand Down Expand Up @@ -135,6 +135,4 @@ class SkipPackageInfo {
.as("${generatedPackagePath}/Assertions does not have \'package-info\' in it")
.doesNotContain("package-info")
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.assertj.generator.gradle

import org.intellij.lang.annotations.Language

/**
* Utilities used in test scripts
*/
Expand All @@ -23,7 +25,7 @@ class TestUtils {
* @param content
* @return
*/
static def buildFile(File file, String content) {
static def buildFile(File file, @Language("Groovy") String content) {
file << """
// Add required plugins and source sets to the sub projects
plugins { id "org.assertj.generator" } // Note must use this syntax
Expand Down
Loading