Details
-
Wish
-
Status: Closed
-
Major
-
Resolution: Implemented
-
2.2-beta-4
-
None
-
None
-
Patch
Description
Please support parametrization of component descriptors. One should be able to specify parameter placeholders in component descriptors, and when referencing component descriptor from an assembly descriptor provide actual parameter value(s) which would then be applied to the parameter placeholders. One should be able to set global parameters (for all component descriptors), and component descriptor specific parameters, with component descriptor specific parameters overriding global ones if their names overlap.
This would be useful if e.g. one uses assembly descriptors to specify assemblies for different deployment environments, and if these assemblies differ (see example [1]) only in which environment specific configuration file should be included in the assembly where this distinction is based on configuration file name suffix - this suffix could be passed to shared component descriptor as parameter, like in example [2].
[1] assembly descriptor example without parameters
<?xml version="1.0" encoding="UTF-8"?> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"> <id>prod</id> <formats> <format>war</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.build.directory}/${project.build.finalName}</directory> <outputDirectory>/</outputDirectory> <excludes> <exclude>**/jdbc.properties</exclude> <exclude>**/jdbc-*.properties</exclude> </excludes> <excludes> <exclude>**/log4j.xml</exclude> <exclude>**/log4j-*.xml</exclude> </excludes> </fileSet> </fileSets> <files> <file> <source>${project.build.outputDirectory}/com/foo/bar/cfg/jdbc-${environment}.properties</source> <outputDirectory>WEB-INF/classes/com/foo/bar/cfg/</outputDirectory> <destName>jdbc.properties</destName> </file> <file> <source>${project.build.outputDirectory}/com/foo/bar/cfg/log4j-${environment}.xml</source> <outputDirectory>WEB-INF/classes/</outputDirectory> <destName>log4j.xml</destName> </file> </files> </assembly>
[2] parametrized component descriptor and usage example
src/main/assembly/component.xml
<component> <fileSets> <fileSet> <directory>${project.build.directory}/${project.build.finalName}</directory> <outputDirectory>/</outputDirectory> <excludes> <exclude>**/jdbc.properties</exclude> <exclude>**/jdbc-*.properties</exclude> </excludes> <excludes> <exclude>**/log4j.xml</exclude> <exclude>**/log4j-*.xml</exclude> </excludes> </fileSet> </fileSets> <files> <file> <source>${project.build.outputDirectory}/com/foo/bar/cfg/jdbc-${environment}.properties</source> <outputDirectory>WEB-INF/classes/com/foo/bar/cfg/</outputDirectory> <destName>jdbc.properties</destName> </file> <file> <source>${project.build.outputDirectory}/com/foo/bar/cfg/log4j-${environment}.xml</source> <outputDirectory>WEB-INF/classes/</outputDirectory> <destName>log4j.xml</destName> </file> </files> </component>
src/main/assembly/packaging-prod.xml
<?xml version="1.0" encoding="UTF-8"?> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"> <id>prod</id> <formats> <format>war</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <componentDescriptors> <componentDescriptor> <pathToComponentDescriptor>src/main/assembly/component.xml</pathToComponentDescriptor> <parameters> <parameter> <name>environment</environment> <value>prod</value> </parameter> </parameters </componentDescriptor> </componentDescriptors> </assembly>
src/main/assembly/packaging-stag.xml
<?xml version="1.0" encoding="UTF-8"?> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"> <id>stag</id> <formats> <format>war</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <componentDescriptors> <componentDescriptor> <pathToComponentDescriptor>src/main/assembly/component.xml</pathToComponentDescriptor> <parameters> <!-- component descriptor specific parameters --> <parameter> <name>environment</environment> <value>stag</value> </parameter> </parameters> </componentDescriptor> </parameters> <!-- global parameters for all component descriptors --> </parameters> </componentDescriptors> </assembly>