Class ProcessRemoteResourcesMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugin.resources.remote.ProcessRemoteResourcesMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo, org.apache.velocity.runtime.log.LogChute

@Mojo(name="process", defaultPhase=GENERATE_RESOURCES, threadSafe=true) public class ProcessRemoteResourcesMojo extends org.apache.maven.plugin.AbstractMojo implements org.apache.velocity.runtime.log.LogChute

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".

  • Field Details

    • TEMPLATE_SUFFIX

      private static final String TEMPLATE_SUFFIX
      See Also:
    • filterDelimiters

      @Parameter protected List<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>${*}invalid input: '&lt'/delimiter>
         <delimiter>@invalid input: '&lt'/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
    • runOnlyAtExecutionRoot

      @Parameter(defaultValue="false") protected boolean runOnlyAtExecutionRoot
      If true, only generate resources in the directory of the root project in a multimodule build. Dependencies from all modules will be aggregated before resource-generation takes place.
      Since:
      1.1
    • basedir

      @Parameter(defaultValue="${basedir}", readonly=true, required=true) protected File basedir
      Used for calculation of execution-root for runOnlyAtExecutionRoot.
    • encoding

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

      @Parameter(defaultValue="${localRepository}", readonly=true, required=true) private org.apache.maven.artifact.repository.ArtifactRepository localRepository
      The local repository taken from Maven's runtime. Typically $HOME/.m2/repository.
    • remoteArtifactRepositories

      @Parameter(defaultValue="${project.remoteArtifactRepositories}", readonly=true, required=true) private List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories
      List of Remote Repositories used by the resolver.
    • project

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

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

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

      @Parameter private 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 List<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
    • supplementModels

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

      @Component private org.apache.maven.project.inheritance.ModelInheritanceAssembler inheritanceAssembler
      Merges supplemental data model with artifact metadata. Useful when processing artifacts with incomplete POM metadata.
    • resourceBundles

      @Parameter(required=true) private List<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 private Map<String,Object> 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

      @Parameter(defaultValue="false") protected boolean includeProjectProperties
      Whether to include properties defined in the project when filtering resources.
      Since:
      1.2
    • velocityFilterInMemoryThreshold

      @Parameter(defaultValue="5242880") protected int velocityFilterInMemoryThreshold
      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
    • resources

      @Parameter(defaultValue="${project.resources}", readonly=true, required=true) private List<org.apache.maven.model.Resource> resources
      The list of resources defined for the project.
    • artifactResolver

      @Component private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver
      Artifact Resolver, needed to resolve and download the resourceBundles.
    • fileFilter

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

      @Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
      Artifact factory, needed to create artifacts.
    • mavenSession

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

      @Component(role=org.apache.maven.project.MavenProjectBuilder.class) private org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder
      ProjectBuilder, needed to create projects from the artifacts.
    • locator

      @Component private org.codehaus.plexus.resource.ResourceManager locator
    • includeScope

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

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

      @Parameter private 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 String excludeArtifactIds
      Comma separated list of Artifact names too exclude.
      Since:
      1.0
    • includeArtifactIds

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

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

      @Parameter(property="includeGroupIds", defaultValue="") protected 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 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).
    • dependencyResolver

      @Component(hint="default") protected org.apache.maven.ProjectDependenciesResolver dependencyResolver
    • velocity

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

      private static final String KEY_PROJECTS
      See Also:
    • KEY_PROJECTS_ORGS

      private static final String KEY_PROJECTS_ORGS
      See Also:
  • Constructor Details

    • ProcessRemoteResourcesMojo

      public ProcessRemoteResourcesMojo()
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Specified by:
      execute in interface org.apache.maven.plugin.Mojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • configureLocator

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

      protected List<org.apache.maven.project.MavenProject> getProjects()
    • resolveProjectArtifacts

      private Set<org.apache.maven.artifact.Artifact> resolveProjectArtifacts()
    • aggregateProjectDependencyArtifacts

      private Set<org.apache.maven.artifact.Artifact> aggregateProjectDependencyArtifacts()
    • getProjectsSortedByOrganization

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

      protected boolean copyResourceIfExists(File file, String relFileName, org.apache.velocity.VelocityContext context) throws IOException, org.apache.maven.plugin.MojoExecutionException
      Throws:
      IOException
      org.apache.maven.plugin.MojoExecutionException
    • getReader

      private Reader getReader(File source) throws IOException
      Throws:
      IOException
    • getWriter

      private Writer getWriter(OutputStream os) throws IOException
      Throws:
      IOException
    • fileWriteIfDiffers

      private void fileWriteIfDiffers(org.apache.commons.io.output.DeferredFileOutputStream outStream) throws IOException
      If the transformation result fits in memory and the destination file already exists then both are compared.

      If destination file is byte-by-byte equal, then it is not overwritten. This improves subsequent compilation times since upstream plugins property see that the resource was not modified.

      Note: the method should be called after DeferredFileOutputStream.close()

      Parameters:
      outStream - Deferred stream
      Throws:
      IOException
    • setupRequest

      private org.apache.maven.shared.filtering.MavenFileFilterRequest setupRequest(org.apache.maven.model.Resource resource, File source, 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(Map<String,Object> properties) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • downloadBundles

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

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

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

      Throws:
      IOException
      UnsupportedEncodingException
      FileNotFoundException
    • 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 String generateSupplementMapKey(String groupId, String artifactId)
    • loadSupplements

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

      private String getLocationTemp(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
    • init

      public void init(org.apache.velocity.runtime.RuntimeServices rs) throws Exception
      Specified by:
      init in interface org.apache.velocity.runtime.log.LogChute
      Throws:
      Exception
    • log

      public void log(int level, String message)
      Specified by:
      log in interface org.apache.velocity.runtime.log.LogChute
    • log

      public void log(int level, String message, Throwable t)
      Specified by:
      log in interface org.apache.velocity.runtime.log.LogChute
    • isLevelEnabled

      public boolean isLevelEnabled(int level)
      Specified by:
      isLevelEnabled in interface org.apache.velocity.runtime.log.LogChute