From 244b6e5f286583685053cf71056f2495f05cc92a Mon Sep 17 00:00:00 2001 From: Martin Klepsch Date: Tue, 9 Jan 2018 12:45:15 +0100 Subject: [PATCH] WIP --- build.sh | 2 +- src/Boot.java | 11 ++++- src/boot/bin/BootSnapshotVersionFetcher.java | 43 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/boot/bin/BootSnapshotVersionFetcher.java diff --git a/build.sh b/build.sh index eb37823..1f46aed 100755 --- a/build.sh +++ b/build.sh @@ -21,7 +21,7 @@ echo -e "\033[0;33m<< Version: $VERSION >>\033[0m"; \ # Build target/loader.jar which serves as foundation for boot.sh/exe -javac -d target src/Boot.java src/boot/bin/ParentClassLoader.java +javac -d target src/Boot.java src/boot/bin/ParentClassLoader.java src/boot/bin/BootSnapshotVersionFetcher.java cp -r resources/* target/ jar cef Boot target/loader.jar -C target/ . diff --git a/src/Boot.java b/src/Boot.java index c249f00..522ccb2 100644 --- a/src/Boot.java +++ b/src/Boot.java @@ -1,6 +1,7 @@ // vim: et:ts=4:sw=4 import boot.bin.ParentClassLoader; +import boot.bin.BootSnapshotVersionFetcher; import java.io.*; import java.net.*; @@ -182,7 +183,15 @@ public class Boot { public static String downloadUrl(String version, String name) throws Exception { - return String.format("https://github.com/boot-clj/boot/releases/download/%s/%s", version, name); } + String urlFormat = "https://clojars.org/repo/boot/base/%s/base-%s-uber.jar"; + System.out.println("passed name " + name + " compare result " + version.compareTo("2.8")); + if (0 < version.compareTo("2.8") && name.equals("boot.jar")) { + if (version.endsWith("SNAPSHOT")) { + return String.format(urlFormat, version, BootSnapshotVersionFetcher.lastSnapshot(version)); } + else { + return String.format(urlFormat, version, version); } + } else { // 2.7.2 and lower download releases from github + return String.format("https://github.com/boot-clj/boot/releases/download/%s/%s", version, name); }} public static File validateBinaryFile(File f) throws Exception { diff --git a/src/boot/bin/BootSnapshotVersionFetcher.java b/src/boot/bin/BootSnapshotVersionFetcher.java new file mode 100644 index 0000000..b36beeb --- /dev/null +++ b/src/boot/bin/BootSnapshotVersionFetcher.java @@ -0,0 +1,43 @@ +package boot.bin; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.Arrays; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public class BootSnapshotVersionFetcher { + + private static class MavenMetadataHandler extends DefaultHandler { + String snapshotVersion; + Deque stack = new ArrayDeque<>(); + + String marker[] = {"value", "snapshotVersion", "snapshotVersions", "versioning", "metadata"}; + + public String getSnapshotVersion() { + return snapshotVersion; } + + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + stack.push(qName); } + + public void endElement(String uri, String localName, String qName) throws SAXException { + stack.pop(); } + + public void characters(char ch[], int start, int length) throws SAXException { + if (Arrays.equals(stack.toArray(), marker) && snapshotVersion == null) { + // String versionString = new String(ch, start, length); + // System.out.println("version " + versionString); + snapshotVersion = new String(ch, start, length); }}}; + + public static String lastSnapshot(String version) throws Exception { + MavenMetadataHandler handler = new MavenMetadataHandler(); + try { SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser saxParser = factory.newSAXParser(); + String metadataFile = String.format("https://clojars.org/repo/boot/base/%s/maven-metadata.xml", version); + saxParser.parse(metadataFile, handler); } + catch (Exception e) { e.printStackTrace(); } + + return handler.getSnapshotVersion(); }} \ No newline at end of file