@@ -251,11 +251,11 @@ public static final class LoadedClasses extends GroovyObjectSupport implements S
251251 private final @ NonNull String prefix ;
252252 /** {@link Class#getName} minus package prefix */
253253 private final @ CheckForNull String clazz ;
254- /** {@code file:/…/libs/NAME/src /} */
254+ /** {@code jar: file:/…/libs/$hash.jar! /} */
255255 private final @ NonNull String srcUrl ;
256256
257257 LoadedClasses (String library , String libraryDirectoryName , boolean trusted , Boolean changelog , Run <?,?> run ) {
258- this (library , trusted , changelog , "" , null , /* cf. LibraryAdder.retrieve */ new File (run .getRootDir (), "libs/" + libraryDirectoryName + ".jar" ).toURI (). toString () );
258+ this (library , trusted , changelog , "" , null , /* cf. LibraryAdder.retrieve */ "jar:" + new File (run .getRootDir (), "libs/" + libraryDirectoryName + ".jar" ).toURI () + "!/" );
259259 }
260260
261261 LoadedClasses (String library , boolean trusted , Boolean changelog , String prefix , String clazz , String srcUrl ) {
@@ -357,11 +357,8 @@ private Class<?> loadClass(String name) {
357357 throw new IllegalAccessException (name + " had no defined code source" );
358358 }
359359 String loc = codeSource .getLocation ().toString ();
360- LOGGER .info (() -> "TODO got " + loc );
361- String actual = canonicalize (loc );
362- String srcUrlC = canonicalize (srcUrl ); // do not do this in constructor: path might not actually exist
363- if (!actual .startsWith (srcUrlC )) {
364- throw new IllegalAccessException (name + " was defined in " + actual + " which was not inside " + srcUrlC );
360+ if (!loc .startsWith (srcUrl )) {
361+ throw new IllegalAccessException (name + " was defined in " + loc + " which was not inside " + srcUrl );
365362 }
366363 if (!Modifier .isPublic (c .getModifiers ())) { // unlikely since Groovy makes classes implicitly public
367364 throw new IllegalAccessException (c + " is not public" );
@@ -374,20 +371,6 @@ private Class<?> loadClass(String name) {
374371 }
375372 }
376373
377- private static String canonicalize (String uri ) {
378- if (uri .startsWith ("jar:" ) && uri .contains ("!/" )) {
379- // See warning in CpsGroovyShell.parseClass.
380- uri = uri .substring (4 , uri .indexOf ("!/" ));
381- }
382- if (uri .startsWith ("file:/" )) {
383- try {
384- return Paths .get (new URI (uri )).toRealPath ().toUri ().toString ();
385- } catch (IOException | URISyntaxException x ) {
386- LOGGER .log (Level .WARNING , "could not canonicalize " + uri , x );
387- }
388- }
389- return uri ;
390- }
391374
392375 }
393376
0 commit comments