This repository has been archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5760f9
commit 244b6e5
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); }} |