Package de.xima.fc.plugin
Class PluginHelper
java.lang.Object
de.xima.fc.plugin.PluginHelper
- Author:
- XIMA MEDIA GmbH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends IFCPlugin>
booleancanPluginBeRegistered(PluginRuntime prtm, Class<T> pluginClass) static EPluginCompatibilitycheckPluginVersion(PluginManifest manifest) static EPluginCompatibilitycheckPluginVersion(String requiredFCVersionStr) static byte[]createDefaultPluginConfig(PluginRuntime runtime) Creates the default plugin configuration data for a given plugin runtime, suitable forIFileEntity.setNewData(byte[]).static byte[]createDefaultPluginConfig(List<? extends IExtendedParameterModel> parameters) static voidcreatePluginErrorProtocolEntry(PluginRuntime pluginRuntime, DefaultPluginLifecycleData lifecycleData, Throwable error, boolean install, boolean initialize) static org.reflections.ReflectionscreateReflections(File file) Creates reflections for the given file if it is an jarstatic Closable<PluginRuntime>createTempRuntime(IThrowingSupplier<InputStream> data, String name, String scopeKey, String runtimeKey, boolean instantiate) Creates a temporary runtime that can be used e.g. for validation.static Closable<PluginRuntime>createTempRuntime(InputStream input, String name, String scopeKey, String runtimeKey, boolean instantiate) Creates a temporary runtime that can be used e.g. for validation.static Closable<PluginRuntime>createTempRuntime(Path jarFile, String name, String scopeKey, String runtimeKey, boolean instantiate) Creates a temporary runtime that can be used e.g. for validation.getAllPlugins(PluginRuntime pluginRuntime) getAllPlugins(org.reflections.Reflections reflect) static List<IBundleProperties>getBundleProperties(org.reflections.Reflections reflect) Method to loadIBundlePropertiesfrom the givenReflectionsstatic StringgetDisplayName(IFCPlugin plugin, Locale locale) Returns the display name of the plugin if it is not null.static FilegetPluginFolder(PluginRuntime runtime) Deprecated.static FilegetPluginFolder(String scopeKey, String runtimeKey) Deprecated.static FileDeprecated.static FilegetPluginJarFile(String scopeKey, String runtimeKey) Deprecated.static PluginManifestgetPluginManifest(PluginRuntime pluginRuntime) Reads the manifest from the JAR file of the given plugin runtime.static PluginManifestgetPluginManifest(File jarFile) Retrieves the plugin manifest for a given plugin JAR file.static PluginManifestgetPluginManifest(InputStream inputStream) Retrieves the plugin manifest for a given plugin JAR file.static PluginManifestgetPluginManifest(Path jarFile) Retrieves the plugin manifest for a given plugin JAR file.static FileDeprecated.static FilegetPluginMetaFile(String scopeKey, String runtimeKey) Deprecated.static de.xima.cmn.props.FileBasedPropertiesConfigurationDeprecated.static de.xima.cmn.props.FileBasedPropertiesConfigurationgetPluginProperties(String scopeKey, String runtimeKey) Deprecated.static FileDeprecated.static FilegetPluginPropertiesFile(String scopeKey, String runtimeKey) Deprecated.static StringgetScopeKey(Mandant man) Deprecated.static booleanhasRemotePlugins(org.reflections.Reflections reflect) static booleanhasServerTypeAnnotation(org.reflections.Reflections reflections) Checks forFcServerTypeannotation inside a givenReflectionsobject.static booleanisPluginJar(File file) Tests if the given file is a jar and contains formcycle-plugins of the typeIFCPluginstatic booleanisPluginNotAllowedOnServer(EFcServerType serverType, EPluginServerRestrictionType serverRestrictionType) static booleanisSystemScope(String scopeKey) Whether the givenscope keyrepresents the system scope.static booleanisUnpacked(org.reflections.Reflections reflections) static Map<String,IBundleConfigParam> readBundleConfigParams(List<IBundleProperties> bundleProps, IPluginResourceHelper resourceHelper, Locale locale) Given a set ofbundle propertyinstances from a plugin, reads and returns all configuration parameters from that plugin.static <M extends IExtendedParameterModel>
List<M>readParameterModels(PluginRuntime runtime, Locale locale, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin.static <M extends IExtendedParameterModel>
List<M>readParameterModels(PluginRuntime runtime, Properties persistedProperties, Locale locale, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin.static <M extends IExtendedParameterModel>
List<M>readParameterModels(Map<String, IBundleConfigParam> preDefinedProperties, Properties persistedProperties, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin.static <M extends IExtendedParameterModel>
List<M>readParameterModels(Map<String, IBundleConfigParam> preDefinedProperties, org.apache.commons.configuration2.Configuration persistedProperties, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin.static <T extends IFCPlugin>
TregisterPlugin(boolean install, boolean initialize, PluginRuntime prtm, Class<T> clazz) static voidremoveJarFileCacheEntries(JarFile jarToDelete) Deprecated.static voidsavePluginProperties(PluginRuntime rtm, Properties props) Deprecated.static voidsavePluginProperties(String scopeKey, String runtimeKey, Properties props) Deprecated.validateConfiguration(PluginRuntime runtime, Locale locale) Validates the configuration of the given plugin bundle against all available validation checks.validateConfiguration(PluginRuntime runtime, Properties properties, Locale locale) Validates the configuration of the given plugin bundle against all available validation checks, using a specified set of saved plugin properties.validateConfigurationAgainstBundlePropertiesSchema(List<? extends IExtendedParameterModel> properties, Locale locale) Validates the properties against the schema defined by abundle propertiesinstance.validateConfigurationAgainstValidationCallback(PluginRuntime runtime, Locale locale) Validates the configuration of the given plugin bundle viaIFCPlugin#validateConfigurationData.validateConfigurationAgainstValidationCallback(PluginRuntime runtime, Properties properties, Locale locale) Validates the configuration of the given plugin bundle viaIFCPlugin#validateConfigurationData.
-
Constructor Details
-
PluginHelper
public PluginHelper()
-
-
Method Details
-
checkPluginVersion
-
createDefaultPluginConfig
Creates the default plugin configuration data for a given plugin runtime, suitable forIFileEntity.setNewData(byte[]).- Parameters:
runtime- Plugin runtime to process.- Returns:
- The default properties data, suitable for
IFileEntity.setNewData(byte[]). - Throws:
IOException- When the data could not be created.
-
createDefaultPluginConfig
public static byte[] createDefaultPluginConfig(List<? extends IExtendedParameterModel> parameters) throws IOException - Parameters:
parameters- Parameter schema from the plugin.- Returns:
- The default properties data, suitable for
IFileEntity.setNewData(byte[]). - Throws:
IOException- When the data could not be created.
-
checkPluginVersion
-
getPluginManifest
Reads the manifest from the JAR file of the given plugin runtime. Requires that the pluginhas a JAR fileand is notsystem-managed.- Parameters:
pluginRuntime- Plugin runtime to process.- Returns:
- The manifest, or
nullwhen no manifest was found.
-
getPluginManifest
Retrieves the plugin manifest for a given plugin JAR file.- Parameters:
inputStream- Input stream for a plugin JAR file.- Returns:
- The plugin manifest, or
nullif it could not be read. - Since:
- 8.0.0
-
readParameterModels
public static <M extends IExtendedParameterModel> List<M> readParameterModels(PluginRuntime runtime, Locale locale, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin. The saved properties aretakenfrom the plugin runtime. UsereadParameterModels(PluginRuntime, Properties, Locale, BiFunction)if you wish to pass a custom set of parameters.Each parameter model represents a known configuration property with a schema, i.e. whether the property is required etc. This method merges all properties defined by the plugin with all existing, persisted properties of the plugin.
- Type Parameters:
M- Type of the parameter model to return.- Parameters:
runtime- Plugin runtime from which to read the current, saved properties.locale- Locale for extracting the pre-defined configuration parameters. Their display name and description require localization.modelFactory- Factory for creating newparameter modelinstances. The first argument isnameof the property, the second argument is itsvalue.- Returns:
- The merged list with all configuration properties.
-
readParameterModels
public static <M extends IExtendedParameterModel> List<M> readParameterModels(PluginRuntime runtime, Properties persistedProperties, Locale locale, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin. Each parameter model represents a known configuration property with a schema, i.e. whether the property is required etc. This method merges all properties defined by the plugin with all existing, persisted properties of the plugin.- Type Parameters:
M- Type of the parameter model to return.- Parameters:
runtime- Plugin runtime from which to read the current, saved properties.persistedProperties- The persisted or saved properties of the plugin, such as from a properties file or from the database.locale- Locale for extracting the pre-defined configuration parameters. Their display name and description require localization.modelFactory- Factory for creating newparameter modelinstances. The first argument isnameof the property, the second argument is itsvalue.- Returns:
- The merged list with all configuration properties.
-
readBundleConfigParams
public static Map<String,IBundleConfigParam> readBundleConfigParams(List<IBundleProperties> bundleProps, IPluginResourceHelper resourceHelper, Locale locale) Given a set ofbundle propertyinstances from a plugin, reads and returns all configuration parameters from that plugin. When a bundle property instance fails toreturna set of configuration parameters, that instance is ignored. -
readParameterModels
public static <M extends IExtendedParameterModel> List<M> readParameterModels(Map<String, IBundleConfigParam> preDefinedProperties, org.apache.commons.configuration2.Configuration persistedProperties, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin. Each parameter model represents a known configuration property with a schema, i.e. whether the property is required etc. This method merges all properties defined by the plugin with all existing, persisted properties of the plugin.- Type Parameters:
M- Type of the parameter model to return.- Parameters:
preDefinedProperties- Pre-defined properties asprovidedby the plugin.persistedProperties- Persisted or saved properties for the plugin, such as from an external configuration file or from the database.modelFactory- Factory for creating newparameter modelinstances. The first argument isnameof the property, the second argument is itsvalue.- Returns:
- The merged list with all configuration properties.
-
readParameterModels
public static <M extends IExtendedParameterModel> List<M> readParameterModels(Map<String, IBundleConfigParam> preDefinedProperties, Properties persistedProperties, com.alibaba.fastjson.util.BiFunction<String, String, M> modelFactory) Creates the parameter models for a plugin. Each parameter model represents a known configuration property with a schema, i.e. whether the property is required etc. This method merges all properties defined by the plugin with all existing, persisted properties of the plugin.- Type Parameters:
M- Type of the parameter model to return.- Parameters:
preDefinedProperties- Pre-defined properties asprovidedby the plugin.persistedProperties- Persisted or saved properties for the plugin, such as from an external configuration file or from the database.modelFactory- Factory for creating newparameter modelinstances. The first argument isnameof the property, the second argument is itsvalue.- Returns:
- The merged list with all configuration properties.
-
validateConfigurationAgainstBundlePropertiesSchema
public static IPluginInitializeValidationResult validateConfigurationAgainstBundlePropertiesSchema(List<? extends IExtendedParameterModel> properties, Locale locale) Validates the properties against the schema defined by abundle propertiesinstance. All required fields must have a value.- Parameters:
properties- Plugin properties with the schema to validate against.locale- Locale for localizing error messages.- Returns:
- Whether the parameters are valid. If they are invalid, a list of
error messageswill also be available.
-
createTempRuntime
public static Closable<PluginRuntime> createTempRuntime(Path jarFile, String name, String scopeKey, String runtimeKey, boolean instantiate) throws IOException Creates a temporary runtime that can be used e.g. for validation. When the returned item isclosed, the temp runtime is cleaned up, but the given source file is not deleted.- Parameters:
jarFile- JAR file with the plugin.name- Name of the plugin JAR, such as the file name.scopeKey-Scope keyof the plugin.runtimeKey-Runtime keyof the plugin.instantiate- Iftrue,instantiatesall contained plugins and adds them to the runtime.- Returns:
- A temporary plugin runtime for the given JAR file.
- Throws:
IOException- When the temporary runtime could not be created.
-
createTempRuntime
public static Closable<PluginRuntime> createTempRuntime(IThrowingSupplier<InputStream> data, String name, String scopeKey, String runtimeKey, boolean instantiate) throws IOException Creates a temporary runtime that can be used e.g. for validation. When the returned item isclosed, the temporary runtime and any created temporary files are cleaned up.- Parameters:
data- Opens an input stream to the data with the JAR file. The supplied input stream will be closed.name- Name of the plugin JAR, such as the file name.scopeKey-Scope keyof the plugin.runtimeKey-Runtime keyof the plugin.instantiate- Iftrue,instantiatesall contained plugins and adds them to the runtime.- Returns:
- A temporary plugin runtime for the given JAR file.
- Throws:
IOException- When the temporary runtime could not be created.
-
createTempRuntime
public static Closable<PluginRuntime> createTempRuntime(InputStream input, String name, String scopeKey, String runtimeKey, boolean instantiate) throws IOException Creates a temporary runtime that can be used e.g. for validation. When the returned item isclosed, the temporary runtime and any created temporary files are cleaned up.- Parameters:
input- Input stream to the data with the JAR file. The input stream will NOT be closed.name- Name of the plugin JAR, such as the file name.scopeKey-Scope keyof the plugin.runtimeKey-Runtime keyof the plugin.instantiate- Iftrue,instantiatesall contained plugins and adds them to the runtime.- Returns:
- A temporary plugin runtime for the given JAR file.
- Throws:
IOException- When the temporary runtime could not be created.
-
validateConfiguration
public static List<IPluginInitializeValidationResult> validateConfiguration(PluginRuntime runtime, Locale locale) Validates the configuration of the given plugin bundle against all available validation checks.This method
reads the saved propertiesfrom the plugin runtime. Usethe method with an explicit properties argumentif you wish to provide a different set of properties.- Parameters:
runtime- Plugin runtime for the plugin bundle. Usually this will be a temporary runtime, as plugins should not be put into service if validation fails.locale- Locale for locale-sensitive operations, such as constructing validation error messages.- Returns:
- A list of validation results, with one result for each plugin.
- See Also:
-
validateConfiguration
public static List<IPluginInitializeValidationResult> validateConfiguration(PluginRuntime runtime, Properties properties, Locale locale) Validates the configuration of the given plugin bundle against all available validation checks, using a specified set of saved plugin properties.- Parameters:
runtime- Plugin runtime for the plugin bundle. Usually this will be a temporary runtime, as plugins should not be put into service if validation fails.properties- Configured plugin properties against which to validate.locale- Locale for locale-sensitive operations, such as constructing validation error messages.- Returns:
- A list of validation results, with one result for each plugin.
- See Also:
-
validateConfigurationAgainstValidationCallback
public static List<IPluginInitializeValidationResult> validateConfigurationAgainstValidationCallback(PluginRuntime runtime, Locale locale) Validates the configuration of the given plugin bundle viaIFCPlugin#validateConfigurationData.This method read the properties from the plugin runtime. Use
the method with an explicit properties argumentif you wish to provide a different set of properties.- Parameters:
runtime- Plugin runtime for the plugin bundle. Usually this will be a temporary runtime, as plugins should not be put into service if validation fails.locale- Locale for locale-sensitive operations, such as constructing validation error messages.- Returns:
- A list of validation results, with one result for each plugin.
-
validateConfigurationAgainstValidationCallback
public static List<IPluginInitializeValidationResult> validateConfigurationAgainstValidationCallback(PluginRuntime runtime, Properties properties, Locale locale) Validates the configuration of the given plugin bundle viaIFCPlugin#validateConfigurationData.- Parameters:
runtime- Plugin runtime for the plugin bundle. Usually this will be a temporary runtime, as plugins should not be put into service if validation fails.properties- Properties representing the plugin configuration that are to be validated.locale- Locale for locale-sensitive operations, such as constructing validation error messages.- Returns:
- A list of validation results, with one result for each plugin.
-
getPluginManifest
Retrieves the plugin manifest for a given plugin JAR file.- Parameters:
jarFile- Plugin JAR file to process.- Returns:
- The plugin manifest, or
nullif it could not be read.
-
getPluginManifest
Retrieves the plugin manifest for a given plugin JAR file.- Parameters:
jarFile- Plugin JAR file to process.- Returns:
- The plugin manifest, or
nullif it could not be read.
-
registerPlugin
public static <T extends IFCPlugin> T registerPlugin(boolean install, boolean initialize, PluginRuntime prtm, Class<T> clazz) throws InstantiationException, IllegalAccessException, FCPluginException -
canPluginBeRegistered
public static <T extends IFCPlugin> boolean canPluginBeRegistered(PluginRuntime prtm, Class<T> pluginClass) - Type Parameters:
T- type of the plugin- Parameters:
prtm- A plugin runtime to check.pluginClass-Classto check- Returns:
- whether or not the given plugin class can be registered in the given plugin scope
-
isSystemScope
Whether the givenscope keyrepresents the system scope. -
isPluginJar
Tests if the given file is a jar and contains formcycle-plugins of the typeIFCPlugin -
isUnpacked
public static boolean isUnpacked(org.reflections.Reflections reflections) - Parameters:
reflections- Reflections to check, as created bycreateReflections(File).- Returns:
truethe class path of the reflections is made of unpacked class files,trueif the classpath was constructed directly from a JAR file.
-
getBundleProperties
Method to loadIBundlePropertiesfrom the givenReflections- Parameters:
reflect-Reflections- Returns:
- IBundleProperties
-
createReflections
Creates reflections for the given file if it is an jar- Parameters:
file- The JAR file with the from the plugin.- Returns:
- A reflections instance for scanning the plugin for classes and resources.
- Throws:
MalformedURLException- if the file URL is malformedIOException- If the JAR file was not unpacked yet and unpacking failed.
-
getAllPlugins
-
getAllPlugins
-
hasRemotePlugins
public static boolean hasRemotePlugins(org.reflections.Reflections reflect) -
hasServerTypeAnnotation
public static boolean hasServerTypeAnnotation(org.reflections.Reflections reflections) Checks forFcServerTypeannotation inside a givenReflectionsobject.- Parameters:
reflections- Reflection data obtained from scanning the classes.- Returns:
trueif anyFcServerTypeannotation was found, otherwisefalse
-
getDisplayName
Returns the display name of the plugin if it is not null. Otherwise returns the plugin name. -
createPluginErrorProtocolEntry
public static void createPluginErrorProtocolEntry(PluginRuntime pluginRuntime, DefaultPluginLifecycleData lifecycleData, Throwable error, boolean install, boolean initialize) -
isPluginNotAllowedOnServer
public static boolean isPluginNotAllowedOnServer(EFcServerType serverType, EPluginServerRestrictionType serverRestrictionType) -
removeJarFileCacheEntries
Deprecated. -
getScopeKey
Deprecated. -
getPluginFolder
Deprecated. -
getPluginFolder
Deprecated. -
getPluginPropertiesFile
Deprecated. -
getPluginPropertiesFile
Deprecated. -
getPluginMetaFile
Deprecated. -
getPluginMetaFile
Deprecated. -
getPluginJarFile
Deprecated. -
getPluginJarFile
Deprecated. -
savePluginProperties
@Deprecated public static void savePluginProperties(PluginRuntime rtm, Properties props) throws IOException Deprecated.- Throws:
IOException
-
savePluginProperties
@Deprecated public static void savePluginProperties(String scopeKey, String runtimeKey, Properties props) throws IOException Deprecated.- Throws:
IOException
-
getPluginProperties
@Deprecated public static de.xima.cmn.props.FileBasedPropertiesConfiguration getPluginProperties(PluginRuntime rtm) Deprecated. -
getPluginProperties
@Deprecated public static de.xima.cmn.props.FileBasedPropertiesConfiguration getPluginProperties(String scopeKey, String runtimeKey) Deprecated.
-