Skip to content

Commit 1ba0eb1

Browse files
authored
Merge pull request #42 from rubensousa/graph
Improve module detection
2 parents 46054a6 + 86bd3b9 commit 1ba0eb1

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/report/DependencyGraphBuilder.kt

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@ import org.gradle.api.artifacts.ProjectDependency
2323

2424
internal class DependencyGraphBuilder {
2525

26-
private val supportedConfigurations = mutableSetOf(
27-
"compileClasspath",
28-
"testCompileClasspath",
29-
"testFixturesCompileClasspath",
30-
)
31-
private val androidConfigurationPatterns = mutableSetOf(
32-
"androidTestUtil", // To exclude test orchestrator in some modules
33-
"AndroidTestCompileClasspath", // Tests would include this configuration pattern for build types and flavors
34-
"UnitTestCompileClasspath" // Tests would include this configuration pattern for build types and flavors
35-
)
36-
3726
fun buildFromDump(projectDump: DependencyGraphDump): List<DependencyGraph> {
3827
val graphs = mutableMapOf<String, DependencyGraph>()
3928
projectDump.modules.forEach { report ->
@@ -72,28 +61,52 @@ internal class DependencyGraphBuilder {
7261
when (dependency) {
7362
is ProjectDependency -> {
7463
if (dependency.path != moduleId) {
75-
graph.addInternalDependency(moduleId, dependency.path)
64+
graph.addInternalDependency(
65+
module = moduleId,
66+
dependency = dependency.path
67+
)
7668
}
7769
}
7870

7971
is ExternalModuleDependency -> {
80-
graph.addExternalDependency(
81-
module = moduleId,
82-
dependency = "${dependency.group}:${dependency.name}",
83-
)
72+
if (dependency.group == null) {
73+
// Java/Kotlin libraries provided to android modules are treated as external modules
74+
// TODO: Improve detection
75+
graph.addInternalDependency(
76+
module = moduleId,
77+
dependency = ":${dependency.name}:${dependency.versionConstraint.displayName}"
78+
)
79+
} else {
80+
graph.addExternalDependency(
81+
module = moduleId,
82+
dependency = "${dependency.group}:${dependency.name}",
83+
)
84+
}
8485
}
8586
}
8687
}
8788
graph
8889
}
8990
}
9091

91-
private fun isConfigurationSupported(configurationId: String): Boolean {
92-
if (supportedConfigurations.contains(configurationId)) {
93-
return true
92+
93+
companion object {
94+
private val supportedConfigurations = mutableSetOf(
95+
"androidTestUtil",
96+
"compileClasspath",
97+
"testCompileClasspath",
98+
"testFixturesCompileClasspath",
99+
)
100+
101+
fun isConfigurationSupported(configurationId: String): Boolean {
102+
return supportedConfigurations.any { pattern ->
103+
configurationId.lowercase().contains(pattern.lowercase())
104+
}
94105
}
95-
return androidConfigurationPatterns.any { pattern ->
96-
configurationId.contains(pattern)
106+
107+
fun isReleaseConfiguration(configurationId: String): Boolean {
108+
return configurationId == "compileClasspath"
109+
|| configurationId.lowercase().contains("releasecompileclasspath")
97110
}
98111
}
99112

projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/report/VerificationReportBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ internal class VerificationReportBuilder(
7575
report.configurations.forEach { configuration ->
7676
// TODO: Until https://github.com/rubensousa/ProjectGuard/issues/3 is clarified,
7777
// filter out test dependencies from the graph reports
78-
if (configuration.id == "compileClasspath") {
79-
val moduleDependencies = graph.getOrPut(report.module) { mutableSetOf() }
78+
val moduleDependencies = graph.getOrPut(report.module) { mutableSetOf() }
79+
if (DependencyGraphBuilder.isReleaseConfiguration(configuration.id)) {
8080
moduleDependencies.addAll(configuration.dependencies.map { dependency ->
8181
DependencyReferenceDump(dependency.id, dependency.isLibrary)
8282
})

sample/android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ android {
1818
}
1919

2020
dependencies {
21+
implementation(":domain:a")
2122
testImplementation(libs.junit)
2223
androidTestImplementation(project(":legacy:a"))
2324
}

0 commit comments

Comments
 (0)