mirror of https://github.com/apache/lucene.git
LUCENE-2510: Some cleanup in the new service class iterator + better messages
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2510@1365143 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fe05af5e84
commit
baa71b943f
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.ServiceConfigurationError;
|
import java.util.ServiceConfigurationError;
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ public final class SPIClassIterator<S> implements Iterator<Class<? extends S>> {
|
||||||
try {
|
try {
|
||||||
this.profilesEnum = loader.getResources(META_INF_SERVICES + clazz.getName());
|
this.profilesEnum = loader.getResources(META_INF_SERVICES + clazz.getName());
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceConfigurationError("Error loading SPI classes.", ioe);
|
throw new ServiceConfigurationError("Error loading SPI profiles for type " + clazz.getName() + " from classpath", ioe);
|
||||||
}
|
}
|
||||||
this.linesIterator = Collections.<String>emptySet().iterator();
|
this.linesIterator = Collections.<String>emptySet().iterator();
|
||||||
}
|
}
|
||||||
|
@ -74,8 +75,8 @@ public final class SPIClassIterator<S> implements Iterator<Class<? extends S>> {
|
||||||
} else {
|
} else {
|
||||||
lines = new ArrayList<String>();
|
lines = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
final URL url = profilesEnum.nextElement();
|
||||||
try {
|
try {
|
||||||
final URL url = profilesEnum.nextElement();
|
|
||||||
final InputStream in = url.openStream();
|
final InputStream in = url.openStream();
|
||||||
IOException priorE = null;
|
IOException priorE = null;
|
||||||
try {
|
try {
|
||||||
|
@ -96,7 +97,7 @@ public final class SPIClassIterator<S> implements Iterator<Class<? extends S>> {
|
||||||
IOUtils.closeWhileHandlingException(priorE, in);
|
IOUtils.closeWhileHandlingException(priorE, in);
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceConfigurationError("Error loading SPI classes.", ioe);
|
throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe);
|
||||||
}
|
}
|
||||||
if (!lines.isEmpty()) {
|
if (!lines.isEmpty()) {
|
||||||
this.linesIterator = lines.iterator();
|
this.linesIterator = lines.iterator();
|
||||||
|
@ -120,10 +121,11 @@ public final class SPIClassIterator<S> implements Iterator<Class<? extends S>> {
|
||||||
assert linesIterator.hasNext();
|
assert linesIterator.hasNext();
|
||||||
final String c = linesIterator.next();
|
final String c = linesIterator.next();
|
||||||
try {
|
try {
|
||||||
// don't initialize the class:
|
// don't initialize the class (pass false as 2nd parameter):
|
||||||
return Class.forName(c, false, loader).asSubclass(clazz);
|
return Class.forName(c, false, loader).asSubclass(clazz);
|
||||||
} catch (ClassNotFoundException cnfe) {
|
} catch (ClassNotFoundException cnfe) {
|
||||||
throw new ServiceConfigurationError("SPI class not found: " + c);
|
throw new ServiceConfigurationError(String.format(Locale.ROOT, "A SPI class of type %s with classname %s does not exist, "+
|
||||||
|
"please fix the file '%s%s' in your classpath.", clazz.getName(), c, META_INF_SERVICES, clazz.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue