Add Version system
This commit is contained in:
parent
d83074cc1e
commit
0eb0c09202
|
@ -14,8 +14,9 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
compile 'com.google.code.gson:gson:+'
|
||||
compile "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"
|
||||
compile 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
compile 'org.apache.maven:maven-artifact:3.6.3'
|
||||
|
||||
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
}
|
||||
|
|
|
@ -37,12 +37,12 @@ public class ManifestJSON extends JSON {
|
|||
public String id;
|
||||
public boolean primary;
|
||||
|
||||
public AddonscriptJSON.Relation toRelation(String mcv) {
|
||||
public AddonscriptJSON.Relation toRelation() {
|
||||
if (id != null && id.startsWith("forge-")) {
|
||||
AddonscriptJSON.Relation rel = new AddonscriptJSON.Relation();
|
||||
rel.type = "modloader";
|
||||
rel.id = "forge";
|
||||
rel.versions = "[" + mcv + id.replaceAll("forge", "") + "]";
|
||||
rel.versions = "[" + id.replaceAll("forge", "") + "]";
|
||||
rel.options = new ArrayList<>();
|
||||
rel.options.add("required");
|
||||
rel.options.add("client");
|
||||
|
@ -107,7 +107,7 @@ public class ManifestJSON extends JSON {
|
|||
|
||||
if (minecraft != null) {
|
||||
for (Modloader l : minecraft.modLoaders) {
|
||||
version.relations.add(l.toRelation(minecraft.version));
|
||||
version.relations.add(l.toRelation());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@ import ley.anvil.addonscript.curse.CurseMeta;
|
|||
import ley.anvil.addonscript.forge.ForgeMeta;
|
||||
import ley.anvil.addonscript.installer.IInstaller;
|
||||
import ley.anvil.addonscript.installer.InternalDirInstaller;
|
||||
import ley.anvil.addonscript.maven.ArtifactDestination;
|
||||
import ley.anvil.addonscript.util.HTTPRequest;
|
||||
import ley.anvil.addonscript.util.Utils;
|
||||
import ley.anvil.addonscript.v1.AddonscriptJSON;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
|
@ -278,6 +278,14 @@ public class ASWrapper {
|
|||
return new MetaData();
|
||||
}
|
||||
|
||||
public Versions getVersions() {
|
||||
try {
|
||||
return new Versions(relation.versions);
|
||||
} catch (InvalidVersionSpecificationException e) {
|
||||
throw new RuntimeException("Error in JSON");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Map<ArtifactDestination, MetaData> getMetaData(ArtifactDestination[] artifacts) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ley.anvil.addonscript.maven;
|
||||
package ley.anvil.addonscript.wrapper;
|
||||
|
||||
import ley.anvil.addonscript.util.Utils;
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package ley.anvil.addonscript.wrapper;
|
||||
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Versions {
|
||||
|
||||
VersionRange range;
|
||||
String latest;
|
||||
|
||||
public Versions(String range) throws InvalidVersionSpecificationException {
|
||||
this.range = VersionRange.createFromVersionSpec(range);
|
||||
String noBrack = range.replace("[", "").replace("]", "").replace("(", "").replace(")", "");
|
||||
String[] parts = noBrack.split(",");
|
||||
for (int i = parts.length - 1; i >= 0; i--) {
|
||||
if (this.range.containsVersion(new DefaultArtifactVersion(parts[i]))) {
|
||||
latest = parts[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(String version) {
|
||||
return range.containsVersion(new DefaultArtifactVersion(version));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLatestKnown() {
|
||||
return latest;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue