Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright (c) 2024. Tony Robalik.
// SPDX-License-Identifier: Apache-2.0
package com.autonomousapps.model
import com.autonomousapps.internal.unsafeLazy
import com.autonomousapps.internal.utils.flatMapToOrderedSet
import com.autonomousapps.internal.utils.flatMapToSet
import com.autonomousapps.internal.utils.fromJson
import com.autonomousapps.model.CodeSource.Kind
import com.autonomousapps.model.declaration.Variant
import com.squareup.moshi.JsonClass
import org.gradle.api.file.Directory
/** Represents a variant-specific view of the project under analysis. */
@Suppress("MemberVisibilityCanBePrivate") // deliberate API
@JsonClass(generateAdapter = false)
data class ProjectVariant(
val coordinates: ProjectCoordinates,
val buildType: String?,
val flavor: String?,
val variant: Variant,
val sources: Set,
val classpath: Set,
val annotationProcessors: Set,
val testInstrumentationRunner: String?
) {
/**
* For typealiases, we check for presence in the bytecode in any context, annotation or otherwise. We do not check
* usages in Android res.
*/
val usedClassesBySrc: Set by unsafeLazy {
codeSource.flatMapToSet {
it.usedNonAnnotationClasses + it.usedAnnotationClasses
}
}
val usedNonAnnotationClassesBySrc: Set by unsafeLazy {
codeSource.flatMapToSet {
it.usedNonAnnotationClasses
}
}
val usedAnnotationClassesBySrc: Set by unsafeLazy {
codeSource.flatMapToSet {
it.usedAnnotationClasses
}
}
val usedClassesByRes: Set by unsafeLazy {
androidResSource.flatMapToSet {
it.usedClasses
}
}
val usedNonAnnotationClasses: Set by unsafeLazy {
usedClassesByRes + usedNonAnnotationClassesBySrc
}
val exposedClasses: Set by unsafeLazy {
codeSource.flatMapToSet {
it.exposedClasses
}
}
val implementationClasses: Set by unsafeLazy {
usedNonAnnotationClasses - exposedClasses
}
val codeSource: List by unsafeLazy {
sources.filterIsInstance()
}
val androidResSource: List by unsafeLazy {
sources.filterIsInstance()
}
val androidAssetsSource: List by unsafeLazy {
sources.filterIsInstance()
}
val imports: Set by unsafeLazy {
codeSource.flatMapToOrderedSet { it.imports }
}
val javaImports: Set by unsafeLazy {
codeSource.filter { it.kind == Kind.JAVA }
.flatMapToOrderedSet { it.imports }
}
val kotlinImports: Set by unsafeLazy {
codeSource.filter { it.kind == Kind.KOTLIN }
.flatMapToOrderedSet { it.imports }
}
val groovyImports: Set by unsafeLazy {
codeSource.filter { it.kind == Kind.GROOVY }
.flatMapToOrderedSet { it.imports }
}
val scalaImports: Set by unsafeLazy {
codeSource.filter { it.kind == Kind.SCALA }
.flatMapToOrderedSet { it.imports }
}
internal fun dependencies(dependenciesDir: Directory): Set {
return classpath.asSequence()
.plus(annotationProcessors)
.map {
val file = dependenciesDir.file(it.toFileName())
if (file.asFile.exists()) {
file.fromJson()
} else {
error("No file ${it.toFileName()}")
}
}
.toSet()
}
}