com.fitbur.mockito.internal.configuration.plugins.PluginFinder Maven / Gradle / Ivy
package com.fitbur.mockito.internal.configuration.plugins;
import com.fitbur.mockito.exceptions.base.MockitoException;
import com.fitbur.mockito.internal.util.io.IOUtil;
import com.fitbur.mockito.plugins.PluginSwitch;
import java.io.InputStream;
import java.net.URL;
class PluginFinder {
private final PluginSwitch pluginSwitch;
public PluginFinder(PluginSwitch pluginSwitch) {
this.pluginSwitch = pluginSwitch;
}
String findPluginClass(Iterable resources) {
for (URL resource : resources) {
InputStream s = null;
try {
s = resource.openStream();
String pluginClassName = new PluginFileReader().readPluginClass(s);
if (pluginClassName == null) {
//For backwards compatibility
//If the resource does not have plugin class name we're ignoring it
continue;
}
if (!pluginSwitch.isEnabled(pluginClassName)) {
continue;
}
return pluginClassName;
} catch(Exception e) {
throw new MockitoException("Problems reading plugin implementation from: " + resource, e);
} finally {
IOUtil.closeQuietly(s);
}
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy