Skip to content

Commit 7977f2e

Browse files
committed
EclipseHelper: ignore .jar file that cannot be found
We recently switched to a more thorough indexing when the EclipseHelper is called as a main class, including inspecting the Class-Path entry of the manifest of .jar files. However, said entries might not refer to existing files, in which case we need to ignore them. While at it, this fixes the bug that .jar files on the class path would not have been accessed properly if their paths contained spaces. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent acaa36e commit 7977f2e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/main/java/org/scijava/annotations/EclipseHelper.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,17 @@ private void maybeIndex(final URL url, final ClassLoader loader) {
168168
debug("Not a file URL: " + url);
169169
return;
170170
}
171-
String path = url.getFile();
172-
if (!path.startsWith("/")) {
171+
File file = FileUtils.urlToFile(url);
172+
if (autoDetectEclipse && !file.isAbsolute()) {
173173
debug("Not an absolute file URL: " + url);
174174
return;
175175
}
176-
if (path.endsWith(".jar")) {
176+
final String name = file.getName();
177+
if (name.endsWith(".jar")) {
178+
if (!file.isFile()) {
179+
debug("Not a file: " + file);
180+
return;
181+
}
177182
/*
178183
* To support mixed development with Eclipse and Maven, let's handle
179184
* the case where Eclipse compiled classes, did not run the annotation
@@ -182,8 +187,8 @@ private void maybeIndex(final URL url, final ClassLoader loader) {
182187
* but crucially also the target/classes/ and target/test-classes/
183188
* directories which may need to be indexed.
184189
*/
185-
if (!autoDetectEclipse || path.matches(".*/target/surefire/surefirebooter[0-9]*\\.jar")) try {
186-
final JarFile jar = new JarFile(path);
190+
if (!autoDetectEclipse || url.toString().matches(".*/target/surefire/surefirebooter[0-9]*\\.jar")) try {
191+
final JarFile jar = new JarFile(file);
187192
Manifest manifest = jar.getManifest();
188193
if (manifest != null) {
189194
final String classPath =
@@ -205,11 +210,10 @@ private void maybeIndex(final URL url, final ClassLoader loader) {
205210
}
206211
return;
207212
}
208-
File directory = FileUtils.urlToFile(url);
209-
if (!directory.isDirectory()) {
213+
if (!file.isDirectory()) {
210214
return;
211215
}
212-
index(directory, loader);
216+
index(file, loader);
213217
}
214218

215219
private void index(File directory, ClassLoader loader) {

0 commit comments

Comments
 (0)