Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Fix a bunch of issues in the containers APIs #1116

Merged
merged 15 commits into from
Sep 18, 2018

Conversation

eskatos
Copy link
Member

@eskatos eskatos commented Sep 17, 2018

This PR covers #1104, #1042, #1108 and contains other related fixes to the containers API.

#1104

Signed-off-by: Paul Merlin <paul@gradle.com>
#1042

Signed-off-by: Paul Merlin <paul@gradle.com>
Signed-off-by: Paul Merlin <paul@gradle.com>
Signed-off-by: Paul Merlin <paul@gradle.com>
and collect incoherences

Signed-off-by: Paul Merlin <paul@gradle.com>
#1108

Signed-off-by: Paul Merlin <paul@gradle.com>
Signed-off-by: Paul Merlin <paul@gradle.com>
Signed-off-by: Paul Merlin <paul@gradle.com>
…n<T>

Signed-off-by: Paul Merlin <paul@gradle.com>
by allowing eval tests to opt-in for generated gradle api extensions

Signed-off-by: Paul Merlin <paul@gradle.com>
by fixing unused variable compiler warning

Signed-off-by: Paul Merlin <paul@gradle.com>
by simplifying jar file creation

Signed-off-by: Paul Merlin <paul@gradle.com>
@eskatos eskatos added this to the 1.0-RC7 milestone Sep 17, 2018
@eskatos eskatos self-assigned this Sep 17, 2018
@eskatos eskatos requested a review from bamboo September 17, 2018 10:13
Copy link
Member

@bamboo bamboo left a comment

Choose a reason for hiding this comment

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

Nice!

import org.junit.Test


class NamedContainersEvalTest : TestWithTempFiles() {
Copy link
Member

Choose a reason for hiding this comment

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

⭕️ NamedContainerDslTest?

}

private
fun assertConfigurationsExtendsFrom(name: String, script: String, configuration: Project.() -> Unit = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

❌ This should occur after its use on the test methods.

@Test
fun `monomorphic named domain object container api`() {

assertConfigurationsExtendsFrom("api", """
Copy link
Member

Choose a reason for hiding this comment

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

❌ The name of this function made me think that the tested configurations should all extend from a configuration named "api". How about renaming to something like testConfigurationContainerVia("api", """...""")?

import kotlin.reflect.KClass


class TaskContainerEvalTest : TestWithTempFiles() {
Copy link
Member

Choose a reason for hiding this comment

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

TaskContainerDslTest?


class TaskContainerEvalTest : TestWithTempFiles() {

companion object {
Copy link
Member

Choose a reason for hiding this comment

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

❌ tests should always come first

import java.io.File


fun File.newProjectBuilder(name: String = this.name): ProjectBuilder =
Copy link
Member

Choose a reason for hiding this comment

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

⭕ a File extension seems wrong here. I'd define this as a regular factory function like newProjectBuilderWith(projectDir: File, name: String = projectDir.name)

*/
fun Project.eval(
script: String,
baseCacheDir: File = file(".gradle/kotlin-dsl-eval-cache"),
Copy link
Member

Choose a reason for hiding this comment

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

❌ this creates interference among the tests because:

  1. the simplified evaluator only hashes the content of the script
  2. it always overwrites the cache contents

I'd move this utility to a base test class where it can set the default baseCacheDir pointing to its own temp folder.

val t3: Task = tasks.getByName<Task>("foo")

val t4: Task = tasks.getByName("bar") {
description += "!"
Copy link
Member

Choose a reason for hiding this comment

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

❌ it would be better to differentiate the strings added to the description so the proper ordering of execution is also tested.

Signed-off-by: Paul Merlin <paul@gradle.com>
Signed-off-by: Paul Merlin <paul@gradle.com>
@eskatos
Copy link
Member Author

eskatos commented Sep 18, 2018

Thanks for the careful review @bamboo, this is ready for another look

Copy link
Member

@bamboo bamboo left a comment

Choose a reason for hiding this comment

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

👍

/**
* Provides a [TaskProvider] delegate for the task of the given type named after the property after configuring it with the given action.
*/
operator fun <U : Task> ExistingDomainObjectDelegateProviderWithTypeAndAction<out TaskContainer, U>.provideDelegate(
Copy link
Contributor

Choose a reason for hiding this comment

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

👀 That is quite a class name. 👀

*/
@Suppress("extension_shadowed_by_member")
inline fun <reified T : Task> TaskContainer.register(name: String): TaskProvider<T> =
register(name, T::class.java)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing a @Suppress("extension_shadowed_by_member") usually flags something isn't going to work correctly in my experience.
Do you have a test that ensures this can be called without an issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, look at other files changed in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants