Skip to content

Commit 5607b3c

Browse files
committed
适配旧插件
1 parent 8a20316 commit 5607b3c

File tree

25 files changed

+117
-123
lines changed

25 files changed

+117
-123
lines changed

Diff for: README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
### 更新内容
99

10+
* 使用Kotlin重构Gradle-plugin
11+
* 使用并发Transform和InstantRun提升编译速度。插件构建不需要clean
1012
* gradle-plugin 更新至4.2.2
1113
* gradle 更新至6.7.1
1214
* 仅支持AndroidX,不再支持Support包
13-
* 使用Kotlin重构Gradle-plugin
14-
* 使用并发Transform和InstantRun提升编译速度。插件构建不需要clean
15-
* 重构还未经过严格测试。稳定版本请使用[Master](https://github.com/CliffLeopard/RePlugin/tree/master)
1615

1716
### 配置
1817

Diff for: build.gradle

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
buildscript {
33
apply from: './plugin_config.gradle'
44
repositories {
5-
maven {
6-
url "http://s3.qbuild.corp.qihoo.net:8360/nexus/content/repositories/360zhushou_Snapshot/"
7-
}
5+
google()
6+
mavenLocal()
87
maven {
98
url "https://plugins.gradle.org/m2/"
109
}
11-
google()
1210
mavenCentral()
1311
}
1412
dependencies {
1513
classpath "com.android.tools.build:gradle:$GRADLE_PLUGIN"
16-
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
14+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
1715
if(SDK_PUBLISH == "false")
1816
{
1917
classpath "com.qihoo360.replugin:replugin-gradle:${RP_VERSION}"
@@ -24,10 +22,8 @@ buildscript {
2422

2523
allprojects {
2624
repositories {
27-
maven {
28-
url "http://s3.qbuild.corp.qihoo.net:8360/nexus/content/repositories/360zhushou_Snapshot/"
29-
}
3025
google()
26+
mavenLocal()
3127
mavenCentral()
3228

3329
}

Diff for: plugin_config.gradle

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
project.ext {
2-
32
GRADLE_PLUGIN = '4.2.2'
4-
KOTLIN_VERSION = '1.5.31'
3+
KOTLIN_VERSION = '1.7.20'
54
PLUGIN_PUBLISH_VERSION = '0.15.0'
65
ASM_VERSION = '9.2'
76

8-
RP_CompileSdkVersion = 30
9-
RP_BuildToolsVersion = '30.0.3'
10-
RP_MinSdkVersion = 16
11-
RP_TargetSdkVersion = 30
7+
RP_CompileSdk = 33
8+
RP_MinSdk = 16
9+
RP_TargetSdk = 33
1210

13-
ANDROIDX_APPCOMPAT = '1.3.1'
14-
ANDROIDX_CORE_KTX = '1.6.0'
11+
ANDROIDX_APPCOMPAT = '1.4.2'
12+
ANDROIDX_CORE_KTX = '1.8.0'
1513
LIVEDATA_KTX = '2.3.1'
16-
GOOGLE_MATERIAL = '1.4.0'
14+
GOOGLE_MATERIAL = '1.6.1'
1715
ANDROIDX_CONSTRAIN = '2.1.1'
1816

1917
JUNIT_VERSION = '4.13.2'
@@ -33,8 +31,8 @@ project.ext {
3331
ESPRESSO_VERSION = '3.3.0'
3432

3533
RP_GROUP = 'com.qihoo360.replugin'
36-
RP_VERSION = '2.4.8-SNAPSHOT'
37-
RP_VERSION_CODE = 248
34+
RP_VERSION = '2.4.9-SNAPSHOT'
35+
RP_VERSION_CODE = 249
3836

3937
RP_USER = 'replugin'
4038
RP_REPO = 'replugin'

Diff for: replugin-gradle/src/main/kotlin/com/qihoo360/replugin/Constants.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package com.qihoo360.replugin
99
*/
1010
object Constants {
1111
//版本号:不要手动修改,当发布时,会根据rp-config.gradle中的RP_VERSION自动替换
12-
private const val VER = "2.4.8-SNAPSHOT"
12+
private const val VER = "2.4.9-SNAPSHOT"
1313

1414
/** 打印信息时候的前缀 */
1515
const val HOST_TAG = "< replugin-host-$VER >"

Diff for: replugin-gradle/src/main/kotlin/com/qihoo360/replugin/task/tools/BuiltInJsonCreator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ class PluginInfo {
9797
var ver: Long = -1
9898

9999
/** 框架版本号 */
100-
var from: Long = -1
100+
var frm: Long = -1
101101

102102
}

Diff for: replugin-gradle/src/main/kotlin/com/qihoo360/replugin/task/tools/PluginInfoParser.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PluginInfoParser(pluginFile: File, extension: HostExtension) : DefaultHand
5555
tagVersionLow -> pluginInfo.low = attributes.getValue(androidValue).toLong()
5656
tagVersionHigh -> pluginInfo.height = attributes.getValue(androidValue).toLong()
5757
tagVersionVer -> pluginInfo.ver = attributes.getValue(androidValue).toLong()
58-
tagFrameWorkVer -> pluginInfo.from = attributes.getValue(androidValue).toLong()
58+
tagFrameWorkVer -> pluginInfo.frm = attributes.getValue(androidValue).toLong()
5959
}
6060

6161
} else if ("manifest" == qName) {

Diff for: replugin-gradle/src/main/kotlin/com/qihoo360/replugin/transform/pool/JarTransformTask.kt

+37-29
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class JarTransformTask(
3030
private val tag = "JarTransformTask"
3131
override fun compute(): Boolean {
3232
jarInputList.forEach { jarInput ->
33-
3433
val md5 = DigestUtils.md5Hex(jarInput.file.absolutePath)
3534
val out = outputProvider.getContentLocation(
3635
md5, jarInput.contentTypes, jarInput.scopes, Format.JAR
@@ -50,36 +49,11 @@ class JarTransformTask(
5049
while (entry != null) {
5150
val outEntry: ZipEntry = copyEntry(entry)
5251
if (!entry.isDirectory && entry.name.endsWith(".class")) {
53-
val name = entry.name.removeSuffix(".class")
54-
val separatorIndex = entry.name.lastIndexOf(File.separatorChar)
55-
val packageName =
56-
if (separatorIndex > -1)
57-
entry.name
58-
.substring(0, separatorIndex)
59-
.removePrefix(File.separator)
60-
.removeSuffix(File.separator)
61-
else ""
62-
val isInnerClass = entry.name.contains("$")
63-
val className =
64-
if (separatorIndex > -1)
65-
entry.name.substring(separatorIndex + 1)
66-
.removeSuffix(".class")
67-
else
68-
entry.name.removeSuffix(".class")
69-
70-
val transformClassInfo = TransformClassInfo(
71-
name,
72-
packageName,
73-
className,
74-
jarInput.file.absolutePath,
75-
out.absolutePath,
76-
jarInput,
77-
true,
78-
isInnerClass
79-
)
52+
val transformClassInfo = buildTransformClassInfo(entry.name, jarInput, out)
8053
val bytes = IOUtils.toByteArray(jar)
8154
try {
82-
val changedBytes = transForm.transformClass(transformClassInfo, bytes)
55+
val changedBytes =
56+
transForm.transformClass(transformClassInfo, bytes)
8357
if (changedBytes == null) {
8458
outJar.putNextEntry(outEntry)
8559
IOUtils.write(bytes, outJar)
@@ -107,6 +81,40 @@ class JarTransformTask(
10781
return true
10882
}
10983

84+
private fun buildTransformClassInfo(
85+
entryName: String,
86+
jarInput: JarInput,
87+
out: File
88+
): TransformClassInfo {
89+
val name = entryName.removeSuffix(".class")
90+
val separatorIndex = entryName.lastIndexOf(File.separatorChar)
91+
val packageName =
92+
if (separatorIndex > -1)
93+
entryName
94+
.substring(0, separatorIndex)
95+
.removePrefix(File.separator)
96+
.removeSuffix(File.separator)
97+
else ""
98+
val isInnerClass = entryName.contains("$")
99+
val className =
100+
if (separatorIndex > -1)
101+
entryName.substring(separatorIndex + 1)
102+
.removeSuffix(".class")
103+
else
104+
entryName.removeSuffix(".class")
105+
106+
return TransformClassInfo(
107+
name,
108+
packageName,
109+
className,
110+
jarInput.file.absolutePath,
111+
out.absolutePath,
112+
jarInput,
113+
true,
114+
isInnerClass
115+
)
116+
}
117+
110118
private fun copyEntry(entry: ZipEntry): ZipEntry {
111119
val newEntry = ZipEntry(entry.name)
112120
newEntry.comment = entry.comment

Diff for: replugin-lib-base/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ plugins {
66
}
77

88
android {
9-
compileSdkVersion RP_CompileSdkVersion
9+
compileSdk RP_CompileSdk
1010

1111
defaultConfig {
12-
minSdkVersion RP_MinSdkVersion
13-
targetSdkVersion RP_TargetSdkVersion
12+
minSdkVersion RP_MinSdk
13+
targetSdkVersion RP_TargetSdk
1414
versionCode RP_VERSION_CODE
1515
versionName RP_VERSION
1616

Diff for: replugin-lib-host/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ plugins {
66
}
77

88
android {
9-
compileSdkVersion RP_CompileSdkVersion
10-
buildToolsVersion RP_BuildToolsVersion
9+
compileSdk RP_CompileSdk
1110

1211
defaultConfig {
13-
minSdkVersion RP_MinSdkVersion
14-
targetSdkVersion RP_TargetSdkVersion
12+
minSdkVersion RP_MinSdk
13+
targetSdkVersion RP_TargetSdk
1514
versionCode RP_VERSION_CODE
1615
versionName RP_VERSION
1716

Diff for: replugin-lib-host/src/main/java/com/qihoo360/loader2/Loader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ final boolean isAppLoaded() {
166166
}
167167

168168
final Context createBaseContext(Context newBase) {
169-
return new PluginContext(newBase, android.R.style.Theme, mClassLoader, mPkgResources, mPluginName, this);
169+
return mPkgContext == null ? new PluginContext(newBase, android.R.style.Theme, mClassLoader, mPkgResources, mPluginName, this) : mPkgContext;
170170
}
171171

172172
final boolean loadDex(ClassLoader parent, int load) {

Diff for: replugin-lib-host/src/main/java/com/qihoo360/loader2/ShellExecutor.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ public static String execute(String cmd) {
2424
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
2525
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
2626
StringBuilder result = new StringBuilder();
27-
String line = reader.readLine();
28-
while (line != null) {
29-
result.append(line);
30-
line = reader.readLine();
27+
try {
28+
String line = reader.readLine();
29+
while (line != null) {
30+
result.append(line);
31+
line = reader.readLine();
32+
}
33+
return result.toString();
34+
} catch (IOException ignore) {
35+
LogDebug.e(TAG, "Error shell:" + cmd);
36+
} finally {
37+
writer.close();
38+
reader.close();
3139
}
32-
writer.close();
33-
reader.close();
34-
return result.toString();
3540
} catch (IOException ignore) {
3641
LogDebug.e(TAG, "Error shell:" + cmd);
3742
}

Diff for: replugin-lib-plugin/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ plugins {
66
}
77

88
android {
9-
compileSdkVersion RP_CompileSdkVersion
10-
buildToolsVersion RP_BuildToolsVersion
9+
compileSdk RP_CompileSdk
1110

1211
defaultConfig {
13-
minSdkVersion RP_MinSdkVersion
14-
targetSdkVersion RP_TargetSdkVersion
12+
minSdkVersion RP_MinSdk
13+
targetSdkVersion RP_TargetSdk
1514
versionCode RP_VERSION_CODE
1615
versionName RP_VERSION
1716

Diff for: sample-host/fresco-host-app/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
apply plugin: 'com.android.application'
22
android {
3-
compileSdkVersion RP_CompileSdkVersion
4-
buildToolsVersion RP_BuildToolsVersion
3+
compileSdk RP_CompileSdk
4+
55
defaultConfig {
6-
minSdkVersion RP_MinSdkVersion
7-
targetSdkVersion RP_TargetSdkVersion
6+
minSdkVersion RP_MinSdk
7+
targetSdkVersion RP_TargetSdk
88

99
applicationId "com.qihoo360.replugin.fresco.host"
1010
versionCode 1

Diff for: sample-host/host-app/build.gradle

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
apply plugin: 'com.android.application'
1818

1919
android {
20-
compileSdkVersion RP_CompileSdkVersion
21-
buildToolsVersion RP_BuildToolsVersion
22-
defaultConfig {
23-
minSdkVersion RP_MinSdkVersion
24-
targetSdkVersion RP_TargetSdkVersion
20+
compileSdk RP_CompileSdk
2521

22+
defaultConfig {
23+
minSdkVersion RP_MinSdk
24+
targetSdkVersion RP_TargetSdk
2625
applicationId "com.qihoo360.replugin.sample.host"
2726
versionCode 1
2827
versionName "1.0"

Diff for: sample-host/host-utils/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
apply plugin: 'com.android.application'
1818

1919
android {
20-
compileSdkVersion RP_CompileSdkVersion
21-
buildToolsVersion RP_BuildToolsVersion
20+
compileSdk RP_CompileSdk
2221

2322
defaultConfig {
24-
minSdkVersion RP_MinSdkVersion
25-
targetSdkVersion RP_TargetSdkVersion
23+
minSdkVersion RP_MinSdk
24+
targetSdkVersion RP_TargetSdk
2625

2726
applicationId "com.qihoo360.replugin.common.utils"
2827

Diff for: sample-plugin/fresco-plugin/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion RP_CompileSdkVersion
5-
buildToolsVersion RP_BuildToolsVersion
4+
compileSdk RP_CompileSdk
65

76
defaultConfig {
8-
minSdkVersion RP_MinSdkVersion
9-
targetSdkVersion RP_TargetSdkVersion
7+
minSdkVersion RP_MinSdk
8+
targetSdkVersion RP_TargetSdk
109

1110
applicationId "com.qihoo360.replugin.fresco.plugin"
1211

Diff for: sample-plugin/plugin-demo1-library/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion RP_CompileSdkVersion
5-
buildToolsVersion RP_BuildToolsVersion
4+
compileSdk RP_CompileSdk
65

76
defaultConfig {
8-
minSdkVersion RP_MinSdkVersion
9-
targetSdkVersion RP_TargetSdkVersion
7+
minSdkVersion RP_MinSdk
8+
targetSdkVersion RP_TargetSdk
109
versionCode 1
1110
versionName "1.0"
1211

Diff for: sample-plugin/plugin-demo1/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
apply plugin: 'com.android.application'
2323

2424
android {
25-
compileSdkVersion RP_CompileSdkVersion
26-
buildToolsVersion RP_BuildToolsVersion
25+
compileSdk RP_CompileSdk
2726

2827
defaultConfig {
29-
minSdkVersion RP_MinSdkVersion
30-
targetSdkVersion RP_TargetSdkVersion
28+
minSdkVersion RP_MinSdk
29+
targetSdkVersion RP_TargetSdk
3130

3231
applicationId "com.qihoo360.replugin.sample.demo1"
3332
versionName "1.1"

Diff for: sample-plugin/plugin-demo2/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
apply plugin: 'com.android.application'
2323

2424
android {
25-
compileSdkVersion RP_CompileSdkVersion
26-
buildToolsVersion RP_BuildToolsVersion
25+
compileSdk RP_CompileSdk
2726

2827
defaultConfig {
29-
minSdkVersion RP_MinSdkVersion
30-
targetSdkVersion RP_TargetSdkVersion
28+
minSdkVersion RP_MinSdk
29+
targetSdkVersion RP_TargetSdk
3130

3231
applicationId "com.qihoo360.replugin.sample.demo2"
3332

0 commit comments

Comments
 (0)