Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
symmetric/symmetric-client/src/test/java/org/jumpmind/symmetric/tool/RefactorTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} |