Class BundlePlugin

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    AntPlugin, InstructionsPlugin, ManifestPlugin

    @Mojo(name="bundle",
          requiresDependencyResolution=TEST,
          threadSafe=true,
          defaultPhase=PACKAGE)
    public class BundlePlugin
    extends org.apache.maven.plugin.AbstractMojo
    Create an OSGi bundle from Maven project
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.maven.artifact.factory.ArtifactFactory artifactFactory  
      protected org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver
      Artifact resolver, needed to download source jars for inclusion in classpath.
      protected org.sonatype.plexus.build.incremental.BuildContext buildContext  
      protected String classifier
      Classifier type of the bundle to be installed.
      protected boolean createDependencyReducedPom
      If true, remove any inlined or embedded dependencies from the resulting pom.
      protected org.apache.maven.shared.dependency.graph.DependencyGraphBuilder dependencyGraphBuilder
      The dependency graph builder to use.
      protected File dependencyReducedPomLocation
      Where to put the dependency reduced pom.
      protected File dumpClasspath
      File where the BND class-path will be dumped
      protected File dumpInstructions
      File where the BND instructions will be dumped
      protected String excludeDependencies
      Comma separated list of artifactIds to exclude from the dependency classpath passed to BND (use "true" to exclude everything)
      protected boolean exportScr
      When true, dump the generated SCR files
      protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
      Local maven repository.
      protected org.apache.maven.shared.dependency.graph.DependencyGraphBuilder m_dependencyGraphBuilder  
      protected File manifestLocation
      Directory where the manifest will be written
      protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder
      ProjectBuilder, needed to create projects from the artifacts.
      protected boolean niceManifest
      Output a nicely formatted manifest that still respects the 72 character line limit.
      protected String packaging
      Packaging type of the bundle to be installed.
      protected org.apache.maven.project.MavenProject project
      The Maven project.
      protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories
      Remote repositories which will be searched for source attachments.
      protected File scrLocation
      Directory where the SCR files will be written
      protected org.apache.maven.execution.MavenSession session  
      protected List<String> supportedProjectTypes
      Project types which this plugin supports.
      protected boolean unpackBundle
      When true, unpack the bundle contents to the outputDirectory
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      BundlePlugin()  
    • Field Detail

      • manifestLocation

        @Parameter(property="manifestLocation",
                   defaultValue="${project.build.outputDirectory}/META-INF")
        protected File manifestLocation
        Directory where the manifest will be written
      • niceManifest

        @Parameter(property="niceManifest",
                   defaultValue="false")
        protected boolean niceManifest
        Output a nicely formatted manifest that still respects the 72 character line limit.
      • dumpInstructions

        @Parameter(property="dumpInstructions")
        protected File dumpInstructions
        File where the BND instructions will be dumped
      • dumpClasspath

        @Parameter(property="dumpClasspath")
        protected File dumpClasspath
        File where the BND class-path will be dumped
      • unpackBundle

        @Parameter(property="unpackBundle")
        protected boolean unpackBundle
        When true, unpack the bundle contents to the outputDirectory
      • excludeDependencies

        @Parameter(property="excludeDependencies")
        protected String excludeDependencies
        Comma separated list of artifactIds to exclude from the dependency classpath passed to BND (use "true" to exclude everything)
      • classifier

        @Parameter
        protected String classifier
        Classifier type of the bundle to be installed. For example, "jdk14". Defaults to none which means this is the project's main bundle.
      • packaging

        @Parameter
        protected String packaging
        Packaging type of the bundle to be installed. For example, "jar". Defaults to none which means use the same packaging as the project.
      • createDependencyReducedPom

        @Parameter
        protected boolean createDependencyReducedPom
        If true, remove any inlined or embedded dependencies from the resulting pom.
      • dependencyReducedPomLocation

        @Parameter(defaultValue="${basedir}/dependency-reduced-pom.xml")
        protected File dependencyReducedPomLocation
        Where to put the dependency reduced pom. Note: setting a value for this parameter with a directory other than ${basedir} will change the value of ${basedir} for all executions that come after the shade execution. This is often not what you want. This is considered an open issue with this plugin.
      • scrLocation

        @Parameter(defaultValue="${project.build.outputDirectory}")
        protected File scrLocation
        Directory where the SCR files will be written
      • exportScr

        @Parameter
        protected boolean exportScr
        When true, dump the generated SCR files
      • m_dependencyGraphBuilder

        @Component
        protected org.apache.maven.shared.dependency.graph.DependencyGraphBuilder m_dependencyGraphBuilder
      • session

        @Parameter(defaultValue="${session}",
                   readonly=true)
        protected org.apache.maven.execution.MavenSession session
      • mavenProjectBuilder

        @Component
        protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder
        ProjectBuilder, needed to create projects from the artifacts.
      • dependencyGraphBuilder

        @Component
        protected org.apache.maven.shared.dependency.graph.DependencyGraphBuilder dependencyGraphBuilder
        The dependency graph builder to use.
      • artifactFactory

        @Component
        protected org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
      • artifactResolver

        @Component
        protected org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver
        Artifact resolver, needed to download source jars for inclusion in classpath.
      • localRepository

        @Parameter(readonly=true,
                   required=true,
                   defaultValue="${localRepository}")
        protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
        Local maven repository.
      • remoteArtifactRepositories

        @Parameter(readonly=true,
                   required=true,
                   defaultValue="${project.remoteArtifactRepositories}")
        protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories
        Remote repositories which will be searched for source attachments.
      • supportedProjectTypes

        @Parameter
        protected List<String> supportedProjectTypes
        Project types which this plugin supports.
      • project

        @Parameter(defaultValue="${project}",
                   readonly=true,
                   required=true)
        protected org.apache.maven.project.MavenProject project
        The Maven project.
      • buildContext

        @Component
        protected org.sonatype.plexus.build.incremental.BuildContext buildContext
    • Constructor Detail

      • BundlePlugin

        public BundlePlugin()
    • Method Detail

      • getProject

        protected org.apache.maven.project.MavenProject getProject()
      • buildDependencyGraph

        protected org.apache.maven.shared.dependency.graph.DependencyNode buildDependencyGraph​(org.apache.maven.project.MavenProject mavenProject)
                                                                                        throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        See Also:
        Mojo.execute()
      • execute

        protected void execute​(org.apache.maven.project.MavenProject currentProject,
                               org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph,
                               Map<String,​String> originalInstructions,
                               Properties properties)
                        throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • reportErrors

        protected boolean reportErrors​(String prefix,
                                       aQute.bnd.osgi.Analyzer analyzer)
      • execute

        protected void execute​(org.apache.maven.project.MavenProject currentProject,
                               org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph,
                               Map<String,​String> originalInstructions,
                               Properties properties,
                               aQute.bnd.osgi.Jar[] classpath)
                        throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getOSGiBuilder

        protected aQute.bnd.osgi.Builder getOSGiBuilder​(org.apache.maven.project.MavenProject currentProject,
                                                        Map<String,​String> originalInstructions,
                                                        Properties properties,
                                                        aQute.bnd.osgi.Jar[] classpath)
                                                 throws Exception
        Throws:
        Exception
      • sanitize

        protected static String sanitize​(Object value)
      • addMavenInstructions

        protected void addMavenInstructions​(org.apache.maven.project.MavenProject currentProject,
                                            org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph,
                                            aQute.bnd.osgi.Builder builder)
                                     throws Exception
        Throws:
        Exception
      • updateExcludesInDeps

        public boolean updateExcludesInDeps​(org.apache.maven.project.MavenProject project,
                                            List<org.apache.maven.model.Dependency> dependencies,
                                            List<org.apache.maven.model.Dependency> transitiveDeps)
                                     throws org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
        Throws:
        org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
      • buildOSGiBundle

        protected aQute.bnd.osgi.Builder buildOSGiBundle​(org.apache.maven.project.MavenProject currentProject,
                                                         org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph,
                                                         Map<String,​String> originalInstructions,
                                                         Properties properties,
                                                         aQute.bnd.osgi.Jar[] classpath)
                                                  throws Exception
        Throws:
        Exception
      • includeMavenResources

        protected static void includeMavenResources​(org.apache.maven.project.MavenProject currentProject,
                                                    aQute.bnd.osgi.Analyzer analyzer,
                                                    org.apache.maven.plugin.logging.Log log)
      • mergeMavenManifest

        protected void mergeMavenManifest​(org.apache.maven.project.MavenProject currentProject,
                                          org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph,
                                          aQute.bnd.osgi.Builder builder)
                                   throws Exception
        Throws:
        Exception
      • mergeManifest

        protected static void mergeManifest​(aQute.bnd.osgi.Instructions instructions,
                                            Manifest... manifests)
                                     throws IOException
        Throws:
        IOException
      • getOptionalPackages

        protected Set<String> getOptionalPackages​(org.apache.maven.project.MavenProject currentProject,
                                                  org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph)
                                           throws IOException,
                                                  org.apache.maven.plugin.MojoExecutionException
        Throws:
        IOException
        org.apache.maven.plugin.MojoExecutionException
      • isTransitivelyOptional

        protected boolean isTransitivelyOptional​(HashSet<String> optionalArtifactIds,
                                                 org.apache.maven.artifact.Artifact artifact)
        Check to see if any dependency along the dependency trail of the artifact is optional.
        Parameters:
        artifact -
      • removeTagFromInstruction

        protected static String removeTagFromInstruction​(String instruction,
                                                         String tag)
      • getClasspath

        protected aQute.bnd.osgi.Jar[] getClasspath​(org.apache.maven.project.MavenProject currentProject,
                                                    org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph)
                                             throws IOException,
                                                    org.apache.maven.plugin.MojoExecutionException
        Throws:
        IOException
        org.apache.maven.plugin.MojoExecutionException
      • getFile

        protected File getFile​(org.apache.maven.artifact.Artifact artifact)
        Get the file for an Artifact
        Parameters:
        artifact -
      • convertVersionToOsgi

        protected String convertVersionToOsgi​(String version)
        Convert a Maven version into an OSGi compliant version
        Parameters:
        version - Maven version
        Returns:
        the OSGi version
      • getBundleName

        protected String getBundleName​(org.apache.maven.project.MavenProject currentProject)
        TODO this should return getMaven2Osgi().getBundleFileName( project.getArtifact() )
      • getBuildDirectory

        protected String getBuildDirectory()
      • setBuildDirectory

        protected void setBuildDirectory​(String _buildirectory)
      • getDefaultProperties

        protected Properties getDefaultProperties​(org.apache.maven.project.MavenProject currentProject)
      • getBase

        protected static File getBase​(org.apache.maven.project.MavenProject currentProject)
      • getOutputDirectory

        protected File getOutputDirectory()
      • setOutputDirectory

        protected void setOutputDirectory​(File _outputDirectory)
      • getMavenResourcePaths

        protected static String getMavenResourcePaths​(org.apache.maven.project.MavenProject currentProject,
                                                      boolean test)
      • getEmbeddableArtifacts

        protected Collection<org.apache.maven.artifact.Artifact> getEmbeddableArtifacts​(org.apache.maven.project.MavenProject currentProject,
                                                                                        org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph,
                                                                                        aQute.bnd.osgi.Analyzer analyzer)
                                                                                 throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • addMavenSourcePath

        protected static void addMavenSourcePath​(org.apache.maven.project.MavenProject currentProject,
                                                 aQute.bnd.osgi.Analyzer analyzer,
                                                 org.apache.maven.plugin.logging.Log log)
      • includeJava9Fixups

        protected static void includeJava9Fixups​(org.apache.maven.project.MavenProject currentProject,
                                                 aQute.bnd.osgi.Analyzer analyzer)
        Downgrade the message "Classes found in the wrong directory" to a warning. This allows the plugin to process a multi-release JAR (see JEP 238, http://openjdk.java.net/jeps/238). Note that the version-specific paths will NOT be visible at runtime nor processed by bnd for imported packages etc. This will not be possible until a runtime solution for multi-release JARs exists in OSGi. This fix only allows these JARs to be processed at all and to be usable on Java 8 (and below), and also on Java 9 where the version-specific customizations are optional.