Cleanup (common URL check code extracted)

This commit is contained in:
Roman Shevchenko
2014-04-30 13:55:00 +04:00
parent 901e60d827
commit 95bce93679
3 changed files with 19 additions and 39 deletions
@@ -150,34 +150,34 @@ public class ClassPath {
@Nullable
private Loader getLoader(final URL url, int index) throws IOException {
String s;
String path;
if (myAcceptUnescapedUrls) {
s = url.getFile();
path = url.getFile();
}
else {
try {
s = url.toURI().getSchemeSpecificPart();
path = url.toURI().getSchemeSpecificPart();
}
catch (URISyntaxException thisShouldNotHappen) {
//noinspection CallToPrintStackTrace
thisShouldNotHappen.printStackTrace();
s = url.getFile();
path = url.getFile();
}
}
Loader loader = null;
if (s != null && new File(s).isDirectory()) {
if (URLUtil.FILE_PROTOCOL.equals(url.getProtocol())) {
if (path != null && URLUtil.FILE_PROTOCOL.equals(url.getProtocol())) {
File file = new File(path);
if (file.isDirectory()) {
loader = new FileLoader(url, index);
}
}
else {
JarLoader jarLoader = new JarLoader(url, myCanLockJars, index);
if (myPreloadJarContents) {
jarLoader.preLoadClasses();
else if (file.isFile()) {
loader = new JarLoader(url, myCanLockJars, index);
if (myPreloadJarContents) {
((JarLoader)loader).preloadClasses();
}
}
loader = jarLoader;
}
if (loader != null && myCanUseCache) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,17 +29,10 @@ class FileLoader extends Loader {
private static int misses;
private static int hits;
@SuppressWarnings({"HardCodedStringLiteral"})
FileLoader(URL url, int index) throws IOException {
super(url, index);
if (!"file".equals(url.getProtocol())) {
throw new IllegalArgumentException("url");
}
else {
final String s = FileUtil.unquote(url.getFile());
myRootDir = new File(s);
myRootDirAbsolutePath = myRootDir.getAbsolutePath();
}
myRootDir = new File(FileUtil.unquote(url.getFile()));
myRootDirAbsolutePath = myRootDir.getAbsolutePath();
}
private void buildPackageCache(final File dir, ClasspathCache cache) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,9 +43,7 @@ class JarLoader extends Loader {
@NotNull
protected ZipFile calc() {
try {
final ZipFile zipFile = doGetZipFile();
if (zipFile == null) throw new RuntimeException("Can't load zip file");
return zipFile;
return doGetZipFile();
}
catch (IOException e) {
throw new RuntimeException(e);
@@ -59,7 +57,7 @@ class JarLoader extends Loader {
myCanLockJar = canLockJar;
}
void preLoadClasses() {
void preloadClasses() {
ZipFile zipFile = null;
try {
zipFile = acquireZipFile();
@@ -102,19 +100,8 @@ class JarLoader extends Loader {
}
}
@Nullable
private ZipFile doGetZipFile() throws IOException {
if (URLUtil.FILE_PROTOCOL.equals(myURL.getProtocol())) {
String s = FileUtil.unquote(myURL.getFile());
if (!new File(s).exists()) {
throw new FileNotFoundException(s);
}
else {
return new ZipFile(s);
}
}
return null;
return new ZipFile(FileUtil.unquote(myURL.getFile()));
}
@Override