fix classpath parsing for jars with no manifest

This commit is contained in:
Jason P. Leasure 2021-05-19 11:24:05 -04:00
parent 22675e9f39
commit cc46064bcd

View file

@ -21,6 +21,7 @@ import java.net.URL;
import java.nio.file.*; import java.nio.file.*;
import java.util.*; import java.util.*;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -220,9 +221,12 @@ public class OSGiUtils {
static void collectPackagesFromJar(Path jarPath, Set<String> packages) { static void collectPackagesFromJar(Path jarPath, Set<String> packages) {
try { try {
try (JarFile jarFile = new JarFile(jarPath.toFile())) { try (JarFile jarFile = new JarFile(jarPath.toFile())) {
Manifest manifest = jarFile.getManifest();
// if this jar is an OSGi bundle, use its declared exports // if this jar is an OSGi bundle, use its declared exports
String exportPackageString = String exportPackageString = manifest != null
jarFile.getManifest().getMainAttributes().getValue(Constants.EXPORT_PACKAGE); ? manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE)
: null;
if (exportPackageString != null) { if (exportPackageString != null) {
String saved = null; String saved = null;
/* /*