Skip to content

Commit d4b4351

Browse files
committed
Apply to Android BasePlugin
Fix #5
1 parent dcee58e commit d4b4351

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ buildscript {
1717
}
1818

1919
dependencies {
20-
classpath("org.lsposed.lsparanoid:gradle-plugin:0.4.4")
20+
classpath("org.lsposed.lsparanoid:gradle-plugin:0.4.5")
2121
// classpath("com.android.tools.build:gradle")
2222
}
2323
}
@@ -48,6 +48,7 @@ The extension object contains the following properties:
4848
- `seed` - `Integer`. A seed that can be used to make obfuscation stable across builds. Default value is `null`, which means that the seed
4949
is computed from input files on each build.
5050
- `global` - `boolean`. If `true`, the obfuscation will be applied to all classes, not only annotated ones. Default value is `false`.
51+
- `includeDependencies` - `boolean`. If `true`, the obfuscation will be applied to all dependencies. Default value is `false`.
5152
- `variantFilter` - `(Variant) -> boolean`. Allows to filter out variants that should be obfuscated. Default value always returns `true`.
5253

5354
How it works

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
allprojects {
22
group = "org.lsposed.lsparanoid"
3-
version = "0.4.4"
3+
version = "0.4.5"
44

55
val javaVersion by extra(JavaVersion.VERSION_11)
66
val kotlinVersion by extra("1.8.0")

gradle-plugin/src/main/java/org/lsposed/lsparanoid/plugin/ParanoidExtension.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ open class ParanoidExtension {
2323
var enabled: Boolean = true
2424
var seed: Int? = null
2525
var global: Boolean = false
26+
var includeDependencies: Boolean = false
2627
var variantFilter: (Variant) -> Boolean = { true }
2728
}

gradle-plugin/src/main/java/org/lsposed/lsparanoid/plugin/ParanoidPlugin.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ package org.lsposed.lsparanoid.plugin
2020
import com.android.build.api.artifact.ScopedArtifact
2121
import com.android.build.api.variant.AndroidComponentsExtension
2222
import com.android.build.api.variant.ScopedArtifacts
23-
import com.android.build.gradle.AppPlugin
2423
import com.android.build.gradle.BaseExtension
2524
import org.gradle.api.Plugin
2625
import org.gradle.api.Project
26+
import org.gradle.api.plugins.BasePlugin
2727
import org.gradle.api.plugins.JavaPlugin
2828

2929
class ParanoidPlugin : Plugin<Project> {
3030
private lateinit var extension: ParanoidExtension
3131

3232
override fun apply(project: Project) {
3333
extension = project.extensions.create("lsparanoid", ParanoidExtension::class.java)
34-
project.plugins.withType(AppPlugin::class.java) { _ ->
34+
project.plugins.withType(BasePlugin::class.java) { _ ->
3535
project.extensions.configure("androidComponents") { it: AndroidComponentsExtension<*, *, *> ->
3636
it.onVariants { variant ->
3737
if (!extension.enabled) return@onVariants
@@ -44,7 +44,7 @@ class ParanoidPlugin : Plugin<Project> {
4444
it.seed.set(extension.seed)
4545
it.global.set(extension.global)
4646
}
47-
variant.artifacts.forScope(ScopedArtifacts.Scope.ALL)
47+
variant.artifacts.forScope(if (extension.includeDependencies) ScopedArtifacts.Scope.ALL else ScopedArtifacts.Scope.PROJECT)
4848
.use(task).toTransform(
4949
ScopedArtifact.CLASSES,
5050
ParanoidTask::jars,

processor/src/main/kotlin/org/lsposed/lsparanoid/processor/StandaloneClassWriter.kt

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,33 @@ class StandaloneClassWriter : ClassWriter {
5353

5454
override fun getCommonSuperClass(type1: String, type2: String): String {
5555
val hierarchy = HashSet<Type>()
56-
if (fileRegistry.findFileForType(getObjectTypeByInternalName(type1)) != null) {
57-
for (mirror in classRegistry.findClassHierarchy(getObjectTypeByInternalName(type1))) {
58-
hierarchy.add(mirror.type)
59-
}
60-
} else {
61-
// compile only classes always assume java.lang.Object its superclass
62-
hierarchy.add(OBJECT_TYPE)
56+
for (mirror in classRegistry.findClassHierarchy(getObjectTypeByInternalName(type1))) {
57+
hierarchy.add(mirror.type)
6358
}
6459

65-
if (fileRegistry.findFileForType(getObjectTypeByInternalName(type2)) != null) {
66-
for (mirror in classRegistry.findClassHierarchy(getObjectTypeByInternalName(type2))) {
67-
if (mirror.type in hierarchy) {
68-
logger.debug("[getCommonSuperClass]: {} & {} = {}", type1, type2, mirror.access)
69-
return mirror.type.internalName
70-
}
60+
for (mirror in classRegistry.findClassHierarchy(getObjectTypeByInternalName(type2))) {
61+
if (mirror.type in hierarchy) {
62+
logger.debug("[getCommonSuperClass]: {} & {} = {}", type1, type2, mirror.access)
63+
return mirror.type.internalName
7164
}
72-
} else {
73-
// compile only classes always assume java.lang.Object as the common superclass
74-
return OBJECT_INTERNAL_NAME
7565
}
7666

7767
logger.warn("[getCommonSuperClass]: {} & {} = NOT FOUND ", type1, type2)
7868
return OBJECT_INTERNAL_NAME
7969
}
8070

8171
private fun ClassRegistry.findClassHierarchy(type: Type.Object): Sequence<ClassMirror> {
82-
return generateSequence(getClassMirror(type)) {
83-
it.superType?.let { getClassMirror(it) }
72+
return generateSequence(getClassMirrorOrObject(type)) {
73+
it.superType?.let { superType -> getClassMirrorOrObject(superType) }
8474
}
8575
}
8676

77+
private fun ClassRegistry.getClassMirrorOrObject(type: Type.Object): ClassMirror? {
78+
return fileRegistry.findFileForType(type)?.let { _ ->
79+
getClassMirror(type)
80+
} ?: getClassMirror(OBJECT_TYPE)
81+
}
82+
8783
companion object {
8884
private val OBJECT_INTERNAL_NAME = getObjectType<Any>().internalName
8985
}

0 commit comments

Comments
 (0)