From 9a99f4e27de2e5c01f417869623e430887e87fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20K=C3=B6nig?= Date: Fri, 18 Feb 2022 14:28:29 +0100 Subject: [PATCH] Use relative paths in classpath to shorten execution line on large apps --- .../com/threerings/getdown/data/Application.java | 6 +++--- .../com/threerings/getdown/data/ClassPath.java | 8 ++++++-- .../threerings/getdown/data/ClassPathTest.java | 4 ++-- .../threerings/getdown/data/PathBuilderTest.java | 15 ++------------- 4 files changed, 13 insertions(+), 20 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 9b6f650..7760e41 100644 --- a/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/core/src/main/java/com/threerings/getdown/data/Application.java @@ -1009,7 +1009,7 @@ public class Application 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 @@ -1028,7 +1028,7 @@ public class Application // @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 @@ -1060,7 +1060,7 @@ public class Application // 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); } diff --git a/core/src/main/java/com/threerings/getdown/data/ClassPath.java b/core/src/main/java/com/threerings/getdown/data/ClassPath.java index 9c2fce3..1823fae 100644 --- a/core/src/main/java/com/threerings/getdown/data/ClassPath.java +++ b/core/src/main/java/com/threerings/getdown/data/ClassPath.java @@ -31,13 +31,17 @@ public class ClassPath *
      *   /path/to/a.jar:/path/to/b.jar
      * 
+ * + * 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(); diff --git a/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java b/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java index 5344f3b..c5998f2 100644 --- a/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java +++ b/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java @@ -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 diff --git a/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java b/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java index 7f35094..af7e789 100644 --- a/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java +++ b/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java @@ -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 @@ -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;