aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/core/Version.java2
-rw-r--r--src/website/lombok/website/CompileChangelog.java77
-rw-r--r--src/website/lombok/website/WebsiteMaker.java59
3 files changed, 127 insertions, 11 deletions
diff --git a/src/core/lombok/core/Version.java b/src/core/lombok/core/Version.java
index 9cea1f1e..035f5e8a 100644
--- a/src/core/lombok/core/Version.java
+++ b/src/core/lombok/core/Version.java
@@ -49,7 +49,7 @@ public class Version {
*/
public static void main(String[] args) {
if (args.length > 0) {
- System.out.printf("Lombok %s\n", getFullVersion());
+ System.out.printf("%s\n", getFullVersion());
} else {
System.out.println(VERSION);
}
diff --git a/src/website/lombok/website/CompileChangelog.java b/src/website/lombok/website/CompileChangelog.java
new file mode 100644
index 00000000..276842be
--- /dev/null
+++ b/src/website/lombok/website/CompileChangelog.java
@@ -0,0 +1,77 @@
+package lombok.website;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.petebevin.markdown.MarkdownProcessor;
+
+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]);
+ boolean latest = args.length > 3 && "-latest".equals(args[2]);
+ String version = args.length > 3 ? 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;
+ if (edge) {
+ result = buildEdge(sectionByVersion(markdown, version));
+ } else if (latest) {
+ result = buildLatest(sectionByVersion(markdown, version));
+ } else {
+ result = 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 String buildEdge(String section) {
+ String latest = section != null ? section : "* No changelog records for this edge release.";
+ return new MarkdownProcessor().markdown(latest);
+ }
+
+ private static String buildLatest(String section) {
+ String latest = section != null ? section : "* No changelog records for this release.";
+ String noIssueLinks = latest.replaceAll("\\[[^]]*[Ii]ssue[^]]*\\]\\([^)]*\\)", "");
+ String noLinks = noIssueLinks.replaceAll("\\[([^]]*)\\]\\([^)]*\\)", "$1");
+ return new MarkdownProcessor().markdown(noLinks);
+ }
+
+ 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.*)?$");
+ Matcher m = p.matcher(markdown);
+ return m.matches() ? m.group(1) : null;
+ }
+} \ No newline at end of file
diff --git a/src/website/lombok/website/WebsiteMaker.java b/src/website/lombok/website/WebsiteMaker.java
index d903340b..fddc1b38 100644
--- a/src/website/lombok/website/WebsiteMaker.java
+++ b/src/website/lombok/website/WebsiteMaker.java
@@ -10,6 +10,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@@ -31,32 +32,70 @@ import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
public class WebsiteMaker {
+ private final String version, fullVersion;
private final File baseDir, outputDir;
- public WebsiteMaker(File baseDir, File outputDir) {
+ public WebsiteMaker(String version, String fullVersion, File baseDir, File outputDir) {
+ this.version = version;
+ this.fullVersion = fullVersion;
this.baseDir = baseDir;
this.outputDir = outputDir;
}
+ private static final class VersionFinder {
+ public static String getVersion() {
+ return getVersion0("getVersion");
+ }
+
+ public static String getFullVersion() {
+ return getVersion0("getFullVersion");
+ }
+
+ private static String getVersion0(String mName) {
+ try {
+ Class<?> c = Class.forName("lombok.core.Version");
+ Method m = c.getMethod(mName);
+ return (String) m.invoke(null);
+ } catch (ClassNotFoundException e) {
+ System.err.println("You need to specify the version string, and the full version string, as first 2 arguments.");
+ System.exit(1);
+ return null;
+ } catch (Exception e) {
+ if (e instanceof RuntimeException) throw (RuntimeException) e;
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
public static void main(String[] args) throws Exception {
File in, out;
- if (args.length == 0) {
+ String version, fullVersion;
+ if (args.length < 2) {
+ version = VersionFinder.getVersion();
+ fullVersion = VersionFinder.getFullVersion();
+ } else {
+ version = args[0];
+ fullVersion = args[1];
+ }
+
+ if (args.length < 3) {
in = new File(".");
if (new File(in, "build.xml").isFile() && new File(in, "website").isDirectory()) in = new File(in, "website");
} else {
- in = new File(args[0]);
+ in = new File(args[2]);
}
- if (args.length < 2) {
+ if (args.length < 4) {
if (new File("./build.xml").isFile() && new File("./website").isDirectory() && new File("./build").isDirectory()) {
out = new File("./build/website");
} else {
out = new File(in, "output");
}
} else {
- out = new File(args[1]);
+ out = new File(args[3]);
}
- WebsiteMaker maker = new WebsiteMaker(in, out);
+
+ WebsiteMaker maker = new WebsiteMaker(version, fullVersion, in, out);
maker.buildWebsite();
}
@@ -151,8 +190,8 @@ public class WebsiteMaker {
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("version", version);
+ data.put("fullVersion", fullVersion);
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();
@@ -167,8 +206,8 @@ public class WebsiteMaker {
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"));
+ if (links.isEmpty() || !links.get(0).get(0).endsWith("lombok-" + version + ".jar")) {
+ links.add(Arrays.asList("downloads/lombok-" + version + ".jar", "lombok-" + version + ".jar"));
}
data.put("linksToVersions", links);