Skip to content

Commit 65a78e0

Browse files
author
Blankj
committed
see 03/16 log
1 parent 2662f8c commit 65a78e0

File tree

15 files changed

+171
-98
lines changed

15 files changed

+171
-98
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ android {
4848

4949
dependencies {
5050
implementation fileTree(include: ['*.jar'], dir: 'libs')
51-
// implementation project(':utilcode')
51+
implementation project(':utilcode')
5252
implementation project(':subutil')
5353
implementation "com.android.support:appcompat-v7:$support_version"
5454
implementation "com.android.support:design:$support_version"
5555
implementation 'com.r0adkll:slidableactivity:2.0.5'
5656
// LeakCanary
5757
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
5858
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
59-
implementation 'com.blankj:utilcode:1.13.4'
59+
// implementation 'com.blankj:utilcode:1.13.4'
6060
}
6161

6262

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
apply from: 'readme.gradle'
32
buildscript {
43
repositories {
54
google()

buildSrc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

buildSrc/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apply plugin: 'groovy'
2+
3+
dependencies {
4+
compile gradleApi()
5+
compile localGroovy()
6+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.blankj.plugin
2+
3+
class FormatUtils {
4+
5+
static def LINE_SEP = System.getProperty("line.separator")
6+
static def LONG_SPACE = " "
7+
8+
static def format(File readmeCN) {
9+
def sb = new StringBuilder(),
10+
lines = readmeCN.readLines("UTF-8"),
11+
i = 0,
12+
size = lines.size()
13+
for (; i < size; ++i) {
14+
String line = lines.get(i)
15+
if (line.contains("* ###")) {
16+
sb.append(line).append(LINE_SEP)
17+
.append("```").append(LINE_SEP)
18+
def maxLen = 0
19+
line = lines.get(i += 2)
20+
// get the max length of space
21+
for (def j = i; !line.equals("```"); line = lines.get(++j)) {
22+
maxLen = Math.max(maxLen, line.replace(" ", "").replace(",", ", ").indexOf(':'))
23+
}
24+
line = lines.get(i)
25+
for (; !line.equals("```"); line = lines.get(++i)) {
26+
def noSpaceLine = line.replace(" ", "")
27+
def spaceLen = maxLen - line.replace(" ", "").replace(",", ", ").indexOf(':')
28+
sb.append(noSpaceLine.substring(0, noSpaceLine.indexOf(':')).replace(",", ", "))
29+
.append(LONG_SPACE.substring(0, spaceLen))// add the space
30+
.append(': ')
31+
.append(line.substring(line.indexOf(':') + 1).trim())
32+
.append(LINE_SEP)
33+
}
34+
sb.append("```")
35+
} else {
36+
sb.append(line)
37+
}
38+
sb.append(LINE_SEP)
39+
}
40+
readmeCN.write(sb.toString(), "UTF-8")
41+
}
42+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.blankj.plugin
2+
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
6+
class ReadmeCorePlugin implements Plugin<Project> {
7+
8+
@Override
9+
void apply(Project project) {
10+
project.extensions.create('readme', ReadmeExtension)
11+
12+
project.task('readmeTask') {
13+
doLast {
14+
println "readmeTask start..."
15+
16+
def readmeCN = project['readme'].readmeCnFile
17+
def readmeEng = project['readme'].readmeFile
18+
readmeOfUtilCode2Eng(readmeCN, readmeEng)
19+
20+
println "readmeTask finished."
21+
}
22+
}
23+
}
24+
25+
static def readmeOfUtilCode2Eng(File readmeCN, File readmeEng) {
26+
FormatUtils.format(readmeCN)
27+
def lines = readmeCN.readLines("UTF-8")
28+
def sb = new StringBuilder()
29+
readmeCN.eachLine { line ->
30+
if (line.contains("* ###")) {
31+
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"))
32+
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf(" -> ")))
33+
} else if (line.contains(": ") && !line.contains("[")) {
34+
sb.append(line.substring(0, line.indexOf(':')).trim())
35+
} else {
36+
sb.append(line)
37+
}
38+
sb.append(FormatUtils.LINE_SEP)
39+
}
40+
readmeEng.write(sb.toString(), "UTF-8")
41+
}
42+
}
43+
44+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.blankj.plugin
2+
3+
class ReadmeExtension {
4+
5+
File readmeFile
6+
File readmeCnFile
7+
8+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.blankj.plugin
2+
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
6+
import static com.blankj.plugin.FormatUtils.LINE_SEP;
7+
8+
class ReadmeSubPlugin implements Plugin<Project> {
9+
10+
@Override
11+
void apply(Project project) {
12+
project.extensions.create('readme', ReadmeExtension)
13+
14+
project.task('readmeTask') {
15+
doLast {
16+
println "readmeTask start..."
17+
18+
def readmeCN = project['readme'].readmeCnFile
19+
def readmeEng = project['readme'].readmeFile
20+
readmeOfSubUtil2Eng(readmeCN, readmeEng)
21+
22+
println "readmeTask finished."
23+
}
24+
}
25+
}
26+
27+
static def readmeOfSubUtil2Eng(File readmeCN, File readmeEng) {
28+
FormatUtils.format(readmeCN)
29+
def lines = readmeCN.readLines("UTF-8"),
30+
sb = new StringBuilder("## How to use" + LINE_SEP
31+
+ LINE_SEP +
32+
"You should copy the following classes which you want to use in your project." + LINE_SEP),
33+
i = 3,
34+
size = lines.size()
35+
for (; i < size; ++i) {
36+
String line = lines.get(i)
37+
if (line.contains("* ###")) {
38+
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"))
39+
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf(" -> ")))
40+
} else if (line.contains(": ") && !line.contains("[")) {
41+
sb.append(line.substring(0, line.indexOf(':')).trim())
42+
} else {
43+
sb.append(line)
44+
}
45+
sb.append(LINE_SEP)
46+
}
47+
readmeEng.write(sb.toString(), "UTF-8")
48+
}
49+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
implementation-class=com.blankj.plugin.ReadmeCorePlugin
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
implementation-class=com.blankj.plugin.ReadmeSubPlugin

readme.gradle

Lines changed: 0 additions & 92 deletions
This file was deleted.

settings.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include ':app',
2-
':utilcode',
3-
':subutil'
2+
':buildSrc',
3+
':subutil',
4+
':utilcode'

subutil/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'com.blankj.readme.sub'
3+
4+
readme {
5+
readmeFile file('README.md')
6+
readmeCnFile file('README-CN.md')
7+
}
28

39
android {
410
compileSdkVersion compile_sdk_version

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 18/03/16 新增 gradle 插件来格式化 README
12
* 18/03/14 修复 KeyboardUtils#getContentViewInvisibleHeight,发布 1.13.4 版本
23
* 18/03/10 完善 Utils#installAppSilent 和 DeviceUtils#getMacAddress,发布 1.13.3 版本
34
* 18/03/09 完善 ActivityUtils#getTopActivity

utilcode/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'com.blankj.readme.core'
3+
4+
readme {
5+
readmeFile file('README.md')
6+
readmeCnFile file('README-CN.md')
7+
}
28

39
android {
410
compileSdkVersion compile_sdk_version
@@ -34,4 +40,4 @@ dependencies {
3440
testImplementation "com.android.support:support-v4:$support_version"
3541
}
3642
apply from: "../bintrayUpload.gradle"
37-
//gradle bintrayUpload
43+
//gradle bintrayUpload

0 commit comments

Comments
 (0)