All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.autonomousapps.internal.analyzer.DependencyAnalyzer.kt Maven / Gradle / Ivy

There is a newer version: 2.6.1
Show newest version
// Copyright (c) 2024. Tony Robalik.
// SPDX-License-Identifier: Apache-2.0
@file:Suppress("UnstableApiUsage")

package com.autonomousapps.internal.analyzer

import com.autonomousapps.internal.OutputPaths
import com.autonomousapps.model.declaration.SourceSetKind
import com.autonomousapps.tasks.*
import org.gradle.api.Project
import org.gradle.api.UnknownDomainObjectException
import org.gradle.api.UnknownTaskException
import org.gradle.api.artifacts.Configuration
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.File

/** Abstraction for differentiating between android-app, android-lib, and java-lib projects.  */
internal interface DependencyAnalyzer {
  /** E.g., `flavorDebug` */
  val variantName: String

  /** E.g., 'flavor' */
  val flavorName: String?

  /** E.g., 'debug' */
  val buildType: String?

  val kind: SourceSetKind

  /** E.g., `FlavorDebug` */
  val variantNameCapitalized: String

  /** E.g., `FlavorDebugTest` */
  val taskNameSuffix: String

  /** E.g., "compileClasspath", "debugCompileClasspath". */
  val compileConfigurationName: String

  /** E.g., "runtimeClasspath", "debugRuntimeClasspath". */
  val runtimeConfigurationName: String

  /** E.g., "kaptDebug" */
  val kaptConfigurationName: String

  /** E.g., "annotationProcessorDebug" */
  val annotationProcessorConfigurationName: String

  /** E.g., "androidx.test.runner.AndroidJUnitRunner" */
  val testInstrumentationRunner: Provider

  val attributeValueJar: String

  /** Kotlin projects have no Java source */
  val javaSourceFiles: Provider>?
  val kotlinSourceFiles: Provider>
  val groovySourceFiles: Provider>
  val scalaSourceFiles: Provider>

  val isDataBindingEnabled: Provider
  val isViewBindingEnabled: Provider

  val outputPaths: OutputPaths

  fun registerByteCodeSourceExploderTask(): TaskProvider

  fun registerManifestComponentsExtractionTask(): TaskProvider? = null

  fun registerFindAndroidResTask(): TaskProvider? = null
  fun registerExplodeXmlSourceTask(): TaskProvider? = null
  fun registerExplodeAssetSourceTask(): TaskProvider? = null

  fun registerFindNativeLibsTask(): TaskProvider? = null

  fun registerFindAndroidLintersTask(): TaskProvider? = null

  fun registerFindAndroidAssetProvidersTask(): TaskProvider? = null

  fun registerFindDeclaredProcsTask(): TaskProvider

  /**
   * This is a no-op for `com.android.application` and JVM `application` projects (including Spring Boot), since they
   * have no meaningful ABI.
   */
  fun registerAbiAnalysisTask(abiExclusions: Provider): TaskProvider? = null

  fun registerAndroidScoreTask(
    synthesizeDependenciesTask: TaskProvider,
    synthesizeProjectViewTask: TaskProvider,
  ): TaskProvider? = null
}

internal abstract class AbstractDependencyAnalyzer(
  protected val project: Project,
) : DependencyAnalyzer {

  // Always null for JVM projects. May be null for Android projects.
  override val testInstrumentationRunner: Provider = project.provider { null }

  protected fun kaptConf(): Configuration? = try {
    project.configurations[kaptConfigurationName]
  } catch (_: UnknownDomainObjectException) {
    null
  }

  protected fun annotationProcessorConf(): Configuration? = try {
    project.configurations[annotationProcessorConfigurationName]
  } catch (_: UnknownDomainObjectException) {
    null
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy