Class ProcessRemoteResourcesMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
,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".-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
(package private) class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate File
The directory containing extra information appended to the generated resources.private org.apache.maven.artifact.factory.ArtifactFactory
Artifact factory, needed to create artifacts.private org.apache.maven.artifact.resolver.ArtifactResolver
Artifact Resolver, needed to resolve and download theresourceBundles
.private boolean
Attaches the resources to the main build of the project as a resource directory.private boolean
Attaches the resources to the test build of the project as a resource directory.protected File
Used for calculation of execution-root forrunOnlyAtExecutionRoot
.protected org.apache.maven.ProjectDependenciesResolver
protected String
The character encoding scheme to be applied when filtering resources.protected String
Comma separated list of Artifact names too exclude.protected String
Comma separated list of GroupId Names to exclude.protected String
Scope to exclude.protected boolean
If we should exclude transitive dependenciesprivate org.apache.maven.shared.filtering.MavenFileFilter
Filtering support, for local resources that override those in the remote bundle.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 String
Comma separated list of Artifact names to include.protected String
Comma separated list of GroupIds to include.protected boolean
Whether to include properties defined in the project when filtering resources.protected String
Scope to include.private org.apache.maven.project.inheritance.ModelInheritanceAssembler
Merges supplemental data model with artifact metadata.private static final String
private static final String
private org.apache.maven.artifact.repository.ArtifactRepository
The local repository taken from Maven's runtime.private org.codehaus.plexus.resource.ResourceManager
private org.apache.maven.project.MavenProjectBuilder
ProjectBuilder, needed to create projects from the artifacts.private org.apache.maven.execution.MavenSession
The Maven session.private File
The directory where processed resources will be placed for packaging.private String
Timestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXX
or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).private org.apache.maven.project.MavenProject
The current Maven project.Additional properties to be passed to Velocity.private List
<org.apache.maven.artifact.repository.ArtifactRepository> List of Remote Repositories used by the resolver.private String[]
When resolving project dependencies, specify the scopes to include.The resource bundles that will be retrieved and processed, expressed withgroupId:artifactId:version[:type[:classifier]]
format.private List
<org.apache.maven.model.Resource> The list of resources defined for the project.protected boolean
If true, only generate resources in the directory of the root project in a multimodule build.private boolean
Skip remote-resource processingList of artifacts that are added to the search path when looking for supplementalModels, expressed withgroupId:artifactId:version[:type[:classifier]]
format.private String[]
Supplemental model data.Map of artifacts to supplemental project object models.private static final String
protected boolean
private org.apache.velocity.app.VelocityEngine
protected int
When the result of velocity transformation fits in memory, it is compared with the actual contents on disk to eliminate unnecessary destination file overwrite.Fields inherited from interface org.apache.velocity.runtime.log.LogChute
DEBUG_ID, DEBUG_PREFIX, ERROR_ID, ERROR_PREFIX, INFO_ID, INFO_PREFIX, TRACE_ID, TRACE_PREFIX, WARN_ID, WARN_PREFIX
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Set
<org.apache.maven.artifact.Artifact> protected org.apache.velocity.VelocityContext
buildVelocityContext
(Map<String, Object> properties) private void
protected boolean
copyResourceIfExists
(File file, String relFileName, org.apache.velocity.VelocityContext context) downloadBundles
(List<String> bundles) void
execute()
private void
fileWriteIfDiffers
(org.apache.commons.io.output.DeferredFileOutputStream outStream) If the transformation result fits in memory and the destination file already exists then both are compared.private static String
generateSupplementMapKey
(String groupId, String artifactId) private String
getLocationTemp
(String name) Convenience method to get the location of the specified file name.protected List
<org.apache.maven.project.MavenProject> getProjectsSortedByOrganization
(List<org.apache.maven.project.MavenProject> projects) private Reader
protected org.apache.maven.model.Model
getSupplement
(org.codehaus.plexus.util.xml.Xpp3Dom supplementModelXml) private Writer
private Writer
getWriter
(RemoteResourcesBundle bundle, File f) void
init
(org.apache.velocity.runtime.RuntimeServices rs) private ClassLoader
initalizeClassloader
(List<File> artifacts) boolean
isLevelEnabled
(int level) loadSupplements
(String[] models) void
void
protected org.apache.maven.model.Model
mergeModels
(org.apache.maven.model.Model parent, org.apache.maven.model.Model child) protected void
processResourceBundles
(ClassLoader classLoader, org.apache.velocity.VelocityContext context) private Set
<org.apache.maven.artifact.Artifact> private org.apache.maven.shared.filtering.MavenFileFilterRequest
setupRequest
(org.apache.maven.model.Resource resource, File source, File file) protected void
validate()
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
TEMPLATE_SUFFIX
- See Also:
-
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: '<'/delimiter> <delimiter>@invalid input: '<'/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 runOnlyAtExecutionRootIf 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
Used for calculation of execution-root forrunOnlyAtExecutionRoot
. -
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") protected String encodingThe character encoding scheme to be applied when filtering resources. -
localRepository
@Parameter(defaultValue="${localRepository}", readonly=true, required=true) private org.apache.maven.artifact.repository.ArtifactRepository localRepositoryThe 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> remoteArtifactRepositoriesList of Remote Repositories used by the resolver. -
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe current Maven project. -
outputDirectory
@Parameter(defaultValue="${project.build.directory}/maven-shared-archive-resources") private File outputDirectoryThe directory where processed resources will be placed for packaging. -
appendedResourcesDirectory
@Parameter(defaultValue="${basedir}/src/main/appended-resources") private File appendedResourcesDirectoryThe directory containing extra information appended to the generated resources. -
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
List of artifacts that are added to the search path when looking for supplementalModels, expressed withgroupId:artifactId:version[:type[:classifier]]
format.- Since:
- 1.1
-
supplementModels
Map of artifacts to supplemental project object models. -
inheritanceAssembler
@Component private org.apache.maven.project.inheritance.ModelInheritanceAssembler inheritanceAssemblerMerges supplemental data model with artifact metadata. Useful when processing artifacts with incomplete POM metadata. -
resourceBundles
The resource bundles that will be retrieved and processed, expressed withgroupId:artifactId:version[:type[:classifier]]
format. -
skip
@Parameter(property="remoteresources.skip", defaultValue="false") private boolean skipSkip remote-resource processing- Since:
- 1.0-alpha-5
-
attachToMain
@Parameter(defaultValue="true", property="attachToMain") private boolean attachToMainAttaches the resources to the main build of the project as a resource directory.- Since:
- 1.5
-
attachToTest
@Parameter(defaultValue="true", property="attachToTest") private boolean attachToTestAttaches the resources to the test build of the project as a resource directory.- Since:
- 1.5
-
properties
Additional properties to be passed to Velocity. Several properties are automatically added:project
- the current MavenProjectprojects
- the list of dependency projectsprojectsSortedByOrganization
- the list of dependency projects sorted by organizationprojectTimespan
- the timespan of the current project (requires inceptionYear in pom)locator
- the ResourceManager that can be used to retrieve additional resources
-
includeProjectProperties
@Parameter(defaultValue="false") protected boolean includeProjectPropertiesWhether to include properties defined in the project when filtering resources.- Since:
- 1.2
-
velocityFilterInMemoryThreshold
@Parameter(defaultValue="5242880") protected int velocityFilterInMemoryThresholdWhen 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> resourcesThe list of resources defined for the project. -
artifactResolver
@Component private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolverArtifact Resolver, needed to resolve and download theresourceBundles
. -
fileFilter
@Component private org.apache.maven.shared.filtering.MavenFileFilter fileFilterFiltering support, for local resources that override those in the remote bundle. -
artifactFactory
@Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactoryArtifact factory, needed to create artifacts. -
mavenSession
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession mavenSessionThe Maven session. -
mavenProjectBuilder
@Component(role=org.apache.maven.project.MavenProjectBuilder.class) private org.apache.maven.project.MavenProjectBuilder mavenProjectBuilderProjectBuilder, needed to create projects from the artifacts. -
locator
@Component private org.codehaus.plexus.resource.ResourceManager locator -
includeScope
Scope to include. An Empty string indicates all scopes (default is "runtime").- Since:
- 1.0
-
excludeScope
Scope to exclude. An Empty string indicates no scopes (default).- Since:
- 1.0
-
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
Comma separated list of Artifact names too exclude.- Since:
- 1.0
-
includeArtifactIds
Comma separated list of Artifact names to include.- Since:
- 1.0
-
excludeGroupIds
Comma separated list of GroupId Names to exclude.- Since:
- 1.0
-
includeGroupIds
Comma separated list of GroupIds to include.- Since:
- 1.0
-
excludeTransitive
@Parameter(property="excludeTransitive", defaultValue="false") protected boolean excludeTransitiveIf we should exclude transitive dependencies- Since:
- 1.0
-
outputTimestamp
Timestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-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
- See Also:
-
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 interfaceorg.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
-
resolveProjectArtifacts
-
aggregateProjectDependencyArtifacts
-
getProjectsSortedByOrganization
-
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
- Throws:
IOException
-
getWriter
- 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
-
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
private Writer getWriter(RemoteResourcesBundle bundle, File f) 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
-
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
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
- Specified by:
init
in interfaceorg.apache.velocity.runtime.log.LogChute
- Throws:
Exception
-
log
- Specified by:
log
in interfaceorg.apache.velocity.runtime.log.LogChute
-
log
- Specified by:
log
in interfaceorg.apache.velocity.runtime.log.LogChute
-
isLevelEnabled
public boolean isLevelEnabled(int level) - Specified by:
isLevelEnabled
in interfaceorg.apache.velocity.runtime.log.LogChute
-