Package com.dtolabs.rundeck.core.plugins
Class JarPluginProviderLoader
- java.lang.Object
-
- com.dtolabs.rundeck.core.plugins.JarPluginProviderLoader
-
- All Implemented Interfaces:
PluginMetadata,PluginResourceLoader,ProviderLoader,FileCache.Cacheable,FileCache.Expireable,java.io.Closeable,java.lang.AutoCloseable
public class JarPluginProviderLoader extends java.lang.Object implements ProviderLoader, FileCache.Expireable, PluginResourceLoader, PluginMetadata, java.io.Closeable
JarPluginProviderLoader can load jar plugin files as provider instances. Calls to load a provider instance should be synchronized as this class will perform file copy operations. Services that want to use this loader need to implementJavaClassProviderLoadable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classJarPluginProviderLoader.CachedJarHolds the cached jar file, dir, libs list and class and resource loaders for a jar plugin
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCACHED_JAR_TIMESTAMP_FORMATprotected java.io.Filecachedirprotected JarPluginProviderLoader.CachedJarcachedJarstatic java.lang.StringJAR_PLUGIN_VERSIONstatic java.lang.StringJAR_PLUGIN_VERSION_1_2static java.lang.StringJAR_PLUGIN_VERSION_2_0protected java.util.DateloadedDateprotected booleanloadLibsFirststatic VersionCompareLOWEST_JAR_PLUGIN_VERSIONprotected java.io.FilepluginJarprotected java.io.FilepluginJarCacheDirectorystatic java.lang.StringRESOURCES_DIR_DEFAULTstatic java.lang.StringRUNDECK_PLUGIN_ARCHIVEstatic java.lang.StringRUNDECK_PLUGIN_AUTHORstatic java.lang.StringRUNDECK_PLUGIN_CLASSNAMESstatic java.lang.StringRUNDECK_PLUGIN_DATEstatic java.lang.StringRUNDECK_PLUGIN_DESCRIPTIONstatic java.lang.StringRUNDECK_PLUGIN_DOCS_LINKstatic java.lang.StringRUNDECK_PLUGIN_FILE_VERSIONstatic java.lang.StringRUNDECK_PLUGIN_LIBSstatic java.lang.StringRUNDECK_PLUGIN_LIBS_LOAD_FIRSTstatic java.lang.StringRUNDECK_PLUGIN_LICENSEstatic java.lang.StringRUNDECK_PLUGIN_NAMEstatic java.lang.StringRUNDECK_PLUGIN_RESOURCESstatic java.lang.StringRUNDECK_PLUGIN_RESOURCES_DIRstatic java.lang.StringRUNDECK_PLUGIN_RUNDECK_COMPAT_VERstatic java.lang.StringRUNDECK_PLUGIN_SOURCE_LINKstatic java.lang.StringRUNDECK_PLUGIN_TAGSstatic java.lang.StringRUNDECK_PLUGIN_TARGET_HOST_COMPATstatic java.lang.StringRUNDECK_PLUGIN_THIRD_PARTY_DEPSstatic java.lang.StringRUNDECK_PLUGIN_URLstatic java.lang.StringRUNDECK_PLUGIN_VERSIONstatic VersionCompareSUPPORTS_RESOURCES_PLUGIN_VERSION
-
Constructor Summary
Constructors Constructor Description JarPluginProviderLoader(java.io.File pluginJar, java.io.File pluginJarCacheDirectory, java.io.File cachedir)JarPluginProviderLoader(java.io.File pluginJar, java.io.File pluginJarCacheDirectory, java.io.File cachedir, boolean loadLibsFirst)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanLoadForService(FrameworkSupportService service)voidclose()Close class loaders and delete cached filesprotected java.io.FilecreateCachedJar(java.io.File dir, java.lang.String jarName)Creates a single cached version of the pluginJar located within pluginJarCacheDirectory deleting all existing versions of pluginJarbooleanequals(java.lang.Object o)voidexpire()Expire the loader cache itemprotected java.util.Collection<java.io.File>extractDependentLibs(java.io.File cachedir)Extract the dependent libs and return the extracted jar filesprotected java.io.FilegenerateCachedJarDir(java.lang.String ident)protected java.lang.StringgenerateCachedJarIdentity()protected java.lang.StringgenerateCachedJarName(java.lang.String ident)java.lang.String[]getClassnames()Get the declared list of provider classnames for the filejava.util.DategetDateLoaded()java.io.FilegetFile()java.lang.StringgetFilename()java.lang.StringgetPluginArtifactName()java.lang.StringgetPluginAuthor()java.util.DategetPluginDate()java.lang.StringgetPluginDescription()java.lang.StringgetPluginDocsLink()java.lang.StringgetPluginFileVersion()java.lang.StringgetPluginId()This id is generated off of the plugin name.java.lang.StringgetPluginLicense()java.lang.StringgetPluginName()java.lang.StringgetPluginSourceLink()java.lang.StringgetPluginThirdPartyDependencies()java.lang.StringgetPluginType()java.lang.StringgetPluginUrl()java.lang.StringgetPluginVersion()Get the version of the plugin, not the file versionjava.lang.StringgetRundeckCompatibilityVersion()java.util.List<java.lang.String>getTags()java.lang.StringgetTargetHostCompatibility()inthashCode()booleanisClosed()protected booleanisEquivalentPluginJar(java.io.File other)booleanisExpired()booleanisLoaderFor(ProviderIdent ident)Return true if the file has a class that provides the ident.static booleanisValidJarPlugin(java.io.File file)Return true if the file is a valid jar plugin filejava.util.List<ProviderIdent>listProviders()List providers availablejava.util.List<java.lang.String>listResources()<T> Tload(PluggableService<T> service, java.lang.String providerName)Load provider instance for the service<T> CloseableProvider<T>loadCloseable(PluggableService<T> service, java.lang.String providerName)Return a closeable provider instancejava.io.InputStreamopenResourceStreamFor(java.lang.String path)Open a stream to load a resource
-
-
-
Field Detail
-
RESOURCES_DIR_DEFAULT
public static final java.lang.String RESOURCES_DIR_DEFAULT
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_ARCHIVE
public static final java.lang.String RUNDECK_PLUGIN_ARCHIVE
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_CLASSNAMES
public static final java.lang.String RUNDECK_PLUGIN_CLASSNAMES
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_RESOURCES
public static final java.lang.String RUNDECK_PLUGIN_RESOURCES
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_RESOURCES_DIR
public static final java.lang.String RUNDECK_PLUGIN_RESOURCES_DIR
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_LIBS
public static final java.lang.String RUNDECK_PLUGIN_LIBS
- See Also:
- Constant Field Values
-
JAR_PLUGIN_VERSION
public static final java.lang.String JAR_PLUGIN_VERSION
- See Also:
- Constant Field Values
-
JAR_PLUGIN_VERSION_1_2
public static final java.lang.String JAR_PLUGIN_VERSION_1_2
- See Also:
- Constant Field Values
-
JAR_PLUGIN_VERSION_2_0
public static final java.lang.String JAR_PLUGIN_VERSION_2_0
- See Also:
- Constant Field Values
-
SUPPORTS_RESOURCES_PLUGIN_VERSION
public static final VersionCompare SUPPORTS_RESOURCES_PLUGIN_VERSION
-
LOWEST_JAR_PLUGIN_VERSION
public static final VersionCompare LOWEST_JAR_PLUGIN_VERSION
-
RUNDECK_PLUGIN_NAME
public static final java.lang.String RUNDECK_PLUGIN_NAME
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_VERSION
public static final java.lang.String RUNDECK_PLUGIN_VERSION
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_FILE_VERSION
public static final java.lang.String RUNDECK_PLUGIN_FILE_VERSION
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_AUTHOR
public static final java.lang.String RUNDECK_PLUGIN_AUTHOR
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_URL
public static final java.lang.String RUNDECK_PLUGIN_URL
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_DATE
public static final java.lang.String RUNDECK_PLUGIN_DATE
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_LIBS_LOAD_FIRST
public static final java.lang.String RUNDECK_PLUGIN_LIBS_LOAD_FIRST
- See Also:
- Constant Field Values
-
CACHED_JAR_TIMESTAMP_FORMAT
public static final java.lang.String CACHED_JAR_TIMESTAMP_FORMAT
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_RUNDECK_COMPAT_VER
public static final java.lang.String RUNDECK_PLUGIN_RUNDECK_COMPAT_VER
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_DESCRIPTION
public static final java.lang.String RUNDECK_PLUGIN_DESCRIPTION
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_LICENSE
public static final java.lang.String RUNDECK_PLUGIN_LICENSE
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_TAGS
public static final java.lang.String RUNDECK_PLUGIN_TAGS
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_THIRD_PARTY_DEPS
public static final java.lang.String RUNDECK_PLUGIN_THIRD_PARTY_DEPS
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_SOURCE_LINK
public static final java.lang.String RUNDECK_PLUGIN_SOURCE_LINK
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_DOCS_LINK
public static final java.lang.String RUNDECK_PLUGIN_DOCS_LINK
- See Also:
- Constant Field Values
-
RUNDECK_PLUGIN_TARGET_HOST_COMPAT
public static final java.lang.String RUNDECK_PLUGIN_TARGET_HOST_COMPAT
- See Also:
- Constant Field Values
-
pluginJar
protected final java.io.File pluginJar
-
pluginJarCacheDirectory
protected final java.io.File pluginJarCacheDirectory
-
cachedir
protected final java.io.File cachedir
-
loadLibsFirst
protected final boolean loadLibsFirst
-
cachedJar
protected JarPluginProviderLoader.CachedJar cachedJar
-
loadedDate
protected java.util.Date loadedDate
-
-
Constructor Detail
-
JarPluginProviderLoader
public JarPluginProviderLoader(java.io.File pluginJar, java.io.File pluginJarCacheDirectory, java.io.File cachedir)
-
JarPluginProviderLoader
public JarPluginProviderLoader(java.io.File pluginJar, java.io.File pluginJarCacheDirectory, java.io.File cachedir, boolean loadLibsFirst)
-
-
Method Detail
-
canLoadForService
public boolean canLoadForService(FrameworkSupportService service)
- Specified by:
canLoadForServicein interfaceProviderLoader- Parameters:
service- service- Returns:
- true if the service can be used to load with this loader, e.g. if it implements any necessary interface
-
listResources
public java.util.List<java.lang.String> listResources() throws PluginException, java.io.IOException- Specified by:
listResourcesin interfacePluginResourceLoader- Returns:
- the list of resources available
- Throws:
PluginExceptionjava.io.IOException
-
openResourceStreamFor
public java.io.InputStream openResourceStreamFor(java.lang.String path) throws PluginException, java.io.IOExceptionDescription copied from interface:PluginResourceLoaderOpen a stream to load a resource- Specified by:
openResourceStreamForin interfacePluginResourceLoader- Parameters:
path- resource path and name- Returns:
- input stream for the resources, must be closed when finished, or null if the plugin does not support resources
- Throws:
PluginException- if a path is requested that was not in the pluginjava.io.IOException- if an error occurs
-
loadCloseable
public <T> CloseableProvider<T> loadCloseable(PluggableService<T> service, java.lang.String providerName) throws ProviderLoaderException
Description copied from interface:ProviderLoaderReturn a closeable provider instance- Specified by:
loadCloseablein interfaceProviderLoader- Type Parameters:
T- type- Parameters:
service- serviceproviderName- provider name- Returns:
- closeable provider
- Throws:
ProviderLoaderException
-
load
public <T> T load(PluggableService<T> service, java.lang.String providerName) throws ProviderLoaderException
Load provider instance for the service- Specified by:
loadin interfaceProviderLoader- Throws:
ProviderLoaderException
-
getClassnames
public java.lang.String[] getClassnames()
Get the declared list of provider classnames for the file
-
getPluginVersion
public java.lang.String getPluginVersion()
Get the version of the plugin, not the file version- Specified by:
getPluginVersionin interfacePluginMetadata- Returns:
-
isEquivalentPluginJar
protected boolean isEquivalentPluginJar(java.io.File other)
- Returns:
- true if the other jar is a copy of the pluginJar based on names returned by generateCachedJarName
-
generateCachedJarIdentity
protected java.lang.String generateCachedJarIdentity()
- Returns:
- a generated name for the pluginJar using the last modified timestamp
-
generateCachedJarName
protected java.lang.String generateCachedJarName(java.lang.String ident)
- Returns:
- a generated name for the pluginJar using the last modified timestamp
-
generateCachedJarDir
protected java.io.File generateCachedJarDir(java.lang.String ident)
- Returns:
- a generated name for the pluginJar using the last modified timestamp
-
createCachedJar
protected java.io.File createCachedJar(java.io.File dir, java.lang.String jarName) throws PluginExceptionCreates a single cached version of the pluginJar located within pluginJarCacheDirectory deleting all existing versions of pluginJar- Parameters:
jarName-- Throws:
PluginException
-
extractDependentLibs
protected java.util.Collection<java.io.File> extractDependentLibs(java.io.File cachedir) throws java.io.IOExceptionExtract the dependent libs and return the extracted jar files- Returns:
- the collection of extracted files
- Throws:
java.io.IOException
-
isLoaderFor
public boolean isLoaderFor(ProviderIdent ident)
Return true if the file has a class that provides the ident.- Specified by:
isLoaderForin interfaceProviderLoader
-
listProviders
public java.util.List<ProviderIdent> listProviders()
Description copied from interface:ProviderLoaderList providers available- Specified by:
listProvidersin interfaceProviderLoader
-
close
public void close() throws java.io.IOExceptionClose class loaders and delete cached files- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
isClosed
public boolean isClosed()
-
isExpired
public boolean isExpired()
-
expire
public void expire()
Expire the loader cache item- Specified by:
expirein interfaceFileCache.Expireable
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isValidJarPlugin
public static boolean isValidJarPlugin(java.io.File file)
Return true if the file is a valid jar plugin file
-
getFilename
public java.lang.String getFilename()
- Specified by:
getFilenamein interfacePluginMetadata- Returns:
- Name of file on disk
-
getFile
public java.io.File getFile()
- Specified by:
getFilein interfacePluginMetadata- Returns:
- Source file on disk
-
getPluginArtifactName
public java.lang.String getPluginArtifactName()
- Specified by:
getPluginArtifactNamein interfacePluginMetadata- Returns:
- The name in plugin.yaml or the Rundeck-Plugin-Name attribute in the jar manifest
-
getPluginAuthor
public java.lang.String getPluginAuthor()
- Specified by:
getPluginAuthorin interfacePluginMetadata- Returns:
- author metadata
-
getPluginFileVersion
public java.lang.String getPluginFileVersion()
- Specified by:
getPluginFileVersionin interfacePluginMetadata- Returns:
- plugin file version
-
getPluginUrl
public java.lang.String getPluginUrl()
- Specified by:
getPluginUrlin interfacePluginMetadata- Returns:
- plugin URL
-
getPluginDate
public java.util.Date getPluginDate()
- Specified by:
getPluginDatein interfacePluginMetadata- Returns:
- build date of plugin
-
getDateLoaded
public java.util.Date getDateLoaded()
- Specified by:
getDateLoadedin interfacePluginMetadata- Returns:
- date loaded
-
getPluginName
public java.lang.String getPluginName()
- Specified by:
getPluginNamein interfacePluginMetadata- Returns:
- plugin name
-
getPluginDescription
public java.lang.String getPluginDescription()
- Specified by:
getPluginDescriptionin interfacePluginMetadata- Returns:
- plugin description
-
getPluginId
public java.lang.String getPluginId()
Description copied from interface:PluginMetadataThis id is generated off of the plugin name. It is the first 12 characters of the sha256 of the plugin name. This is set automatically by the system. No need to add it manually.- Specified by:
getPluginIdin interfacePluginMetadata- Returns:
- plugin id
-
getRundeckCompatibilityVersion
public java.lang.String getRundeckCompatibilityVersion()
- Specified by:
getRundeckCompatibilityVersionin interfacePluginMetadata- Returns:
- version of Rundeck with which this plugin is compatible
-
getTargetHostCompatibility
public java.lang.String getTargetHostCompatibility()
- Specified by:
getTargetHostCompatibilityin interfacePluginMetadata- Returns:
- os family with which this plugin is compatible
-
getTags
public java.util.List<java.lang.String> getTags()
- Specified by:
getTagsin interfacePluginMetadata- Returns:
- tags
-
getPluginLicense
public java.lang.String getPluginLicense()
- Specified by:
getPluginLicensein interfacePluginMetadata- Returns:
- plugin license
-
getPluginThirdPartyDependencies
public java.lang.String getPluginThirdPartyDependencies()
- Specified by:
getPluginThirdPartyDependenciesin interfacePluginMetadata- Returns:
- plugin third party dependencies
-
getPluginSourceLink
public java.lang.String getPluginSourceLink()
- Specified by:
getPluginSourceLinkin interfacePluginMetadata- Returns:
- link to plugin source
-
getPluginDocsLink
public java.lang.String getPluginDocsLink()
- Specified by:
getPluginDocsLinkin interfacePluginMetadata- Returns:
- link to plugin docs
-
getPluginType
public java.lang.String getPluginType()
- Specified by:
getPluginTypein interfacePluginMetadata- Returns:
- plugin type
-
-