|
24 | 24 |
|
25 | 25 | package org.jenkinsci.plugins.workflow.libs; |
26 | 26 |
|
27 | | -import hudson.AbortException; |
28 | 27 | import hudson.Extension; |
29 | 28 | import hudson.ExtensionList; |
30 | 29 | import hudson.FilePath; |
|
50 | 49 | import java.util.logging.Logger; |
51 | 50 | import edu.umd.cs.findbugs.annotations.CheckForNull; |
52 | 51 | import edu.umd.cs.findbugs.annotations.NonNull; |
| 52 | +import java.util.jar.JarEntry; |
53 | 53 | import java.util.jar.JarFile; |
54 | 54 | import java.util.regex.Matcher; |
55 | 55 | import java.util.regex.Pattern; |
@@ -299,32 +299,27 @@ static URL retrieve(@NonNull LibraryRecord record, @NonNull LibraryRetriever ret |
299 | 299 | Run<?,?> run = (Run) executable; |
300 | 300 | LibrariesAction action = run.getAction(LibrariesAction.class); |
301 | 301 | if (action != null) { |
302 | | - // TODO handle *.jar |
303 | 302 | FilePath libs = new FilePath(run.getRootDir()).child("libs"); |
304 | 303 | for (LibraryRecord library : action.getLibraries()) { |
305 | | - FilePath libResources = libs.child(library.getDirectoryName() + "/resources/"); |
306 | | - FilePath f = libResources.child(name); |
307 | | - if (!new File(f.getRemote()).getCanonicalFile().toPath().startsWith(new File(libResources.getRemote()).getCanonicalPath())) { |
308 | | - throw new AbortException(name + " references a file that is not contained within the library: " + library.name); |
309 | | - } else if (f.exists()) { |
310 | | - resources.put(library.name, readResource(f, encoding)); |
| 304 | + FilePath libJar = libs.child(library.getDirectoryName() + ".jar"); |
| 305 | + try (JarFile jf = new JarFile(libJar.getRemote())) { |
| 306 | + JarEntry je = jf.getJarEntry("resources/" + name); |
| 307 | + if (je != null) { |
| 308 | + try (InputStream in = jf.getInputStream(je)) { |
| 309 | + if ("Base64".equals(encoding)) { |
| 310 | + resources.put(library.name, Base64.getEncoder().encodeToString(IOUtils.toByteArray(in))); |
| 311 | + } else { |
| 312 | + resources.put(library.name, IOUtils.toString(in, encoding)); // The platform default is used if encoding is null. |
| 313 | + } |
| 314 | + } |
| 315 | + } |
311 | 316 | } |
312 | 317 | } |
313 | 318 | } |
314 | 319 | } |
315 | 320 | return resources; |
316 | 321 | } |
317 | 322 |
|
318 | | - private static String readResource(FilePath file, @CheckForNull String encoding) throws IOException, InterruptedException { |
319 | | - try (InputStream in = file.read()) { |
320 | | - if ("Base64".equals(encoding)) { |
321 | | - return Base64.getEncoder().encodeToString(IOUtils.toByteArray(in)); |
322 | | - } else { |
323 | | - return IOUtils.toString(in, encoding); // The platform default is used if encoding is null. |
324 | | - } |
325 | | - } |
326 | | - } |
327 | | - |
328 | 323 | @Extension public static class GlobalVars extends GlobalVariableSet { |
329 | 324 |
|
330 | 325 | @Override public Collection<GlobalVariable> forRun(Run<?,?> run) { |
|
0 commit comments