Class AbstractProcessRemoteResourcesMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    AggregateProcessRemoteResourcesMojo, ProcessRemoteResourcesMojo

    public abstract class AbstractProcessRemoteResourcesMojo
    extends org.apache.maven.plugin.AbstractMojo

    Pull down resourceBundles containing remote resources and process the resources contained inside. When that is done, the resources are injected into the current (in-memory) Maven project, making them available to the process-resources phase.

    Resources that end in ".vm" are treated as Velocity templates. For those, the ".vm" is stripped off for the final artifact name and it's fed through Velocity to have properties expanded, conditions processed, etc...

    Resources that don't end in ".vm" are copied "as is".

    This is a support abstract class, with two non-aggregating and aggregating implementations.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.File appendedResourcesDirectory
      The directory containing extra information appended to the generated resources.
      private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager  
      private boolean attachToMain
      Attaches the resources to the main build of the project as a resource directory.
      private boolean attachToTest
      Attaches the resources to the test build of the project as a resource directory.
      protected java.lang.String encoding
      The character encoding scheme to be applied when filtering resources.
      protected java.lang.String excludeArtifactIds
      Comma separated list of Artifact names to exclude.
      protected java.lang.String excludeGroupIds
      Comma separated list of GroupId Names to exclude.
      protected java.lang.String excludeScope
      Scope to exclude.
      protected boolean excludeTransitive
      If we should exclude transitive dependencies
      private org.apache.maven.shared.filtering.MavenFileFilter fileFilter
      Filtering support, for local resources that override those in the remote bundle.
      protected java.util.List<java.lang.String> filterDelimiters
      In cases where a local resource overrides one from a remote resource bundle, that resource should be filtered if the resource set specifies it.
      protected java.lang.String includeArtifactIds
      Comma separated list of Artifact names to include.
      protected java.lang.String includeGroupIds
      Comma separated list of GroupIds to include.
      protected boolean includeProjectProperties
      Deprecated.
      as Maven Project is available in Velocity context we can simply use $project.properties.propertyName
      protected java.lang.String includeScope
      Scope to include.
      private ModelInheritanceAssembler inheritanceAssembler
      Merges supplemental data model with artifact metadata.
      private static java.lang.String KEY_PROJECTS  
      private static java.lang.String KEY_PROJECTS_ORGS  
      private org.codehaus.plexus.resource.ResourceManager locator  
      protected org.apache.maven.execution.MavenSession mavenSession
      The Maven session.
      private java.io.File outputDirectory
      The directory where processed resources will be placed for packaging.
      private java.lang.String outputTimestamp
      Timestamp for reproducible output archive entries, either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
      protected org.apache.maven.project.MavenProject project
      The current project.
      private org.apache.maven.project.ProjectBuilder projectBuilder  
      protected java.util.Map<java.lang.String,​java.lang.String> properties
      Additional properties to be passed to Velocity.
      protected org.eclipse.aether.RepositorySystem repoSystem  
      protected java.lang.String[] resolveScopes
      When resolving project dependencies, specify the scopes to include.
      private java.util.List<java.lang.String> resourceBundles
      The resource bundles that will be retrieved and processed, expressed with groupId:artifactId:version[:type[:classifier]] format.
      private boolean skip
      Skip remote-resource processing
      private java.util.List<java.lang.String> supplementalModelArtifacts
      List of artifacts that are added to the search path when looking for supplementalModels, expressed with groupId:artifactId:version[:type[:classifier]] format.
      private java.lang.String[] supplementalModels
      Supplemental model data.
      private java.util.Map<java.lang.String,​org.apache.maven.model.Model> supplementModels
      Map of artifacts to supplemental project object models.
      private static java.lang.String TEMPLATE_SUFFIX  
      protected boolean useDefaultFilterDelimiters  
      private boolean useProjectFiles
      Indicate if project workspace files with the same name should be used instead of the ones from the bundle.
      private org.apache.velocity.app.VelocityEngine velocity  
      protected int velocityFilterInMemoryThreshold
      Deprecated.
      not used anymore
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractProcessRemoteResourcesMojo​(org.eclipse.aether.RepositorySystem repoSystem, org.apache.maven.shared.filtering.MavenFileFilter fileFilter, org.codehaus.plexus.resource.ResourceManager locator, org.apache.maven.project.ProjectBuilder projectBuilder, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.velocity.VelocityContext buildVelocityContext()  
      private void configureLocator()  
      private boolean copyProjectRootIfExists​(java.io.File outputFile, java.lang.String bundleResourceName)  
      protected boolean copyResourceIfExists​(java.io.File outputFile, java.lang.String bundleResourceName, org.apache.velocity.VelocityContext context, java.lang.String encoding)  
      private java.util.List<java.io.File> downloadBundles​(java.util.List<java.lang.String> bundles)  
      void execute()  
      private static java.lang.String generateSupplementMapKey​(java.lang.String groupId, java.lang.String artifactId)  
      protected abstract java.util.Set<org.apache.maven.artifact.Artifact> getAllDependencies()
      Returns all the transitive hull of all the involved maven projects.
      protected abstract java.util.Set<org.apache.maven.artifact.Artifact> getDirectDependencies()
      Returns all the direct dependencies of all the involved maven projects.
      private java.lang.String getLocationTemp​(java.lang.String name)
      Convenience method to get the location of the specified file name.
      protected java.util.List<org.apache.maven.project.MavenProject> getProjects()  
      protected java.util.Map<org.apache.maven.model.Organization,​java.util.List<org.apache.maven.project.MavenProject>> getProjectsSortedByOrganization​(java.util.List<org.apache.maven.project.MavenProject> projects)  
      private java.io.Reader getReader​(java.lang.String readerEncoding, java.io.File file)  
      protected org.apache.maven.model.Model getSupplement​(org.codehaus.plexus.util.xml.Xpp3Dom supplementModelXml)  
      private java.io.Writer getWriter​(java.lang.String writerEncoding, java.io.OutputStream outputStream)  
      private java.lang.ClassLoader initalizeClassloader​(java.util.List<java.io.File> artifacts)  
      private java.util.Map<java.lang.String,​org.apache.maven.model.Model> loadSupplements​(java.lang.String[] models)  
      protected org.apache.maven.model.Model mergeModels​(org.apache.maven.model.Model parent, org.apache.maven.model.Model child)  
      protected void processResourceBundles​(java.lang.ClassLoader classLoader, org.apache.velocity.VelocityContext context)  
      private org.apache.maven.shared.filtering.MavenFileFilterRequest setupRequest​(org.apache.maven.model.Resource resource, java.io.File source, java.io.File file)  
      protected void validate()  
      private void verifyRequiredProperties​(RemoteResourcesBundle bundle, java.net.URL url)  
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • filterDelimiters

        @Parameter
        protected java.util.List<java.lang.String> filterDelimiters

        In cases where a local resource overrides one from a remote resource bundle, that resource should be filtered if the resource set specifies it. In those cases, this parameter defines the list of delimiters for filterable expressions. These delimiters are specified in the form 'beginToken*endToken'. If no '*' is given, the delimiter is assumed to be the same for start and end.

        So, the default filtering delimiters might be specified as:

         <delimiters>
           <delimiter>${*}</delimiter>
           <delimiter>@</delimiter>
         </delimiters>
         
        Since the '@' delimiter is the same on both ends, we don't need to specify '@*@' (though we can).
        Since:
        1.1
      • useDefaultFilterDelimiters

        @Parameter(defaultValue="true")
        protected boolean useDefaultFilterDelimiters
        Since:
        1.1
      • encoding

        @Parameter(property="encoding",
                   defaultValue="${project.build.sourceEncoding}")
        protected java.lang.String encoding
        The character encoding scheme to be applied when filtering resources.
      • outputDirectory

        @Parameter(property="outputDirectory",
                   defaultValue="${project.build.directory}/maven-shared-archive-resources")
        private java.io.File outputDirectory
        The directory where processed resources will be placed for packaging.
      • appendedResourcesDirectory

        @Parameter(defaultValue="${basedir}/src/main/appended-resources")
        private java.io.File appendedResourcesDirectory
        The directory containing extra information appended to the generated resources.
      • supplementalModels

        @Parameter
        private java.lang.String[] supplementalModels
        Supplemental model data. Useful when processing artifacts with incomplete POM metadata.

        By default, this Mojo looks for supplemental model data in the file "${appendedResourcesDirectory}/supplemental-models.xml".

        Since:
        1.0-alpha-5
      • supplementalModelArtifacts

        @Parameter
        private java.util.List<java.lang.String> supplementalModelArtifacts
        List of artifacts that are added to the search path when looking for supplementalModels, expressed with groupId:artifactId:version[:type[:classifier]] format.
        Since:
        1.1
      • resourceBundles

        @Parameter(property="resourceBundles",
                   required=true)
        private java.util.List<java.lang.String> resourceBundles
        The resource bundles that will be retrieved and processed, expressed with groupId:artifactId:version[:type[:classifier]] format.
      • skip

        @Parameter(property="remoteresources.skip",
                   defaultValue="false")
        private boolean skip
        Skip remote-resource processing
        Since:
        1.0-alpha-5
      • attachToMain

        @Parameter(defaultValue="true",
                   property="attachToMain")
        private boolean attachToMain
        Attaches the resources to the main build of the project as a resource directory.
        Since:
        1.5
      • attachToTest

        @Parameter(defaultValue="true",
                   property="attachToTest")
        private boolean attachToTest
        Attaches the resources to the test build of the project as a resource directory.
        Since:
        1.5
      • properties

        @Parameter
        protected java.util.Map<java.lang.String,​java.lang.String> properties
        Additional properties to be passed to Velocity. Several properties are automatically added:
        • project - the current MavenProject
        • projects - the list of dependency projects
        • projectsSortedByOrganization - the list of dependency projects sorted by organization
        • projectTimespan - the timespan of the current project (requires inceptionYear in pom)
        • locator - the ResourceManager that can be used to retrieve additional resources
        See the javadoc for MavenProject for information about the properties on the MavenProject.
      • includeProjectProperties

        @Deprecated
        @Parameter(defaultValue="false")
        protected boolean includeProjectProperties
        Deprecated.
        as Maven Project is available in Velocity context we can simply use $project.properties.propertyName
        Whether to include properties defined in the project when filtering resources.
        Since:
        1.2
      • velocityFilterInMemoryThreshold

        @Deprecated
        @Parameter(defaultValue="5242880")
        protected int velocityFilterInMemoryThreshold
        Deprecated.
        not used anymore
        When the result of velocity transformation fits in memory, it is compared with the actual contents on disk to eliminate unnecessary destination file overwrite. This improves build times since further build steps typically rely on the modification date.
        Since:
        1.6
      • mavenSession

        @Parameter(defaultValue="${session}",
                   readonly=true,
                   required=true)
        protected org.apache.maven.execution.MavenSession mavenSession
        The Maven session.
      • project

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

        @Parameter(property="includeScope",
                   defaultValue="runtime")
        protected java.lang.String includeScope
        Scope to include. An Empty string indicates all scopes (default is "runtime").
        Since:
        1.0
      • excludeScope

        @Parameter(property="excludeScope",
                   defaultValue="")
        protected java.lang.String excludeScope
        Scope to exclude. An Empty string indicates no scopes (default).
        Since:
        1.0
      • resolveScopes

        @Parameter
        protected java.lang.String[] resolveScopes
        When resolving project dependencies, specify the scopes to include. The default is the same as "includeScope" if there are no exclude scopes set. Otherwise, it defaults to "test" to grab all the dependencies so the exclude filters can filter out what is not needed.
        Since:
        1.5
      • excludeArtifactIds

        @Parameter(property="excludeArtifactIds",
                   defaultValue="")
        protected java.lang.String excludeArtifactIds
        Comma separated list of Artifact names to exclude.
        Since:
        1.0
      • includeArtifactIds

        @Parameter(property="includeArtifactIds",
                   defaultValue="")
        protected java.lang.String includeArtifactIds
        Comma separated list of Artifact names to include.
        Since:
        1.0
      • excludeGroupIds

        @Parameter(property="excludeGroupIds",
                   defaultValue="")
        protected java.lang.String excludeGroupIds
        Comma separated list of GroupId Names to exclude.
        Since:
        1.0
      • includeGroupIds

        @Parameter(property="includeGroupIds",
                   defaultValue="")
        protected java.lang.String includeGroupIds
        Comma separated list of GroupIds to include.
        Since:
        1.0
      • excludeTransitive

        @Parameter(property="excludeTransitive",
                   defaultValue="false")
        protected boolean excludeTransitive
        If we should exclude transitive dependencies
        Since:
        1.0
      • outputTimestamp

        @Parameter(defaultValue="${project.build.outputTimestamp}")
        private java.lang.String outputTimestamp
        Timestamp for reproducible output archive entries, either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
      • useProjectFiles

        @Parameter(defaultValue="false")
        private boolean useProjectFiles
        Indicate if project workspace files with the same name should be used instead of the ones from the bundle.
        Since:
        3.3.0
      • supplementModels

        private java.util.Map<java.lang.String,​org.apache.maven.model.Model> supplementModels
        Map of artifacts to supplemental project object models.
      • inheritanceAssembler

        private final ModelInheritanceAssembler inheritanceAssembler
        Merges supplemental data model with artifact metadata. Useful when processing artifacts with incomplete POM metadata.
      • velocity

        private org.apache.velocity.app.VelocityEngine velocity
      • repoSystem

        protected final org.eclipse.aether.RepositorySystem repoSystem
      • fileFilter

        private final org.apache.maven.shared.filtering.MavenFileFilter fileFilter
        Filtering support, for local resources that override those in the remote bundle.
      • locator

        private final org.codehaus.plexus.resource.ResourceManager locator
      • projectBuilder

        private final org.apache.maven.project.ProjectBuilder projectBuilder
      • artifactHandlerManager

        private final org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
      • KEY_PROJECTS_ORGS

        private static final java.lang.String KEY_PROJECTS_ORGS
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractProcessRemoteResourcesMojo

        protected AbstractProcessRemoteResourcesMojo​(org.eclipse.aether.RepositorySystem repoSystem,
                                                     org.apache.maven.shared.filtering.MavenFileFilter fileFilter,
                                                     org.codehaus.plexus.resource.ResourceManager locator,
                                                     org.apache.maven.project.ProjectBuilder projectBuilder,
                                                     org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager)
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • configureLocator

        private void configureLocator()
                               throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getProjects

        protected java.util.List<org.apache.maven.project.MavenProject> getProjects()
      • getAllDependencies

        protected abstract java.util.Set<org.apache.maven.artifact.Artifact> getAllDependencies()
        Returns all the transitive hull of all the involved maven projects.
      • getDirectDependencies

        protected abstract java.util.Set<org.apache.maven.artifact.Artifact> getDirectDependencies()
        Returns all the direct dependencies of all the involved maven projects.
      • getProjectsSortedByOrganization

        protected java.util.Map<org.apache.maven.model.Organization,​java.util.List<org.apache.maven.project.MavenProject>> getProjectsSortedByOrganization​(java.util.List<org.apache.maven.project.MavenProject> projects)
      • copyResourceIfExists

        protected boolean copyResourceIfExists​(java.io.File outputFile,
                                               java.lang.String bundleResourceName,
                                               org.apache.velocity.VelocityContext context,
                                               java.lang.String encoding)
                                        throws java.io.IOException,
                                               org.apache.maven.plugin.MojoExecutionException
        Throws:
        java.io.IOException
        org.apache.maven.plugin.MojoExecutionException
      • copyProjectRootIfExists

        private boolean copyProjectRootIfExists​(java.io.File outputFile,
                                                java.lang.String bundleResourceName)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getReader

        private java.io.Reader getReader​(java.lang.String readerEncoding,
                                         java.io.File file)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getWriter

        private java.io.Writer getWriter​(java.lang.String writerEncoding,
                                         java.io.OutputStream outputStream)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • setupRequest

        private org.apache.maven.shared.filtering.MavenFileFilterRequest setupRequest​(org.apache.maven.model.Resource resource,
                                                                                      java.io.File source,
                                                                                      java.io.File file)
      • validate

        protected void validate()
                         throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • buildVelocityContext

        protected org.apache.velocity.VelocityContext buildVelocityContext()
      • downloadBundles

        private java.util.List<java.io.File> downloadBundles​(java.util.List<java.lang.String> bundles)
                                                      throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • initalizeClassloader

        private java.lang.ClassLoader initalizeClassloader​(java.util.List<java.io.File> artifacts)
                                                    throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • processResourceBundles

        protected void processResourceBundles​(java.lang.ClassLoader classLoader,
                                              org.apache.velocity.VelocityContext context)
                                       throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • verifyRequiredProperties

        private void verifyRequiredProperties​(RemoteResourcesBundle bundle,
                                              java.net.URL url)
                                       throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getSupplement

        protected org.apache.maven.model.Model getSupplement​(org.codehaus.plexus.util.xml.Xpp3Dom supplementModelXml)
                                                      throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • mergeModels

        protected org.apache.maven.model.Model mergeModels​(org.apache.maven.model.Model parent,
                                                           org.apache.maven.model.Model child)
      • generateSupplementMapKey

        private static java.lang.String generateSupplementMapKey​(java.lang.String groupId,
                                                                 java.lang.String artifactId)
      • loadSupplements

        private java.util.Map<java.lang.String,​org.apache.maven.model.Model> loadSupplements​(java.lang.String[] models)
                                                                                            throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getLocationTemp

        private java.lang.String getLocationTemp​(java.lang.String name)
        Convenience method to get the location of the specified file name.
        Parameters:
        name - the name of the file whose location is to be resolved
        Returns:
        a String that contains the absolute file name of the file