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

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
martinklepsch committed Jan 9, 2018
1 parent c5760f9 commit 5dab96c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/ .

Expand Down
15 changes: 13 additions & 2 deletions src/Boot.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// vim: et:ts=4:sw=4

import boot.bin.ParentClassLoader;
import boot.bin.BootSnapshotVersionFetcher;

import java.io.*;
import java.net.*;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -224,7 +233,9 @@ public class Boot {
String v = p.getProperty(version);
String vv = (v == null) ? version : v;
String nn = "boot." + ((v == null) ? "jar" : "sh");
return download(downloadUrl(vv, nn), binaryFileCreate(vv)); }
String url = downloadUrl(vv, nn);
System.out.println("Downloading " + nn + " / " + vv + " from " + url);
return download(url, binaryFileCreate(vv)); }

public static URLClassLoader
loadJar(File jar) throws Exception {
Expand Down
43 changes: 43 additions & 0 deletions src/boot/bin/BootSnapshotVersionFetcher.java
Original file line number Diff line number Diff line change
@@ -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<String> 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(); }}

0 comments on commit 5dab96c

Please sign in to comment.