Skip to content

Commit

Permalink
Prep for 1.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
eschlenz committed Sep 15, 2021
2 parents 8323232 + d04565a commit 6f4e22e
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 18 deletions.
21 changes: 18 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ dist: trusty
jdk: openjdk11
android:
components:
- tools
- android-29
- build-tools-29.0.2
- extra-android-m2repository

env:
global:
- TARGET_VERSION=30
- ANDROID_BUILD_TOOLS_VERSION=30.0.2
- ANDROID_HOME=~/android-sdk

before_install:
- touch $HOME/.android/repositories.cfg
- wget "https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip" -O commandlinetools.zip
- unzip commandlinetools.zip -d $ANDROID_HOME/
- yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "platforms;android-${TARGET_VERSION}" --sdk_root=$ANDROID_HOME
- yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" --sdk_root=$ANDROID_HOME

before_script:
- chmod +x gradlew

script:
- rm -Rf $HOME/.m2/repository/com/ibotta/gradle/aop/
- ./publishLocal.sh
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ buildscript {
dependencies {
...
classpath "com.ibotta:plugin:1.1.0"
classpath "com.ibotta:plugin:1.2.0"
...
}
}
Expand All @@ -70,7 +70,7 @@ buildscript {
dependencies {
...
classpath("com.ibotta:plugin:1.1.0")
classpath("com.ibotta:plugin:1.2.0")
...
}
}
Expand Down Expand Up @@ -134,12 +134,12 @@ aopWeave {

# A Note on Kotlin 1.5+, SAM Conversion, Lambdas and AOP Annotations
As of Kotlin 1.5.0 the compiler now performs Single Abstract Method (SAM) conversions. This, unfortunately, seems to
break certain aspects of AspectJ weaving. For an example, please see issue #8.
break certain aspects of AspectJ weaving. For an example, please see issue [#8](https://github.com/Ibotta/gradle-aspectj-pipeline-plugin/issues/8).

If you have lambdas that aren't being woven correctly by AspectJ, you can work around it by using the following
compiler option:

```aidl
```
kotlinOptions {
freeCompilerArgs = ["-Xsam-conversions=class"]
}
Expand All @@ -148,9 +148,9 @@ kotlinOptions {
# We Have Sample Apps!
In this project, you will find a few sample apps that use this plugin to perform some simple AOP weaving. They include tests to help prove that the weaving occurred, and is running as expected. Maybe you have a Kotlin only project, or Java only, or a mix! We have examples of each:

- [Kotlin Only Sample App](sample-kotlin)
- [Java Only Sample App](sample-java)
- [Mixed Java/Kotlin Sample App](sample-mixed)
- [Kotlin Only Sample App](sample-kotlin)
- [Java Only Sample App](sample-java)
- [Mixed Java/Kotlin Sample App](sample-mixed)

# How To Build The Project
If you've made no code changes to the project, and simply want to build it, then you can just run the following command from the root of the project: `./gradlew build`
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Plugin {
const val DISPLAY_NAME = "Android AspectJ Gradle Plugin"
const val JVM_TARGET = "1.8"
private const val BUILD_NUMBER = "" // Dynamically updated by publishLocal.sh on Travis. Otherwise left as-is.
const val VERSION = "1.1.0$BUILD_NUMBER"
const val VERSION = "1.2.0$BUILD_NUMBER"
val TAGS = listOf("Gradle", "Plugin", "Android", "AspectJ", "Kotlin", "Java")
}

Expand Down Expand Up @@ -37,14 +37,14 @@ object Sdk {
}

object Versions {
const val ANDROID_BUILD_TOOLS_VERSION = "4.1.0"
const val ANDROID_BUILD_TOOLS_VERSION = "7.0.2"
const val APPCOMPAT_VERSION = "1.1.0"
const val ASPECTJ_VERSION = "1.9.6"
const val GRADLE_PLUGIN_PUBLISH_VERSION = "0.12.0"
const val JACOCO_ANDROID_VERSION = "0.2"
const val JUNIT_VERSION = "5.7.0"
const val KOTLIN_VERSION = "1.4.10"
const val KOTLIN_DSL_VERSION = "1.4.1"
const val KOTLIN_DSL_VERSION = "2.1.6"
const val KOTLINX_SERIALIZATION_RUNTIME_VERSION = "0.20.0"
const val MOCKITO_CORE_VERSION = "3.5.13"
const val MOCKK_VERSION = "1.10.2"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
13 changes: 12 additions & 1 deletion plugin/src/main/kotlin/com/ibotta/gradle/aop/ExtFunctions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.ibotta.gradle.aop

import com.android.build.gradle.tasks.ExtractAnnotations
import com.hiya.plugins.JacocoAndroidUnitTestReportExtension
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.UnknownDomainObjectException
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.compile.AbstractCompile
Expand All @@ -15,6 +15,7 @@ private const val KAPT_TASK_TEMPLATE = "kapt%sKotlin"
private const val JAVA_COMPILE_TASK_TEMPLATE = "compile%sJavaWithJavac"
private const val KOTLIN_COMPILE_TASK_TEMPLATE = "compile%sKotlin"
private const val JACOCO_REPORT_TASK_TEMPLATE = "jacocoTest%sUnitTestReport"
private const val EXTRACT_ANNOTATIONS_TASK_TEMPLATE = "extract%sAnnotations"
private const val JACOCO_ANDROID_REPORT_EXTENSION = "jacocoAndroidUnitTestReport"
const val LANG_JAVA = "Java"
const val LANG_KOTLIN = "Kotlin"
Expand Down Expand Up @@ -56,6 +57,16 @@ fun Project.jacocoReportTaskProvider(variantName: String): TaskProvider<JacocoRe
}
}

fun Project.extractAnnotationsTaskProvider(variantName: String): TaskProvider<ExtractAnnotations>? {
val extractAnnotationsTask = tasks.namedOrNull(EXTRACT_ANNOTATIONS_TASK_TEMPLATE.format(variantName))

return if (extractAnnotationsTask != null) {
extractAnnotationsTask as TaskProvider<ExtractAnnotations>
} else {
null
}
}

fun Project.jacocoAndroidReportExtension(): JacocoAndroidUnitTestReportExtension? {
val jacocoExt = extensions.findByName(JACOCO_ANDROID_REPORT_EXTENSION)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.android.build.gradle.AppPlugin
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.LibraryPlugin
import com.android.build.gradle.tasks.ExtractAnnotations
import com.hiya.plugins.JacocoAndroidUnitTestReportExtension
import org.gradle.api.GradleException
import org.gradle.api.Plugin
Expand Down Expand Up @@ -35,6 +36,7 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
private const val ANDROID_JAR_TEMPLATE = "%s/platforms/%s/android.jar"
private const val PRE_WEAVE_DIR_TEMPLATE = "preWeave/%s/%s"
private const val POST_WEAVE_DIR_TEMPLATE = "postWeave/%s"
private const val PATTERN_ORIGINAL_KOTLINC_OUTPUT_DIR = "tmp/kotlin-classes/"
private const val AOP_WEAVE_TASK = "aopWeave%s"
private const val AOP_LOG = "aop.log"
}
Expand Down Expand Up @@ -90,6 +92,7 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
val aopWeaveProvider = project.tasks
.register(AOP_WEAVE_TASK.format(variantNameCapitalized), AopWeaveTask::class.java)
val jacocoReportTaskProvider = project.jacocoReportTaskProvider(variantNameCapitalized)
val extractAnnotationsTaskProvider = project.extractAnnotationsTaskProvider(variantNameCapitalized)

// Before Kapt can run, we'll need to restore any pre-weave classes from previous
// runs of compile tasks back into the destination directories. This is where Kapt
Expand All @@ -112,6 +115,13 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
configureJacocoReportTask(jacocoReportTaskProvider, postWeaveDir)
}

// We may encounter an "extract<Variant>Annotations" task which expects the original
// Kotlin compilation directory to exist. We'll need to reconfigure it to work
// correctly.
if (extractAnnotationsTaskProvider != null) {
configureExtractAnnotationsTask(extractAnnotationsTaskProvider, preWeaveKotlinDir)
}

// We'll need this jar for weaving.
val androidJarPath = ANDROID_JAR_TEMPLATE.format(
android.sdkDirectory.absolutePath,
Expand Down Expand Up @@ -219,6 +229,43 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
}
}

/**
* At some point in the 7.0.X versions of the Android Gradle Plugin changes, an
* "extract<Variant>Annotations" started appearing to run just after Kotlin compilation. This
* task started to fail, as it no longer could find the
* "<project>/build/tmp/kotlin-classes/<variant>" directory.
*
* Since this directory was never created due to how we are managing the output directories on
* compilation tasks (in order to allow AOP weaving to occur), we need to make sure two things
* happen:
*
* 1. Make sure that "extract<Variant>Annotations" task doesn't fail due to a missing directory.
* We'll simply make sure this directory exists, as a workaround.
*
* 2. We need to ensure the actual Kotlin compilation output directory is included in the list
* needed by this task. Unfortunately, "classpath" is what we'd like to modify, but it's
* immutable. However, looking at the logic in the "ExtractAnnotations" class, it copies
* everything from "bootClasspath" to "classpath" before executing. And "bootClasspath" is
* mutable. So if we add the true compilation output directory to the "bootClasspath", it will
* pick up the compiled classes correctly, and "just work".
*/
private fun configureExtractAnnotationsTask(
extractAnnotationsProvider: TaskProvider<ExtractAnnotations>,
preWeaveKotlinDir: Provider<Directory>
) {
extractAnnotationsProvider.configure {
doFirst {
classpath.files.forEach {
if (it.path.contains(PATTERN_ORIGINAL_KOTLINC_OUTPUT_DIR) && !it.exists()) {
it.mkdirs()
}
}
}

bootClasspath += project.files(preWeaveKotlinDir)
}
}

private fun configureAopWeaveTask(
project: Project,
extension: AopWeaveExtension,
Expand Down
2 changes: 1 addition & 1 deletion sample-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
}

lintOptions {
isWarningsAsErrors = true
isWarningsAsErrors = false
isAbortOnError = true
}

Expand Down
2 changes: 1 addition & 1 deletion sample-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
}

lintOptions {
isWarningsAsErrors = true
isWarningsAsErrors = false
isAbortOnError = true
}

Expand Down
2 changes: 1 addition & 1 deletion sample-mixed/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
}

lintOptions {
isWarningsAsErrors = true
isWarningsAsErrors = false
isAbortOnError = true
}

Expand Down

0 comments on commit 6f4e22e

Please sign in to comment.