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

WIP. Proving that DAGP can handle suspend functions. #936

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class AbstractJvmSpec extends AbstractFunctionalSpec {
@SuppressWarnings('unused')
def cleanup() {
if (gradleProject != null && shouldClean) {
clean(gradleProject.rootDir)
// clean(gradleProject.rootDir)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.autonomousapps.jvm

import com.autonomousapps.android.AbstractAndroidSpec
import com.autonomousapps.jvm.projects.KotlinSuspendProject

import static com.autonomousapps.advice.truth.BuildHealthSubject.buildHealth
import static com.autonomousapps.utils.Runner.build
import static com.google.common.truth.Truth.assertAbout

@SuppressWarnings('GroovyAssignabilityCheck')
final class KotlinSuspendSpec extends AbstractJvmSpec {

def "can detect functions that take suspend parameters (#gradleVersion)"() {
given:
def project = new KotlinSuspendProject()
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')

then:
assertAbout(buildHealth())
.that(project.actualBuildHealth())
.isEquivalentIgnoringModuleAdvice(project.expectedBuildHealth)

where:
gradleVersion << gradleVersions()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.autonomousapps.jvm.projects

import com.autonomousapps.AbstractProject
import com.autonomousapps.kit.*
import com.autonomousapps.model.ProjectAdvice

import static com.autonomousapps.AdviceHelper.actualProjectAdvice
import static com.autonomousapps.AdviceHelper.emptyProjectAdviceFor
import static com.autonomousapps.kit.Dependency.project

final class KotlinSuspendProject extends AbstractProject {

final GradleProject gradleProject

KotlinSuspendProject() {
this.gradleProject = build()
}

private GradleProject build() {
def builder = newGradleProjectBuilder()
builder.withRootProject { root ->
root.gradleProperties = GradleProperties.minimalJvmProperties()
}
builder.withSubproject('consumer') { consumer ->
consumer.withBuildScript { bs ->
bs.plugins = [Plugin.kotlinPluginNoVersion]
bs.dependencies = [
project('implementation', ':producer')
]
}
consumer.sources = consumerSources
}
builder.withSubproject('producer') { producer ->
producer.withBuildScript { bs ->
bs.plugins = [Plugin.kotlinPluginNoVersion]
}
producer.sources = producerSources
}

def project = builder.build()
project.writer().write()
return project
}

private static final List<Source> consumerSources = [
new Source(
SourceType.KOTLIN, 'Consumer.kt', 'com/example/consumer',
'''\
package com.example.consumer

import com.example.producer.*

internal class Consumer {

fun doTheThing() {
complicatedThing(Datum()) {
getApiResult()
}
}

suspend fun getApiResult(): ApiResult<String, String> = TODO()
}'''.stripIndent()
)
]

private static final List<Source> producerSources = [
new Source(
SourceType.KOTLIN, 'Producer.kt', 'com/example/producer',
'''\
package com.example.producer

fun <E : Any> complicatedThing(
datum: Datum,
body: suspend () -> ApiResult<*, E>
): Unit = TODO()

class Datum

class ApiResult<A, B>'''.stripIndent()
)
]

Set<ProjectAdvice> actualBuildHealth() {
return actualProjectAdvice(gradleProject)
}

final Set<ProjectAdvice> expectedBuildHealth = emptyProjectAdviceFor(':consumer', ':producer',)
}