Skip to content

Commit

Permalink
set -> list
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jul 22, 2024
1 parent b77dab9 commit d47d436
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DowngradingClassLoader extends ClassLoader implements Closeable {

public DowngradingClassLoader(ClassDowngrader downgrader) throws IOException {
super();
Set<File> apiJar = downgrader.flags.findJavaApi();
List<File> apiJar = downgrader.flags.findJavaApi();
if (apiJar != null) {
for (File file : apiJar) {
delegates.add(new JarFileResourceProvider(new JarFile(file)));
Expand All @@ -42,7 +42,7 @@ public DowngradingClassLoader(ClassDowngrader downgrader) throws IOException {

public DowngradingClassLoader(ClassDowngrader downgrader, ClassLoader parent) throws IOException {
super(parent);
Set<File> apiJar = downgrader.flags.findJavaApi();
List<File> apiJar = downgrader.flags.findJavaApi();
if (apiJar != null) {
for (File file : apiJar) {
delegates.add(new JarFileResourceProvider(new JarFile(file)));
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -162,9 +163,9 @@ public Logger.Level getLogLevel() {
/**
* internal method to resolve the java api jar
*/
private static Set<File> foundApi = null;
private static List<File> foundApi = null;

public Set<File> findJavaApi() {
public List<File> findJavaApi() {
try {
if (api != null) {
return api;
Expand All @@ -176,21 +177,21 @@ public Set<File> findJavaApi() {
synchronized (Flags.class) {
Constants.DIR.mkdirs();
Path tmp = Constants.DIR.toPath().resolve("jvmdg-api- " + jvmdgVersion + " .jar");
Set<File> prop = getJavaApiFromSystemProperty();
List<File> prop = getJavaApiFromSystemProperty();
if (prop != null) {
foundApi = prop;
return prop;
}
URL url = getJavaApiFromShade();
if (Files.exists(tmp)) {
if (url == null) {
foundApi = Collections.singleton(tmp.toFile());
foundApi = Collections.singletonList(tmp.toFile());
return foundApi;
} else {
try (InputStream in = url.openStream()) {
try (InputStream in2 = Files.newInputStream(tmp)) {
if (hash(in).equals(hash(in2))) {
foundApi = Collections.singleton(tmp.toFile());
foundApi = Collections.singletonList(tmp.toFile());
return foundApi;
}
}
Expand All @@ -204,7 +205,7 @@ public Set<File> findJavaApi() {
if (url != null) {
try (InputStream in = url.openStream()) {
Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
foundApi = Collections.singleton(tmp.toFile());
foundApi = Collections.singletonList(tmp.toFile());
return foundApi;
}
}
Expand Down Expand Up @@ -276,12 +277,12 @@ private URL getJavaApiFromShade() throws IOException {
return ClassDowngrader.class.getResource("/META-INF/lib/java-api.jar");
}

private Set<File> getJavaApiFromSystemProperty() throws IOException {
private List<File> getJavaApiFromSystemProperty() throws IOException {
String api = System.getProperty(Constants.JAVA_API);
if (api == null) {
return null;
}
Set<File> files = new HashSet<>();
List<File> files = new ArrayList<>();
for (String s : api.split(File.pathSeparator)) {
files.add(new File(s));
}
Expand Down

0 comments on commit d47d436

Please sign in to comment.