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

Improve jdeps tracking and add test cases #1115

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -191,6 +191,9 @@ class JdepsGenExtension(
descriptor.typeConstructor.supertypes.forEach {
collectTypeReferences(it)
}
descriptor.annotations.forEach { annotation ->
collectTypeReferences(annotation.type)
}
}
is FunctionDescriptor -> {
descriptor.returnType?.let { collectTypeReferences(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,87 @@ class KotlinBuilderJvmJdepsTest(private val enableK2Compiler: Boolean) {
assertIncomplete(jdeps).isEmpty()
}

@Test
fun `java annotation on class is an explict dep`() {
val dependingTarget = runJdepsCompileTask { c: KotlinJvmTestBuilder.TaskBuilder ->
c.addSource(
"AnotherClass.kt",
"""
package something

@JavaAnnotation
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test case demonstrates how it fails to track runtime class annotations as a used type.

class AnotherClass {
}
"""
)
c.addDirectDependencies(TEST_FIXTURES_DEP)
}
val jdeps = depsProto(dependingTarget)

assertThat(jdeps.ruleLabel).isEqualTo(dependingTarget.label())

assertExplicit(jdeps).contains(TEST_FIXTURES_DEP.singleCompileJar())
assertImplicit(jdeps).isEmpty()
assertUnused(jdeps).isEmpty()
assertIncomplete(jdeps).isEmpty()
}

@Test
fun `java sealed classes`() {
val dependingTarget = runJdepsCompileTask { c: KotlinJvmTestBuilder.TaskBuilder ->
c.addSource(
"AnotherClass.kt",
"""
package something

import pkg.assertion.ExampleException

sealed class SomeClass {
companion object {
fun mapExceptions(exception: Exception) = when (exception) {
is ExampleException -> exception
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test case demonstrates how it fails to track ExampleException as a used type.

else -> exception
}
}
}
"""
)
c.addDirectDependencies(TEST_FIXTURES_DEP)
}
val jdeps = depsProto(dependingTarget)

assertThat(jdeps.ruleLabel).isEqualTo(dependingTarget.label())

assertExplicit(jdeps).contains(TEST_FIXTURES_DEP.singleCompileJar())
assertImplicit(jdeps).isEmpty()
assertUnused(jdeps).isEmpty()
assertIncomplete(jdeps).isEmpty()
}

@Test
fun `java classes with inheritance`() {
val dependingTarget = runJdepsCompileTask { c: KotlinJvmTestBuilder.TaskBuilder ->
c.addSource(
"AnotherClass.kt",
"""
package something

class SomeClass : SomeClassWithInheritance.BaseClassCallback {
}
"""
)
c.addDirectDependencies(TEST_FIXTURES_DEP)
}
val jdeps = depsProto(dependingTarget)

assertThat(jdeps.ruleLabel).isEqualTo(dependingTarget.label())

assertExplicit(jdeps).contains(TEST_FIXTURES_DEP.singleCompileJar())
assertImplicit(jdeps).isEmpty()
assertUnused(jdeps).isEmpty()
assertIncomplete(jdeps).isEmpty()
}

@Test
fun `java annotation on property is an explict dep`() {
val dependingTarget = runJdepsCompileTask { c: KotlinJvmTestBuilder.TaskBuilder ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package something;

public abstract class BaseClass {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pkg.assertion;

public class ExampleException extends RuntimeException {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package something;

public class SomeClassWithInheritance extends BaseClass {


interface BaseClassCallback {

}
}