Class 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 of Pepper. 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 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
    • Constructor Detail

      • PepperOSGiConnector

        public PepperOSGiConnector()
    • Method Detail

      • isInitialized

        public boolean isInitialized()
        Description copied from interface: PepperConnector
        Returns whether this object has been initialized.
        Specified by:
        isInitialized in interface PepperConnector
        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 property PepperOSGiRunner.PROP_TEST_DISABLED to true.
        Specified by:
        init in interface PepperConnector
      • startEquinox

        protected org.osgi.framework.BundleContext startEquinox()
                                                         throws Exception
        Starts the OSGi Equinox environment.
        Returns:
        Throws:
        Exception
      • stopOSGi

        public void stopOSGi()
                      throws Exception
        Stops the OSGi environment.
        Throws:
        Exception
      • getConfiguration

        public org.corpus_tools.pepper.common.PepperConfiguration getConfiguration()
        {@inheritDoc Pepper#getConfiguration()}
        Specified by:
        getConfiguration in interface org.corpus_tools.pepper.common.Pepper
      • setConfiguration

        public void setConfiguration​(org.corpus_tools.pepper.common.PepperConfiguration configuration)
        Specified by:
        setConfiguration in interface org.corpus_tools.pepper.common.Pepper
      • getPepper

        protected org.corpus_tools.pepper.common.Pepper getPepper()
        Returns an instance of Pepper, which is running inside OSGi. This class will be resolved via the BundleContext. If it was resolved once, a singleton instance of this object is returned.
        Returns:
        Pepper from inside the OSGi environment.
      • getBundleContext

        public org.osgi.framework.BundleContext getBundleContext()
        Returns the BundleContext object used for this PepperConnector
        Returns:
      • setBundleContext

        public void setBundleContext​(org.osgi.framework.BundleContext bundleContext)
        Sets the BundleContext object 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 package
        packageVersion - 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 property Constants.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 are
        bundleAction - a flag, which shows if bundle has to be started or just installed
        dropinPaths - A list of additionally paths to load bundles from
        Throws:
        org.osgi.framework.BundleException
        URISyntaxException
        IOException
      • 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.BundleException
        IOException
      • 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.BundleException
        IOException
      • 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:
        createJob in interface org.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:
        getJob in interface org.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:
        removeJob in interface org.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:
        getRegisteredModules in interface org.corpus_tools.pepper.common.Pepper
      • getRegisteredModulesAsString

        public String getRegisteredModulesAsString()
        Specified by:
        getRegisteredModulesAsString in interface org.corpus_tools.pepper.common.Pepper
      • selfTest

        public Collection<String> selfTest()
        Specified by:
        selfTest in interface org.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 OSGi Bundle.
      • 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 id
        artifactId - -- the project's artifact id
        version - -- 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 id
        artifactId - -- the project's artifact id
        version - -- 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:
        findAppropriateImporters in interface org.corpus_tools.pepper.common.Pepper
        Throws:
        FileNotFoundException
      • getRegisteredImporters

        public Collection<org.corpus_tools.pepper.common.PepperModuleDesc> getRegisteredImporters()
        Specified by:
        getRegisteredImporters in interface org.corpus_tools.pepper.common.Pepper
      • checkFitness

        public Collection<org.corpus_tools.pepper.common.ModuleFitness> checkFitness()
        Specified by:
        checkFitness in interface org.corpus_tools.pepper.common.Pepper