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 class
JarPluginProviderLoader.CachedJar
Holds 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.String
CACHED_JAR_TIMESTAMP_FORMAT
protected java.io.File
cachedir
protected JarPluginProviderLoader.CachedJar
cachedJar
static java.lang.String
JAR_PLUGIN_VERSION
static java.lang.String
JAR_PLUGIN_VERSION_1_2
static java.lang.String
JAR_PLUGIN_VERSION_2_0
protected java.util.Date
loadedDate
protected boolean
loadLibsFirst
static VersionCompare
LOWEST_JAR_PLUGIN_VERSION
protected java.io.File
pluginJar
protected java.io.File
pluginJarCacheDirectory
static java.lang.String
RESOURCES_DIR_DEFAULT
static java.lang.String
RUNDECK_PLUGIN_ARCHIVE
static java.lang.String
RUNDECK_PLUGIN_AUTHOR
static java.lang.String
RUNDECK_PLUGIN_CLASSNAMES
static java.lang.String
RUNDECK_PLUGIN_DATE
static java.lang.String
RUNDECK_PLUGIN_DESCRIPTION
static java.lang.String
RUNDECK_PLUGIN_DOCS_LINK
static java.lang.String
RUNDECK_PLUGIN_FILE_VERSION
static java.lang.String
RUNDECK_PLUGIN_LIBS
static java.lang.String
RUNDECK_PLUGIN_LIBS_LOAD_FIRST
static java.lang.String
RUNDECK_PLUGIN_LICENSE
static java.lang.String
RUNDECK_PLUGIN_NAME
static java.lang.String
RUNDECK_PLUGIN_RESOURCES
static java.lang.String
RUNDECK_PLUGIN_RESOURCES_DIR
static java.lang.String
RUNDECK_PLUGIN_RUNDECK_COMPAT_VER
static java.lang.String
RUNDECK_PLUGIN_SOURCE_LINK
static java.lang.String
RUNDECK_PLUGIN_TAGS
static java.lang.String
RUNDECK_PLUGIN_TARGET_HOST_COMPAT
static java.lang.String
RUNDECK_PLUGIN_THIRD_PARTY_DEPS
static java.lang.String
RUNDECK_PLUGIN_URL
static java.lang.String
RUNDECK_PLUGIN_VERSION
static VersionCompare
SUPPORTS_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 boolean
canLoadForService(FrameworkSupportService service)
void
close()
Close class loaders and delete cached filesprotected java.io.File
createCachedJar(java.io.File dir, java.lang.String jarName)
Creates a single cached version of the pluginJar located within pluginJarCacheDirectory deleting all existing versions of pluginJarboolean
equals(java.lang.Object o)
void
expire()
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.File
generateCachedJarDir(java.lang.String ident)
protected java.lang.String
generateCachedJarIdentity()
protected java.lang.String
generateCachedJarName(java.lang.String ident)
java.lang.String[]
getClassnames()
Get the declared list of provider classnames for the filejava.util.Date
getDateLoaded()
java.io.File
getFile()
java.lang.String
getFilename()
java.lang.String
getPluginArtifactName()
java.lang.String
getPluginAuthor()
java.util.Date
getPluginDate()
java.lang.String
getPluginDescription()
java.lang.String
getPluginDocsLink()
java.lang.String
getPluginFileVersion()
java.lang.String
getPluginId()
This id is generated off of the plugin name.java.lang.String
getPluginLicense()
java.lang.String
getPluginName()
java.lang.String
getPluginSourceLink()
java.lang.String
getPluginThirdPartyDependencies()
java.lang.String
getPluginType()
java.lang.String
getPluginUrl()
java.lang.String
getPluginVersion()
Get the version of the plugin, not the file versionjava.lang.String
getRundeckCompatibilityVersion()
java.util.List<java.lang.String>
getTags()
java.lang.String
getTargetHostCompatibility()
int
hashCode()
boolean
isClosed()
protected boolean
isEquivalentPluginJar(java.io.File other)
boolean
isExpired()
boolean
isLoaderFor(ProviderIdent ident)
Return true if the file has a class that provides the ident.static boolean
isValidJarPlugin(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> T
load(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.InputStream
openResourceStreamFor(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:
canLoadForService
in 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:
listResources
in interfacePluginResourceLoader
- Returns:
- the list of resources available
- Throws:
PluginException
java.io.IOException
-
openResourceStreamFor
public java.io.InputStream openResourceStreamFor(java.lang.String path) throws PluginException, java.io.IOException
Description copied from interface:PluginResourceLoader
Open a stream to load a resource- Specified by:
openResourceStreamFor
in 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:ProviderLoader
Return a closeable provider instance- Specified by:
loadCloseable
in 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:
load
in 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:
getPluginVersion
in 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 PluginException
Creates 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.IOException
Extract 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:
isLoaderFor
in interfaceProviderLoader
-
listProviders
public java.util.List<ProviderIdent> listProviders()
Description copied from interface:ProviderLoader
List providers available- Specified by:
listProviders
in interfaceProviderLoader
-
close
public void close() throws java.io.IOException
Close class loaders and delete cached files- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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:
expire
in interfaceFileCache.Expireable
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in 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:
getFilename
in interfacePluginMetadata
- Returns:
- Name of file on disk
-
getFile
public java.io.File getFile()
- Specified by:
getFile
in interfacePluginMetadata
- Returns:
- Source file on disk
-
getPluginArtifactName
public java.lang.String getPluginArtifactName()
- Specified by:
getPluginArtifactName
in 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:
getPluginAuthor
in interfacePluginMetadata
- Returns:
- author metadata
-
getPluginFileVersion
public java.lang.String getPluginFileVersion()
- Specified by:
getPluginFileVersion
in interfacePluginMetadata
- Returns:
- plugin file version
-
getPluginUrl
public java.lang.String getPluginUrl()
- Specified by:
getPluginUrl
in interfacePluginMetadata
- Returns:
- plugin URL
-
getPluginDate
public java.util.Date getPluginDate()
- Specified by:
getPluginDate
in interfacePluginMetadata
- Returns:
- build date of plugin
-
getDateLoaded
public java.util.Date getDateLoaded()
- Specified by:
getDateLoaded
in interfacePluginMetadata
- Returns:
- date loaded
-
getPluginName
public java.lang.String getPluginName()
- Specified by:
getPluginName
in interfacePluginMetadata
- Returns:
- plugin name
-
getPluginDescription
public java.lang.String getPluginDescription()
- Specified by:
getPluginDescription
in interfacePluginMetadata
- Returns:
- plugin description
-
getPluginId
public java.lang.String getPluginId()
Description copied from interface:PluginMetadata
This 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:
getPluginId
in interfacePluginMetadata
- Returns:
- plugin id
-
getRundeckCompatibilityVersion
public java.lang.String getRundeckCompatibilityVersion()
- Specified by:
getRundeckCompatibilityVersion
in interfacePluginMetadata
- Returns:
- version of Rundeck with which this plugin is compatible
-
getTargetHostCompatibility
public java.lang.String getTargetHostCompatibility()
- Specified by:
getTargetHostCompatibility
in interfacePluginMetadata
- Returns:
- os family with which this plugin is compatible
-
getTags
public java.util.List<java.lang.String> getTags()
- Specified by:
getTags
in interfacePluginMetadata
- Returns:
- tags
-
getPluginLicense
public java.lang.String getPluginLicense()
- Specified by:
getPluginLicense
in interfacePluginMetadata
- Returns:
- plugin license
-
getPluginThirdPartyDependencies
public java.lang.String getPluginThirdPartyDependencies()
- Specified by:
getPluginThirdPartyDependencies
in interfacePluginMetadata
- Returns:
- plugin third party dependencies
-
getPluginSourceLink
public java.lang.String getPluginSourceLink()
- Specified by:
getPluginSourceLink
in interfacePluginMetadata
- Returns:
- link to plugin source
-
getPluginDocsLink
public java.lang.String getPluginDocsLink()
- Specified by:
getPluginDocsLink
in interfacePluginMetadata
- Returns:
- link to plugin docs
-
getPluginType
public java.lang.String getPluginType()
- Specified by:
getPluginType
in interfacePluginMetadata
- Returns:
- plugin type
-
-