blob: 60b70aa3d108ffd064cd475e81d8b98b92467de9 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package lombok.website;
import com.petebevin.markdown.MarkdownProcessor;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CompileChangelog {
public static void main(String[] args) {
String fileIn = args[0];
String fileOut = args[1];
boolean edge = args.length > 3 && "-edge".equals(args[2]);
String version = edge ? args[3] : null;
try {
FileInputStream in = new FileInputStream(fileIn);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] b = new byte[65536];
while (true) {
int r = in.read(b);
if ( r == -1 ) break;
out.write(b, 0, r);
}
in.close();
String markdown = new String(out.toByteArray(), "UTF-8");
String result = edge ? buildEdge(markdown, version) : build(markdown);
FileOutputStream file = new FileOutputStream(fileOut);
file.write(result.getBytes("UTF-8"));
file.close();
System.exit(0);
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
}
private static String build(String markdown) {
return new MarkdownProcessor().markdown(markdown);
}
private static final Pattern LAST_CHANGELOG = Pattern.compile(
"^.*### v$", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
private static String buildEdge(String markdown, String version) {
if (version.toUpperCase().endsWith("-HEAD") || version.toUpperCase().endsWith("-EDGE")) {
version = version.substring(0, version.length() - 5);
}
Pattern p = Pattern.compile(
"(?is-m)^.*###\\s*v" + version + ".*?\n(.*?)(?:###\\s*v.*)?$");
Matcher m = p.matcher(markdown);
String subMarkdown = m.matches() ? m.group(1) : "* No changelog records for this edge release.";
return new MarkdownProcessor().markdown(subMarkdown);
}
}
|