added os version recognition for libraries

master
Stefan Dollase 2016-11-20 18:35:33 +01:00
parent 72a1c99a34
commit 1caf96139f
5 changed files with 15 additions and 7 deletions

View File

@ -38,7 +38,7 @@ public enum LibraryFinder {
private static File getLibraryFile(File librariesDirectory, LibraryJson library) {
try {
if (library.isActive(getOs())) {
if (library.isActive(getOs(), OperatingSystemDetector.getVersion())) {
return getLibraryFile(getLibrarySearchPath(librariesDirectory, library.getName()));
} else {
return null;

View File

@ -24,13 +24,13 @@ public class LibraryJson {
* applicable rule. However, this might be wrong so we need to take the most
* specific rule? For now this works fine.
*/
public boolean isActive(String os) {
public boolean isActive(String os, String version) {
if (rules.isEmpty()) {
return true;
}
boolean result = false;
for (LibraryRuleJson rule : rules) {
if (rule.isApplicable(os)) {
if (rule.isApplicable(os, version)) {
result = rule.isAllowed();
}
}

View File

@ -14,8 +14,8 @@ public class LibraryRuleJson {
public LibraryRuleJson() {
}
public boolean isApplicable(String os) {
return this.os == null || this.os.getName().equals(os);
public boolean isApplicable(String os, String version) {
return this.os == null || this.os.isApplicable(os, version);
}
public boolean isAllowed() {

View File

@ -1,17 +1,20 @@
package amidst.mojangapi.file.json.version;
import java.util.regex.Pattern;
import amidst.documentation.GsonConstructor;
import amidst.documentation.Immutable;
@Immutable
public class LibraryRuleOsJson {
private volatile String name;
private volatile String version;
@GsonConstructor
public LibraryRuleOsJson() {
}
public String getName() {
return name;
public boolean isApplicable(String os, String version) {
return this.name.equals(os) && (this.version == null || Pattern.matches(this.version, version));
}
}

View File

@ -7,6 +7,7 @@ public enum OperatingSystemDetector {
;
private static String OS_NAME = System.getProperty("os.name").toLowerCase();
private static String OS_VERSION = System.getProperty("os.version");
public static boolean isWindows() {
return OS_NAME.indexOf("win") >= 0;
@ -23,4 +24,8 @@ public enum OperatingSystemDetector {
public static boolean isSolaris() {
return OS_NAME.indexOf("sunos") >= 0;
}
public static String getVersion() {
return OS_VERSION;
}
}