diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-09-11 21:25:05 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-10-26 00:07:18 +0200 |
commit | 6fc0cd736c5def296ec7c963ba6e6ec5032d08c9 (patch) | |
tree | 04060fc487fb81e6382e492a728d9fd25e7fc9ae /src/website/lombok | |
parent | 033660088bc9f184de7afb512fa752c4ccc70f83 (diff) | |
download | lombok-6fc0cd736c5def296ec7c963ba6e6ec5032d08c9.tar.gz lombok-6fc0cd736c5def296ec7c963ba6e6ec5032d08c9.tar.bz2 lombok-6fc0cd736c5def296ec7c963ba6e6ec5032d08c9.zip |
website-only now available.
Diffstat (limited to 'src/website/lombok')
-rw-r--r-- | src/website/lombok/website/CompileChangelog.java | 39 | ||||
-rw-r--r-- | src/website/lombok/website/FetchCurrentVersion.java | 33 | ||||
-rw-r--r-- | src/website/lombok/website/WebsiteMaker.java | 2 |
3 files changed, 70 insertions, 4 deletions
diff --git a/src/website/lombok/website/CompileChangelog.java b/src/website/lombok/website/CompileChangelog.java index b1ef53c0..8912434e 100644 --- a/src/website/lombok/website/CompileChangelog.java +++ b/src/website/lombok/website/CompileChangelog.java @@ -1,10 +1,12 @@ package lombok.website; +import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.StringReader; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -37,7 +39,7 @@ public class CompileChangelog { } else if (latest) { result = buildLatest(sectionByVersion(markdown, version)); } else { - result = markdownToHtml(markdown); + result = markdownToHtml(sectionStartingAt(markdown, version)); } FileOutputStream file = new FileOutputStream(fileOut); @@ -68,6 +70,12 @@ public class CompileChangelog { return markdownToHtml(raw); } + public static String getHtmlStartingAtSection(File root, String version) throws IOException { + File f = new File(root, "doc/changelog.markdown"); + String raw = readFile(f); + return markdownToHtml(sectionStartingAt(raw, version)); + } + private static String readFile(File f) throws IOException { byte[] b = new byte[65536]; FileInputStream in = new FileInputStream(f); @@ -101,13 +109,38 @@ public class CompileChangelog { return markdownToHtml(noLinks); } + private static String sectionStartingAt(String markdown, String version) { + if (version.toUpperCase().endsWith("-HEAD") || version.toUpperCase().endsWith("-EDGE")) { + version = version.substring(0, version.length() - 5); + } + + Pattern p = Pattern.compile("^.*###\\s*v(.*)$"); + BufferedReader br = new BufferedReader(new StringReader(markdown)); + StringBuilder out = new StringBuilder(); + int state = 0; + try { + for (String line = br.readLine(); line != null; line = br.readLine()) { + if (state < 2) { + Matcher m = p.matcher(line); + if (m.matches()) state = m.group(1).startsWith(version) ? 2 : 1; + } + if (state != 1) { + out.append(line); + out.append("\n"); + } + } + return out.toString(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + private static String sectionByVersion(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.*)?$"); + Pattern p = Pattern.compile("(?is-m)^.*###\\s*v" + version + ".*?\n(.*?)(?:###\\s*v.*)?$"); Matcher m = p.matcher(markdown); return m.matches() ? m.group(1) : null; } diff --git a/src/website/lombok/website/FetchCurrentVersion.java b/src/website/lombok/website/FetchCurrentVersion.java new file mode 100644 index 00000000..6c1ca639 --- /dev/null +++ b/src/website/lombok/website/FetchCurrentVersion.java @@ -0,0 +1,33 @@ +package lombok.website; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class FetchCurrentVersion { + private FetchCurrentVersion() {} + + private static final Pattern VERSION_PATTERN = Pattern.compile("^.*<\\s*span\\s+id\\s*=\\s*[\"'](currentVersion|currentVersionFull)[\"'](?:\\s+style\\s*=\\s*[\"']display\\s*:\\s*none;?[\"'])?\\s*>\\s*([^\t<]+)\\s*<\\s*/\\s*span\\s*>.*$"); + + public static void main(String[] args) throws IOException { + System.out.print(fetchVersionFromSite(args.length == 0 || args[0].equals("full"))); + } + + public static String fetchVersionFromSite(boolean fetchFull) throws IOException { + InputStream in = new URL("https://projectlombok.org/download").openStream(); + try { + BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + for (String line = br.readLine(); line != null; line = br.readLine()) { + Matcher m = VERSION_PATTERN.matcher(line); + if (m.matches() && m.group(1).equals("currentVersionFull") == fetchFull) return m.group(2); + } + throw new IOException("Expected a span with id 'currentVersion'"); + } finally { + in.close(); + } + } +} diff --git a/src/website/lombok/website/WebsiteMaker.java b/src/website/lombok/website/WebsiteMaker.java index 6e773346..88556b97 100644 --- a/src/website/lombok/website/WebsiteMaker.java +++ b/src/website/lombok/website/WebsiteMaker.java @@ -335,7 +335,7 @@ public class WebsiteMaker { data.put("fullVersion", fullVersion); data.put("timestampString", currentTime); data.put("year", "" + new GregorianCalendar().get(Calendar.YEAR)); - data.put("changelog", CompileChangelog.getHtml(baseDir.getParentFile())); + data.put("changelog", CompileChangelog.getHtmlStartingAtSection(baseDir.getParentFile(), version)); data.put("changelogEdge", CompileChangelog.getHtmlForEdge(baseDir.getParentFile(), version)); return data; |