Skip to content

Commit 1f8aac1

Browse files
authored
Merge pull request #57 from Archinamon/bintray
Bintray to rule them all!
2 parents 779e34a + 9aa6ed2 commit 1f8aac1

32 files changed

+185
-31
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# GradleAspectJ-Android
22
[![Kotlin](https://img.shields.io/badge/Kotlin-1.1.1-blue.svg)](http://kotlinlang.org) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AspectJ%20Gradle-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/4578) ![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg) [![](https://jitpack.io/v/Archinamon/GradleAspectJ-Android.svg)](https://jitpack.io/#Archinamon/GradleAspectJ-Android) [![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)
3+
[ ![Download](https://api.bintray.com/packages/archinamon/maven/android-gradle-aspectj/images/download.svg) ](https://bintray.com/archinamon/maven/android-gradle-aspectj/_latestVersion)
34

45
A Gradle plugin which enables AspectJ for Android builds.
56
Supports writing code with AspectJ-lang in `.aj` files and in java-annotation style.
67
Full support of Android product flavors and build types.
78
Support Kotlin, Groovy, Scala and any other languages that compiles into java bytecode.
89

9-
Actual version: `com.archinamon:android-gradle-aspectj:3.0.2`.
10+
Actual version: `com.archinamon:android-gradle-aspectj:3.0.3`.
1011
<br />
1112
Friendly with <a href="https://zeroturnaround.com/software/jrebel-for-android/" target="_blank">jRebel for Android</a>!
1213

@@ -48,7 +49,7 @@ Don't forget to add `mavenCentral()` due to some dependencies inside AspectJ-gra
4849

4950
Add the plugin to your `buildscript`'s `dependencies` section:
5051
```groovy
51-
classpath 'com.github.Archinamon:GradleAspectJ-Android:3.0.2'
52+
classpath 'com.github.Archinamon:GradleAspectJ-Android:3.0.3'
5253
```
5354

5455
Apply the `aspectj` plugin:
@@ -149,7 +150,13 @@ Currently it has some limitations:
149150

150151
Working tests
151152
-------
152-
Just write a test and run them! If any errors occurrs please write an issue :)
153+
```groovy
154+
apply plugin: 'com.archinamon.aspectj-test'
155+
```
156+
157+
Test scope configuration inherits `aspectj-ext` behavior with strictly excluding compile and transform tasks from non-test build variant.
158+
In other words only instrumentation `androidTest` will work with this sub-plugin.
159+
In case unit tests doesn't really have any specials (excluding source/target code version base) so `aspectj-test` scope won't affect `unitTest` variants.
153160

154161
ProGuard
155162
-------

AspectJ-gradle/build.gradle renamed to android-gradle-aspectj/build.gradle

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ buildscript {
66
mavenCentral()
77
}
88
dependencies {
9+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
910
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1011
}
1112
}
1213

1314
apply plugin: 'kotlin'
1415
apply plugin: 'maven'
16+
apply plugin: 'com.jfrog.bintray'
1517

1618
project.ext {
1719
aspectjVersion = '1.8.10'
@@ -22,6 +24,7 @@ dependencies {
2224
jcenter()
2325
mavenCentral()
2426
maven { url 'http://repository.jetbrains.com/utils' }
27+
maven { url "https://dl.bintray.com/archinamon/maven" }
2528
}
2629

2730
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
@@ -36,13 +39,34 @@ dependencies {
3639
}
3740

3841
group = 'com.archinamon'
39-
version = '3.0.2'
42+
version = '3.0.3'
4043

41-
// local archive :: debug mode
42-
uploadArchives {
43-
repositories {
44-
mavenDeployer {
45-
repository(url: uri('../'))
44+
task sourcesJar(type: Jar, dependsOn: classes) {
45+
classifier = 'sources'
46+
from sourceSets.main.allSource
47+
}
48+
49+
artifacts {
50+
archives sourcesJar
51+
}
52+
53+
if (project.hasProperty('bintray_user') && project.hasProperty('bintray_apiKey')) {
54+
bintray {
55+
user = bintray_user
56+
key = bintray_apiKey
57+
58+
configurations = ['archives']
59+
pkg {
60+
repo = "maven"
61+
name = "android-gradle-aspectj"
62+
// websiteUrl = siteUrl
63+
vcsUrl = "https://github.com/Archinamon/GradleAspectJ-Android"
64+
licenses = ["Apache-2.0"]
65+
publish = true
66+
version {
67+
name = project.version
68+
released = new Date()
69+
}
4670
}
4771
}
4872
}

AspectJ-gradle/src/main/kotlin/com/archinamon/AndroidConfig.kt renamed to android-gradle-aspectj/src/main/kotlin/com/archinamon/AndroidConfig.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.archinamon
22

33
import com.android.build.gradle.*
4+
import com.archinamon.plugin.ConfigScope
45
import org.gradle.api.GradleException
56
import org.gradle.api.Project
67
import java.io.File
@@ -12,9 +13,9 @@ const val MISDEFINITION = "Illegal definition: $ASPECTJ_PLUGIN should be defined
1213
const private val TAG = "AJC:"
1314
const private val PLUGIN_EXCEPTION = "$TAG You must apply the Android plugin or the Android library plugin"
1415

15-
internal class AndroidConfig(val project: Project) {
16+
internal class AndroidConfig(val project: Project, val scope: ConfigScope) {
1617

17-
val extAndroid: TestedExtension
18+
val extAndroid: BaseExtension
1819
val isLibraryPlugin: Boolean
1920
val plugin: BasePlugin
2021

@@ -27,6 +28,10 @@ internal class AndroidConfig(val project: Project) {
2728
extAndroid = project.extensions.getByType(LibraryExtension::class.java)
2829
plugin = project.plugins.getPlugin(LibraryPlugin::class.java)
2930
isLibraryPlugin = true
31+
} else if (project.plugins.hasPlugin(TestPlugin::class.java)) {
32+
extAndroid = project.extensions.getByType(TestExtension::class.java)
33+
plugin = project.plugins.getPlugin(TestPlugin::class.java)
34+
isLibraryPlugin = false
3035
} else {
3136
isLibraryPlugin = false
3237
throw GradleException(PLUGIN_EXCEPTION)

AspectJ-gradle/src/main/kotlin/com/archinamon/api/AspectJCompileTask.kt renamed to android-gradle-aspectj/src/main/kotlin/com/archinamon/api/AspectJCompileTask.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ internal open class AspectJCompileTask: AbstractCompile() {
4949
return this
5050
}
5151

52-
fun buildAndAttach() {
53-
val android = AndroidConfig(project)
54-
52+
fun buildAndAttach(android: AndroidConfig) {
5553
val options = mutableMapOf(
5654
Pair("overwrite", true),
5755
Pair("group", "build"),

AspectJ-gradle/src/main/kotlin/com/archinamon/api/AspectJTransform.kt renamed to android-gradle-aspectj/src/main/kotlin/com/archinamon/api/AspectJTransform.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.android.build.gradle.internal.variant.BaseVariantData
88
import com.android.build.gradle.internal.variant.BaseVariantOutputData
99
import com.android.utils.FileUtils
1010
import com.archinamon.AndroidConfig
11+
import com.archinamon.plugin.ConfigScope
1112
import com.archinamon.utils.*
1213
import com.archinamon.utils.DependencyFilter.isIncludeFilterMatched
1314
import com.google.common.collect.Sets
@@ -22,13 +23,15 @@ private const val AJRUNTIME = "aspectjrt"
2223
private const val SLICER_DETECTED_ERROR = "Running with InstantRun slicer when weaver extended not allowed!"
2324

2425
enum class BuildPolicy {
26+
2527
SIMPLE,
2628
COMPLEX,
2729
LIBRARY
2830
}
2931

3032
internal class StdTransformer(project: Project): AspectJTransform(project, BuildPolicy.SIMPLE)
3133
internal class ExtTransformer(project: Project): AspectJTransform(project, BuildPolicy.COMPLEX)
34+
internal class TstTransformer(project: Project): AspectJTransform(project, BuildPolicy.COMPLEX)
3235
internal class LibTransformer(project: Project): AspectJTransform(project, BuildPolicy.LIBRARY) {
3336

3437
override fun getScopes(): MutableSet<QualifiedContent.Scope> {
@@ -119,6 +122,12 @@ internal sealed class AspectJTransform(val project: Project, private val policy:
119122
}
120123

121124
override fun transform(transformInvocation: TransformInvocation) {
125+
// bypassing transformer for non-test variant data in ConfigScope.TEST
126+
if (!verifyBypassInTestScope(transformInvocation.context)) {
127+
logBypassTransformation()
128+
return
129+
}
130+
122131
val outputProvider = transformInvocation.outputProvider
123132
val includeJars = config.aspectj().includeJar
124133
val includeAspects = config.aspectj().includeAspectsFromJar
@@ -198,6 +207,15 @@ internal sealed class AspectJTransform(val project: Project, private val policy:
198207

199208
/* Internal */
200209

210+
private fun verifyBypassInTestScope(ctx: Context): Boolean {
211+
val variant = (ctx as TransformTask).variantName
212+
213+
return when (config.scope) {
214+
ConfigScope.TEST -> variant.contains("androidtest", true)
215+
else -> true
216+
}
217+
}
218+
201219
private fun includeCompiledAspects(transformInvocation: TransformInvocation, outputDir: File) {
202220
val compiledAj = project.file("${project.buildDir}/aspectj/${(transformInvocation.context as TransformTask).variantName}")
203221
if (compiledAj.exists()) {

0 commit comments

Comments
 (0)