diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-01-06 01:19:45 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-05-29 21:01:53 +0200 |
commit | 6d0264e1970dbf205346d3655f21c39ac889a730 (patch) | |
tree | 8027a9da945c76ec8efcaff15e2653358952acc6 /src/website/lombok | |
parent | 599b6aab677439ae1bdea2cdca3233d0b763fd3f (diff) | |
download | lombok-6d0264e1970dbf205346d3655f21c39ac889a730.tar.gz lombok-6d0264e1970dbf205346d3655f21c39ac889a730.tar.bz2 lombok-6d0264e1970dbf205346d3655f21c39ac889a730.zip |
the all-versions page is fetched in order to allow generating an updated copy of that page.
Diffstat (limited to 'src/website/lombok')
-rw-r--r-- | src/website/lombok/website/WebsiteMaker.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/website/lombok/website/WebsiteMaker.java b/src/website/lombok/website/WebsiteMaker.java index 299b4211..ef078db6 100644 --- a/src/website/lombok/website/WebsiteMaker.java +++ b/src/website/lombok/website/WebsiteMaker.java @@ -1,18 +1,26 @@ package lombok.website; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Writer; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import de.java2html.Java2Html; import freemarker.cache.FileTemplateLoader; @@ -140,12 +148,30 @@ public class WebsiteMaker { } } - private Map<String, Object> createDataModel() { + private static final Pattern LOMBOK_LINK = Pattern.compile("^.*<a(?: (?:id|class|rel|rev|download|target|type)(?:=\"[^\"]*\")?)* href=\"([^\"]+)\"(?: (?:id|class|rel|rev|download|target|type)(?:=\"[^\"]*\")?)*>([^<]+)</a>.*$"); + private Map<String, Object> createDataModel() throws IOException { Map<String, Object> data = new HashMap<String, Object>(); data.put("version", lombok.core.Version.getVersion()); data.put("fullVersion", lombok.core.Version.getFullVersion()); data.put("year", "" + new GregorianCalendar().get(Calendar.YEAR)); data.put("usages", new HtmlMaker(new File(baseDir, "usageExamples"))); + InputStream in = new URL("https://projectlombok.org/all-versions.html").openStream(); + ArrayList<List<String>> links = new ArrayList<List<String>>(); + try { + BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + for (String line = br.readLine(); line != null; line = br.readLine()) { + Matcher m = LOMBOK_LINK.matcher(line); + if (m.matches()) links.add(Arrays.asList(m.group(1), m.group(2))); + } + } finally { + in.close(); + } + + if (links.isEmpty() || !links.get(0).get(0).endsWith("lombok-" + lombok.core.Version.getVersion() + ".jar")) { + links.add(Arrays.asList("downloads/lombok-" + lombok.core.Version.getVersion() + ".jar", "lombok-" + lombok.core.Version.getVersion() + ".jar")); + } + + data.put("linksToVersions", links); return data; } |