Skip to content

Commit

Permalink
Added Historical Data Param
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Dec 2, 2024
1 parent 5d47d16 commit 22cee8d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
examples/jvm-with-anvil/ Anvil
examples/scopes/ @handstandsam
examples/app/ AppTeam
examples/app/ @handstandsam
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx8g
org.gradle.jvmargs=-Xmx16g
kotlin.code.style=official
android.useAndroidX=true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.squareup.invert.internal.NoOpOwnershipCollector
import com.squareup.invert.models.ConfigurationName
import org.gradle.api.Project
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile

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

@get:InputFile
@get:Input
internal val historicalDataFileProperty = objects.property<String?>(String::class.java)

fun ownershipCollector(ownershipCollector: InvertOwnershipCollector) {
ownershipCollectorProperty.set(ownershipCollector)
}

fun historicalData(historicalDataFile: String) {
this.historicalDataFileProperty.set(historicalDataFile)
}

fun includeSubproject(invertShouldIncludeSubProject: (subproject: Project) -> Boolean) {
includeSubProjectCalculatorProperty.set(object : InvertIncludeSubProjectCalculator {
override fun invoke(
Expand Down Expand Up @@ -79,6 +88,10 @@ open class InvertExtension(project: Project) {
statCollectors.add(statCollector)
}

internal fun getHistoricalDataFilePath(): String? {
return historicalDataFileProperty.orNull
}

internal fun getStatCollectors(): Collection<StatCollector> {
return statCollectors
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class InvertReportWriter(

val globalStats = computeGlobalTotals(allProjectsStatsData, collectedOwnershipInfo)

// val historicalDataWithCurrent = historicalData
// + HistoricalData(
// reportMetadata = reportMetadata,
// statTotalsAndMetadata = CollectedStatTotalsJsReportModel(globalStats)
// )

// JSON Report
InvertJsonReportWriter(invertLogger, rootBuildReportsDir).createInvertJsonReport(
reportMetadata = reportMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import com.squareup.invert.internal.report.GradleProjectAnalysisCombiner
import com.squareup.invert.internal.report.InvertReportWriter
import com.squareup.invert.logging.GradleInvertLogger
import com.squareup.invert.logging.InvertLogger
import com.squareup.invert.models.InvertSerialization.InvertJson
import com.squareup.invert.models.js.HistoricalData
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.builtins.ListSerializer
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.UrlArtifactRepository
Expand All @@ -20,6 +23,7 @@ import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.File
Expand All @@ -41,6 +45,10 @@ abstract class InvertTask : DefaultTask() {
@get:Internal
abstract var statCollectors: List<StatCollector>?

@get:Optional
@get:Input
abstract val historicalDataFileProperty: Property<String?>

@get:Input
abstract val projectPath: Property<String>

Expand Down Expand Up @@ -86,6 +94,20 @@ abstract class InvertTask : DefaultTask() {
)
)

val historicalDataFile: File? = historicalDataFileProperty.orNull?.let { File(it) }
val historicalData: List<HistoricalData> =
if (historicalDataFile?.isFile == true && historicalDataFile.length() > 0) {
try {
val fileContents = historicalDataFile.readText()
InvertJson.decodeFromString(ListSerializer(HistoricalData.serializer()), fileContents)
} catch (e: Exception) {
invertLogger().warn("Failed to read historical data file: $e")
listOf()
}
} else {
listOf()
}

InvertReportWriter(
invertLogger = invertLogger(),
rootBuildReportsDir = invertReportDir,
Expand All @@ -96,7 +118,7 @@ abstract class InvertTask : DefaultTask() {
collectedDependencies = allCollectedData.collectedDependencies,
collectedConfigurations = allCollectedData.collectedConfigurations,
collectedPlugins = allCollectedData.collectedPlugins,
historicalData = emptyList(),
historicalData = historicalData,
)
}
}
Expand All @@ -117,7 +139,7 @@ abstract class InvertTask : DefaultTask() {
InvertFileUtils.REPORTS_SLASH_INVERT_PATH
)
)

this.historicalDataFileProperty.set(extension.getHistoricalDataFilePath())
this.statCollectors = extension.getStatCollectors().toList()

this.mavenRepoUrls.set(
Expand Down

0 comments on commit 22cee8d

Please sign in to comment.