Search in sources :

Example 1 with ExtensionRefreshException

use of com.qlangtech.tis.extension.impl.ExtensionRefreshException in project tis by qlangtech.

the class PluginManager method start.

public void start(List<PluginWrapper> plugins) throws Exception {
    Map<String, PluginWrapper> pluginsByName = plugins.stream().collect(Collectors.toMap(PluginWrapper::getShortName, p -> p));
    // recalculate dependencies of plugins optionally depending the newly deployed ones.
    for (PluginWrapper depender : this.plugins) {
        if (plugins.contains(depender)) {
            // skip itself.
            continue;
        }
        for (PluginWrapper.Dependency d : depender.getOptionalDependencies()) {
            PluginWrapper dependee = pluginsByName.get(d.shortName);
            if (dependee != null) {
                // this plugin depends on the newly loaded one!
                // recalculate dependencies!
                getPluginStrategy().updateDependency(depender, dependee);
                break;
            }
        }
    }
    // Redo who depends on who.
    resolveDependentPlugins();
    try {
        TIS.get().refreshExtensions();
    } catch (ExtensionRefreshException e) {
        throw new IOException("Failed to refresh extensions after installing some plugins", e);
    }
    for (PluginWrapper p : plugins) {
        // TODO:According to the postInitialize() documentation, one may expect that
        // p.getPluginOrFail() NPE will continue the initialization. Keeping the original behavior ATM
        p.getPluginOrFail().postInitialize();
    }
    // run initializers in the added plugins
    Reactor r = new Reactor(InitMilestone.ordering());
    Set<ClassLoader> loaders = plugins.stream().map(p -> p.classLoader).collect(Collectors.toSet());
    r.addAll(new InitializerFinder(uberClassLoader) {

        @Override
        protected boolean filter(Method e) {
            return !loaders.contains(e.getDeclaringClass().getClassLoader()) || super.filter(e);
        }
    }.discoverTasks(r));
    new InitReactorRunner().run(r);
}
Also used : ClassicPluginStrategy(com.qlangtech.tis.extension.impl.ClassicPluginStrategy) InitMilestone(com.qlangtech.tis.extension.init.InitMilestone) FilenameFilter(java.io.FilenameFilter) java.util(java.util) ExtensionRefreshException(com.qlangtech.tis.extension.impl.ExtensionRefreshException) URL(java.net.URL) TIS(com.qlangtech.tis.TIS) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentMap(java.util.concurrent.ConcurrentMap) CenterResource(com.qlangtech.tis.manage.common.CenterResource) InitializerFinder(com.qlangtech.tis.util.InitializerFinder) CyclicGraphDetector(com.qlangtech.tis.extension.util.CyclicGraphDetector) InitStrategy(com.qlangtech.tis.extension.init.InitStrategy) WeakReference(java.lang.ref.WeakReference) Method(java.lang.reflect.Method) Executable(org.jvnet.hudson.reactor.Executable) YesNoMaybe(com.qlangtech.tis.util.YesNoMaybe) Reactor(org.jvnet.hudson.reactor.Reactor) Logger(org.slf4j.Logger) TaskGraphBuilder(org.jvnet.hudson.reactor.TaskGraphBuilder) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Util(com.qlangtech.tis.util.Util) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) MissingDependencyException(com.qlangtech.tis.extension.impl.MissingDependencyException) Collectors(java.util.stream.Collectors) TaskBuilder(org.jvnet.hudson.reactor.TaskBuilder) File(java.io.File) UpdateCenter(com.qlangtech.tis.extension.model.UpdateCenter) ClassLoaderReflectionToolkit(com.qlangtech.tis.extension.util.ClassLoaderReflectionToolkit) InitReactorRunner(com.qlangtech.tis.extension.init.InitReactorRunner) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) InitializerFinder(com.qlangtech.tis.util.InitializerFinder) ExtensionRefreshException(com.qlangtech.tis.extension.impl.ExtensionRefreshException) IOException(java.io.IOException) Method(java.lang.reflect.Method) InitReactorRunner(com.qlangtech.tis.extension.init.InitReactorRunner) Reactor(org.jvnet.hudson.reactor.Reactor)

Aggregations

TIS (com.qlangtech.tis.TIS)1 ClassicPluginStrategy (com.qlangtech.tis.extension.impl.ClassicPluginStrategy)1 ExtensionRefreshException (com.qlangtech.tis.extension.impl.ExtensionRefreshException)1 MissingDependencyException (com.qlangtech.tis.extension.impl.MissingDependencyException)1 InitMilestone (com.qlangtech.tis.extension.init.InitMilestone)1 InitReactorRunner (com.qlangtech.tis.extension.init.InitReactorRunner)1 InitStrategy (com.qlangtech.tis.extension.init.InitStrategy)1 UpdateCenter (com.qlangtech.tis.extension.model.UpdateCenter)1 ClassLoaderReflectionToolkit (com.qlangtech.tis.extension.util.ClassLoaderReflectionToolkit)1 CyclicGraphDetector (com.qlangtech.tis.extension.util.CyclicGraphDetector)1 CenterResource (com.qlangtech.tis.manage.common.CenterResource)1 InitializerFinder (com.qlangtech.tis.util.InitializerFinder)1 Util (com.qlangtech.tis.util.Util)1 YesNoMaybe (com.qlangtech.tis.util.YesNoMaybe)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 WeakReference (java.lang.ref.WeakReference)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1