Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions java17/src/main/java/io/papermc/paperclip/Paperclip.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package io.papermc.paperclip;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.*;

public final class Paperclip {

Expand Down Expand Up @@ -80,11 +75,13 @@ private static URL[] setupClasspath() {
// This is due to change we make to some library classes inside the versions jar
final Collection<URL> versionUrls = classpathUrls.get("versions").values();
final Collection<URL> libraryUrls = classpathUrls.get("libraries").values();
final Collection<URL> extraUrls = findExtraClasspathUrls();

final URL[] emptyArray = new URL[0];
final URL[] urls = new URL[versionUrls.size() + libraryUrls.size()];
final URL[] urls = new URL[versionUrls.size() + libraryUrls.size() + extraUrls.size()];
System.arraycopy(versionUrls.toArray(emptyArray), 0, urls, 0, versionUrls.size());
System.arraycopy(libraryUrls.toArray(emptyArray), 0, urls, versionUrls.size(), libraryUrls.size());
System.arraycopy(extraUrls.toArray(emptyArray), 0, urls, versionUrls.size() + libraryUrls.size(), extraUrls.size());
return urls;
}

Expand Down Expand Up @@ -241,4 +238,22 @@ private static void applyPatches(
throw Util.fail("Failed to apply patches", e);
}
}

private static Collection<URL> findExtraClasspathUrls() {
String extraClasspathUrlsString = System.getProperty("paperclip.extraClasspathUrls");
if (extraClasspathUrlsString == null) {
return Collections.emptyList();
}
String[] extraClasspathStrings = extraClasspathUrlsString.split(File.pathSeparator);
Collection<URL> extraClasspathUrls = new ArrayList<>();
try {
for (String extraClasspathString : extraClasspathStrings) {
File extraClasspathFile = new File(extraClasspathString);
extraClasspathUrls.add(extraClasspathFile.toURI().toURL());
}
} catch (MalformedURLException e) {
throw Util.fail("Failed to parse extra classpath URLs", e);
}
return extraClasspathUrls;
}
}