Skip to content

Commit 98fb549

Browse files
author
Blankj
committed
see 11/24 log
1 parent 36e3ff6 commit 98fb549

4 files changed

Lines changed: 95 additions & 98 deletions

File tree

build.gradle

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

4243
junit_version = '4.12'
4344
robolectric_version = '3.1.2'
44-
}
45+
}
46+
47+

readme.gradle

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import groovy.transform.Field
2+
3+
@Field LINE_SEP = System.getProperty("line.separator")
4+
@Field LONG_SPACE = " "
5+
6+
task readmeTask << {
7+
def readmeCN = file("./utilcode/README-CN.md")
8+
def readmeEng = file("./utilcode/README.md")
9+
readmeOfUtilCode2Eng(readmeCN, readmeEng)
10+
11+
readmeCN = file("./subutil/README-CN.md")
12+
readmeEng = file("./subutil/README.md")
13+
readmeOfSubUtil2Eng(readmeCN, readmeEng)
14+
}
15+
16+
def readmeOfUtilCode2Eng(File readmeCN, File readmeEng) {
17+
format(readmeCN)
18+
def lines = readmeCN.readLines("UTF-8")
19+
def sb = new StringBuilder()
20+
readmeCN.eachLine { line ->
21+
if (line.contains("* ###")) {
22+
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"))
23+
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf("")))
24+
} else if (line.contains(": ") && !line.contains("[")) {
25+
sb.append(line.substring(0, line.indexOf(':')).trim())
26+
} else {
27+
sb.append(line)
28+
}
29+
sb.append(LINE_SEP)
30+
}
31+
readmeEng.write(sb.toString(), "UTF-8")
32+
}
33+
34+
def readmeOfSubUtil2Eng(File readmeCN, File readmeEng) {
35+
format(readmeCN)
36+
def lines = readmeCN.readLines("UTF-8"),
37+
sb = new StringBuilder("## How to use" + LINE_SEP
38+
+ LINE_SEP +
39+
"You should copy the following classes which you want to use in your project." + LINE_SEP),
40+
i = 3,
41+
size = lines.size()
42+
for (; i < size; ++i) {
43+
String line = lines.get(i)
44+
if (line.contains("* ###")) {
45+
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"))
46+
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf("")))
47+
} else if (line.contains(": ") && !line.contains("[")) {
48+
sb.append(line.substring(0, line.indexOf(':')).trim())
49+
} else {
50+
sb.append(line)
51+
}
52+
sb.append(LINE_SEP)
53+
}
54+
readmeEng.write(sb.toString(), "UTF-8")
55+
}
56+
57+
def format(File readmeCN) {
58+
def sb = new StringBuilder(),
59+
lines = readmeCN.readLines("UTF-8"),
60+
i = 0,
61+
size = lines.size()
62+
for (; i < size; ++i) {
63+
String line = lines.get(i)
64+
if (line.contains("* ###")) {
65+
sb.append(line).append(LINE_SEP)
66+
.append("```").append(LINE_SEP)
67+
def maxLen = 0
68+
line = lines.get(i += 2)
69+
// get the max length of space
70+
for (def j = i; !line.equals("```"); line = lines.get(++j)) {
71+
maxLen = Math.max(maxLen, line.replace(" ", "").replace(",", ", ").indexOf(':'))
72+
}
73+
line = lines.get(i)
74+
for (; !line.equals("```"); line = lines.get(++i)) {
75+
def noSpaceLine = line.replace(" ", "")
76+
def spaceLen = maxLen - line.replace(" ", "").replace(",", ", ").indexOf(':')
77+
sb.append(noSpaceLine.substring(0, noSpaceLine.indexOf(':')).replace(",", ", "))
78+
.append(LONG_SPACE.substring(0, spaceLen))// add the space
79+
.append(": ")
80+
.append(noSpaceLine.substring(noSpaceLine.indexOf(':') + 1))
81+
.append(LINE_SEP)
82+
}
83+
sb.append("```")
84+
} else {
85+
sb.append(line)
86+
}
87+
sb.append(LINE_SEP)
88+
}
89+
readmeCN.write(sb.toString(), "UTF-8")
90+
}

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 17/11/24 新增readme格式化的gradle脚本
12
* 17/11/15 修改资源分包位置,使其更合理
23
* 17/11/10 LogUtils新增日志头部,感谢Kanade
34
* 17/11/07 完善LogUtils无tag的多参数

utilcode/src/test/java/com/blankj/utilcode/util/TestUtils.java

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
import org.robolectric.RuntimeEnvironment;
77
import org.robolectric.annotation.Config;
88

9-
import java.io.File;
10-
import java.util.List;
11-
12-
import static com.blankj.utilcode.util.TestConfig.FILE_SEP;
13-
import static com.blankj.utilcode.util.TestConfig.LINE_SEP;
14-
159
/**
1610
* <pre>
1711
* author: Blankj
@@ -28,97 +22,6 @@ public static void init() {
2822
Utils.init(RuntimeEnvironment.application);
2923
}
3024

31-
private static final String LONG_SPACE = " ";
32-
33-
// @Test
34-
public void readme2Eng() throws Exception {
35-
String rootPath = new File(System.getProperty("user.dir")).getAbsolutePath() + FILE_SEP;
36-
File readmeCN = new File(rootPath + "utilcode" + FILE_SEP + "README-CN.md");
37-
File readme = new File(rootPath + "utilcode" + FILE_SEP + "README.md");
38-
readmeOfUtilCode(readmeCN, readme);
39-
40-
readmeCN = new File(rootPath + "subutil" + FILE_SEP + "README-CN.md");
41-
readme = new File(rootPath + "subutil" + FILE_SEP + "README.md");
42-
readmeOfSubUtil(readmeCN, readme);
43-
}
44-
45-
46-
private void readmeOfUtilCode(File readmeCN, File readme) throws Exception {
47-
formatCN(readmeCN);
48-
List<String> lines = FileIOUtils.readFile2List(readmeCN, "UTF-8");
49-
StringBuilder sb = new StringBuilder();
50-
for (String line : lines) {
51-
if (line.contains("* ###")) {
52-
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"));
53-
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf("→")));
54-
} else if (line.contains(": ") && !line.contains("[")) {
55-
sb.append(line.substring(0, line.indexOf(':')).trim());
56-
} else {
57-
sb.append(line);
58-
}
59-
sb.append(LINE_SEP);
60-
}
61-
FileIOUtils.writeFileFromString(readme, sb.toString());
62-
}
63-
64-
65-
private void readmeOfSubUtil(File readmeCN, File readme) throws Exception {
66-
formatCN(readmeCN);
67-
List<String> lines = FileIOUtils.readFile2List(readmeCN, "UTF-8");
68-
StringBuilder sb = new StringBuilder("## How to use" + LINE_SEP
69-
+ LINE_SEP +
70-
"You should copy the following classes which you want to use in your project." + LINE_SEP);
71-
for (int i = 3, len = lines.size(); i < len; ++i) {
72-
String line = lines.get(i);
73-
if (line.contains("* ###")) {
74-
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"));
75-
sb.append("* ### About ").append(utilsName).append(line.substring(line.indexOf("→")));
76-
} else if (line.contains(": ") && !line.contains("[")) {
77-
sb.append(line.substring(0, line.indexOf(':')).trim());
78-
} else {
79-
sb.append(line);
80-
}
81-
sb.append(LINE_SEP);
82-
}
83-
FileIOUtils.writeFileFromString(readme, sb.toString());
84-
}
85-
86-
public void formatCN(File file) throws Exception {
87-
List<String> list = FileIOUtils.readFile2List(file, "UTF-8");
88-
StringBuilder sb = new StringBuilder();
89-
for (int i = 0, len = list.size(); i < len; ++i) {
90-
String line = list.get(i);
91-
if (line.contains("* ###")) {
92-
sb.append(line).append(LINE_SEP);
93-
int maxLen = 0;
94-
line = list.get(++i);
95-
// get the max length of space
96-
for (int j = i; !line.equals(""); line = list.get(++j)) {
97-
if (line.equals("```")) continue;
98-
maxLen = Math.max(maxLen, line.replace(" ", "").replace(",", ", ").indexOf(':'));
99-
}
100-
line = list.get(i);
101-
for (; !line.equals(""); line = list.get(++i)) {
102-
if (line.equals("```")) {
103-
sb.append("```");
104-
} else {
105-
String noSpaceLine = line.replace(" ", "");
106-
int spaceLen = maxLen - line.replace(" ", "").replace(",", ", ").indexOf(':');
107-
sb.append(noSpaceLine.substring(0, noSpaceLine.indexOf(':')).replace(",", ", "))
108-
.append(LONG_SPACE.substring(0, spaceLen))// add the space
109-
.append(": ")
110-
.append(noSpaceLine.substring(noSpaceLine.indexOf(':') + 1));
111-
}
112-
sb.append(LINE_SEP);
113-
}
114-
} else {
115-
sb.append(line);
116-
}
117-
sb.append(LINE_SEP);
118-
}
119-
FileIOUtils.writeFileFromString(file, sb.toString());
120-
}
121-
12225
@Test
12326
public void test() throws Exception {
12427

0 commit comments

Comments
 (0)