Merge pull request #280 from toolbox4minecraft/added-os-version-recognition-for-libraries
added os version recognition for librariesmaster
commit
a0dac9c0d9
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue