/
RefactorTool.java
44 lines (36 loc) · 1.39 KB
/
RefactorTool.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package org.jumpmind.symmetric.tool;
import java.io.File;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
public class RefactorTool {
public static void main(String[] args) throws Exception {
File dir = new File(System.getProperty("user.dir")).getParentFile();
Collection<File> files = FileUtils.listFiles(dir, new String[] { "java" }, true);
for (File file : files) {
if (file.getAbsolutePath().contains("/symmetric-")) {
System.out.println("Refactoring file: " + file.getName());
StringBuilder contents = new StringBuilder(FileUtils.readFileToString(file));
if (refactor(contents)) {
FileUtils.write(file, contents.toString());
}
}
}
}
protected static boolean refactor(StringBuilder contents) {
String[] lines = contents.toString().split("\n");
contents.setLength(0);
int logmode = 0;
for (String line : lines) {
if (line.contains("log.") || line.contains("logger.")) {
logmode = 4;
}
if (!line.contains("String.format") && logmode > 0) {
line = line.replace("%s", "{}");
line = line.replace("%d", "{}");
}
contents.append(line);
contents.append("\n");
}
return true;
}
}