Skip to content

Commit a3be577

Browse files
authored
Merge pull request #43 from Badya/master
Improvements to plugin lifecycle #42
2 parents b5ed70a + 17c7546 commit a3be577

File tree

11 files changed

+56
-39
lines changed

11 files changed

+56
-39
lines changed

AspectJ-gradle/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
}
3636

3737
group = 'com.archinamon'
38-
version = '3.0.0'
38+
version = '3.0.1'
3939

4040
// local archive :: debug mode
4141
uploadArchives {

AspectJ-gradle/src/main/kotlin/com/archinamon/AspectJExtension.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ open class AspectJExtension {
55
open var ajc = "1.8.10"
66

77
open var includeAllJars = false
8-
open var includeJar = mutableListOf<String>()
8+
open var includeJar = mutableSetOf<String>()
99

10-
open var includeAspectsFromJar = mutableListOf<String>()
11-
open var ajcArgs = mutableListOf<String>()
10+
open var includeAspectsFromJar = mutableSetOf<String>()
11+
open var ajcArgs = mutableSetOf<String>()
1212

1313
open var weaveInfo = true
1414
open var debugInfo = false

AspectJ-gradle/src/main/kotlin/com/archinamon/api/AspectJCompileTask.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ internal open class AspectJCompileTask: AbstractCompile() {
6868

6969
task.source(sources)
7070
task.classpath = classpath()
71-
7271
findCompiledAspectsInClasspath(task, config.includeAspectsFromJar)
7372

7473
task.aspectJWeaver.ajSources = sources
@@ -94,6 +93,7 @@ internal open class AspectJCompileTask: AbstractCompile() {
9493
// javaCompile.classpath does not contain exploded-aar/**/jars/*.jars till first run
9594
javaCompiler.doLast {
9695
task.classpath = classpath()
96+
findCompiledAspectsInClasspath(task, config.includeAspectsFromJar)
9797
}
9898

9999
//apply behavior
@@ -104,9 +104,9 @@ internal open class AspectJCompileTask: AbstractCompile() {
104104
return SimpleFileCollection(javaCompiler.classpath.files + javaCompiler.destinationDir)
105105
}
106106

107-
private fun findCompiledAspectsInClasspath(task: AspectJCompileTask, aspectsFromJar: List<String>) {
107+
private fun findCompiledAspectsInClasspath(task: AspectJCompileTask, aspectsFromJar: Collection<String>) {
108108
val classpath: FileCollection = task.classpath
109-
val aspects: ArrayList<File> = ArrayList()
109+
val aspects: MutableSet<File> = mutableSetOf()
110110

111111
classpath.forEach { file ->
112112
if (aspectsFromJar.isNotEmpty() && DependencyFilter.isIncludeFilterMatched(file, aspectsFromJar)) {
@@ -127,9 +127,9 @@ internal open class AspectJCompileTask: AbstractCompile() {
127127

128128
destinationDir.deleteRecursively()
129129

130-
aspectJWeaver.classPath = ArrayList(classpath.files)
130+
aspectJWeaver.classPath = LinkedHashSet(classpath.files)
131131
aspectJWeaver.doWeave()
132132

133133
logCompilationFinish()
134134
}
135-
}
135+
}

AspectJ-gradle/src/main/kotlin/com/archinamon/api/AspectJWeaver.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,16 @@ internal class AspectJWeaver(val project: Project) {
3939
var breakOnError: Boolean = false
4040
var experimental: Boolean = false
4141

42-
var ajcArgs = ArrayList<String>()
42+
var ajcArgs = LinkedHashSet<String>()
4343

44-
var ajSources: ArrayList<File> = ArrayList()
44+
var ajSources: MutableSet<File> = LinkedHashSet()
4545
internal set(ajSources) {
46-
ajSources.filterNot { this.ajSources.contains(it) }
47-
.forEach { this.ajSources.add(it) }
46+
ajSources.forEach { this.ajSources.add(it) }
4847
}
4948

50-
var aspectPath: ArrayList<File> = ArrayList()
51-
var inPath: ArrayList<File> = ArrayList()
52-
var classPath: ArrayList<File> = ArrayList()
49+
var aspectPath: MutableSet<File> = LinkedHashSet()
50+
var inPath: MutableSet<File> = LinkedHashSet()
51+
var classPath: MutableSet<File> = LinkedHashSet()
5352
var bootClasspath: String? = null
5453
var sourceCompatibility: String? = null
5554
var targetCompatibility: String? = null
@@ -168,7 +167,7 @@ internal class AspectJWeaver(val project: Project) {
168167
}
169168
}
170169

171-
private inline operator fun <reified E> MutableList<in E>.plus(elem: E): MutableList<in E> {
170+
private inline operator fun <reified E> MutableCollection<in E>.plus(elem: E): MutableCollection<in E> {
172171
this.add(elem)
173172
return this
174173
}

AspectJ-gradle/src/main/kotlin/com/archinamon/plugin/PluginSetup.kt

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

33
import com.android.build.gradle.AppPlugin
4-
import com.android.build.gradle.BasePlugin
54
import com.android.build.gradle.LibraryPlugin
65
import com.archinamon.AndroidConfig
76
import com.archinamon.AspectJExtension

AspectJ-gradle/src/main/kotlin/com/archinamon/utils/AarExploring.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal fun findPackageNameIfAar(input: File): String {
1212

1313
do {
1414
f = f?.parentFile
15-
} while (f?.isDirectory!! && !f.listFiles()?.any(::findManifest)!!)
15+
} while (f?.isDirectory!! && !f.listFiles().any(::findManifest))
1616

1717
val manifest = f.listFiles().find(::findManifest)
1818
if (manifest != null) {

AspectJ-gradle/src/main/kotlin/com/archinamon/utils/DependencyFilter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ internal object DependencyFilter {
1515
EXCLUDE
1616
}
1717

18-
internal fun isExcludeFilterMatched(file: File?, filters: List<String>?): Boolean {
18+
internal fun isExcludeFilterMatched(file: File?, filters: Collection<String>?): Boolean {
1919
return isFilterMatched(file, filters, Policy.EXCLUDE)
2020
}
2121

22-
internal fun isIncludeFilterMatched(file: File?, filters: List<String>?): Boolean {
22+
internal fun isIncludeFilterMatched(file: File?, filters: Collection<String>?): Boolean {
2323
return isFilterMatched(file, filters, Policy.INCLUDE)
2424
}
2525

26-
private fun isFilterMatched(file: File?, filters: List<String>?, filterPolicy: Policy): Boolean {
26+
private fun isFilterMatched(file: File?, filters: Collection<String>?, filterPolicy: Policy): Boolean {
2727
if (file === null) {
2828
return false
2929
}

AspectJ-gradle/src/main/kotlin/com/archinamon/utils/StatusLogger.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal fun logExtraAjcArgumentAlreadyExists(arg: String) {
5252
println("extra AjC argument $arg already exists in build config")
5353
}
5454

55-
internal fun logBuildParametersAdapted(args: MutableList<String?>, logfile: String) {
55+
internal fun logBuildParametersAdapted(args: MutableCollection<String?>, logfile: String) {
5656
var params: String = ""
5757

5858
args.forEach { params += if (it?.startsWith('-')!!) "$it :: " else ( if (it.length > 200) "[ list files ],\n" else "$it, ") }

AspectJ-gradle/src/main/kotlin/com/archinamon/utils/VariantUtils.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.gradle.api.file.FileCollection
88
import org.gradle.api.internal.file.collections.SimpleFileCollection
99
import org.gradle.api.tasks.compile.JavaCompile
1010
import java.io.File
11-
import java.util.ArrayList
1211

1312
fun getJavaTask(baseVariantData: BaseVariantData<out BaseVariantOutputData>): JavaCompile? {
1413
if (baseVariantData.javacTask != null) {
@@ -36,8 +35,8 @@ fun getAjSourceAndExcludeFromJavac(project: Project, variantData: BaseVariantDat
3635
return aspects.filter(File::exists)
3736
}
3837

39-
fun findAjSourcesForVariant(project: Project, variantName: String): ArrayList<File> {
40-
val possibleDirs: MutableList<File> = mutableListOf()
38+
fun findAjSourcesForVariant(project: Project, variantName: String): MutableSet<File> {
39+
val possibleDirs: MutableSet<File> = mutableSetOf()
4140
if (project.file("src/main/aspectj").exists()) {
4241
possibleDirs.add(project.file("src/main/aspectj"))
4342
}
@@ -47,25 +46,24 @@ fun findAjSourcesForVariant(project: Project, variantName: String): ArrayList<Fi
4746
root.forEach { file ->
4847
types.forEach { type ->
4948
if (file.name.contains(type.toLowerCase()) &&
50-
file.list().any { it.contains("aspectj") } &&
51-
!possibleDirs.contains(file)) {
49+
file.list().any { it.contains("aspectj") }) {
5250
possibleDirs.add(File(file, "aspectj"))
5351
}
5452
}
5553
}
5654

57-
return ArrayList(possibleDirs)
55+
return LinkedHashSet(possibleDirs)
5856
}
5957

6058
fun getVariantDataList(plugin: BasePlugin): List<BaseVariantData<out BaseVariantOutputData>> {
6159
return plugin.variantManager.variantDataList
6260
}
6361

64-
internal infix fun <E> ArrayList<in E>.shl(elem: E): ArrayList<in E> {
62+
internal infix fun <E> MutableCollection<in E>.shl(elem: E): MutableCollection<in E> {
6563
this.add(elem)
6664
return this
6765
}
6866

69-
internal infix fun <E> ArrayList<in E>.from(elems: List<E>) {
67+
internal infix fun <E> MutableCollection<in E>.from(elems: Collection<E>) {
7068
this.addAll(elems)
7169
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.archinamon.utils
2+
3+
import org.junit.Rule
4+
import org.junit.Test
5+
import org.junit.rules.TemporaryFolder
6+
import java.io.File
7+
8+
class AarExploringTest {
9+
@Rule
10+
@JvmField
11+
val folder = TemporaryFolder()
12+
13+
@Test
14+
fun noNPEIfFileNotExist() {
15+
findPackageNameIfAar(File("/build-cache/this/file/not/exist"))
16+
}
17+
18+
}

0 commit comments

Comments
 (0)