001/* 002 * Copyright 2018 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.runtime.plugin; 017 018import java.util.Collection; 019import java.util.Map; 020 021import org.ametys.runtime.plugin.PluginsManager.InactivityCause; 022 023/** 024 * An activator of {@link Feature features}, which will be loaded by the {@link PluginsManager}. 025 * <br>The implemententations must define the strategy in order to determine which extension points, components, etc. need to be loaded. 026 */ 027public interface FeatureActivator 028{ 029 /** 030 * Computes the actual plugins and features to load, based on values selected by the administrator.<br> 031 * This method does not actually load nor execute any Java code. It reads plugins definitions, selects active features and gets components and extensions definitions. 032 * @param componentsConfig chosen components, among those with the same role. 033 * @param safeMode <code>true</code> if application is in safe mode 034 * @return all information gathered during plugins reading. 035 */ 036 PluginsInformation computeActiveFeatures(Map<String, String> componentsConfig, boolean safeMode); 037 038 /** 039 * Dumps the given {@link PluginsInformation}, in order to log in debug level. 040 * @param pluginInfo The information about plugins 041 * @return The string to display in debug level 042 */ 043 String fullDump(PluginsInformation pluginInfo); 044 045 /** 046 * Dumps the given {@link PluginsInformation}, in order to log in info level. 047 * @param pluginInfo The information about plugins 048 * @return The string to display in info level 049 */ 050 String shortDump(PluginsInformation pluginInfo); 051 052 /** 053 * Helper class containing all relevant information after features list computation. 054 */ 055 static class PluginsInformation 056 { 057 private Map<String, Plugin> _plugins; 058 private Map<String, Feature> _features; 059 private Map<String, InactivityCause> _inactiveFeatures; 060 private Map<String, ExtensionPointDefinition> _extensionPoints; 061 private Map<String, Map<String, ExtensionDefinition>> _extensions; 062 private Map<String, ComponentDefinition> _components; 063 private Collection<PluginIssue> _errors; 064 065 PluginsInformation(Map<String, Plugin> plugins, Map<String, Feature> features, Map<String, InactivityCause> inactiveFeatures, Map<String, ExtensionPointDefinition> extensionPoints, Map<String, Map<String, ExtensionDefinition>> extensions, Map<String, ComponentDefinition> components, Collection<PluginIssue> errors) 066 { 067 _plugins = plugins; 068 _features = features; 069 _inactiveFeatures = inactiveFeatures; 070 _extensionPoints = extensionPoints; 071 _extensions = extensions; 072 _components = components; 073 _errors = errors; 074 } 075 076 Map<String, Plugin> getPlugins() 077 { 078 return _plugins; 079 } 080 081 Map<String, Feature> getFeatures() 082 { 083 return _features; 084 } 085 086 Map<String, InactivityCause> getInactiveFeatures() 087 { 088 return _inactiveFeatures; 089 } 090 091 Map<String, ExtensionPointDefinition> getExtensionPoints() 092 { 093 return _extensionPoints; 094 } 095 096 Map<String, Map<String, ExtensionDefinition>> getExtensions() 097 { 098 return _extensions; 099 } 100 101 Map<String, ComponentDefinition> getComponents() 102 { 103 return _components; 104 } 105 106 /** 107 * Returns all errors collected during initialization phase. 108 * @return all errors collected during initialization phase. 109 */ 110 Collection<PluginIssue> getErrors() 111 { 112 return _errors; 113 } 114 } 115}