Skip to content

Commit 37fd0e2

Browse files
committed
see 05/09 log
1 parent f61eb1a commit 37fd0e2

File tree

9 files changed

+343
-159
lines changed

9 files changed

+343
-159
lines changed

bus-gradle-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ gradlePlugin {
2727

2828
dependencies {
2929
implementation "com.android.tools.build:gradle:3.4.0"
30-
implementation 'com.android.tools.build:gradle-api:3.4.0'
30+
implementation "com.android.tools.build:gradle-api:3.4.0"
3131

3232
implementation dep.javassist
3333
implementation dep.commons_io
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package com.blankj.bus
2+
3+
import com.android.build.api.transform.*
4+
import com.android.build.gradle.internal.pipeline.TransformManager
5+
import com.blankj.util.JavassistUtils
6+
import com.blankj.util.JsonUtils
7+
import com.blankj.util.LogUtils
8+
import com.google.common.base.Preconditions
9+
import org.apache.commons.io.FileUtils
10+
import org.gradle.api.Project
11+
12+
import java.util.function.Predicate
13+
14+
class BusTransformAsm extends Transform {
15+
16+
Project mProject;
17+
18+
BusTransformAsm(Project project) {
19+
mProject = project
20+
}
21+
22+
@Override
23+
String getName() {
24+
return "busTransform"
25+
}
26+
27+
@Override
28+
Set<QualifiedContent.ContentType> getInputTypes() {
29+
return TransformManager.CONTENT_CLASS
30+
}
31+
32+
@Override
33+
Set<? super QualifiedContent.Scope> getScopes() {
34+
return TransformManager.SCOPE_FULL_PROJECT
35+
}
36+
37+
@Override
38+
boolean isIncremental() {
39+
return true
40+
}
41+
42+
@Override
43+
void transform(TransformInvocation transformInvocation)
44+
throws TransformException, InterruptedException, IOException {
45+
super.transform(transformInvocation)
46+
def outputProvider = transformInvocation.getOutputProvider()
47+
Preconditions.checkNotNull(outputProvider, "Missing output object for transform " + getName());
48+
49+
LogUtils.l(getName() + " started")
50+
51+
long stTime = System.currentTimeMillis();
52+
53+
def inputs = transformInvocation.getInputs()
54+
def referencedInputs = transformInvocation.getReferencedInputs()
55+
def isIncremental = transformInvocation.isIncremental()
56+
57+
if(!isIncremental) {
58+
outputProvider.deleteAll();
59+
}
60+
61+
JavassistUtils.init(mProject)
62+
BusScan busScan = new BusScan()
63+
64+
for (TransformInput input : transformInvocation.getInputs()) {
65+
for (DirectoryInput dirInput : input.getDirectoryInputs()) {// 遍历文件夹
66+
File dir = dirInput.file
67+
JavassistUtils.getPool().appendClassPath(dir.absolutePath)
68+
69+
def dest = outputProvider.getContentLocation(
70+
dirInput.name,
71+
dirInput.contentTypes,
72+
dirInput.scopes,
73+
Format.DIRECTORY
74+
)
75+
FileUtils.copyDirectory(dir, dest)
76+
77+
LogUtils.l("scan dir: $dir [$dest]")
78+
79+
if(isIncremental) {
80+
switch(status) {
81+
case Status.NOTCHANGED:
82+
break;
83+
case Status.ADDED:
84+
case Status.CHANGED:
85+
transformJar(jarInput.getFile(), dest, status);
86+
break;
87+
case Status.REMOVED:
88+
if (dest.exists()) {
89+
FileUtils.forceDelete(dest);
90+
}
91+
break;
92+
}
93+
} else {
94+
//Forgive me!, Some project will store 3rd-party aar for serveral copies in dexbuilder folder,,unknown issue.
95+
if(inDuplcatedClassSafeMode() & !isIncremental && !flagForCleanDexBuilderFolder) {
96+
cleanDexBuilderFolder(dest);
97+
flagForCleanDexBuilderFolder = true;
98+
}
99+
transformJar(jarInput.getFile(), dest, status);
100+
}
101+
102+
103+
busScan.scanDir(dir)
104+
}// 遍历文件夹结束
105+
106+
for (JarInput jarInput : input.getJarInputs()) {// 遍历 jar 文件
107+
File jar = jarInput.file
108+
JavassistUtils.getPool().appendClassPath(jarInput.file.absolutePath)
109+
110+
def jarName = jarInput.name
111+
def dest = outputProvider.getContentLocation(
112+
jarName,
113+
jarInput.contentTypes,
114+
jarInput.scopes,
115+
Format.JAR
116+
)
117+
FileUtils.copyFile(jar, dest)
118+
119+
if (jarName.startsWith("com.blankj:utilcode:")
120+
|| jarName.startsWith("com.blankj:utilcodex:")
121+
|| jarName.contains("utilcode-lib")) {
122+
busScan.busJar = dest
123+
LogUtils.l("bus jar: $jarName [$dest]")
124+
return
125+
}
126+
127+
if (jumpScan(jarName)) {
128+
LogUtils.l("jump jar: $jarName [$dest]")
129+
return
130+
}
131+
132+
LogUtils.l("scan jar: $jarName [$dest]")
133+
busScan.scanJar(jar)
134+
}
135+
}// 遍历 jar 文件结束
136+
137+
if (busScan.busJar != null) {
138+
File jsonFile = new File(mProject.projectDir.getAbsolutePath(), "__bus__.json")
139+
String busJson = JsonUtils.getFormatJson(busScan.busStaticMap)
140+
LogUtils.l(jsonFile.toString() + ": " + busJson)
141+
FileUtils.write(jsonFile, busJson)
142+
BusInject.start(busScan.busStaticMap, busScan.busJar)
143+
} else {
144+
LogUtils.l('u should <implementation "com.blankj:utilcode:1.22.+">')
145+
}
146+
147+
LogUtils.l(getName() + " finished: " + (System.currentTimeMillis() - stTime) + "ms")
148+
}
149+
150+
private static boolean jumpScan(String jarName) {
151+
boolean isExcept = false
152+
for (String except : Config.EXCEPTS) {
153+
if (jarName.startsWith(except)) {
154+
isExcept = true
155+
break
156+
}
157+
}
158+
isExcept
159+
}
160+
}

lib/base/src/main/java/com/blankj/lib/base/BaseActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private void initSwipeBack() {
8989
swipeLayout.setOnFullSwipeListener(new SwipePanel.OnFullSwipeListener() {
9090
@Override
9191
public void onFullSwipe(int direction) {
92-
finish();
9392
swipeLayout.close(direction);
93+
finish();
9494
}
9595
});
9696
}

lib/base/src/main/java/com/blankj/lib/base/BaseApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void initLog() {
7272
.setSingleTagSwitch(true)// 一条日志仅输出一条,默认开,为美化 AS 3.1 的 Logcat
7373
.setConsoleFilter(LogUtils.V)// log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
7474
.setFileFilter(LogUtils.V)// log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
75-
.setStackDeep(1)// log 栈深度,默认为 1
75+
.setStackDeep(100)// log 栈深度,默认为 1
7676
.setStackOffset(0)// 设置栈偏移,比如二次封装的话就需要设置,默认为 0
7777
.setSaveDays(3)// 设置日志可保留天数,默认为 -1 表示无限时长
7878
// 新增 ArrayList 格式化器,默认已支持 Array, Throwable, Bundle, Intent 的格式化输出
@@ -81,7 +81,8 @@ public void initLog() {
8181
public String format(ArrayList arrayList) {
8282
return "LogUtils Formatter ArrayList { " + arrayList.toString() + " }";
8383
}
84-
});
84+
})
85+
.setFileWriter(null);
8586
LogUtils.i(config.toString());
8687
}
8788

utilcode/lib/src/main/java/com/blankj/utilcode/util/BusUtils.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import android.text.TextUtils;
2222
import android.util.Log;
2323

24-
import java.io.BufferedReader;
25-
import java.io.File;
26-
import java.io.FileReader;
2724
import java.lang.annotation.ElementType;
2825
import java.lang.annotation.Retention;
2926
import java.lang.annotation.RetentionPolicy;
@@ -253,20 +250,7 @@ public static void post(@NonNull String key, @NonNull Bundle data) {
253250
}
254251

255252
private static boolean isMainProcess() {
256-
return Utils.getApp().getPackageName().equals(getCurrentProcessName());
257-
}
258-
259-
private static String getCurrentProcessName() {
260-
try {
261-
File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
262-
BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
263-
String processName = mBufferedReader.readLine().trim();
264-
mBufferedReader.close();
265-
return processName;
266-
} catch (Exception e) {
267-
e.printStackTrace();
268-
return "";
269-
}
253+
return Utils.getApp().getPackageName().equals(Utils.getCurrentProcessName());
270254
}
271255

272256
private static boolean isAppInstalled(@NonNull final String pkgName) {
@@ -340,7 +324,7 @@ public void handleMessage(Message msg) {
340324
public void onServiceConnected(ComponentName name, IBinder service) {
341325
Log.d("BusUtils", "client service connected " + name);
342326
mServer = new Messenger(service);
343-
int key = getCurrentProcessName().hashCode();
327+
int key = Utils.getCurrentProcessName().hashCode();
344328
Message msg = Message.obtain(mReceiveServeMsgHandler, WHAT_SUBSCRIBE, key, 0);
345329
msg.replyTo = mClient;
346330
try {

0 commit comments

Comments
 (0)