Skip to content

Commit 84e1ce6

Browse files
committed
Added Historical Data Param
1 parent 5d47d16 commit 84e1ce6

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
examples/jvm-with-anvil/ Anvil
21
examples/scopes/ @handstandsam
3-
examples/app/ AppTeam
2+
examples/app/ @handstandsam

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
org.gradle.jvmargs=-Xmx8g
1+
org.gradle.jvmargs=-Xmx16g
22
kotlin.code.style=official
33
android.useAndroidX=true
44

invert-gradle-plugin/src/main/kotlin/com/squareup/invert/InvertExtension.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.squareup.invert.internal.NoOpOwnershipCollector
66
import com.squareup.invert.models.ConfigurationName
77
import org.gradle.api.Project
88
import org.gradle.api.tasks.Input
9+
import org.gradle.api.tasks.InputFile
910

1011
/**
1112
* Extension for configuring the [InvertGradlePlugin]
@@ -45,10 +46,18 @@ open class InvertExtension(project: Project) {
4546
internal val includeConfigurationProperty =
4647
objects.property(InvertIncludeConfigurationCalculator::class.java)
4748

49+
@get:InputFile
50+
@get:Input
51+
internal val historicalDataFileProperty = objects.property<String?>(String::class.java)
52+
4853
fun ownershipCollector(ownershipCollector: InvertOwnershipCollector) {
4954
ownershipCollectorProperty.set(ownershipCollector)
5055
}
5156

57+
fun historicalData(historicalDataFile: String) {
58+
this.historicalDataFileProperty.set(historicalDataFile)
59+
}
60+
5261
fun includeSubproject(invertShouldIncludeSubProject: (subproject: Project) -> Boolean) {
5362
includeSubProjectCalculatorProperty.set(object : InvertIncludeSubProjectCalculator {
5463
override fun invoke(
@@ -79,6 +88,10 @@ open class InvertExtension(project: Project) {
7988
statCollectors.add(statCollector)
8089
}
8190

91+
internal fun getHistoricalDataFilePath(): String? {
92+
return historicalDataFileProperty.orNull
93+
}
94+
8295
internal fun getStatCollectors(): Collection<StatCollector> {
8396
return statCollectors
8497
}

invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class InvertReportWriter(
4444

4545
val globalStats = computeGlobalTotals(allProjectsStatsData, collectedOwnershipInfo)
4646

47+
val historicalDataWithCurrent = historicalData + HistoricalData(
48+
reportMetadata = reportMetadata,
49+
statTotalsAndMetadata = CollectedStatTotalsJsReportModel(globalStats)
50+
)
51+
4752
// JSON Report
4853
InvertJsonReportWriter(invertLogger, rootBuildReportsDir).createInvertJsonReport(
4954
reportMetadata = reportMetadata,
@@ -53,7 +58,7 @@ class InvertReportWriter(
5358
allPluginsData = collectedPlugins,
5459
allOwnersData = collectedOwners,
5560
globalStats = globalStats,
56-
historicalData = historicalData,
61+
historicalData = historicalDataWithCurrent,
5762
)
5863

5964
// HTML/JS Report
@@ -67,11 +72,10 @@ class InvertReportWriter(
6772
collectedOwnershipInfo = collectedOwnershipInfo,
6873
allProjectsConfigurationsData = collectedConfigurations,
6974
globalStatTotals = CollectedStatTotalsJsReportModel(globalStats),
70-
historicalData = historicalData,
75+
historicalData = historicalDataWithCurrent,
7176
)
7277
}
7378

74-
7579
/**
7680
* This provides a warning to the user to let them know that a module was found as a dependency
7781
* but was not scanned itself. In order to get a full picture of the project, all should

invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/tasks/InvertTask.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import com.squareup.invert.internal.report.GradleProjectAnalysisCombiner
1111
import com.squareup.invert.internal.report.InvertReportWriter
1212
import com.squareup.invert.logging.GradleInvertLogger
1313
import com.squareup.invert.logging.InvertLogger
14+
import com.squareup.invert.models.InvertSerialization.InvertJson
15+
import com.squareup.invert.models.js.HistoricalData
1416
import kotlinx.coroutines.runBlocking
17+
import kotlinx.serialization.builtins.ListSerializer
1518
import org.gradle.api.DefaultTask
1619
import org.gradle.api.Project
1720
import org.gradle.api.artifacts.repositories.UrlArtifactRepository
@@ -20,6 +23,7 @@ import org.gradle.api.provider.ListProperty
2023
import org.gradle.api.provider.Property
2124
import org.gradle.api.tasks.Input
2225
import org.gradle.api.tasks.Internal
26+
import org.gradle.api.tasks.Optional
2327
import org.gradle.api.tasks.OutputDirectory
2428
import org.gradle.api.tasks.TaskAction
2529
import java.io.File
@@ -41,6 +45,10 @@ abstract class InvertTask : DefaultTask() {
4145
@get:Internal
4246
abstract var statCollectors: List<StatCollector>?
4347

48+
@get:Optional
49+
@get:Input
50+
abstract val historicalDataFileProperty: Property<String?>
51+
4452
@get:Input
4553
abstract val projectPath: Property<String>
4654

@@ -86,6 +94,20 @@ abstract class InvertTask : DefaultTask() {
8694
)
8795
)
8896

97+
val historicalDataFile: File? = historicalDataFileProperty.orNull?.let { File(it) }
98+
val historicalData: List<HistoricalData> =
99+
if (historicalDataFile?.isFile == true && historicalDataFile.length() > 0) {
100+
try {
101+
val fileContents = historicalDataFile.readText()
102+
InvertJson.decodeFromString(ListSerializer(HistoricalData.serializer()), fileContents)
103+
} catch (e: Exception) {
104+
invertLogger().warn("Failed to read historical data file: $e")
105+
listOf()
106+
}
107+
} else {
108+
listOf()
109+
}
110+
89111
InvertReportWriter(
90112
invertLogger = invertLogger(),
91113
rootBuildReportsDir = invertReportDir,
@@ -96,7 +118,7 @@ abstract class InvertTask : DefaultTask() {
96118
collectedDependencies = allCollectedData.collectedDependencies,
97119
collectedConfigurations = allCollectedData.collectedConfigurations,
98120
collectedPlugins = allCollectedData.collectedPlugins,
99-
historicalData = emptyList(),
121+
historicalData = historicalData,
100122
)
101123
}
102124
}
@@ -117,7 +139,7 @@ abstract class InvertTask : DefaultTask() {
117139
InvertFileUtils.REPORTS_SLASH_INVERT_PATH
118140
)
119141
)
120-
142+
this.historicalDataFileProperty.set(extension.getHistoricalDataFilePath())
121143
this.statCollectors = extension.getStatCollectors().toList()
122144

123145
this.mavenRepoUrls.set(

0 commit comments

Comments
 (0)