[0-9]+-[0-9]+-[0-9]+)");
Matcher changelogVersionMatcher = changelogVersionPattern.matcher(changeLog);
int prevMatchEnd = -1;
String prevVersion = null;
String prevDate = null;
String releases = "";
while (changelogVersionMatcher.find()) {
if (prevMatchEnd != -1) {
if (prevVersion.equals(latestMetainfoVersion)) {
break;
}
String versionChangelog = changeLog.substring(prevMatchEnd, changelogVersionMatcher.start()).trim();
String[] parts = (versionChangelog + "\r\n").split("\r?\n");
String prev = null;
String description = "";
String li = "";
for (String s : parts) {
if (s.startsWith("### ")) {
if (!li.isEmpty()) {
description += "\t\t\t\t\t" + filterLiText(li) + "" + newline;
li = "";
}
if (!description.isEmpty()) {
description += "\t\t\t\t" + newline;
}
description += "\t\t\t\t" + s.substring(4).trim() + "
" + newline;
description += "\t\t\t\t" + newline;
continue;
}
if (s.startsWith("- ")) {
if (!li.isEmpty()) {
description += "\t\t\t\t\t- " + filterLiText(li) + "
" + newline;
}
li = s.trim().substring(2);
} else {
if (!s.trim().isEmpty()) {
li = li + " " + s.trim();
}
}
}
if (!li.isEmpty()) {
description += "\t\t\t\t\t- " + filterLiText(li) + "
" + newline;
}
if (!description.isEmpty()) {
description += "\t\t\t\t
" + newline;
}
String release = "\t\t" + newline
+ "\t\t\t" + newline
+ description
+ "\t\t\t" + newline
+ "\t\t" + newline;
releases += release;
}
prevVersion = changelogVersionMatcher.group("version");
prevDate = changelogVersionMatcher.group("date");
prevMatchEnd = changelogVersionMatcher.end();
}
metainfo = metainfo.replaceAll("", ("" + newline + releases).trim());
Helper.writeFile(METAINFO_FILENAME, metainfo.getBytes("UTF-8"));
}
private static String filterLiText(String li) {
li = li.replaceAll("\\[(#[0-9]+)\\]", "$1");
li = li.replaceAll("\\[(PR[0-9]+)\\]", "$1");
li = li.replace("&", "&");
return li;
}
}