From bb995508d972c9c31e0855351904fa76eeb94c79 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 6 Jan 2020 14:14:52 -0800 Subject: [PATCH] Added support for adding arbitrary classpath entries. --- .../threerings/getdown/data/Application.java | 14 ++++++++++++++ .../threerings/getdown/data/PathBuilder.java | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/threerings/getdown/data/Application.java b/core/src/main/java/com/threerings/getdown/data/Application.java index 8b6991f..7943d38 100644 --- a/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/core/src/main/java/com/threerings/getdown/data/Application.java @@ -345,6 +345,15 @@ public class Application return _resources; } + /** + * Returns a list of strings (usually file paths relative to the app root dir) to add to the + * classpath. + */ + public List getClassPathDirectories () + { + return _cpdirs; + } + /** * Returns the digest of the given {@code resource}. */ @@ -751,6 +760,7 @@ public class Application _jvmargs.clear(); _appargs.clear(); _txtJvmArgs.clear(); + _cpdirs.clear(); String appPrefix = _envc.appId == null ? "" : (_envc.appId + "."); @@ -781,6 +791,9 @@ public class Application // look for custom arguments fillAssignmentListFromPairs("extra.txt", _txtJvmArgs); + // add any extra classpath entries + addAll(config.getMultiValue(appPrefix + "classpath"), _cpdirs); + // extract some info used to configure our child process on macOS _dockName = config.getString("ui.name"); _dockIconPath = config.getString("ui.mac_dock_icon", "../desktop.icns"); @@ -1758,6 +1771,7 @@ public class Application protected List _codes = new ArrayList<>(); protected List _resources = new ArrayList<>(); + protected List _cpdirs = new ArrayList<>(); protected int _verifyTimeout = 60; diff --git a/core/src/main/java/com/threerings/getdown/data/PathBuilder.java b/core/src/main/java/com/threerings/getdown/data/PathBuilder.java index 57e9275..1f10d0d 100644 --- a/core/src/main/java/com/threerings/getdown/data/PathBuilder.java +++ b/core/src/main/java/com/threerings/getdown/data/PathBuilder.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.IOException; import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.zip.ZipFile; @@ -40,9 +41,10 @@ public class PathBuilder public static ClassPath buildDefaultClassPath (Application app) { LinkedHashSet classPathEntries = new LinkedHashSet(); - for (Resource resource: app.getActiveCodeResources()) { + for (Resource resource : app.getActiveCodeResources()) { classPathEntries.add(resource.getFinalTarget()); } + addClassPathDirectories(app, classPathEntries); return new ClassPath(classPathEntries); } @@ -64,15 +66,27 @@ public class PathBuilder ResourceCache cache = new ResourceCache(codeCacheDir); LinkedHashSet classPathEntries = new LinkedHashSet<>(); - for (Resource resource: app.getActiveCodeResources()) { + for (Resource resource : app.getActiveCodeResources()) { String digest = app.getDigest(resource); File entry = cache.cacheFile(resource.getFinalTarget(), digest.substring(0, 2), digest); classPathEntries.add(entry); } + addClassPathDirectories(app, classPathEntries); + return new ClassPath(classPathEntries); } + private static void addClassPathDirectories (Application app, Set classPathEntries) { + for (String cpdir : app.getClassPathDirectories()) { + File cpfile = new File(cpdir); + if (!cpfile.isAbsolute()) { + cpfile = new File(app.getAppDir(), cpdir); + } + classPathEntries.add(cpfile); + } + } + /** * Builds a {@link ClassPath} instance by first caching all native jars (indicated by * nresource=[native jar]), unpacking them, and referencing the locations of each of the