diff --git a/HMCL/build.gradle b/HMCL/build.gradle index 94ee39715..278163dbd 100644 --- a/HMCL/build.gradle +++ b/HMCL/build.gradle @@ -47,8 +47,9 @@ mainClassName = 'org.jackhuang.hmcl.Main' dependencies { implementation project(":HMCLCore") - implementation project(":JSTUN") implementation rootProject.files("lib/JFoenix.jar") + + implementation group: 'de.javawi.jstun', name: 'jstun', version: '0.7.4' } def digest(String algorithm, byte[] bytes) { @@ -117,13 +118,8 @@ compileJava11Java { targetCompatibility = 11 } -jar { - enabled = false - dependsOn shadowJar -} - shadowJar { - classifier = null + classifier = "shadow" manifest { attributes 'Created-By': 'Copyright(c) 2013-2021 huangyuhui.', @@ -156,12 +152,6 @@ shadowJar { 'javafx.base/com.sun.javafx.event' ].join(" ") } - - doLast { - repack(jar.archivePath) // see repack() - attachSignature(jar.archivePath) - createChecksum(jar.archivePath) - } } task proguard(type: proguard.gradle.ProGuardTask) { @@ -192,6 +182,7 @@ task proguard(type: proguard.gradle.ProGuardTask) { dontwarn 'org.jackhuang.hmcl.util.Pack200Utils' dontwarn 'com.sun.javafx.**' dontwarn 'com.jfoenix.**' + dontwarn 'org.apache.**' adaptclassstrings @@ -236,8 +227,6 @@ task proguard(type: proguard.gradle.ProGuardTask) { task finalJar(type: Jar) { dependsOn proguard - classifier = 'final' - manifest = shadowJar.manifest from { proguard.outJarFiles.collect { zipTree(it)} } @@ -246,6 +235,17 @@ task finalJar(type: Jar) { from { shadowJar.outputs.files.collect { zipTree(it) } } include("META-INF/versions/**") } + + doLast { + repack(jar.archivePath) // see repack() + attachSignature(jar.archivePath) + createChecksum(jar.archivePath) + } +} + +jar { + enabled = false + dependsOn finalJar } def createExecutable(String suffix, String header) { diff --git a/HMCLCore/build.gradle b/HMCLCore/build.gradle index 27d9427c2..67c3f9c4b 100644 --- a/HMCLCore/build.gradle +++ b/HMCLCore/build.gradle @@ -13,5 +13,7 @@ dependencies { api group: 'com.github.steveice10', name: 'opennbt', version: '1.1' api group: 'com.nqzero', name: 'permit-reflect', version: '0.3' api group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1' + api group: 'org.apache.commons', name: 'commons-compress', version: '1.21' + api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0' compileOnlyApi group: 'org.jetbrains', name: 'annotations', version: '16.0.3' } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/JavaVersionConstraint.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/JavaVersionConstraint.java index 9701df327..2a1d4c531 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/JavaVersionConstraint.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/JavaVersionConstraint.java @@ -17,8 +17,8 @@ */ package org.jackhuang.hmcl.game; +import org.apache.commons.lang3.Range; import org.jackhuang.hmcl.util.Lang; -import org.jackhuang.hmcl.util.Range; import org.jackhuang.hmcl.util.platform.Architecture; import org.jackhuang.hmcl.util.platform.JavaVersion; import org.jackhuang.hmcl.util.platform.OperatingSystem; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Range.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Range.java deleted file mode 100644 index 495e762de..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Range.java +++ /dev/null @@ -1,509 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2021 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.util; - -import java.util.Comparator; -import java.util.Objects; - -public final class Range { - - @SuppressWarnings({"rawtypes", "unchecked"}) - private enum ComparableComparator implements Comparator { - INSTANCE; - - /** - * Comparable based compare implementation. - * - * @param obj1 left hand side of comparison - * @param obj2 right hand side of comparison - * @return negative, 0, positive comparison value - */ - @Override - public int compare(final Object obj1, final Object obj2) { - return ((Comparable) obj1).compareTo(obj2); - } - } - - /** - * Serialization version. - * - * @see java.io.Serializable - */ - private static final long serialVersionUID = 1L; - - /** - *

Obtains a range with the specified minimum and maximum values (both inclusive).

- * - *

The range uses the natural ordering of the elements to determine where - * values lie in the range.

- * - *

The arguments may be passed in the order (min,max) or (max,min). - * The getMinimum and getMaximum methods will return the correct values.

- * - * @param the type of the elements in this range - * @param fromInclusive the first value that defines the edge of the range, inclusive - * @param toInclusive the second value that defines the edge of the range, inclusive - * @return the range object, not null - * @throws IllegalArgumentException if either element is null - * @throws ClassCastException if the elements are not {@code Comparable} - */ - public static > Range between(final T fromInclusive, final T toInclusive) { - return between(fromInclusive, toInclusive, null); - } - - /** - *

Obtains a range with the specified minimum and maximum values (both inclusive).

- * - *

The range uses the specified {@code Comparator} to determine where - * values lie in the range.

- * - *

The arguments may be passed in the order (min,max) or (max,min). - * The getMinimum and getMaximum methods will return the correct values.

- * - * @param the type of the elements in this range - * @param fromInclusive the first value that defines the edge of the range, inclusive - * @param toInclusive the second value that defines the edge of the range, inclusive - * @param comparator the comparator to be used, null for natural ordering - * @return the range object, not null - * @throws IllegalArgumentException if either element is null - * @throws ClassCastException if using natural ordering and the elements are not {@code Comparable} - */ - public static Range between(final T fromInclusive, final T toInclusive, final Comparator comparator) { - return new Range<>(fromInclusive, toInclusive, comparator); - } - - /** - *

Obtains a range using the specified element as both the minimum - * and maximum in this range.

- * - *

The range uses the natural ordering of the elements to determine where - * values lie in the range.

- * - * @param the type of the elements in this range - * @param element the value to use for this range, not null - * @return the range object, not null - * @throws IllegalArgumentException if the element is null - * @throws ClassCastException if the element is not {@code Comparable} - */ - public static > Range is(final T element) { - return between(element, element, null); - } - - /** - *

Obtains a range using the specified element as both the minimum - * and maximum in this range.

- * - *

The range uses the specified {@code Comparator} to determine where - * values lie in the range.

- * - * @param the type of the elements in this range - * @param element the value to use for this range, must not be {@code null} - * @param comparator the comparator to be used, null for natural ordering - * @return the range object, not null - * @throws IllegalArgumentException if the element is null - * @throws ClassCastException if using natural ordering and the elements are not {@code Comparable} - */ - public static Range is(final T element, final Comparator comparator) { - return between(element, element, comparator); - } - - /** - * The ordering scheme used in this range. - */ - private final Comparator comparator; - - /** - * Cached output hashCode (class is immutable). - */ - private transient int hashCode; - - /** - * The maximum value in this range (inclusive). - */ - private final T maximum; - - /** - * The minimum value in this range (inclusive). - */ - private final T minimum; - - /** - * Cached output toString (class is immutable). - */ - private transient String toString; - - /** - * Creates an instance. - * - * @param element1 the first element, not null - * @param element2 the second element, not null - * @param comp the comparator to be used, null for natural ordering - */ - @SuppressWarnings("unchecked") - private Range(final T element1, final T element2, final Comparator comp) { - if (element1 == null || element2 == null) { - throw new IllegalArgumentException("Elements in a range must not be null: element1=" + - element1 + ", element2=" + element2); - } - if (comp == null) { - this.comparator = ComparableComparator.INSTANCE; - } else { - this.comparator = comp; - } - if (this.comparator.compare(element1, element2) < 1) { - this.minimum = element1; - this.maximum = element2; - } else { - this.minimum = element2; - this.maximum = element1; - } - } - - public boolean isEmpty() { - return comparator.compare(minimum, maximum) > 0; - } - - /** - *

Checks whether the specified element occurs within this range.

- * - * @param element the element to check for, null returns false - * @return true if the specified element occurs within this range - */ - public boolean contains(final T element) { - if (element == null) { - return false; - } - return comparator.compare(element, minimum) > -1 && comparator.compare(element, maximum) < 1; - } - - /** - *

Checks whether this range contains all the elements of the specified range.

- * - *

This method may fail if the ranges have two different comparators or element types.

- * - * @param otherRange the range to check, null returns false - * @return true if this range contains the specified range - * @throws RuntimeException if ranges cannot be compared - */ - public boolean containsRange(final Range otherRange) { - if (otherRange == null) { - return false; - } - return contains(otherRange.minimum) - && contains(otherRange.maximum); - } - - /** - *

Checks where the specified element occurs relative to this range.

- * - *

The API is reminiscent of the Comparable interface returning {@code -1} if - * the element is before the range, {@code 0} if contained within the range and - * {@code 1} if the element is after the range.

- * - * @param element the element to check for, not null - * @return -1, 0 or +1 depending on the element's location relative to the range - */ - public int elementCompareTo(final T element) { - // Comparable API says throw NPE on null - Objects.requireNonNull(element); - if (isAfter(element)) { - return -1; - } - if (isBefore(element)) { - return 1; - } - return 0; - } - - // Element tests - //-------------------------------------------------------------------- - - /** - *

Compares this range to another object to test if they are equal.

. - * - *

To be equal, the minimum and maximum values must be equal, which - * ignores any differences in the comparator.

- * - * @param obj the reference object with which to compare - * @return true if this object is equal - */ - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (obj == null || obj.getClass() != getClass()) { - return false; - } - @SuppressWarnings("unchecked") // OK because we checked the class above - final Range range = (Range) obj; - return minimum.equals(range.minimum) && - maximum.equals(range.maximum); - } - - /** - *

Gets the comparator being used to determine if objects are within the range.

- * - *

Natural ordering uses an internal comparator implementation, thus this - * method never returns null. See {@link #isNaturalOrdering()}.

- * - * @return the comparator being used, not null - */ - public Comparator getComparator() { - return comparator; - } - - /** - *

Gets the maximum value in this range.

- * - * @return the maximum value in this range, not null - */ - public T getMaximum() { - return maximum; - } - - /** - *

Gets the minimum value in this range.

- * - * @return the minimum value in this range, not null - */ - public T getMinimum() { - return minimum; - } - - /** - *

Gets a suitable hash code for the range.

- * - * @return a hash code value for this object - */ - @Override - public int hashCode() { - int result = hashCode; - if (hashCode == 0) { - result = 17; - result = 37 * result + getClass().hashCode(); - result = 37 * result + minimum.hashCode(); - result = 37 * result + maximum.hashCode(); - hashCode = result; - } - return result; - } - - /** - * Calculate the intersection of {@code this} and an overlapping Range. - * - * @param other overlapping Range - * @return range representing the intersection of {@code this} and {@code other} ({@code this} if equal) - * @throws IllegalArgumentException if {@code other} does not overlap {@code this} - * @since 3.0.1 - */ - public Range intersectionWith(final Range other) { - if (!this.isOverlappedBy(other)) { - throw new IllegalArgumentException(String.format( - "Cannot calculate intersection with non-overlapping range %s", other)); - } - if (this.equals(other)) { - return this; - } - final T min = getComparator().compare(minimum, other.minimum) < 0 ? other.minimum : minimum; - final T max = getComparator().compare(maximum, other.maximum) < 0 ? maximum : other.maximum; - return between(min, max, getComparator()); - } - - /** - *

Checks whether this range is after the specified element.

- * - * @param element the element to check for, null returns false - * @return true if this range is entirely after the specified element - */ - public boolean isAfter(final T element) { - if (element == null) { - return false; - } - return comparator.compare(element, minimum) < 0; - } - - /** - *

Checks whether this range is completely after the specified range.

- * - *

This method may fail if the ranges have two different comparators or element types.

- * - * @param otherRange the range to check, null returns false - * @return true if this range is completely after the specified range - * @throws RuntimeException if ranges cannot be compared - */ - public boolean isAfterRange(final Range otherRange) { - if (otherRange == null) { - return false; - } - return isAfter(otherRange.maximum); - } - - /** - *

Checks whether this range is before the specified element.

- * - * @param element the element to check for, null returns false - * @return true if this range is entirely before the specified element - */ - public boolean isBefore(final T element) { - if (element == null) { - return false; - } - return comparator.compare(element, maximum) > 0; - } - - /** - *

Checks whether this range is completely before the specified range.

- * - *

This method may fail if the ranges have two different comparators or element types.

- * - * @param otherRange the range to check, null returns false - * @return true if this range is completely before the specified range - * @throws RuntimeException if ranges cannot be compared - */ - public boolean isBeforeRange(final Range otherRange) { - if (otherRange == null) { - return false; - } - return isBefore(otherRange.minimum); - } - - /** - *

Checks whether this range ends with the specified element.

- * - * @param element the element to check for, null returns false - * @return true if the specified element occurs within this range - */ - public boolean isEndedBy(final T element) { - if (element == null) { - return false; - } - return comparator.compare(element, maximum) == 0; - } - - /** - *

Whether or not the Range is using the natural ordering of the elements.

- * - *

Natural ordering uses an internal comparator implementation, thus this - * method is the only way to check if a null comparator was specified.

- * - * @return true if using natural ordering - */ - public boolean isNaturalOrdering() { - return comparator == ComparableComparator.INSTANCE; - } - - /** - *

Checks whether this range is overlapped by the specified range.

- * - *

Two ranges overlap if there is at least one element in common.

- * - *

This method may fail if the ranges have two different comparators or element types.

- * - * @param otherRange the range to test, null returns false - * @return true if the specified range overlaps with this - * range; otherwise, {@code false} - * @throws RuntimeException if ranges cannot be compared - */ - public boolean isOverlappedBy(final Range otherRange) { - if (otherRange == null) { - return false; - } - return otherRange.contains(minimum) - || otherRange.contains(maximum) - || contains(otherRange.minimum); - } - - /** - *

Checks whether this range starts with the specified element.

- * - * @param element the element to check for, null returns false - * @return true if the specified element occurs within this range - */ - public boolean isStartedBy(final T element) { - if (element == null) { - return false; - } - return comparator.compare(element, minimum) == 0; - } - - /** - *

- * Fits the given element into this range by returning the given element or, if out of bounds, the range minimum if - * below, or the range maximum if above. - *

- *
-     * Range<Integer> range = Range.between(16, 64);
-     * range.fit(-9) -->  16
-     * range.fit(0)  -->  16
-     * range.fit(15) -->  16
-     * range.fit(16) -->  16
-     * range.fit(17) -->  17
-     * ...
-     * range.fit(63) -->  63
-     * range.fit(64) -->  64
-     * range.fit(99) -->  64
-     * 
- * - * @param element the element to check for, not null - * @return the minimum, the element, or the maximum depending on the element's location relative to the range - * @since 3.10 - */ - public T fit(final T element) { - Objects.requireNonNull(element); - if (isAfter(element)) { - return minimum; - } - if (isBefore(element)) { - return maximum; - } - return element; - } - - /** - *

Gets the range as a {@code String}.

- * - *

The format of the String is '[min..max]'.

- * - * @return the {@code String} representation of this range - */ - @Override - public String toString() { - if (toString == null) { - toString = "[" + minimum + ".." + maximum + "]"; - } - return toString; - } - - /** - *

Formats the receiver using the given format.

- * - *

This uses {@link java.util.Formattable} to perform the formatting. Three variables may - * be used to embed the minimum, maximum and comparator. - * Use {@code %1$s} for the minimum element, {@code %2$s} for the maximum element - * and {@code %3$s} for the comparator. - * The default format used by {@code toString()} is {@code [%1$s..%2$s]}.

- * - * @param format the format string, optionally containing {@code %1$s}, {@code %2$s} and {@code %3$s}, not null - * @return the formatted string, not null - */ - public String toString(final String format) { - return String.format(format, minimum, maximum, comparator); - } - -} diff --git a/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java b/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java index 94e56e025..3acc77245 100644 --- a/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java +++ b/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.game; -import org.jackhuang.hmcl.util.Range; +import org.apache.commons.lang3.Range; import org.jackhuang.hmcl.util.versioning.VersionNumber; import org.junit.Assert; import org.junit.Test; diff --git a/settings.gradle b/settings.gradle index d5019c6d4..7a267504a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,4 +2,3 @@ rootProject.name = 'HMCL3' include ':HMCL' include ':HMCLCore' include ':HMCLTransformerDiscoveryService' -include ':JSTUN'