Skip to content

Commit 7cd66ff

Browse files
committed
see 01/20 log
1 parent f799e70 commit 7cd66ff

File tree

18 files changed

+278
-167
lines changed

18 files changed

+278
-167
lines changed

buildApp.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply {
22
plugin "com.android.application"
33
plugin "kotlin-android"
44
plugin "kotlin-android-extensions"
5-
if (Config.depConfig.plugin_bus.isApply) {
6-
plugin Config.depConfig.plugin_bus.pluginId
7-
}
85
if (Config.depConfig.plugin_api.isApply) {
96
plugin Config.depConfig.plugin_api.pluginId
107
}
8+
if (Config.depConfig.plugin_bus.isApply) {
9+
plugin Config.depConfig.plugin_bus.pluginId
10+
}
1111
}
1212

1313
configSigning()

buildSrc/src/main/groovy/Config.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Config {
2727
/*Never delete this line*/
2828
/*Generated by "config.json"*/
2929
plugin_api_gradle_plugin : new DepConfig(true, true, ":plugin:api-gradle-plugin"),
30-
plugin_bus_gradle_plugin : new DepConfig(false, true, ":plugin:bus-gradle-plugin"),
30+
plugin_bus_gradle_plugin : new DepConfig(true, true, ":plugin:bus-gradle-plugin"),
3131
feature_mock : new DepConfig(false, true, ":feature:mock"),
3232
feature_launcher_app : new DepConfig(true, true, ":feature:launcher:app"),
3333
feature_main_app : new DepConfig(false, true, ":feature:main:app"),
@@ -54,8 +54,12 @@ class Config {
5454
// 本地第一次上传插件新的版本需设置 isApply = false, useLocal = true
5555
// 本地上传成功之后 isApply = true 即可应用插件来调试,后续版本更新无需设置 isApply = false
5656
// 发布版本的话把 isApply = false, useLocal = false,更新版本号,发布成功后 isApply = true 即可使用远程库版本
57-
plugin_api : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:api-gradle-plugin:1.3-release", pluginId: "com.blankj.api"),
58-
plugin_bus : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:bus-gradle-plugin:2.5", pluginId: "com.blankj.bus"),
57+
plugin_api : new DepConfig(isApply: false, useLocal: true, pluginPath: "com.blankj:api-gradle-plugin:1.3-r4", pluginId: "com.blankj.api"),
58+
//./gradlew plugin:api-gradle-plugin:uploadArchives // 上传到本地 maven
59+
//./gradlew plugin:api-gradle-plugin:bintrayUpload // 上传到 jcenter
60+
plugin_bus : new DepConfig(isApply: true, useLocal: true, pluginPath: "com.blankj:bus-gradle-plugin:2.5", pluginId: "com.blankj.bus"),
61+
//./gradlew plugin:bus-gradle-plugin:uploadArchives // 上传到本地 maven
62+
//./gradlew plugin:bus-gradle-plugin:bintrayUpload // 上传到 jcenter
5963

6064
support_appcompat_v7 : new DepConfig("com.android.support:appcompat-v7:$supportVersion"),
6165
support_design : new DepConfig("com.android.support:design:$supportVersion"),

buildSrc/src/main/groovy/ConfigUtils.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import org.gradle.api.invocation.Gradle
1414
class ConfigUtils {
1515

1616
static init(Gradle gradle) {
17+
GitUtils.init(gradle)
1718
generateDep(gradle)
1819
addCommonGradle(gradle)
1920
TaskDurationUtils.init(gradle)
20-
GitUtils.init(gradle)
2121
}
2222

2323
/**

buildSrc/src/main/groovy/GitUtils.groovy

Lines changed: 87 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,104 @@ import java.text.SimpleDateFormat
1414
*/
1515
class GitUtils {
1616

17-
private static String sCurBranchName;
17+
private static Project rootProject;
1818

1919
static void init(Gradle gradle) {
20-
gradle.rootProject(new Action<Project>() {
21-
@Override
22-
void execute(Project project) {
23-
sCurBranchName = getGitBranch()
24-
addGitPushTask(project)
25-
addGitPushAndMerge2MasterTask(project)
26-
addGitNewBranchTask(project)
20+
rootProject = gradle.rootProject
21+
addGitHelpTask()
22+
// gradle.rootProject(new Action<Project>() {
23+
// @Override
24+
// void execute(Project project) {
25+
// addGitHelpTask()
26+
// }
27+
// })
28+
}
29+
30+
static def addGitHelpTask() {
31+
rootProject.task("gitHelp").doLast {
32+
def commands = [
33+
" ############## input command code #################",
34+
" # [1] Git Push #",
35+
" # [2] Git Push And Merge to Master #",
36+
" # [3] Git New Branch #",
37+
" # [0] exit #",
38+
" ###################################################",
39+
]
40+
String commandTips = String.join(System.getProperty("line.separator"), commands)
41+
while (true) {
42+
GLog.l(commandTips)
43+
Scanner scanner = new Scanner(System.in)
44+
def input = scanner.next()
45+
GLog.l(input)
46+
switch (input) {
47+
case "1":
48+
gitPush()
49+
break
50+
case "2":
51+
gitPushAndMerge2Master()
52+
break
53+
case "3":
54+
gitNewBranch()
55+
break
56+
case "0":
57+
return
58+
}
2759
}
28-
})
60+
}
2961
}
3062

31-
static def getGitBranch() {
32-
return ShellUtils.execCmd('git symbolic-ref --short -q HEAD').successMsg
63+
static void gitPush() {
64+
String branchName = getGitBranch()
65+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd")
66+
String date = simpleDateFormat.format(new Date())
67+
exeCmd(
68+
"git add -A",
69+
"git commit -m \"see $date log\"",
70+
"git push origin $branchName"
71+
)
3372
}
3473

35-
static void addGitPushTask(Project project) {
36-
project.task("gitPush").doLast {
37-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd")
38-
String date = simpleDateFormat.format(new Date())
39-
GLog.d(ShellUtils.execCmd([
40-
"git add -A",
41-
"git commit -m \"see $date log\"",
42-
"git push origin $sCurBranchName"
43-
] as String[]))
44-
}
74+
static void gitPushAndMerge2Master() {
75+
String branchName = getGitBranch()
76+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd")
77+
String date = simpleDateFormat.format(new Date())
78+
exeCmd(
79+
"git add -A",
80+
"git commit -m \"see $date log\"",
81+
"git push origin $branchName",
82+
"git checkout master",
83+
"git merge $branchName",
84+
"git push origin master",
85+
"git checkout $branchName"
86+
)
4587
}
4688

47-
static void addGitPushAndMerge2MasterTask(Project project) {
48-
project.task("gitPushAndMerge2Master").doLast {
49-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd")
50-
String date = simpleDateFormat.format(new Date())
51-
GLog.d(ShellUtils.execCmd([
52-
"git add -A",
53-
"git commit -m \"see $date log\"",
54-
"git push origin $sCurBranchName",
55-
"git checkout master",
56-
"git merge $sCurBranchName",
57-
"git push origin master",
58-
"git checkout $sCurBranchName",
59-
] as String[]))
60-
}
89+
static void gitNewBranch() {
90+
exeCmd(
91+
"git checkout master",
92+
"git checkout -b ${Config.versionName}",
93+
"git push origin ${Config.versionName}:${Config.versionName}",
94+
)
6195
}
6296

63-
static void addGitNewBranchTask(Project project) {
64-
project.task("gitNewBranch").doLast {
65-
GLog.d(ShellUtils.execCmd([
66-
"git checkout master",
67-
"git checkout -b ${Config.versionName}",
68-
"git push origin ${Config.versionName}:${Config.versionName}",
69-
] as String[]))
97+
private static def getGitBranch() {
98+
return exeCmd("git symbolic-ref --short -q HEAD")
99+
}
100+
101+
private static def exeCmd(String... cmds) {
102+
String output = ""
103+
for (def cmd in cmds) {
104+
output = _exeCmd(cmd)
70105
}
106+
return output
107+
}
108+
109+
private static def _exeCmd(String cmd) {
110+
def output = new StringBuilder()
111+
GLog.l("Execute command: ${cmd}")
112+
def cmdResult = ShellUtils.execCmd(cmd)
113+
GLog.l("$cmdResult")
114+
return cmdResult.successMsg
71115
}
72116
}
73-
// ./gradlew gitPush
74-
// ./gradlew gitPushAndMerge2Master
75-
// ./gradlew gitNewBranch
117+
// ./gradlew gitHelp

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"proConfigDesc": "proConfig 配置的是使用本地还是仓库,优先级低于 appConfig 和 pkgConfig",
77
"proConfig": [
88
{"isApply": true, "useLocal": true, "localPath": ":plugin:api-gradle-plugin"},
9-
{"isApply": false, "useLocal": true, "localPath": ":plugin:bus-gradle-plugin"},
9+
{"isApply": true, "useLocal": true, "localPath": ":plugin:bus-gradle-plugin"},
1010
{"isApply": true, "useLocal": true, "localPath": ":feature:mock"},
1111
{"isApply": true, "useLocal": true, "localPath": ":feature:launcher:app"},
1212
{"isApply": true, "useLocal": true, "localPath": ":feature:main:app"},

lib/utilcode/README-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ applyPressedBgAlpha : 应用点击后对背景改变透明度
272272
applyPressedBgDark : 应用点击后对背景加深
273273
applySingleDebouncing : 对单视图应用防抖点击
274274
applyGlobalDebouncing : 对所有设置 GlobalDebouncing 的视图应用防抖点击
275+
expandClickArea : 扩大点击区域
275276
back2HomeFriendly : 友好地返回桌面
276277
ClickUtils#OnDebouncingClickListener: 防抖点击监听器
277278
ClickUtils#OnMultiClickListener : 连续点击监听器

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

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,12 @@ public final class ApiUtils {
2727

2828
private static final String PREFIX = "blankj.api/";
2929

30-
private Map<Class, BaseApi> mApiMap = new ConcurrentHashMap<>();
31-
private Map<Class, Class> mInjectApiImplMap = new HashMap<>();
30+
private Map<Class, Object> apiClass_apiInstance_map = new ConcurrentHashMap<>();
31+
private Map<Class, Class> apiClass_apiImplClass_map = new HashMap<>();
3232

3333
private ApiUtils() {
3434
}
3535

36-
private void registerApiInner(Class implClass) {
37-
if (implClass == null) return;
38-
Class superclass = implClass.getSuperclass();
39-
if (superclass == null) return;
40-
mInjectApiImplMap.put(superclass, implClass);
41-
}
42-
43-
public static void registerApi(Class implClass) {
44-
getInstance().registerApiInner(implClass);
45-
}
46-
4736
/**
4837
* Get api.
4938
*
@@ -64,7 +53,7 @@ public String toString() {
6453
getAllApis();
6554
StringBuilder sb = new StringBuilder();
6655
sb.append("ApiUtils {");
67-
for (Map.Entry<Class, Class> entry : mInjectApiImplMap.entrySet()) {
56+
for (Map.Entry<Class, Class> entry : apiClass_apiImplClass_map.entrySet()) {
6857
sb.append("\n ")
6958
.append(entry.getKey().getName())
7059
.append(": ")
@@ -79,16 +68,16 @@ private static ApiUtils getInstance() {
7968
}
8069

8170
private <Result> Result getApiInner(Class apiClass) {
82-
BaseApi api = mApiMap.get(apiClass);
83-
if (api == null) {
71+
Object apiInstance = apiClass_apiInstance_map.get(apiClass);
72+
if (apiInstance == null) {
8473
synchronized (this) {
85-
api = mApiMap.get(apiClass);
86-
if (api == null) {
74+
apiInstance = apiClass_apiInstance_map.get(apiClass);
75+
if (apiInstance == null) {
8776
Class implClass = getApiImplClass(apiClass);
8877
if (implClass != null) {
8978
try {
90-
api = (BaseApi) implClass.newInstance();
91-
mApiMap.put(apiClass, api);
79+
apiInstance = implClass.newInstance();
80+
apiClass_apiInstance_map.put(apiClass, apiInstance);
9281
} catch (Exception ignore) {
9382
Log.e(TAG, "The api of <" + implClass + "> has no parameterless constructor.");
9483
return null;
@@ -101,11 +90,11 @@ private <Result> Result getApiInner(Class apiClass) {
10190
}
10291
}
10392
//noinspection unchecked
104-
return (Result) api;
93+
return (Result) apiInstance;
10594
}
10695

10796
private Class getApiImplClass(Class apiClass) {
108-
Class apiImplClass = mInjectApiImplMap.get(apiClass);
97+
Class apiImplClass = apiClass_apiImplClass_map.get(apiClass);
10998
if (apiImplClass != null) return apiImplClass;
11099
try {
111100
String[] apiImpls = Utils.getApp().getAssets().list(PREFIX + apiClass.getName());
@@ -133,26 +122,39 @@ private Class getApiImplClass(Class apiClass) {
133122
return null;
134123
}
135124
apiImplClass = Class.forName(className);
125+
return registerApiInner(apiClass, apiImplClass);
126+
} catch (ClassNotFoundException e) {
127+
e.printStackTrace();
128+
} catch (IOException e) {
129+
e.printStackTrace();
130+
}
131+
return null;
132+
}
133+
134+
private Class registerApiInner(Class apiClass, Class apiImplClass) {
135+
if (apiImplClass == null) return null;
136+
if (apiClass == null) {
136137
Class superclass = apiImplClass.getSuperclass();
137-
if (superclass != null) {
138-
//noinspection unchecked
139-
if (apiClass.isAssignableFrom(apiImplClass)) {
140-
mInjectApiImplMap.put(apiClass, apiImplClass);
141-
return apiImplClass;
142-
} else {
143-
Log.e(TAG, "<" + apiImplClass.getName() + ">'s superClass is <"
144-
+ superclass.getName() + ">, not <" + apiClass.getName() + ">");
145-
return null;
146-
}
147-
} else {
148-
Log.e(TAG, "<" + apiImplClass.getName() + ">'s superClass is <" +
149-
"null>, not <" + apiClass.getName() + ">");
138+
if (superclass == null) {
139+
Log.e(TAG, "<" + apiImplClass.getName() + ">'s superClass is null");
150140
return null;
151141
}
152-
} catch (Exception e) {
153-
e.printStackTrace();
142+
apiClass = superclass;
143+
}
144+
//noinspection unchecked
145+
if (apiClass.isAssignableFrom(apiImplClass)) {
146+
apiClass_apiImplClass_map.put(apiClass, apiImplClass);
147+
return apiImplClass;
148+
} else {
149+
Log.e(TAG, "<" + apiImplClass.getName() + ">'s superClass is <"
150+
+ apiClass.getName() + ">, not <" + apiClass.getName() + ">");
154151
return null;
155152
}
153+
154+
}
155+
156+
static void registerApi(Class<? extends BaseApi> implClass) {
157+
getInstance().registerApiInner(null, implClass);
156158
}
157159

158160
private void getAllApis() {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public static boolean isAppInstalled(@NonNull final String pkgName) {
152152
try {
153153
return packageManager.getApplicationInfo(pkgName, 0) != null;
154154
} catch (PackageManager.NameNotFoundException e) {
155-
e.printStackTrace();
156155
return false;
157156
}
158157
}

0 commit comments

Comments
 (0)