Skip to content

Commit 65f78d3

Browse files
author
zhangyang06
committed
[feat] 保证工程编译成功
1 parent 7b714a2 commit 65f78d3

File tree

9 files changed

+82
-26
lines changed

9 files changed

+82
-26
lines changed

Plugin/AutoRegister/build.gradle

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
apply plugin: 'groovy'
2-
apply plugin: 'java-gradle-plugin'
3-
1+
plugins {
2+
id("kotlin")
3+
id("groovy")
4+
id("java-gradle-plugin")
5+
}
46
dependencies {
57
implementation gradleApi()
68
implementation localGroovy()
79
implementation project(":BasePlugin")
810
implementation "com.android.tools.build:gradle:$apgVersion"
9-
implementation 'commons-io:commons-io:2.6'
11+
implementation 'commons-io:commons-io:2.11.0'
1012
implementation 'org.javassist:javassist:3.20.0-GA'
1113
}
1214

Plugin/AutoRegister/src/main/java/com/kronos/autoregister/AutoRegisterPlugin.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package com.kronos.autoregister
22

33
import com.android.build.gradle.AppExtension
4-
import com.kronos.autoregister.AutoRegisterConfig
5-
import com.kronos.autoregister.AutoRegisterPlugin
64
import org.gradle.api.Plugin
75
import org.gradle.api.Project
86

9-
internal class AutoRegisterPlugin : Plugin<Project> {
7+
class AutoRegisterPlugin : Plugin<Project> {
108

119
override fun apply(project: Project) {
1210
project.extensions.create(EXT_NAME, AutoRegisterConfig::class.java)
1311
if (project.plugins.hasPlugin("com.android.application")) {
14-
1512
val appExtension = project.extensions.getByType(
1613
AppExtension::class.java
1714
)

Plugin/AutoRegister/src/main/java/com/kronos/autoregister/NewAutoRegisterTransform.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.kronos.plugin.base.TransformCallBack;
1616

1717
import org.apache.commons.io.IOUtils;
18-
import org.gradle.internal.impldep.com.google.common.collect.ImmutableSet;
1918
import org.jetbrains.annotations.NotNull;
2019
import org.jetbrains.annotations.Nullable;
2120
import org.objectweb.asm.ClassReader;
@@ -82,8 +81,10 @@ public void delete(String s, byte[] bytes) {
8281
baseTransform.openSimpleScan();
8382
baseTransform.startTransform();
8483
TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
84+
HashSet<QualifiedContent.Scope> set = new HashSet<>();
85+
set.add(QualifiedContent.Scope.PROJECT);
8586
File dest = outputProvider.getContentLocation("kronos_router", TransformManager.CONTENT_CLASS,
86-
ImmutableSet.of(QualifiedContent.Scope.PROJECT), Format.DIRECTORY);
87+
set, Format.DIRECTORY);
8788
generateInitClass(dest.getAbsolutePath(), items, deleteItems);
8889
}
8990

RouterAnnotation/build.gradle.kts

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
1+
import java.util.*
2+
13
plugins {
24
id("java-library")
35
id("kotlin")
46
}
57

8+
9+
task("stubLib", JavaCompile::class) {
10+
source(file("src/stub/java"))
11+
classpath = project.files(getAndroidJar("32"))
12+
// libraries
13+
destinationDirectory.set(File(project.buildDir, "/tmp/stubLibs"))
14+
}
15+
16+
task("stubLibsJar", Jar::class) {
17+
archiveBaseName.set("stub")
18+
archiveVersion.set("1.0")
19+
from(tasks.getByName("stubLib"))
20+
include("**/*.class")
21+
}
22+
623
dependencies {
724
// implementation fileTree(dir: 'libs', include: ['*.jar'])
8-
}
25+
// compileOnly(getAndroidJar("32"))
26+
val stub = tasks.getByName("stubLibsJar").outputs.files
27+
compileOnly(stub)
28+
}
29+
30+
31+
fun getAndroidJar(compileSdkVersion: String): String {
32+
var androidSdkDir =
33+
System.getenv(com.android.tools.analytics.Environment.EnvironmentVariable.ANDROID_SDK_HOME.key)
34+
if (androidSdkDir.isNullOrEmpty()) {
35+
val propertiesFile = rootProject.file("local.properties")
36+
if (propertiesFile.exists()) {
37+
val properties = Properties()
38+
properties.load(propertiesFile.inputStream())
39+
androidSdkDir = properties.getProperty("sdk.dir")
40+
}
41+
}
42+
if (androidSdkDir.isNullOrEmpty()) {
43+
throw StopExecutionException("please declares your 'sdk.dir' to file 'local.properties'")
44+
}
45+
val path = "platforms${File.separator}android-${compileSdkVersion}${File.separator}android.jar"
46+
return File(androidSdkDir.toString(), path).absolutePath
47+
}
48+

RouterAnnotation/src/main/java/com/kronos/router/BindRouter.kt

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import kotlin.reflect.KClass
88
* Created by Leif Zhang on 2016/12/2.
99
1010
*/
11-
@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
11+
@Target(
12+
AnnotationTarget.ANNOTATION_CLASS,
13+
AnnotationTarget.CLASS,
14+
AnnotationTarget.FUNCTION,
15+
AnnotationTarget.PROPERTY_GETTER,
16+
AnnotationTarget.PROPERTY_SETTER
17+
)
1218
@Retention(RetentionPolicy.CLASS)
13-
annotation class BindRouter(val urls: Array<String>, val weight: Int = 0, val interceptors: Array<KClass<*>> = [])
19+
annotation class BindRouter(
20+
val urls: Array<String>,
21+
val weight: Int = 0,
22+
val interceptors: Array<KClass<*>> = []
23+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.kronos.interceptor;
2+
3+
public interface Interceptor {
4+
}

app/build.gradle.kts

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ plugins {
44
// 这个 id 就是在 versionPlugin 文件夹下 build.gradle.kts.kts.kts.kts 文件内定义的id
55
id("com.android.application")
66
id("kotlin-android")
7-
id("kotlin-kapt")
87
id("com.google.devtools.ksp")
9-
// id("router-register")
8+
id("router-register")
109
}
1110

1211
android {
@@ -19,7 +18,7 @@ android {
1918
}
2019
buildTypes {
2120
getByName("release") {
22-
// minifyEnabled(false)
21+
// minifyEnabled(false)
2322
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
2423
}
2524
}
@@ -49,7 +48,7 @@ dependencies {
4948

5049
implementation("com.github.leifzhang:secondmoudle:$routerVersion")
5150
implementation("com.github.leifzhang:CoroutineSupport:$routerVersion")
52-
kapt("com.github.leifzhang:compiler:$routerVersion")
51+
// kapt("com.github.leifzhang:compiler:$routerVersion")
5352

5453
val lifecycle_version = "2.3.1"
5554

@@ -77,5 +76,5 @@ dependencies {
7776
// optional - ReactiveStreams support for LiveData
7877
implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version")
7978

80-
// ksp(project(":kspCompiler"))
79+
ksp(project(":kspCompiler"))
8180
}

kspCompiler/src/main/java/com/kronos/ksp/compiler/KotlinPoetExe.kt

+11-7
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ internal interface TypeParameterResolver {
5656
}
5757

5858
internal fun List<KSTypeParameter>.toTypeParameterResolver(
59-
fallback: TypeParameterResolver? = null,
60-
sourceType: String? = null,
59+
fallback: TypeParameterResolver? = null,
60+
sourceType: String? = null,
6161
): TypeParameterResolver {
6262
val parametersMap = LinkedHashMap<String, TypeVariableName>()
6363
val typeParamResolver = { id: String ->
6464
parametersMap[id]
65-
?: fallback?.get(id)
66-
?: throw IllegalStateException("No type argument found for $id! Anaylzing $sourceType")
65+
?: fallback?.get(id)
66+
?: throw IllegalStateException("No type argument found for $id! Anaylzing $sourceType")
6767
}
6868

6969
val resolver = object : TypeParameterResolver {
@@ -93,7 +93,7 @@ internal fun KSClassDeclaration.toClassName(): ClassName {
9393
val typesString = qualifiedName!!.asString().removePrefix("$pkgName.")
9494

9595
val simpleNames = typesString
96-
.split(".")
96+
.split(".")
9797
return ClassName(pkgName, simpleNames)
9898
}
9999

@@ -103,7 +103,7 @@ internal fun KSTypeParameter.toTypeName(typeParamResolver: TypeParameterResolver
103103
}
104104

105105
internal fun KSTypeParameter.toTypeVariableName(
106-
typeParamResolver: TypeParameterResolver,
106+
typeParamResolver: TypeParameterResolver,
107107
): TypeVariableName {
108108
val typeVarName = name.getShortName()
109109
val typeVarBounds = bounds.map { it.toTypeName(typeParamResolver) }
@@ -112,7 +112,11 @@ internal fun KSTypeParameter.toTypeVariableName(
112112
CONTRAVARIANT -> KModifier.IN
113113
else -> null
114114
}
115-
return TypeVariableName(typeVarName, bounds = typeVarBounds, variance = typeVarVariance)
115+
return TypeVariableName(
116+
typeVarName,
117+
bounds = typeVarBounds.toList(),
118+
variance = typeVarVariance
119+
)
116120
}
117121

118122
internal fun KSTypeArgument.toTypeName(typeParamResolver: TypeParameterResolver): TypeName {

secondmoudle/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ plugins {
44
// 这个 id 就是在 versionPlugin 文件夹下 build.gradle.kts.kts 文件内定义的id
55
id("com.android.library")
66
id("kotlin-android")
7-
id("kotlin-android-extensions")
87
id("kotlin-kapt")
98
id("com.google.devtools.ksp")
109
}

0 commit comments

Comments
 (0)