Skip to content

Commit

Permalink
Fix webapp multi-release JAR processing
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
  • Loading branch information
avpinchuk committed Aug 2, 2023
1 parent 92d30b0 commit d60cdfc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand All @@ -39,10 +39,12 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import static java.lang.Runtime.version;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.TRACE;
import static java.lang.System.Logger.Level.WARNING;
import static java.util.concurrent.Executors.newScheduledThreadPool;
import static java.util.zip.ZipFile.OPEN_READ;
import static org.glassfish.web.loader.LogFacade.getString;

/**
Expand Down Expand Up @@ -212,7 +214,7 @@ private boolean openJARs() {
continue;
}
try {
jarResource.jarFile = new JarFile(jarResource.file);
jarResource.jarFile = new JarFile(jarResource.file, true, OPEN_READ, version());
} catch (IOException e) {
LOG.log(DEBUG, "Failed to open JAR", e);
lastJarFileAccess = 0L;
Expand Down Expand Up @@ -274,9 +276,9 @@ private ResourceEntry createResourceEntry(String name, File file, JarFile jarFil

private static void extractResource(JarFile jarFile, File loaderDir, String pathPrefix) {
LOG.log(DEBUG, "extractResource(jarFile={0}, loaderDir={1}, pathPrefix={2})", jarFile, loaderDir, pathPrefix);
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements()) {
JarEntry jarEntry = jarEntries.nextElement();
Iterator<JarEntry> jarEntries = jarFile.versionedStream().iterator();
while (jarEntries.hasNext()) {
JarEntry jarEntry = jarEntries.next();
if (!jarEntry.isDirectory() && !jarEntry.getName().endsWith(".class")) {
File resourceFile = new File(loaderDir, jarEntry.getName());
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -39,6 +40,9 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static java.lang.Runtime.version;
import static java.util.zip.ZipFile.OPEN_READ;

/**
* Utility class - contains util methods used for implementation of
* pluggable Shared Library features
Expand Down Expand Up @@ -243,13 +247,14 @@ public static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
URLClassLoader ucl = (URLClassLoader) cl;
for(URL u : ucl.getURLs()) {
String path = u.getPath();
File file = new File(path);
try {
if(path.endsWith(".jar")) {
JarFile jf = new JarFile(path);
JarFile jf = new JarFile(file, true, OPEN_READ, version());
try {
Enumeration<JarEntry> entries = jf.entries();
while(entries.hasMoreElements()) {
JarEntry anEntry = entries.nextElement();
Iterator<JarEntry> entries = jf.versionedStream().iterator();
while(entries.hasNext()) {
JarEntry anEntry = entries.next();
if(anEntry.isDirectory()) {
continue;
}
Expand Down Expand Up @@ -285,7 +290,6 @@ public static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
jf.close();
}
} else {
File file = new File(path);
if (file.exists()) {
if (file.isDirectory()) {
scanDirectory(file, classInfo);
Expand Down

0 comments on commit d60cdfc

Please sign in to comment.