Commit 270ff261 authored by neo's avatar neo

[dev] add extract commit from diff

parent 5142fba3
package com.neo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class ExtractCommitFromDiff {
public static final String LINE_SPLITER = "\r\n";
public static void main(String[] args) {
try (BufferedReader burReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(
"C:\\Users\\Neo Wang\\workspace\\atms\\atms-gen\\target\\test-classes\\diff.txt"))))) {
String line = null;
List<Diff> diffs = new ArrayList<>();
Diff diff = null;
while ((line = burReader.readLine()) != null) {
if (line.contains("diff --git")) {
if (diff != null) diffs.add(diff);
diff = new Diff();
diff.fileName = line.substring(line.lastIndexOf("/atms-dao") + 1, line.length());
} else if (line.startsWith("+") || line.startsWith("-")) {
if (line.startsWith("++") || line.startsWith("--")) continue;
if (diff == null) {
System.out.println(line);
throw new RuntimeException("not init");
}
diff.diffLine.add(line);
}
}
List<Diff> orderDiffs = diffs.stream().sorted(Comparator.comparing(Diff::length)).collect(Collectors.toList());
orderDiffs.forEach(m -> {
if (m.fileName.contains("Example") ) {
System.out.println(m.fileName);
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
static class Diff {
String fileName;
List<String> diffLine = new ArrayList<>();
@Override
public String toString() {
StringBuilder builder = new StringBuilder(fileName);
builder.append(LINE_SPLITER);
diffLine.forEach(m -> {
if (!m.contains("*") && !m.contains("deleteByPrimaryKey") && !m.contains("selectByPrimaryKey")
&& !m.contains("import") && m.trim().length() > 1)
builder.append(m).append(LINE_SPLITER);
});
return builder.toString();
}
public int length() {
return diffLine.stream().filter(m -> {
return !m.contains("*") && !m.contains("deleteByPrimaryKey") && !m.contains("selectByPrimaryKey")
&& !m.contains("import") && m.trim().length() > 1;
}).collect(Collectors.toList()).size();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment