Skip to content

Commit

Permalink
Fix multimodule resolution
Browse files Browse the repository at this point in the history
This fixes an issue where if subproject `X` depends on subproject `Y`, `:X:expedite` does not automatically compile `Y`.
  • Loading branch information
ogolberg authored Sep 29, 2023
1 parent f1ad925 commit 21a8f13
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Expediter

[![Github Actions](https://github.com/open-toast/expediter/actions/workflows/ci.yml/badge.svg)](https://github.com/open-toast/can-i-use-anvil/actions/workflows/ci.yml)
[![Github Actions](https://github.com/open-toast/expediter/actions/workflows/ci.yml/badge.svg)](https://github.com/open-toast/expediter/actions/workflows/ci.yml)
[![Maven Central](https://img.shields.io/maven-central/v/com.toasttab.expediter/core)](https://search.maven.org/artifact/com.toasttab.expediter/core)
[![Gradle Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/com/toasttab/expediter/plugin/maven-metadata.xml.svg?label=gradle-portal&color=yellowgreen)](https://plugins.gradle.org/plugin/com.toasttab.expediter)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.util.jar.JarInputStream
import java.util.zip.ZipFile

class ClasspathScanner(
private val elements: Collection<File>
private val elements: Iterable<File>
) : ApplicationTypesProvider {
override fun types(): List<ApplicationType> = elements.flatMap { types(it) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ApplicationClassSelector constructor(
) {
constructor() : this(mutableListOf())

constructor(configuration: String) : this(mutableListOf(configuration))
constructor(configuration: String, sourceSet: String) : this(configurations = mutableListOf(configuration), sourceSets = mutableListOf(sourceSet))
fun configuration(configuration: String) {
configurations.add(configuration)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package com.toasttab.expediter.gradle

import org.gradle.api.Project
import org.gradle.api.artifacts.ArtifactCollection
import org.gradle.api.attributes.Attribute
import java.io.File
import org.gradle.kotlin.dsl.artifacts

private val ARTIFACT_TYPE_ATTR = Attribute.of("artifactType", String::class.java)

Expand All @@ -28,6 +29,7 @@ class ArtifactSelector(
private fun android() {
artifactType = "android-classes"
}

init {
project.pluginManager.withPlugin("com.android.library") {
android()
Expand All @@ -37,10 +39,11 @@ class ArtifactSelector(
android()
}
}
fun artifacts(configuration: String): Collection<File> {

fun artifacts(configuration: String): ArtifactCollection {
return project.configurations.getByName(configuration).incoming.artifactView {
lenient(true)
attributes.attribute(ARTIFACT_TYPE_ATTR, artifactType)
}.artifacts.artifacts.map { it.file }
}.artifacts
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.toasttab.expediter.gradle
import com.toasttab.expediter.ignore.Ignore

abstract class ExpediterExtension {
var application: ApplicationClassSelector = ApplicationClassSelector(configuration = "runtimeClasspath")
var application: ApplicationClassSelector = ApplicationClassSelector(configuration = "runtimeClasspath", sourceSet = "main")
var platform: PlatformClassSelector = PlatformClassSelector(platformClassloader = true)

var ignore: Ignore = Ignore.NOTHING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class ExpediterPlugin : Plugin<Project> {

project.tasks.register<ExpediterTask>("expedite") {
for (conf in extension.application.configurations) {
applicationClasspath.from(selector.artifacts(conf))
artifactCollection(selector.artifacts(conf))
}

for (file in extension.application.files) {
applicationClasspath.from(file)
files.from(file)
}

for (sourceSet in extension.application.sourceSets) {
applicationClasspath.from(project.sourceSet(sourceSet).java.classesDirectory)
files.from(project.sourceSet(sourceSet).java.classesDirectory)
}

jvmVersion = extension.platform.jvmVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import com.toasttab.expediter.types.PlatformTypeProvider
import com.toasttab.expediter.types.PlatformTypeProviderChain
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.artifacts.ArtifactCollection
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
Expand All @@ -41,9 +43,27 @@ import java.io.File

@CacheableTask
abstract class ExpediterTask : DefaultTask() {
private val configurationArtifacts = mutableListOf<ArtifactCollection>()

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val applicationClasspath: ConfigurableFileCollection
@get:PathSensitive(PathSensitivity.ABSOLUTE)
val artifacts: FileCollection get() {
return if (configurationArtifacts.isEmpty()) {
project.objects.fileCollection()
} else {
configurationArtifacts.map {
it.artifactFiles
}.reduce(FileCollection::plus)
}
}

@get:InputFiles
@get:PathSensitive(PathSensitivity.ABSOLUTE)
abstract val files: ConfigurableFileCollection

fun artifactCollection(artifactCollection: ArtifactCollection) {
configurationArtifacts.add(artifactCollection)
}

@OutputFile
lateinit var report: File
Expand Down Expand Up @@ -95,7 +115,7 @@ abstract class ExpediterTask : DefaultTask() {

val issues = Expediter(
ignore,
ClasspathScanner(applicationClasspath.files),
ClasspathScanner(artifacts + files),
PlatformTypeProviderChain(
providers
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import kotlin.io.path.readText
class ExpediterPluginIntegrationTest {
@Test
fun `android compat`(project: TestProject) {
project.createRunner()
val pout = project.createRunner()
.withArguments("check")
.buildAndFail()

Expand Down Expand Up @@ -74,4 +74,37 @@ class ExpediterPluginIntegrationTest {
)
)
}

@Test
fun multimodule(project: TestProject) {
project.createRunner().withArguments("app:expedite").buildAndFail()

val report = IssueReport.fromJson(project.dir.resolve("app/build/expediter.json").readText())

expectThat(report.issues).containsExactlyInAnyOrder(
Issue.MissingMember(
"test/A",
MemberAccess.MethodAccess(
"java/lang/String",
MemberSymbolicReference.MethodSymbolicReference(
"isBlank",
"()Z"
),
MethodAccessType.VIRTUAL
)
),

Issue.MissingMember(
"test/B",
MemberAccess.MethodAccess(
"java/lang/String",
MemberSymbolicReference.MethodSymbolicReference(
"isBlank",
"()Z"
),
MethodAccessType.VIRTUAL
)
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
java
id("com.toasttab.expediter")
}

expediter {
failOnIssues = true

platform {
jvmVersion = 8
}
}

dependencies {
implementation(project(":lib"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023 Toast Inc.
*
* 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
* http://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 test;

public class B {
void f() {
String s = "";
s.isBlank();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("com.toasttab.testkit.coverage") version "0.0.2"
}

subprojects {
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
java
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023 Toast Inc.
*
* 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
* http://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 test;

public class A {
void f() {
String s = "";
s.isBlank();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rootProject.name = "test"

include(":lib", ":app")

0 comments on commit 21a8f13

Please sign in to comment.