Class PepperOSGiConnector
- java.lang.Object
-
- org.corpus_tools.pepper.connectors.impl.PepperOSGiConnector
-
- All Implemented Interfaces:
org.corpus_tools.pepper.common.Pepper,PepperConnector
public class PepperOSGiConnector extends Object implements org.corpus_tools.pepper.common.Pepper, PepperConnector
This class is an implementation ofPepper. It acts as a bridge between the pure java environment and the Pepper universe inside the OSGi environment. This class should help not dealing with OSGi issues when using Pepper and therefore enables it to use Pepper as an embedded library.- Author:
- Florian Zipser, Martin Klotz, Stephan Druskat
-
-
Field Summary
Fields Modifier and Type Field Description static StringPROP_OSGI_BUNDLESname of system property to determine the locations of OSGi bundles
-
Constructor Summary
Constructors Constructor Description PepperOSGiConnector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSharedPackage(String packageName, String packageVersion)Adds a package to the list of shared packages.Collection<org.corpus_tools.pepper.common.ModuleFitness>checkFitness()StringcreateJob(){@inheritDoc Pepper#createJob()}Set<String>findAppropriateImporters(org.eclipse.emf.common.util.URI corpusPath)StringgetBlacklist()org.osgi.framework.BundlegetBundle(String groupId, String artifactId, String version)This method returns the bundle matching the specified maven project.org.osgi.framework.BundleContextgetBundleContext()Returns theBundleContextobject used for thisPepperConnectorLonggetBundleId(URI location)Returns the bundle id to an already installed bundle from the passed location.org.corpus_tools.pepper.common.PepperConfigurationgetConfiguration(){@inheritDoc Pepper#getConfiguration()}StringgetFrameworkVersion()returns the version of pepper-framework read from the pepper-framework OSGiBundle.org.corpus_tools.pepper.common.PepperJobgetJob(String id){@inheritDoc Pepper#getJob(String)}protected org.corpus_tools.pepper.common.PeppergetPepper()Returns an instance ofPepper, which is running inside OSGi.PepperStarterConfigurationgetPepperStarterConfiguration()Collection<org.corpus_tools.pepper.common.PepperModuleDesc>getRegisteredImporters()Collection<org.corpus_tools.pepper.common.PepperModuleDesc>getRegisteredModules(){@inheritDoc Pepper#getRegisteredModules()}StringgetRegisteredModulesAsString()protected StringgetSharedPackages()Returns a String, containing a formatted list of packages to be shared between current classloader and OSGi classloaders.voidinit()Starts the OSGi environment and installs and starts all bundles located in the plugin directory.org.osgi.framework.Bundleinstall(URI bundleURI)Installs the given bundle, but does not start it.org.osgi.framework.BundleinstallAndCopy(URI bundleURI)Installs the given bundle and copies it to the plugin path, but does not start it.protected Collection<org.osgi.framework.Bundle>installBundles(URI pluginPath, List<URI> dropinPaths)Tries to install all jar-files, of the given pluginPath.booleanisInitialized()Returns whether this object has been initialized.booleanisSingleton(org.osgi.framework.Bundle bundle)Returns whether the given bundle is a singleton.StringprintDependencies(String bundleId)prints all transitive dependencies of the specified bundle, if the bundle can be related to a maven projectStringprintDependencies(String groupId, String artifactId, String version, String repositoryUrl)prints all transitive dependencies of the specified maven projectbooleanremove(String bundleName)Removes the passed bundle from the OSGi content and removes its jar file and folder if exist.booleanremoveJob(String id){@inheritDoc Pepper#removeJob(String)}Collection<String>selfTest()voidsetBundleContext(org.osgi.framework.BundleContext bundleContext)Sets theBundleContextobject used for this connectorvoidsetConfiguration(org.corpus_tools.pepper.common.PepperConfiguration configuration)voidstart(Long bundleId)Starts the passed bundleprotected voidstartBundles(Collection<org.osgi.framework.Bundle> bundles)Starts all bundle being contained in the given list of bundles.protected org.osgi.framework.BundleContextstartEquinox()Starts the OSGi Equinox environment.voidstopOSGi()Stops the OSGi environment.voiduninstall(Long bundleId)Uninstalls a bundle from OSGi context.voiduninstall(URI location)Uninstalls a bundle from OSGi context.booleanupdate(String groupId, String artifactId, String repositoryUrl, boolean isSnapshot, boolean ignoreFrameworkVersion)This method checks the pepperModules in the modules.xml for updates and triggers the installation process if a newer version is available
-
-
-
Field Detail
-
PROP_OSGI_BUNDLES
public static final String PROP_OSGI_BUNDLES
name of system property to determine the locations of OSGi bundles- See Also:
- Constant Field Values
-
-
Method Detail
-
isInitialized
public boolean isInitialized()
Description copied from interface:PepperConnectorReturns whether this object has been initialized.- Specified by:
isInitializedin interfacePepperConnector- Returns:
- true, if object has been initialized, false otherwise
-
init
public void init()
Starts the OSGi environment and installs and starts all bundles located in the plugin directory.
Sets propertyPepperOSGiRunner.PROP_TEST_DISABLEDto true.- Specified by:
initin interfacePepperConnector
-
startEquinox
protected org.osgi.framework.BundleContext startEquinox() throws ExceptionStarts the OSGi Equinox environment.- Returns:
- Throws:
Exception
-
getConfiguration
public org.corpus_tools.pepper.common.PepperConfiguration getConfiguration()
{@inheritDoc Pepper#getConfiguration()}- Specified by:
getConfigurationin interfaceorg.corpus_tools.pepper.common.Pepper
-
getPepperStarterConfiguration
public PepperStarterConfiguration getPepperStarterConfiguration()
- Returns:
- configuration as
PepperStarterConfiguration
-
setConfiguration
public void setConfiguration(org.corpus_tools.pepper.common.PepperConfiguration configuration)
- Specified by:
setConfigurationin interfaceorg.corpus_tools.pepper.common.Pepper
-
getPepper
protected org.corpus_tools.pepper.common.Pepper getPepper()
Returns an instance ofPepper, which is running inside OSGi. This class will be resolved via theBundleContext. If it was resolved once, a singleton instance of this object is returned.- Returns:
Pepperfrom inside the OSGi environment.
-
getBundleContext
public org.osgi.framework.BundleContext getBundleContext()
Returns theBundleContextobject used for thisPepperConnector- Returns:
-
setBundleContext
public void setBundleContext(org.osgi.framework.BundleContext bundleContext)
Sets theBundleContextobject used for this connector- Parameters:
bundleContext- the object to be set
-
addSharedPackage
public void addSharedPackage(String packageName, String packageVersion)
Adds a package to the list of shared packages. The shared packages are necessary to bridge the OSGi container. In OSGi each bundle has its own classloader, which is a different one than in a standard Java application. In Java classes needs to be load by the same class loader to have a unique identification. For instance to share Salt objects between Pepper modules and the application outside OSGi they need to be added to shared packeges.- Parameters:
packageName- name of the packagepackageVersion- version of the package (normally the bundle's version)
-
getSharedPackages
protected String getSharedPackages()
Returns a String, containing a formatted list of packages to be shared between current classloader and OSGi classloaders. The list is formatted as it could be taken of the propertyConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA.
-
installBundles
protected Collection<org.osgi.framework.Bundle> installBundles(URI pluginPath, List<URI> dropinPaths) throws org.osgi.framework.BundleException, URISyntaxException, IOException
Tries to install all jar-files, of the given pluginPath.
Each installed jar will be added to system property "osgi.bundles" as reference:file:JAR_FILE.- Parameters:
pluginPath- path where the bundles arebundleAction- a flag, which shows if bundle has to be started or just installeddropinPaths- A list of additionally paths to load bundles from- Throws:
org.osgi.framework.BundleExceptionURISyntaxExceptionIOException
-
getBundleId
public Long getBundleId(URI location)
Returns the bundle id to an already installed bundle from the passed location.
-
installAndCopy
public org.osgi.framework.Bundle installAndCopy(URI bundleURI) throws org.osgi.framework.BundleException, IOException
Installs the given bundle and copies it to the plugin path, but does not start it.
If the the URI is of scheme http or https, the file will be downloaded.
If the URI points to a zip file, it will be extracted and copied.- Parameters:
bundleURI-- Returns:
- Throws:
org.osgi.framework.BundleExceptionIOException
-
install
public org.osgi.framework.Bundle install(URI bundleURI) throws org.osgi.framework.BundleException
Installs the given bundle, but does not start it.- Parameters:
bundleURI-- Returns:
- Throws:
org.osgi.framework.BundleException
-
uninstall
public void uninstall(Long bundleId) throws org.osgi.framework.BundleException
Uninstalls a bundle from OSGi context.- Throws:
org.osgi.framework.BundleException
-
uninstall
public void uninstall(URI location) throws org.osgi.framework.BundleException
Uninstalls a bundle from OSGi context.- Throws:
org.osgi.framework.BundleException
-
remove
public boolean remove(String bundleName) throws org.osgi.framework.BundleException, IOException
Removes the passed bundle from the OSGi content and removes its jar file and folder if exist.- Throws:
org.osgi.framework.BundleExceptionIOException
-
start
public void start(Long bundleId)
Starts the passed bundle- Parameters:
bundle-
-
startBundles
protected void startBundles(Collection<org.osgi.framework.Bundle> bundles) throws org.osgi.framework.BundleException
Starts all bundle being contained in the given list of bundles.- Parameters:
bundles- a list of bundles to start- Throws:
org.osgi.framework.BundleException
-
createJob
public String createJob()
{@inheritDoc Pepper#createJob()}- Specified by:
createJobin interfaceorg.corpus_tools.pepper.common.Pepper
-
getJob
public org.corpus_tools.pepper.common.PepperJob getJob(String id) throws org.corpus_tools.pepper.exceptions.JobNotFoundException
{@inheritDoc Pepper#getJob(String)}- Specified by:
getJobin interfaceorg.corpus_tools.pepper.common.Pepper- Throws:
org.corpus_tools.pepper.exceptions.JobNotFoundException
-
removeJob
public boolean removeJob(String id) throws org.corpus_tools.pepper.exceptions.JobNotFoundException
{@inheritDoc Pepper#removeJob(String)}- Specified by:
removeJobin interfaceorg.corpus_tools.pepper.common.Pepper- Throws:
org.corpus_tools.pepper.exceptions.JobNotFoundException
-
getRegisteredModules
public Collection<org.corpus_tools.pepper.common.PepperModuleDesc> getRegisteredModules()
{@inheritDoc Pepper#getRegisteredModules()}- Specified by:
getRegisteredModulesin interfaceorg.corpus_tools.pepper.common.Pepper
-
getRegisteredModulesAsString
public String getRegisteredModulesAsString()
- Specified by:
getRegisteredModulesAsStringin interfaceorg.corpus_tools.pepper.common.Pepper
-
selfTest
public Collection<String> selfTest()
- Specified by:
selfTestin interfaceorg.corpus_tools.pepper.common.Pepper
-
update
public boolean update(String groupId, String artifactId, String repositoryUrl, boolean isSnapshot, boolean ignoreFrameworkVersion)
This method checks the pepperModules in the modules.xml for updates and triggers the installation process if a newer version is available
-
getFrameworkVersion
public String getFrameworkVersion()
returns the version of pepper-framework read from the pepper-framework OSGiBundle.
-
getBlacklist
public String getBlacklist()
-
getBundle
public org.osgi.framework.Bundle getBundle(String groupId, String artifactId, String version)
This method returns the bundle matching the specified maven project.- Parameters:
groupId- -- the project's group idartifactId- -- the project's artifact idversion- -- the project's version- Returns:
- the bundle, if it exists and can be determined, otherwise null
-
isSingleton
public boolean isSingleton(org.osgi.framework.Bundle bundle)
Returns whether the given bundle is a singleton.
-
printDependencies
public String printDependencies(String bundleId)
prints all transitive dependencies of the specified bundle, if the bundle can be related to a maven project- Parameters:
bundleId- -- the bundle's id- Returns:
- all dependencies as printable tree string
-
printDependencies
public String printDependencies(String groupId, String artifactId, String version, String repositoryUrl)
prints all transitive dependencies of the specified maven project- Parameters:
groupId- -- the project's group idartifactId- -- the project's artifact idversion- -- the project's version- Returns:
- all dependencies as printable tree string
-
findAppropriateImporters
public Set<String> findAppropriateImporters(org.eclipse.emf.common.util.URI corpusPath) throws FileNotFoundException
- Specified by:
findAppropriateImportersin interfaceorg.corpus_tools.pepper.common.Pepper- Throws:
FileNotFoundException
-
getRegisteredImporters
public Collection<org.corpus_tools.pepper.common.PepperModuleDesc> getRegisteredImporters()
- Specified by:
getRegisteredImportersin interfaceorg.corpus_tools.pepper.common.Pepper
-
checkFitness
public Collection<org.corpus_tools.pepper.common.ModuleFitness> checkFitness()
- Specified by:
checkFitnessin interfaceorg.corpus_tools.pepper.common.Pepper
-
-