Skip to content

Commit bed0e43

Browse files
committed
Only provide actionable module structure advice
The threshold of 2 uses of android features is totally arbitrary and not helpful in practice. This is especially true for the "Has Android library dependencies" advice, for which there is really no workaround and happens extremely frequently in our build.
1 parent 7ce2e73 commit bed0e43

File tree

6 files changed

+8
-21
lines changed

6 files changed

+8
-21
lines changed

src/functionalTest/groovy/com/autonomousapps/android/ReasonSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ final class ReasonSpec extends AbstractAndroidSpec {
9898
"""\
9999
----------------------------------------
100100
You asked about the Android score for ':proj'.
101-
There was no Android-related module structure advice for this project. It uses several Android features.
101+
There was no Android-related module structure advice for this project. It uses at least one Android feature.
102102
----------------------------------------
103103

104104
Android features:

src/main/kotlin/com/autonomousapps/internal/advice/ProjectHealthConsoleReportBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ internal class ProjectHealthConsoleReportBuilder(
137137

138138
moduleAdvice.forEach { m ->
139139
when (m) {
140-
is AndroidScore -> if (m.couldBeJvm()) append(m.text())
140+
is AndroidScore -> if (m.shouldBeJvm()) append(m.text())
141141
}
142142
}
143143
}

src/main/kotlin/com/autonomousapps/internal/reason/ModuleAdviceExplainer.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ internal class ModuleAdviceExplainer(
4343
"You have been advised to change this project from an Android project to a JVM project. No use of any " +
4444
"Android feature was detected."
4545
)
46-
finalAndroidScore.couldBeJvm() -> append(
47-
"You have been advised to change this project from an Android project to a JVM project. Only limited use " +
48-
"of Android feature was detected."
49-
)
5046
else -> append(
51-
"There was no Android-related module structure advice for this project. It uses several Android features."
47+
"There was no Android-related module structure advice for this project. It uses at least one Android feature."
5248
)
5349
}
5450
}

src/main/kotlin/com/autonomousapps/model/ModuleAdvice.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,9 @@ data class AndroidScore(
7070
/** True if this project uses no Android facilities at all. */
7171
fun shouldBeJvm(): Boolean = score == 0f
7272

73-
/** True if this project only uses some limited number of Android facilities. */
74-
fun couldBeJvm(): Boolean = score < THRESHOLD
75-
76-
override fun isActionable(): Boolean = couldBeJvm()
73+
override fun isActionable(): Boolean = shouldBeJvm()
7774

7875
internal companion object {
79-
private const val THRESHOLD = 2f
80-
8176
fun ofVariants(scores: Collection<AndroidScoreVariant>): AndroidScore? {
8277
// JVM projects don't have an AndroidScore
8378
if (scores.isEmpty()) return null

src/main/kotlin/com/autonomousapps/tasks/GenerateBuildHealthTask.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ abstract class GenerateBuildHealthTask : DefaultTask() {
126126
projectAdvice.moduleAdvice.filterIsInstance<AndroidScore>().forEach {
127127
if (it.shouldBeJvm()) {
128128
androidMetricsBuilder.shouldBeJvmCount++
129-
} else if (it.couldBeJvm()) {
130-
androidMetricsBuilder.couldBeJvmCount++
131129
}
132130
}
133131
}

src/test/kotlin/com/autonomousapps/internal/reason/ModuleAdviceExplainerTest.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ internal class ModuleAdviceExplainerTest {
3030
).inOrder()
3131
}
3232

33-
@Test fun `can explain there is little reason for this to be an Android project`() {
33+
@Test fun `can explain there is at least one reason for this to be an Android project`() {
3434
// Given
3535
val score = Fixture.emptyScore.copy(
36-
hasBuildConfig = true,
3736
hasAndroidDependencies = true
3837
)
3938
val computer = Fixture(
@@ -47,14 +46,13 @@ internal class ModuleAdviceExplainerTest {
4746
// Then
4847
assertThat(reason.decolorize().lines()).containsExactlyElementsIn(
4948
"""
50-
49+
5150
----------------------------------------
5251
You asked about the Android score for ':root'.
53-
You have been advised to change this project from an Android project to a JVM project. Only limited use of Android feature was detected.
52+
There was no Android-related module structure advice for this project. It uses at least one Android feature.
5453
----------------------------------------
55-
54+
5655
Android features:
57-
* Includes BuildConfig.
5856
* Has Android library dependencies.
5957
""".trimIndent().lines()
6058
).inOrder()

0 commit comments

Comments
 (0)