5050import edu .umd .cs .findbugs .annotations .CheckForNull ;
5151import edu .umd .cs .findbugs .annotations .NonNull ;
5252import java .net .URI ;
53+ import java .nio .charset .StandardCharsets ;
5354import java .util .jar .JarEntry ;
5455import java .util .jar .JarFile ;
5556import java .util .regex .Matcher ;
@@ -358,20 +359,24 @@ static URL retrieve(@NonNull LibraryRecord record, @NonNull LibraryRetriever ret
358359 Run <?,?> run = (Run ) executable ;
359360 LibrariesAction action = run .getAction (LibrariesAction .class );
360361 if (action != null ) {
361- // TODO handle *.jar
362362 FilePath libs = new FilePath (run .getRootDir ()).child ("libs" );
363363 for (LibraryRecord library : action .getLibraries ()) {
364364 if (library .trusted ) {
365365 continue ; // TODO JENKINS-41157 allow replay of trusted libraries if you have ADMINISTER
366366 }
367- for (String rootName : new String [] {"src" , "vars" }) {
368- FilePath root = libs .child (library .getDirectoryName () + "/" + rootName );
369- if (!root .isDirectory ()) {
370- continue ;
371- }
372- for (FilePath groovy : root .list ("**/*.groovy" )) {
373- String clazz = className (groovy .getRemote (), root .getRemote ());
374- scripts .put (clazz , groovy .readToString ()); // TODO no idea what encoding the Groovy compiler uses
367+ FilePath jar = libs .child (library .getDirectoryName () + ".jar" );
368+ if (!jar .exists ()) {
369+ continue ;
370+ }
371+ try (JarFile jf = new JarFile (jar .getRemote ())) {
372+ for (JarEntry je : (Iterable <JarEntry >) jf .stream ()::iterator ) {
373+ if (je .getName ().endsWith (".groovy" )) {
374+ String text ;
375+ try (InputStream is = jf .getInputStream (je )) {
376+ text = IOUtils .toString (is , StandardCharsets .UTF_8 ); // TODO no idea what encoding the Groovy compiler uses
377+ }
378+ scripts .put (je .getName ().replaceFirst ("[.]groovy$" , "" ).replace ('/' , '.' ), text );
379+ }
375380 }
376381 }
377382 }
@@ -383,10 +388,6 @@ static URL retrieve(@NonNull LibraryRecord record, @NonNull LibraryRetriever ret
383388 return scripts ;
384389 }
385390
386- static String className (String groovy , String root ) {
387- return groovy .replaceFirst ("^" + Pattern .quote (root ) + "[/\\ \\ ](.+)[.]groovy" , "$1" ).replace ('/' , '.' ).replace ('\\' , '.' );
388- }
389-
390391 }
391392
392393 @ Extension public static class Copier extends FlowCopier .ByRun {
0 commit comments