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.LogChutePull 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 Classes Modifier and Type Class Description (package private) classProcessRemoteResourcesMojo.OrganizationComparator(package private) classProcessRemoteResourcesMojo.ProjectComparator
-
Field Summary
Fields Modifier and Type Field Description private java.io.FileappendedResourcesDirectoryThe directory containing extra information appended to the generated resources.private org.apache.maven.artifact.factory.ArtifactFactoryartifactFactoryArtifact factory, needed to create artifacts.private org.apache.maven.artifact.resolver.ArtifactResolverartifactResolverArtifact Resolver, needed to resolve and download theresourceBundles.private booleanattachToMainAttaches the resources to the main build of the project as a resource directory.private booleanattachToTestAttaches the resources to the test build of the project as a resource directory.protected java.io.FilebasedirUsed for calculation of execution-root forrunOnlyAtExecutionRoot.protected org.apache.maven.ProjectDependenciesResolverdependencyResolverprotected java.lang.StringencodingThe character encoding scheme to be applied when filtering resources.protected java.lang.StringexcludeArtifactIdsComma separated list of Artifact names too exclude.protected java.lang.StringexcludeGroupIdsComma separated list of GroupId Names to exclude.protected java.lang.StringexcludeScopeScope to exclude.protected booleanexcludeTransitiveIf we should exclude transitive dependenciesprivate org.apache.maven.shared.filtering.MavenFileFilterfileFilterFiltering support, for local resources that override those in the remote bundle.protected java.util.List<java.lang.String>filterDelimitersIn 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.StringincludeArtifactIdsComma separated list of Artifact names to include.protected java.lang.StringincludeGroupIdsComma separated list of GroupIds to include.protected booleanincludeProjectPropertiesWhether to include properties defined in the project when filtering resources.protected java.lang.StringincludeScopeScope to include.private org.apache.maven.project.inheritance.ModelInheritanceAssemblerinheritanceAssemblerMerges supplemental data model with artifact metadata.private static java.lang.StringKEY_PROJECTSprivate static java.lang.StringKEY_PROJECTS_ORGSprivate org.apache.maven.artifact.repository.ArtifactRepositorylocalRepositoryThe local repository taken from Maven's runtime.private org.codehaus.plexus.resource.ResourceManagerlocatorprivate org.apache.maven.project.MavenProjectBuildermavenProjectBuilderProjectBuilder, needed to create projects from the artifacts.private org.apache.maven.execution.MavenSessionmavenSessionThe Maven session.private java.io.FileoutputDirectoryThe directory where processed resources will be placed for packaging.private java.lang.StringoutputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).private org.apache.maven.project.MavenProjectprojectThe current Maven project.private java.util.Map<java.lang.String,java.lang.Object>propertiesAdditional properties to be passed to Velocity.private java.util.List<org.apache.maven.artifact.repository.ArtifactRepository>remoteArtifactRepositoriesList of Remote Repositories used by the resolver.private java.lang.String[]resolveScopesWhen resolving project dependencies, specify the scopes to include.private java.util.List<java.lang.String>resourceBundlesThe resource bundles that will be retrieved and processed, expressed withgroupId:artifactId:version[:type[:classifier]]format.private java.util.List<org.apache.maven.model.Resource>resourcesThe list of resources defined for the project.protected booleanrunOnlyAtExecutionRootIf true, only generate resources in the directory of the root project in a multimodule build.private booleanskipSkip remote-resource processingprivate java.util.List<java.lang.String>supplementalModelArtifactsList of artifacts that are added to the search path when looking for supplementalModels, expressed withgroupId:artifactId:version[:type[:classifier]]format.private java.lang.String[]supplementalModelsSupplemental model data.private java.util.Map<java.lang.String,org.apache.maven.model.Model>supplementModelsMap of artifacts to supplemental project object models.private static java.lang.StringTEMPLATE_SUFFIXprotected booleanuseDefaultFilterDelimitersprivate org.apache.velocity.app.VelocityEnginevelocityprotected intvelocityFilterInMemoryThresholdWhen the result of velocity transformation fits in memory, it is compared with the actual contents on disk to eliminate unnecessary destination file overwrite.
-
Constructor Summary
Constructors Constructor Description ProcessRemoteResourcesMojo()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.Set<org.apache.maven.artifact.Artifact>aggregateProjectDependencyArtifacts()protected org.apache.velocity.VelocityContextbuildVelocityContext(java.util.Map<java.lang.String,java.lang.Object> properties)private voidconfigureLocator()protected booleancopyResourceIfExists(java.io.File file, java.lang.String relFileName, org.apache.velocity.VelocityContext context)private java.util.List<java.io.File>downloadBundles(java.util.List<java.lang.String> bundles)voidexecute()private voidfileWriteIfDiffers(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 java.lang.StringgenerateSupplementMapKey(java.lang.String groupId, java.lang.String artifactId)private java.lang.StringgetLocationTemp(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.ReadergetReader(java.io.File source)protected org.apache.maven.model.ModelgetSupplement(org.codehaus.plexus.util.xml.Xpp3Dom supplementModelXml)private java.io.WritergetWriter(java.io.OutputStream os)private java.io.WritergetWriter(RemoteResourcesBundle bundle, java.io.File f)voidinit(org.apache.velocity.runtime.RuntimeServices rs)private java.lang.ClassLoaderinitalizeClassloader(java.util.List<java.io.File> artifacts)booleanisLevelEnabled(int level)private java.util.Map<java.lang.String,org.apache.maven.model.Model>loadSupplements(java.lang.String[] models)voidlog(int level, java.lang.String message)voidlog(int level, java.lang.String message, java.lang.Throwable t)protected org.apache.maven.model.ModelmergeModels(org.apache.maven.model.Model parent, org.apache.maven.model.Model child)protected voidprocessResourceBundles(java.lang.ClassLoader classLoader, org.apache.velocity.VelocityContext context)private java.util.Set<org.apache.maven.artifact.Artifact>resolveProjectArtifacts()private org.apache.maven.shared.filtering.MavenFileFilterRequestsetupRequest(org.apache.maven.model.Resource resource, java.io.File source, java.io.File file)protected voidvalidate()
-
-
-
Field Detail
-
TEMPLATE_SUFFIX
private static final java.lang.String TEMPLATE_SUFFIX
- See Also:
- Constant Field Values
-
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
-
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 java.io.File basedirUsed for calculation of execution-root forrunOnlyAtExecutionRoot.
-
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") protected java.lang.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 java.util.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 java.io.File outputDirectoryThe directory where processed resources will be placed for packaging.
-
appendedResourcesDirectory
@Parameter(defaultValue="${basedir}/src/main/appended-resources") private java.io.File appendedResourcesDirectoryThe 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 withgroupId:artifactId:version[:type[:classifier]]format.- Since:
- 1.1
-
supplementModels
private java.util.Map<java.lang.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 java.util.List<java.lang.String> 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
@Parameter private java.util.Map<java.lang.String,java.lang.Object> 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 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 java.util.List<org.apache.maven.model.Resource> resourcesThe list of resources defined for the project.
-
artifactResolver
@Component private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver
Artifact Resolver, needed to resolve and download theresourceBundles.
-
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 mavenSessionThe 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 java.lang.String includeScopeScope to include. An Empty string indicates all scopes (default is "runtime").- Since:
- 1.0
-
excludeScope
@Parameter(property="excludeScope", defaultValue="") protected java.lang.String excludeScopeScope to exclude. An Empty string indicates no scopes (default).- Since:
- 1.0
-
resolveScopes
@Parameter private 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 excludeArtifactIdsComma separated list of Artifact names too exclude.- Since:
- 1.0
-
includeArtifactIds
@Parameter(property="includeArtifactIds", defaultValue="") protected java.lang.String includeArtifactIdsComma separated list of Artifact names to include.- Since:
- 1.0
-
excludeGroupIds
@Parameter(property="excludeGroupIds", defaultValue="") protected java.lang.String excludeGroupIdsComma separated list of GroupId Names to exclude.- Since:
- 1.0
-
includeGroupIds
@Parameter(property="includeGroupIds", defaultValue="") protected java.lang.String includeGroupIdsComma 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
@Parameter(defaultValue="${project.build.outputTimestamp}") private java.lang.String outputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor 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 java.lang.String KEY_PROJECTS
- See Also:
- Constant Field Values
-
KEY_PROJECTS_ORGS
private static final java.lang.String KEY_PROJECTS_ORGS
- See Also:
- Constant Field Values
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Specified by:
executein 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
protected java.util.List<org.apache.maven.project.MavenProject> getProjects()
-
resolveProjectArtifacts
private java.util.Set<org.apache.maven.artifact.Artifact> resolveProjectArtifacts()
-
aggregateProjectDependencyArtifacts
private java.util.Set<org.apache.maven.artifact.Artifact> aggregateProjectDependencyArtifacts()
-
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 file, java.lang.String relFileName, org.apache.velocity.VelocityContext context) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException- Throws:
java.io.IOExceptionorg.apache.maven.plugin.MojoExecutionException
-
getReader
private java.io.Reader getReader(java.io.File source) throws java.io.IOException- Throws:
java.io.IOException
-
getWriter
private java.io.Writer getWriter(java.io.OutputStream os) throws java.io.IOException- Throws:
java.io.IOException
-
fileWriteIfDiffers
private void fileWriteIfDiffers(org.apache.commons.io.output.DeferredFileOutputStream outStream) throws java.io.IOExceptionIf 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:
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(java.util.Map<java.lang.String,java.lang.Object> properties) throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
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
-
getWriter
private java.io.Writer getWriter(RemoteResourcesBundle bundle, java.io.File f) throws java.io.IOException, java.io.UnsupportedEncodingException, java.io.FileNotFoundException
- Throws:
java.io.IOExceptionjava.io.UnsupportedEncodingExceptionjava.io.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 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
-
init
public void init(org.apache.velocity.runtime.RuntimeServices rs) throws java.lang.Exception- Specified by:
initin interfaceorg.apache.velocity.runtime.log.LogChute- Throws:
java.lang.Exception
-
log
public void log(int level, java.lang.String message)- Specified by:
login interfaceorg.apache.velocity.runtime.log.LogChute
-
log
public void log(int level, java.lang.String message, java.lang.Throwable t)- Specified by:
login interfaceorg.apache.velocity.runtime.log.LogChute
-
isLevelEnabled
public boolean isLevelEnabled(int level)
- Specified by:
isLevelEnabledin interfaceorg.apache.velocity.runtime.log.LogChute
-
-