![JAR search and dependency download from the Maven repository](/logo.png)
com.mycila.plugin.spi.DefaultPluginLoader Maven / Gradle / Ivy
/**
* Copyright (C) 2008 Mathieu Carbou
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mycila.plugin.spi;
import com.mycila.log.Logger;
import com.mycila.log.Loggers;
import com.mycila.plugin.api.DuplicatePluginException;
import com.mycila.plugin.api.Plugin;
import com.mycila.plugin.api.PluginBinding;
import com.mycila.plugin.api.PluginCreationException;
import com.mycila.plugin.api.PluginIOException;
import com.mycila.plugin.api.PluginLoader;
import static com.mycila.plugin.spi.Ensure.*;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import static java.util.Arrays.*;
import java.util.Collection;
import java.util.Collections;
import static java.util.Collections.*;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
/**
* @author Mathieu Carbou ([email protected])
*/
final class DefaultPluginLoader implements PluginLoader {
private static final Logger LOGGER = Loggers.get(DefaultPluginLoader.class);
final Class pluginsType;
final String descriptor;
Set exclusions = Collections.emptySet();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
DefaultPluginLoader(Class pluginsType) {
this(pluginsType, null); // just to be sure a resource with this name does not exist ;)
}
DefaultPluginLoader(Class pluginsType, String descriptor) {
notNull("Plugin type", pluginsType);
this.pluginsType = pluginsType;
this.descriptor = descriptor != null ?
descriptor.startsWith("/") ? descriptor.substring(1) : descriptor :
null;
}
public Set> loadPlugins() {
LOGGER.debug("Loading plugins from descriptors {0}...", descriptor);
Set> plugins = new HashSet>();
Enumeration configs = loadDescriptors();
while (configs.hasMoreElements()) {
URL descriptor = configs.nextElement();
Properties p = loadDescriptor(descriptor);
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy