Skip to content
This repository was archived by the owner on Jan 25, 2019. It is now read-only.

Commit 28caf61

Browse files
committed
WIP
1 parent c5760f9 commit 28caf61

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ echo -e "\033[0;33m<< Version: $VERSION >>\033[0m"; \
2121

2222
# Build target/loader.jar which serves as foundation for boot.sh/exe
2323

24-
javac -d target src/Boot.java src/boot/bin/ParentClassLoader.java
24+
javac -d target src/Boot.java src/boot/bin/ParentClassLoader.java src/boot/bin/BootSnapshotVersionFetcher.java
2525
cp -r resources/* target/
2626
jar cef Boot target/loader.jar -C target/ .
2727

src/Boot.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// vim: et:ts=4:sw=4
22

33
import boot.bin.ParentClassLoader;
4+
import boot.bin.BootSnapshotVersionFetcher;
45

56
import java.io.*;
67
import java.net.*;
@@ -182,7 +183,14 @@ public class Boot {
182183

183184
public static String
184185
downloadUrl(String version, String name) throws Exception {
185-
return String.format("https://github.com/boot-clj/boot/releases/download/%s/%s", version, name); }
186+
if (0 < version.compareTo("2.8") && name.equals("boot.jar")) {
187+
String urlFormat = "https://clojars.org/repo/boot/base/%s/base-%s-uber.jar";
188+
if (version.endsWith("SNAPSHOT")) {
189+
return String.format(urlFormat, version, BootSnapshotVersionFetcher.lastSnapshot(version)); }
190+
else {
191+
return String.format(urlFormat, version, version); }
192+
} else { // 2.7.2 and lower download releases from github
193+
return String.format("https://github.com/boot-clj/boot/releases/download/%s/%s", version, name); }}
186194

187195
public static File
188196
validateBinaryFile(File f) throws Exception {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package boot.bin;
2+
3+
import java.util.ArrayDeque;
4+
import java.util.Deque;
5+
import java.util.Arrays;
6+
import javax.xml.parsers.SAXParser;
7+
import javax.xml.parsers.SAXParserFactory;
8+
import org.xml.sax.Attributes;
9+
import org.xml.sax.SAXException;
10+
import org.xml.sax.helpers.DefaultHandler;
11+
12+
public class BootSnapshotVersionFetcher {
13+
14+
private static class MavenMetadataHandler extends DefaultHandler {
15+
String snapshotVersion;
16+
Deque<String> stack = new ArrayDeque<>();
17+
18+
String marker[] = {"value", "snapshotVersion", "snapshotVersions", "versioning", "metadata"};
19+
20+
public String getSnapshotVersion() {
21+
return snapshotVersion; }
22+
23+
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
24+
stack.push(qName); }
25+
26+
public void endElement(String uri, String localName, String qName) throws SAXException {
27+
stack.pop(); }
28+
29+
public void characters(char ch[], int start, int length) throws SAXException {
30+
if (Arrays.equals(stack.toArray(), marker) && snapshotVersion == null) {
31+
// String versionString = new String(ch, start, length);
32+
// System.out.println("version " + versionString);
33+
snapshotVersion = new String(ch, start, length); }}};
34+
35+
public static String lastSnapshot(String version) throws Exception {
36+
MavenMetadataHandler handler = new MavenMetadataHandler();
37+
try { SAXParserFactory factory = SAXParserFactory.newInstance();
38+
SAXParser saxParser = factory.newSAXParser();
39+
String metadataFile = String.format("https://clojars.org/repo/boot/base/%s/maven-metadata.xml", version);
40+
saxParser.parse(metadataFile, handler); }
41+
catch (Exception e) { e.printStackTrace(); }
42+
43+
return handler.getSnapshotVersion(); }}

0 commit comments

Comments
 (0)