Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative paths in classpath to shorten execution line on large apps #260

Merged
merged 1 commit into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ public Process createProcess (boolean optimum)
ClassPath classPath = PathBuilder.buildClassPath(this);
if (!dashJarMode) {
args.add("-classpath");
args.add(classPath.asArgumentString());
args.add(classPath.asArgumentString(getAppDir()));
}

// we love our Mac users, so we do nice things to preserve our application identity
Expand All @@ -1028,7 +1028,7 @@ public Process createProcess (boolean optimum)
// @TODO optional getdown.txt parameter to set addCurrentLibraryPath to true or false?
ClassPath javaLibPath = PathBuilder.buildLibsPath(this, true);
if (javaLibPath != null) {
args.add("-Djava.library.path=" + javaLibPath.asArgumentString());
args.add("-Djava.library.path=" + javaLibPath.asArgumentString(getAppDir()));
}

// pass along any pass-through arguments
Expand Down Expand Up @@ -1060,7 +1060,7 @@ public Process createProcess (boolean optimum)
// if we're in -jar mode add those arguments, otherwise add the app class name
if (dashJarMode) {
args.add("-jar");
args.add(classPath.asArgumentString());
args.add(classPath.asArgumentString(getAppDir()));
} else {
args.add(_class);
}
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/com/threerings/getdown/data/ClassPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ public ClassPath (LinkedHashSet<File> classPathEntries)
* <pre>
* /path/to/a.jar:/path/to/b.jar
* </pre>
*
* The paths are relativized to dir.
*
* @param dir the working directory of the process
*/
public String asArgumentString ()
public String asArgumentString (File dir)
{
StringBuilder builder = new StringBuilder();
String delimiter = "";
for (File entry: _classPathEntries) {
builder.append(delimiter).append(entry.getAbsolutePath());
builder.append(delimiter).append(dir.toPath().relativize(entry.toPath()));
delimiter = File.pathSeparator;
}
return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class ClassPathTest
@Test public void shouldCreateValidArgumentString ()
{
assertEquals(
_firstJar.getAbsolutePath() + File.pathSeparator + _secondJar.getAbsolutePath(),
_classPath.asArgumentString());
"a.jar:b.jar",
_classPath.asArgumentString(_folder.getRoot()));
}

@Test public void shouldProvideJarUrls () throws MalformedURLException, URISyntaxException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public class PathBuilderTest
@Test public void shouldBuildDefaultClassPath () throws IOException
{
ClassPath classPath = PathBuilder.buildDefaultClassPath(_application);
String expectedClassPath = _firstJarFile.getAbsolutePath() + File.pathSeparator +
_secondJarFile.getAbsolutePath();
assertEquals(expectedClassPath, classPath.asArgumentString());
assertEquals("a.jar:b.jar", classPath.asArgumentString(_appdir.getRoot()));
}

@Test public void shouldBuildCachedClassPath () throws IOException
Expand All @@ -47,17 +45,8 @@ public class PathBuilderTest
when(_application.getDigest(_secondJar)).thenReturn("second");
when(_application.getCodeCacheRetentionDays()).thenReturn(1);

Path firstCachedJarFile = _appdir.getRoot().toPath().
resolve(PathBuilder.CODE_CACHE_DIR).resolve("fi").resolve("first.jar");

Path secondCachedJarFile = _appdir.getRoot().toPath().
resolve(PathBuilder.CODE_CACHE_DIR).resolve("se").resolve("second.jar");

String expectedClassPath = firstCachedJarFile.toAbsolutePath() + File.pathSeparator +
secondCachedJarFile.toAbsolutePath();

ClassPath classPath = PathBuilder.buildCachedClassPath(_application);
assertEquals(expectedClassPath, classPath.asArgumentString());
assertEquals(".cache/fi/first.jar:.cache/se/second.jar", classPath.asArgumentString(_appdir.getRoot()));
}

@Mock protected Application _application;
Expand Down