This commit is contained in:
parent
7b43cf36bb
commit
fedd2fe2d8
@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
**1.1.6**
|
||||||
|
* Drop Dom4j Dependency
|
||||||
|
|
||||||
**1.1.5**
|
**1.1.5**
|
||||||
* Add JSON Strategy
|
* Add JSON Strategy
|
||||||
|
|
||||||
|
@ -30,9 +30,6 @@ dependencies {
|
|||||||
implementation "com.squareup.moshi:moshi:${project.moshi_version}"
|
implementation "com.squareup.moshi:moshi:${project.moshi_version}"
|
||||||
includeTransitive "com.squareup.moshi:moshi:${project.moshi_version}"
|
includeTransitive "com.squareup.moshi:moshi:${project.moshi_version}"
|
||||||
|
|
||||||
implementation "org.dom4j:dom4j:${project.dom4j_version}"
|
|
||||||
includeTransitive "org.dom4j:dom4j:${project.dom4j_version}"
|
|
||||||
|
|
||||||
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
|
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,10 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
fabric_loader_version = 0.8.8+build.202
|
fabric_loader_version = 0.8.8+build.202
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.1.5
|
mod_version = 1.1.6
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_api_version = 0.13.1+build.370-1.16
|
fabric_api_version = 0.13.1+build.370-1.16
|
||||||
modmenu_version = 1.12.2+build.16
|
modmenu_version = 1.12.2+build.16
|
||||||
moshi_version = 1.9.2
|
moshi_version = 1.9.2
|
||||||
dom4j_version = 2.1.3
|
|
||||||
|
@ -7,19 +7,36 @@ import com.thebrokenrail.modupdater.data.ModUpdate;
|
|||||||
import com.thebrokenrail.modupdater.util.Util;
|
import com.thebrokenrail.modupdater.util.Util;
|
||||||
import net.fabricmc.loader.api.SemanticVersion;
|
import net.fabricmc.loader.api.SemanticVersion;
|
||||||
import net.fabricmc.loader.util.version.VersionParsingException;
|
import net.fabricmc.loader.util.version.VersionParsingException;
|
||||||
import org.dom4j.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.dom4j.DocumentException;
|
import org.w3c.dom.Node;
|
||||||
import org.dom4j.Node;
|
import org.w3c.dom.NodeList;
|
||||||
import org.dom4j.io.SAXReader;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPath;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MavenStrategy implements UpdateStrategy {
|
public class MavenStrategy implements UpdateStrategy {
|
||||||
private final SAXReader reader = new SAXReader();
|
private final DocumentBuilder builder;
|
||||||
|
|
||||||
|
public MavenStrategy() {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setValidating(true);
|
||||||
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
|
try {
|
||||||
|
builder = factory.newDocumentBuilder();
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -48,17 +65,26 @@ public class MavenStrategy implements UpdateStrategy {
|
|||||||
|
|
||||||
Document doc;
|
Document doc;
|
||||||
try (InputStream source = new ByteArrayInputStream(data.getBytes())) {
|
try (InputStream source = new ByteArrayInputStream(data.getBytes())) {
|
||||||
doc = reader.read(source);
|
doc = builder.parse(source);
|
||||||
} catch (DocumentException | IOException e) {
|
} catch (IOException | SAXException e) {
|
||||||
ModUpdater.logWarn(name, e.toString());
|
ModUpdater.logWarn(name, e.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Node> versions = doc.selectNodes("/metadata/versioning/versions/*");
|
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||||
|
NodeList versions;
|
||||||
|
try {
|
||||||
|
versions = (NodeList) xPath.compile("/metadata/versioning/versions/*").evaluate(doc, XPathConstants.NODESET);
|
||||||
|
} catch (XPathExpressionException e) {
|
||||||
|
ModUpdater.logWarn(name, e.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String newestVersion = null;
|
String newestVersion = null;
|
||||||
for (Node node : versions) {
|
for (int i = 0; i < versions.getLength(); i++) {
|
||||||
String version = node.getText();
|
Node node = versions.item(i);
|
||||||
|
|
||||||
|
String version = node.getTextContent();
|
||||||
if (Util.isVersionCompatible(version)) {
|
if (Util.isVersionCompatible(version)) {
|
||||||
if (newestVersion != null) {
|
if (newestVersion != null) {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user