This commit is contained in:
Phillip Webb
2016-04-07 12:20:10 -07:00
parent 6ff09bc876
commit 6550bb4cf1
3 changed files with 26 additions and 28 deletions

View File

@@ -92,17 +92,16 @@ final class ChangeableUrls implements Iterable<URL> {
private static List<URL> getUrlsFromClassPathOfJarManifestIfPossible(URL url) {
JarFile jarFile = getJarFileIfPossible(url);
if (jarFile != null) {
try {
return getUrlsFromClassPathAttribute(jarFile.getManifest());
}
catch (IOException ex) {
throw new IllegalStateException(
"Failed to read Class-Path attribute from manifest of jar "
+ url);
}
if (jarFile == null) {
return Collections.<URL>emptyList();
}
try {
return getUrlsFromClassPathAttribute(jarFile.getManifest());
}
catch (IOException ex) {
throw new IllegalStateException(
"Failed to read Class-Path attribute from manifest of jar " + url);
}
return Collections.<URL>emptyList();
}
private static JarFile getJarFileIfPossible(URL url) {
@@ -119,19 +118,20 @@ final class ChangeableUrls implements Iterable<URL> {
}
private static List<URL> getUrlsFromClassPathAttribute(Manifest manifest) {
List<URL> urls = new ArrayList<URL>();
String classPathAttribute = manifest.getMainAttributes()
String classPath = manifest.getMainAttributes()
.getValue(Attributes.Name.CLASS_PATH);
if (StringUtils.hasText(classPathAttribute)) {
for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute,
" ")) {
try {
urls.add(new URL(entry));
}
catch (MalformedURLException ex) {
throw new IllegalStateException(
"Class-Path attribute contains malformed URL", ex);
}
if (!StringUtils.hasText(classPath)) {
return Collections.emptyList();
}
String[] entries = StringUtils.delimitedListToStringArray(classPath, " ");
List<URL> urls = new ArrayList<URL>(entries.length);
for (String entry : entries) {
try {
urls.add(new URL(entry));
}
catch (MalformedURLException ex) {
throw new IllegalStateException(
"Class-Path attribute contains malformed URL", ex);
}
}
return urls;