Skip to content

Commit a0da689

Browse files
committed
made deploader even more robust
1 parent 1061940 commit a0da689

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
import java.util.concurrent.atomic.AtomicBoolean;
7070
import java.util.concurrent.atomic.AtomicLong;
7171
import java.util.function.Function;
72-
import java.util.jar.JarFile;
72+
import java.util.jar.JarInputStream;
7373
import java.util.regex.Pattern;
7474
import java.util.stream.Collectors;
7575
import java.util.stream.Stream;
76-
import java.util.zip.ZipFile;
76+
import java.util.zip.ZipEntry;
7777

7878
public class DependencyLoaderImpl {
7979

@@ -191,14 +191,13 @@ private static Stream<URL> scanSourceMetaInf(URL source) {
191191
return Stream.empty();
192192
}
193193
LOG.debug("Scanning {} for dependencies", source);
194-
val path = source.getPath();
194+
val fileName = source.getFile();
195195
val output = new ArrayList<URL>();
196-
if (path.endsWith(".jar") || path.endsWith(".zip")) {
196+
if (fileName.endsWith(".jar")) {
197197
//Scan jar file for json in META-INF, add them to the list
198-
try (val jarFile = (ZipFile)(path.endsWith("jar") ? new JarFile(path) : new ZipFile(path))) {
199-
val entries = jarFile.entries();
200-
while (entries.hasMoreElements()) {
201-
val entry = entries.nextElement();
198+
try (val inputStream = source.openStream(); val jarFile = new JarInputStream(inputStream)) {
199+
ZipEntry entry;
200+
while ((entry = jarFile.getNextEntry()) != null) {
202201
if (!entry.getName().startsWith("META-INF") || !entry.getName().endsWith(".json")) {
203202
continue;
204203
}
@@ -209,12 +208,12 @@ private static Stream<URL> scanSourceMetaInf(URL source) {
209208
}
210209
}
211210
} catch (IOException e) {
212-
LOG.error("Failed to open jar file {}", path);
211+
LOG.error("Failed to open jar file {}", source.getPath());
213212
}
214213
} else {
215-
val dir = new File(path);
214+
val dir = new File(fileName);
216215
if (!dir.exists() || !dir.isDirectory()) {
217-
LOG.warn("Skipping non-directory, nor jar, nor zip source: {}", source);
216+
LOG.warn("Skipping non-directory, nor jar source: {}", source);
218217
return Stream.empty();
219218
}
220219
//Scan directory for json in META-INF, add them to the list

0 commit comments

Comments
 (0)