|
37 | 37 | * only if the new code is made subject to such option by the copyright
|
38 | 38 | * holder.
|
39 | 39 | */
|
40 |
| -// Portions Copyright [2014-2021] [Payara Foundation and/or its affiliates] |
| 40 | +// Portions Copyright [2014-2024] [Payara Foundation and/or its affiliates] |
41 | 41 |
|
42 | 42 | package org.glassfish.web.deployment.archivist;
|
43 | 43 |
|
44 | 44 | import com.sun.enterprise.deployment.Application;
|
| 45 | +import com.sun.enterprise.deployment.EarType; |
45 | 46 | import org.glassfish.deployment.common.RootDeploymentDescriptor;
|
46 | 47 | import com.sun.enterprise.deployment.EjbBundleDescriptor;
|
47 | 48 | import com.sun.enterprise.deployment.EjbDescriptor;
|
|
75 | 76 | import java.util.ArrayList;
|
76 | 77 | import java.util.Enumeration;
|
77 | 78 | import java.util.HashMap;
|
| 79 | +import java.util.LinkedHashSet; |
78 | 80 | import java.util.List;
|
79 | 81 | import java.util.Map;
|
80 |
| -import java.util.Vector; |
| 82 | +import java.util.Set; |
81 | 83 | import java.net.URL;
|
82 | 84 | import java.util.logging.Level;
|
83 | 85 | import java.util.logging.Logger;
|
@@ -296,24 +298,33 @@ protected String getArchiveExtension() {
|
296 | 298 | /**
|
297 | 299 | * @return a list of libraries included in the archivist
|
298 | 300 | */
|
299 |
| - public Vector<String> getLibraries(Archive archive) { |
| 301 | + public Set<String> getLibraries(ReadableArchive archive) throws IOException { |
| 302 | + Set<String> libraries = new LinkedHashSet<>(); |
| 303 | + // WAR libraries |
| 304 | + extractLibraries(archive, true, libraries); |
| 305 | + ReadableArchive parentArchive = archive.getParentArchive(); |
| 306 | + if (parentArchive != null && parentArchive.getExtraData(ArchiveType.class).toString().equals(EarType.ARCHIVE_TYPE)) { |
| 307 | + // EAR shared libraries |
| 308 | + extractLibraries(parentArchive.getSubArchive("lib"), false, libraries); |
| 309 | + } |
| 310 | + return libraries; |
| 311 | + } |
300 | 312 |
|
301 |
| - Enumeration<String> entries = archive.entries(); |
| 313 | + private static void extractLibraries(Archive archive, boolean hasWebInfPrefix, Set<String> libs) { |
| 314 | + Enumeration<String> entries = archive != null ? archive.entries() : null; |
302 | 315 | if (entries==null)
|
303 |
| - return null; |
| 316 | + return; |
304 | 317 |
|
305 |
| - Vector<String> libs = new Vector<String>(); |
306 | 318 | while (entries.hasMoreElements()) {
|
307 | 319 |
|
308 | 320 | String entryName = entries.nextElement();
|
309 |
| - if (!entryName.startsWith("WEB-INF/lib")) { |
310 |
| - continue; // not in WEB-INF... |
| 321 | + if (hasWebInfPrefix && !entryName.startsWith("WEB-INF/lib")) { |
| 322 | + continue; // not in prefix (i.e. WEB-INF)... |
311 | 323 | }
|
312 | 324 | if (entryName.endsWith(".jar")) {
|
313 | 325 | libs.add(entryName);
|
314 | 326 | }
|
315 | 327 | }
|
316 |
| - return libs; |
317 | 328 | }
|
318 | 329 |
|
319 | 330 | @Override
|
@@ -381,54 +392,50 @@ private List<WebFragmentDescriptor> readStandardFragments(WebBundleDescriptorImp
|
381 | 392 | ReadableArchive archive) throws IOException {
|
382 | 393 |
|
383 | 394 | List<WebFragmentDescriptor> wfList = new ArrayList<WebFragmentDescriptor>();
|
384 |
| - Vector libs = getLibraries(archive); |
385 |
| - if (libs != null && libs.size() > 0) { |
386 |
| - |
387 |
| - for (int i = 0; i < libs.size(); i++) { |
388 |
| - String lib = (String)libs.get(i); |
389 |
| - Archivist wfArchivist = new WebFragmentArchivist(this, habitat); |
390 |
| - wfArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation()); |
391 |
| - wfArchivist.setRuntimeXMLValidationLevel( |
392 |
| - this.getRuntimeXMLValidationLevel()); |
393 |
| - wfArchivist.setAnnotationProcessingRequested(false); |
394 |
| - |
395 |
| - WebFragmentDescriptor wfDesc = null; |
396 |
| - ReadableArchive embeddedArchive = archive.getSubArchive(lib); |
397 |
| - try { |
398 |
| - if (embeddedArchive != null && |
399 |
| - wfArchivist.hasStandardDeploymentDescriptor(embeddedArchive)) { |
400 |
| - try { |
401 |
| - wfDesc = (WebFragmentDescriptor)wfArchivist.open(embeddedArchive); |
402 |
| - } catch(SAXParseException ex) { |
403 |
| - IOException ioex = new IOException(); |
404 |
| - ioex.initCause(ex); |
405 |
| - throw ioex; |
406 |
| - } |
407 |
| - } else { |
408 |
| - wfDesc = new WebFragmentDescriptor(); |
409 |
| - wfDesc.setExists(false); |
410 |
| - } |
411 |
| - } finally { |
412 |
| - if (embeddedArchive != null) { |
413 |
| - embeddedArchive.close(); |
| 395 | + for (String lib : getLibraries(archive)) { |
| 396 | + Archivist wfArchivist = new WebFragmentArchivist(this, habitat); |
| 397 | + wfArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation()); |
| 398 | + wfArchivist.setRuntimeXMLValidationLevel( |
| 399 | + this.getRuntimeXMLValidationLevel()); |
| 400 | + wfArchivist.setAnnotationProcessingRequested(false); |
| 401 | + |
| 402 | + WebFragmentDescriptor wfDesc = null; |
| 403 | + ReadableArchive embeddedArchive = lib.startsWith("WEB-INF") |
| 404 | + ? archive.getSubArchive(lib) : archive.getParentArchive().getSubArchive("lib").getSubArchive(lib); |
| 405 | + try { |
| 406 | + if (embeddedArchive != null && |
| 407 | + wfArchivist.hasStandardDeploymentDescriptor(embeddedArchive)) { |
| 408 | + try { |
| 409 | + wfDesc = (WebFragmentDescriptor)wfArchivist.open(embeddedArchive); |
| 410 | + } catch(SAXParseException ex) { |
| 411 | + IOException ioex = new IOException(); |
| 412 | + ioex.initCause(ex); |
| 413 | + throw ioex; |
414 | 414 | }
|
| 415 | + } else { |
| 416 | + wfDesc = new WebFragmentDescriptor(); |
| 417 | + wfDesc.setExists(false); |
| 418 | + } |
| 419 | + } finally { |
| 420 | + if (embeddedArchive != null) { |
| 421 | + embeddedArchive.close(); |
415 | 422 | }
|
416 |
| - wfDesc.setJarName(lib.substring(lib.lastIndexOf('/') + 1)); |
417 |
| - wfList.add(wfDesc); |
| 423 | + } |
| 424 | + wfDesc.setJarName(lib.substring(lib.lastIndexOf('/') + 1)); |
| 425 | + wfList.add(wfDesc); |
418 | 426 |
|
419 |
| - descriptor.putJarNameWebFragmentNamePair(wfDesc.getJarName(), wfDesc.getName()); |
| 427 | + descriptor.putJarNameWebFragmentNamePair(wfDesc.getJarName(), wfDesc.getName()); |
420 | 428 |
|
421 |
| - } |
| 429 | + } |
422 | 430 |
|
423 |
| - if (((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor() != null) { |
424 |
| - wfList = ((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor().order(wfList); |
425 |
| - } else { |
426 |
| - OrderingDescriptor.sort(wfList); |
427 |
| - } |
| 431 | + if (((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor() != null) { |
| 432 | + wfList = ((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor().order(wfList); |
| 433 | + } else { |
| 434 | + OrderingDescriptor.sort(wfList); |
| 435 | + } |
428 | 436 |
|
429 |
| - for (WebFragmentDescriptor wf : wfList) { |
430 |
| - descriptor.addOrderedLib(wf.getJarName()); |
431 |
| - } |
| 437 | + for (WebFragmentDescriptor wf : wfList) { |
| 438 | + descriptor.addOrderedLib(wf.getJarName()); |
432 | 439 | }
|
433 | 440 |
|
434 | 441 | return wfList;
|
|
0 commit comments