Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/main/kotlin/com/autonomousapps/internal/OutputPaths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class OutputPaths(
val dependenciesDir = dir("${variantDirectory}/dependencies")
val explodedSourcePath = file("${intermediatesDir}/exploded-source.json")
val explodingBytecodePath = file("${intermediatesDir}/exploding-bytecode.json")
val syntheticProjectPath = file("${intermediatesDir}/synthetic-project.json")
val syntheticProjectPath = file("${intermediatesDir}/synthetic-project.json.gz")
val dependencyTraceReportPath = file("${variantDirectory}/dependency-trace-report.json")
val typeUsagePath = file("${variantDirectory}/type-usage.json")
val androidScorePath = file("${variantDirectory}/android-score.json")
Expand Down
15 changes: 13 additions & 2 deletions src/main/kotlin/com/autonomousapps/internal/utils/moshi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,21 @@ public inline fun <reified T> File.bufferWriteJsonSet(
* By default, the output is compacted.
*
* @param obj The object to write to file
* @param compress Whether to compress output with gzip.
* @param indent The indent to control how the result is formatted
*/
public inline fun <reified T> File.bufferWriteJson(obj: T, indent: String = noJsonIndent) {
JsonWriter.of(sink().buffer()).use { writer ->
public inline fun <reified T> File.bufferWriteJson(
obj: T,
compress: Boolean = false,
indent: String = noJsonIndent,
) {
val buffer = if (compress) {
GzipSink(sink()).buffer()
} else {
sink().buffer()
}

JsonWriter.of(buffer).use { writer ->
getJsonAdapter<T>().indent(indent).toJson(writer, obj)
}
}
Expand Down
32 changes: 20 additions & 12 deletions src/main/kotlin/com/autonomousapps/internal/utils/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ internal inline fun <reified T> RegularFile.fromJsonSet(
internal inline fun <reified T> File.fromJsonSet(
compressed: Boolean = false,
): Set<T> {
val source = if (compressed) {
GzipSource(source()).buffer()
} else {
bufferRead()
}

return source.use { getJsonSetAdapter<T>().fromJson(it)!! }
return bufferRead(compressed).use { getJsonSetAdapter<T>().fromJson(it)!! }
}

/** Buffers reads of the RegularFileProperty from disk to the set. */
Expand Down Expand Up @@ -122,14 +116,20 @@ internal inline fun <reified K, reified V> File.fromJsonMap(): Map<K, V> {
}

/** Buffer reads of the RegularFileProperty from disk to the set. */
internal inline fun <reified T> RegularFileProperty.fromJson(): T = get().fromJson()
internal inline fun <reified T> RegularFileProperty.fromJson(
compressed: Boolean = false,
): T = get().fromJson(compressed)

/** Buffer reads of the RegularFile from disk to the set. */
internal inline fun <reified T> RegularFile.fromJson(): T = asFile.fromJson()
internal inline fun <reified T> RegularFile.fromJson(
compressed: Boolean = false,
): T = asFile.fromJson(compressed)

/** Buffer reads of the File from disk to the set. */
internal inline fun <reified T> File.fromJson(): T {
return bufferRead().use { reader ->
internal inline fun <reified T> File.fromJson(
compressed: Boolean = false,
): T {
return bufferRead(compressed).use { reader ->
getJsonAdapter<T>().fromJson(reader)!!
}
}
Expand All @@ -140,7 +140,15 @@ internal fun RegularFile.readLines(): List<String> = asFile.readLines()

internal fun RegularFileProperty.readText(): String = get().asFile.readText()

private fun File.bufferRead(): BufferedSource = source().buffer()
private fun File.bufferRead(
compressed: Boolean = false,
): BufferedSource {
return if (compressed) {
GzipSource(source()).buffer()
} else {
source().buffer()
}
}

internal fun String.capitalizeSafely(): String {
return replaceFirstChar(Char::uppercase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class AndroidScoreTask @Inject constructor(

public abstract class Action : WorkAction<Parameters> {

private val project = parameters.syntheticProject.fromJson<ProjectVariant>()
private val project = parameters.syntheticProject.fromJson<ProjectVariant>(compressed = true)
private val dependencies = project.dependencies(parameters.dependencies.get())

override fun execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public abstract class ComputeTypeUsageTask @Inject constructor(
val output = parameters.output.getAndDelete()

// 1. Load data
val project = parameters.syntheticProject.fromJson<ProjectVariant>()
val project = parameters.syntheticProject.fromJson<ProjectVariant>(compressed = true)
val dependencies = project.dependencies(parameters.dependencies.get())
val classToCoords = buildClassIndex()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public abstract class ComputeUsagesTask @Inject constructor(
private val graph = parameters.graph.fromJson<DependencyGraphView>()
private val graphRuntime = parameters.graphRuntime.fromJson<DependencyGraphView>()
private val declarations = parameters.declarations.fromJsonSet<Declaration>()
private val project = parameters.syntheticProject.fromJson<ProjectVariant>()
private val project = parameters.syntheticProject.fromJson<ProjectVariant>(compressed = true)
private val dependencies = project.dependencies(parameters.dependencies.get())
private val duplicateClasses =
parameters.duplicateClassesReports.get().asSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class DiscoverClasspathDuplicationTask : DefaultTask() {
@TaskAction public fun action() {
val output = output.getAndDelete()

val project = syntheticProject.fromJson<ProjectVariant>()
val project = syntheticProject.fromJson<ProjectVariant>(compressed = true)
val duplicates = ClasspathAnalyzer(project, classpathName.get(), classpath).duplicates()

output.writeText(duplicates.toJson())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public abstract class SynthesizeProjectViewTask @Inject constructor(
excludedIdentifiers = excludedIdentifiers,
)

output.bufferWriteJson(projectVariant)
output.bufferWriteJson(projectVariant, compress = true)
}

private fun CodeSource.excludeUsages(usagesExclusions: UsagesExclusions): CodeSource {
Expand Down