Skip to content

Commit

Permalink
Extract AGP version-specific code into its own modules
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 453493907
  • Loading branch information
java-team-github-bot authored and Dagger Team committed Jun 7, 2022
1 parent 6380d4f commit 9df8561
Show file tree
Hide file tree
Showing 34 changed files with 870 additions and 250 deletions.
4 changes: 2 additions & 2 deletions .github/actions/test-gradle-plugin/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ description: 'Tests the Hilt Gradle plugin.'
runs:
using: "composite"
steps:
- name: 'Install Java ${{ env.USE_JAVA_VERSION }}'
- name: 'Install Java 11'
uses: actions/setup-java@v2
with:
distribution: '${{ env.USE_JAVA_DISTRIBUTION }}'
java-version: '${{ env.USE_JAVA_VERSION }}'
java-version: '11'
- name: 'Check out repository'
uses: actions/checkout@v2
- name: 'Cache local Maven repository'
Expand Down
9 changes: 9 additions & 0 deletions java/dagger/hilt/android/plugin/agp-wrapper-4-2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}

dependencies {
implementation project(':agp-wrapper')
implementation gradleApi()
compileOnly "com.android.tools.build:gradle:4.2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.component.Component
import com.android.build.api.extension.AndroidComponentsExtension
import org.gradle.api.Project

@Suppress("UnstableApiUsage")
class AndroidComponentsExtensionCompatApi42Impl(
private val project: Project
) : AndroidComponentsExtensionCompat {

override fun onAllVariants(block: (ComponentCompat) -> Unit) {
val actual = project.extensions.getByType(AndroidComponentsExtension::class.java)
val allSelectors = actual.selector().all()
val wrapFunction: (Component) -> Unit = { block.invoke(ComponentCompatApi42Impl(it)) }
actual.onVariants(allSelectors, wrapFunction)
actual.androidTests(allSelectors, wrapFunction)
actual.unitTests(allSelectors, wrapFunction)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.component.Component
import com.android.build.api.instrumentation.AsmClassVisitorFactory
import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationParameters
import com.android.build.api.instrumentation.InstrumentationScope

@Suppress("UnstableApiUsage")
internal class ComponentCompatApi42Impl(private val component: Component) : ComponentCompat() {

override val name: String
get() = component.name

override fun <ParamT : InstrumentationParameters> transformClassesWith(
classVisitorFactoryImplClass: Class<out AsmClassVisitorFactory<ParamT>>,
scope: InstrumentationScope,
instrumentationParamsConfig: (ParamT) -> Unit
) {
component.transformClassesWith(classVisitorFactoryImplClass, scope, instrumentationParamsConfig)
}

override fun setAsmFramesComputationMode(mode: FramesComputationMode) {
component.setAsmFramesComputationMode(mode)
}
}
9 changes: 9 additions & 0 deletions java/dagger/hilt/android/plugin/agp-wrapper-7-0/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}

dependencies {
implementation project(':agp-wrapper')
implementation gradleApi()
compileOnly "com.android.tools.build:gradle:7.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.ApplicationVariant
import com.android.build.api.variant.LibraryVariant
import org.gradle.api.Project

class AndroidComponentsExtensionCompatApi70Impl(
private val project: Project
) : AndroidComponentsExtensionCompat {

@Suppress("UnstableApiUsage")
override fun onAllVariants(block: (ComponentCompat) -> Unit) {
val actual = project.extensions.getByType(AndroidComponentsExtension::class.java)
actual.onVariants { variant ->
block.invoke(ComponentCompatApi70Impl(variant))

when (variant) {
is ApplicationVariant -> variant.androidTest
is LibraryVariant -> variant.androidTest
else -> null
}?.let { block.invoke(ComponentCompatApi70Impl(it)) }

variant.unitTest?.let { block.invoke(ComponentCompatApi70Impl(it)) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.instrumentation.AsmClassVisitorFactory
import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationParameters
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.api.variant.Component

internal class ComponentCompatApi70Impl(private val component: Component) : ComponentCompat() {

override val name: String
get() = component.name

@Suppress("UnstableApiUsage")
override fun <ParamT : InstrumentationParameters> transformClassesWith(
classVisitorFactoryImplClass: Class<out AsmClassVisitorFactory<ParamT>>,
scope: InstrumentationScope,
instrumentationParamsConfig: (ParamT) -> Unit
) {
component.transformClassesWith(classVisitorFactoryImplClass, scope, instrumentationParamsConfig)
}

override fun setAsmFramesComputationMode(mode: FramesComputationMode) {
component.setAsmFramesComputationMode(mode)
}
}
9 changes: 9 additions & 0 deletions java/dagger/hilt/android/plugin/agp-wrapper-7-1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}

dependencies {
implementation project(':agp-wrapper')
implementation gradleApi()
compileOnly "com.android.tools.build:gradle:7.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.HasAndroidTest
import org.gradle.api.Project

class AndroidComponentsExtensionCompatApi71Impl(
private val project: Project
) : AndroidComponentsExtensionCompat {

override fun onAllVariants(block: (ComponentCompat) -> Unit) {
val actual = project.extensions.getByType(AndroidComponentsExtension::class.java)
actual.onVariants { variant ->
block.invoke(ComponentCompatApi71Impl(variant))

(variant as? HasAndroidTest)?.androidTest?.let { block.invoke(ComponentCompatApi71Impl(it)) }

variant.unitTest?.let { block.invoke(ComponentCompatApi71Impl(it)) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.instrumentation.AsmClassVisitorFactory
import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationParameters
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.api.variant.Component

internal class ComponentCompatApi71Impl(private val component: Component) : ComponentCompat() {

override val name: String
get() = component.name

@Suppress("UnstableApiUsage")
override fun <ParamT : InstrumentationParameters> transformClassesWith(
classVisitorFactoryImplClass: Class<out AsmClassVisitorFactory<ParamT>>,
scope: InstrumentationScope,
instrumentationParamsConfig: (ParamT) -> Unit
) {
component.transformClassesWith(classVisitorFactoryImplClass, scope, instrumentationParamsConfig)
}

override fun setAsmFramesComputationMode(mode: FramesComputationMode) {
component.setAsmFramesComputationMode(mode)
}
}
9 changes: 9 additions & 0 deletions java/dagger/hilt/android/plugin/agp-wrapper-7-2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}

dependencies {
implementation project(':agp-wrapper')
implementation gradleApi()
compileOnly "com.android.tools.build:gradle:7.2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.HasAndroidTest
import org.gradle.api.Project

class AndroidComponentsExtensionCompatApi72Impl(
private val project: Project
) : AndroidComponentsExtensionCompat {

override fun onAllVariants(block: (ComponentCompat) -> Unit) {
val actual = project.extensions.getByType(AndroidComponentsExtension::class.java)
actual.onVariants { variant ->
block.invoke(ComponentCompatApi72Impl(variant))

(variant as? HasAndroidTest)?.androidTest?.let { block.invoke(ComponentCompatApi72Impl(it)) }

variant.unitTest?.let { block.invoke(ComponentCompatApi72Impl(it)) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.android.plugin.util

import com.android.build.api.instrumentation.AsmClassVisitorFactory
import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationParameters
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.api.variant.Component

internal class ComponentCompatApi72Impl(private val component: Component) : ComponentCompat() {

override val name: String
get() = component.name

@Suppress("UnstableApiUsage")
override fun <ParamT : InstrumentationParameters> transformClassesWith(
classVisitorFactoryImplClass: Class<out AsmClassVisitorFactory<ParamT>>,
scope: InstrumentationScope,
instrumentationParamsConfig: (ParamT) -> Unit
) {
component.instrumentation.transformClassesWith(
classVisitorFactoryImplClass,
scope,
instrumentationParamsConfig
)
}

@Suppress("UnstableApiUsage")
override fun setAsmFramesComputationMode(mode: FramesComputationMode) {
component.instrumentation.setAsmFramesComputationMode(mode)
}
}
Loading

0 comments on commit 9df8561

Please sign in to comment.