Author: jdcasey Date: Tue Sep 21 20:41:29 2010 New Revision: 999627 URL: http://svn.apache.org/viewvc?rev=999627&view=rev Log: [MASSEMBLY-435] Provide access to artifact properties for dependency artifacts and current module, for calculating both outputDirectory and outputFileNameMapping
Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/pom.xml (with props) maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/test/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/test/App.java (with props) maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/pom.xml (with props) maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/test/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/test/App.java (with props) maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/pom.xml (with props) maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/assembly/ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/assembly/bin.xml (with props) maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/pom.xml (with props) maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/verify.bsh (with props) Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/pom.xml?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/pom.xml (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/pom.xml Tue Sep 21 20:41:29 2010 @@ -0,0 +1,9 @@ +<?xml version="1.0"?><project> + <parent> + <artifactId>parent</artifactId> + <groupId>test</groupId> + <version>1</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>child1</artifactId> +</project> Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/test/App.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/test/App.java?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/test/App.java (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/test/App.java Tue Sep 21 20:41:29 2010 @@ -0,0 +1,13 @@ +package test; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child1/src/main/java/test/App.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/pom.xml?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/pom.xml (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/pom.xml Tue Sep 21 20:41:29 2010 @@ -0,0 +1,13 @@ +<?xml version='1.0'?> +<project> + <parent> + <artifactId>parent</artifactId> + <groupId>test</groupId> + <version>1</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>child2</artifactId> + <version>2</version> + +</project> + Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/test/App.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/test/App.java?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/test/App.java (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/test/App.java Tue Sep 21 20:41:29 2010 @@ -0,0 +1,13 @@ +package test; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child2/src/main/java/test/App.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/pom.xml?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/pom.xml (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/pom.xml Tue Sep 21 20:41:29 2010 @@ -0,0 +1,54 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>test</groupId> + <artifactId>parent</artifactId> + <version>1</version> + </parent> + + <artifactId>child3</artifactId> + + <name>DependencySet::By-Version</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>test</groupId> + <artifactId>child1</artifactId> + <version>1</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>test</groupId> + <artifactId>child2</artifactId> + <version>2</version> + <scope>runtime</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptors> + <descriptor>src/main/assembly/bin.xml</descriptor> + </descriptors> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/assembly/bin.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/assembly/bin.xml?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/assembly/bin.xml (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/assembly/bin.xml Tue Sep 21 20:41:29 2010 @@ -0,0 +1,14 @@ +<assembly> + <id>bin</id> + <formats> + <format>dir</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <dependencySets> + <dependencySet> + <scope>runtime</scope> + <useProjectArtifact>false</useProjectArtifact> + <outputDirectory>${artifact.baseVersion}</outputDirectory> + </dependencySet> + </dependencySets> +</assembly> \ No newline at end of file Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/child3/src/main/assembly/bin.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/pom.xml?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/pom.xml (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/pom.xml Tue Sep 21 20:41:29 2010 @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.plugin.assembly.test</groupId> + <artifactId>it-project-parent</artifactId> + <version>1</version> + </parent> + + <groupId>test</groupId> + <artifactId>parent</artifactId> + <packaging>pom</packaging> + <version>1</version> + + <modules> + <module>child1</module> + <module>child2</module> + <module>child3</module> + </modules> +</project> Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/verify.bsh?rev=999627&view=auto ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/verify.bsh (added) +++ maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/verify.bsh Tue Sep 21 20:41:29 2010 @@ -0,0 +1,28 @@ +import java.io.*; + +try +{ + File dir = new File( basedir, "child3/target/child3-1-bin" ); + + File f = new File( dir, "1/child1-1.jar" ); + if ( !f.exists() || !f.isFile() ) + { + System.out.println( "Could not find dependency file: " + f ); + return false; + } + + f = new File( dir, "2/child2-2.jar" ); + if ( !f.exists() || !f.isFile() ) + { + System.out.println( "Could not find dependency file: " + f ); + return false; + } + + return true; +} +catch( IOException e ) +{ + e.printStackTrace(); +} + +return false; Propchange: maven/plugins/trunk/maven-assembly-plugin/src/it/projects/dependency-sets/depSet-byDepVersion/verify.bsh ------------------------------------------------------------------------------ svn:eol-style = native Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java?rev=999627&r1=999626&r2=999627&view=diff ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java (original) +++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddDependencySetsTask.java Tue Sep 21 20:41:29 2010 @@ -361,7 +361,10 @@ public class AddDependencySetsTask model.setDescription( "Stub for " + depArtifact.getId() ); - return new MavenProject( model ); + final MavenProject project = new MavenProject( model ); + project.setArtifact( depArtifact ); + + return project; } protected Set<Artifact> resolveDependencyArtifacts( final DependencySet dependencySet ) Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java?rev=999627&r1=999626&r2=999627&view=diff ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java (original) +++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java Tue Sep 21 20:41:29 2010 @@ -19,10 +19,6 @@ package org.apache.maven.plugin.assembly * under the License. */ -import java.io.IOException; -import java.util.Collections; -import java.util.Properties; - import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.assembly.AssemblerConfigurationSource; @@ -36,27 +32,31 @@ import org.codehaus.plexus.interpolation import org.codehaus.plexus.interpolation.StringSearchInterpolator; import org.codehaus.plexus.util.StringUtils; +import java.io.IOException; +import java.util.Collections; +import java.util.Properties; + /** * @version $Id$ */ public final class AssemblyFormatUtils { - + private AssemblyFormatUtils() { } /** * Get the full name of the distribution artifact - * + * * @param assembly * @return the distribution name */ - public static String getDistributionName( Assembly assembly, AssemblerConfigurationSource configSource ) + public static String getDistributionName( final Assembly assembly, final AssemblerConfigurationSource configSource ) { - String finalName = configSource.getFinalName(); - boolean appendAssemblyId = configSource.isAssemblyIdAppended(); - String classifier = configSource.getClassifier(); + final String finalName = configSource.getFinalName(); + final boolean appendAssemblyId = configSource.isAssemblyIdAppended(); + final String classifier = configSource.getClassifier(); String distributionName = finalName; if ( appendAssemblyId ) @@ -75,18 +75,21 @@ public final class AssemblyFormatUtils } /** - * @deprecated Use {...@link AssemblyFormatUtils#getOutputDirectory(String, MavenProject, MavenProject, String, AssemblerConfigurationSource)} - * instead. + * @deprecated Use + * {...@link AssemblyFormatUtils#getOutputDirectory(String, MavenProject, MavenProject, String, AssemblerConfigurationSource)} + * instead. */ - public static String getOutputDirectory( String output, MavenProject mainProject, MavenProject artifactProject, - String finalName ) + @Deprecated + public static String getOutputDirectory( final String output, final MavenProject mainProject, + final MavenProject artifactProject, final String finalName ) throws AssemblyFormattingException { return getOutputDirectory( output, mainProject, null, artifactProject, finalName, null ); } - public static String getOutputDirectory( String output, MavenProject mainProject, MavenProject artifactProject, - String finalName, AssemblerConfigurationSource configSource ) + public static String getOutputDirectory( final String output, final MavenProject mainProject, + final MavenProject artifactProject, final String finalName, + final AssemblerConfigurationSource configSource ) throws AssemblyFormattingException { return getOutputDirectory( output, mainProject, null, artifactProject, finalName, configSource ); @@ -95,28 +98,32 @@ public final class AssemblyFormatUtils /** * ORDER OF INTERPOLATION PRECEDENCE: * <ol> - * <li> Support for special expressions, like ${finalName} (use the assembly plugin configuration not the build config)</li> - * <li> prefixed with "module." if moduleProject is non-null - * <ol><li>MavenProject instance for module being assembled</li></ol> + * <li>Support for special expressions, like ${finalName} (use the assembly plugin configuration not the build + * config)</li> + * <li>prefixed with "module." if moduleProject is non-null + * <ol> + * <li>MavenProject instance for module being assembled</li> + * </ol> * </li> * <li>prefixed with "artifact." if artifactProject is non-null - * <ol><li>MavenProject instance for artifact</li></ol> + * <ol> + * <li>MavenProject instance for artifact</li> + * </ol> * </li> * <li>user-defined properties from the command line</li> * <li>prefixed with "pom." or "project.", or no prefix at all - * <ol><li>MavenProject instance from current build</li></ol> + * <ol> + * <li>MavenProject instance from current build</li> + * </ol> * </li> * <li>properties from main project</li> * <li>system properties, from the MavenSession instance (to support IDEs)</li> * <li>environment variables.</li> * </ol> */ - public static String getOutputDirectory( String output, - MavenProject mainProject, - MavenProject moduleProject, - MavenProject artifactProject, - String finalName, - AssemblerConfigurationSource configSource ) + public static String getOutputDirectory( final String output, final MavenProject mainProject, + final MavenProject moduleProject, final MavenProject artifactProject, + final String finalName, final AssemblerConfigurationSource configSource ) throws AssemblyFormattingException { String value = output; @@ -125,9 +132,9 @@ public final class AssemblyFormatUtils value = ""; } - StringSearchInterpolator interpolator = new StringSearchInterpolator(); + final StringSearchInterpolator interpolator = new StringSearchInterpolator(); - Properties specialExpressionOverrides = new Properties(); + final Properties specialExpressionOverrides = new Properties(); if ( finalName != null ) { @@ -137,21 +144,29 @@ public final class AssemblyFormatUtils // 1 interpolator.addValueSource( new PropertiesBasedValueSource( specialExpressionOverrides ) ); - + if ( moduleProject != null ) { // 2 interpolator.addValueSource( new PrefixedObjectValueSource( "module.", moduleProject ) ); + if ( moduleProject.getArtifact() != null ) + { + interpolator.addValueSource( new PrefixedObjectValueSource( "module.", moduleProject.getArtifact() ) ); + } } if ( artifactProject != null ) { // 3 interpolator.addValueSource( new PrefixedObjectValueSource( "artifact.", artifactProject ) ); + if ( artifactProject.getArtifact() != null ) + { + interpolator.addValueSource( new PrefixedObjectValueSource( "artifact.", artifactProject.getArtifact() ) ); + } } MavenSession session = null; - + if ( configSource != null ) { session = configSource.getMavenSession(); @@ -163,11 +178,11 @@ public final class AssemblyFormatUtils { userProperties = session.getExecutionProperties(); } - catch ( NoSuchMethodError nsmer ) + catch ( final NoSuchMethodError nsmer ) { // OK, so user is using Maven <= 2.0.8. No big deal. } - + if ( userProperties != null ) { // 4 @@ -175,14 +190,17 @@ public final class AssemblyFormatUtils } } } - + if ( mainProject != null ) { // 5 - interpolator.addValueSource( new PrefixedObjectValueSource( InterpolationConstants.PROJECT_PREFIXES, mainProject, true ) ); - + interpolator.addValueSource( new PrefixedObjectValueSource( InterpolationConstants.PROJECT_PREFIXES, + mainProject, true ) ); + // 6 - interpolator.addValueSource( new PrefixedPropertiesValueSource( InterpolationConstants.PROJECT_PROPERTIES_PREFIXES, mainProject.getProperties(), true ) ); + interpolator.addValueSource( new PrefixedPropertiesValueSource( + InterpolationConstants.PROJECT_PROPERTIES_PREFIXES, + mainProject.getProperties(), true ) ); } Properties commandLineProperties = System.getProperties(); @@ -194,31 +212,35 @@ public final class AssemblyFormatUtils } } - catch ( NoSuchMethodError nsmer ) + catch ( final NoSuchMethodError nsmer ) { // OK, so user is using Maven <= 2.0.8. No big deal. } - + // 7 interpolator.addValueSource( new PropertiesBasedValueSource( commandLineProperties ) ); try { // 8 - interpolator.addValueSource( new PrefixedPropertiesValueSource( Collections.singletonList( "env." ), CommandLineUtils.getSystemEnvVars( false ), true ) ); + interpolator.addValueSource( new PrefixedPropertiesValueSource( Collections.singletonList( "env." ), + CommandLineUtils.getSystemEnvVars( false ), + true ) ); } - catch ( IOException e ) + catch ( final IOException e ) { - throw new AssemblyFormattingException( "Failed to retrieve OS environment variables. Reason: " + e.getMessage(), e ); + throw new AssemblyFormattingException( "Failed to retrieve OS environment variables. Reason: " + + e.getMessage(), e ); } try { value = interpolator.interpolate( value ); } - catch ( InterpolationException e ) + catch ( final InterpolationException e ) { - throw new AssemblyFormattingException( "Failed to interpolate output directory. Reason: " + e.getMessage(), e ); + throw new AssemblyFormattingException( "Failed to interpolate output directory. Reason: " + e.getMessage(), + e ); } if ( ( value.length() > 0 ) && !value.endsWith( "/" ) && !value.endsWith( "\\" ) ) @@ -230,7 +252,7 @@ public final class AssemblyFormatUtils { value = value.substring( 1 ); } - + value = StringUtils.replace( value, "//", "/" ); value = StringUtils.replace( value, "\\\\", "\\" ); value = StringUtils.replace( value, "./", "" ); @@ -240,19 +262,21 @@ public final class AssemblyFormatUtils } /** - * @deprecated Use {...@link AssemblyFormatUtils#evaluateFileNameMapping(String, Artifact, MavenProject, MavenProject, AssemblerConfigurationSource)} - * instead. + * @deprecated Use + * {...@link AssemblyFormatUtils#evaluateFileNameMapping(String, Artifact, MavenProject, MavenProject, AssemblerConfigurationSource)} + * instead. */ - public static String evaluateFileNameMapping( String expression, Artifact artifact, MavenProject mainProject, - MavenProject artifactProject ) + @Deprecated + public static String evaluateFileNameMapping( final String expression, final Artifact artifact, + final MavenProject mainProject, final MavenProject artifactProject ) throws AssemblyFormattingException { return evaluateFileNameMapping( expression, artifact, mainProject, null, null, artifactProject, null ); } - public static String evaluateFileNameMapping( String expression, Artifact artifact, MavenProject mainProject, - MavenProject artifactProject, - AssemblerConfigurationSource configSource ) + public static String evaluateFileNameMapping( final String expression, final Artifact artifact, + final MavenProject mainProject, final MavenProject artifactProject, + final AssemblerConfigurationSource configSource ) throws AssemblyFormattingException { return evaluateFileNameMapping( expression, artifact, mainProject, null, null, artifactProject, configSource ); @@ -262,24 +286,28 @@ public final class AssemblyFormatUtils * ORDER OF INTERPOLATION PRECEDENCE: * <ol> * <li>prefixed with "module.", if moduleProject != null - * <ol> - * <li>Artifact instance for module, if moduleArtifact != null</li> - * <li>ArtifactHandler instance for module, if moduleArtifact != null</li> - * <li>MavenProject instance for module</li> - * </ol> + * <ol> + * <li>Artifact instance for module, if moduleArtifact != null</li> + * <li>ArtifactHandler instance for module, if moduleArtifact != null</li> + * <li>MavenProject instance for module</li> + * </ol> * </li> * <li>prefixed with "artifact." - * <ol> - * <li>Artifact instance</li> - * <li>ArtifactHandler instance for artifact</li> - * <li>MavenProject instance for artifact</li> - * </ol> + * <ol> + * <li>Artifact instance</li> + * <li>ArtifactHandler instance for artifact</li> + * <li>MavenProject instance for artifact</li> + * </ol> * </li> * <li>prefixed with "pom." or "project." - * <ol><li>MavenProject instance from current build</li></ol> + * <ol> + * <li>MavenProject instance from current build</li> + * </ol> * </li> * <li>no prefix, using main project instance - * <ol><li>MavenProject instance from current build</li></ol> + * <ol> + * <li>MavenProject instance from current build</li> + * </ol> * </li> * <li>Support for special expressions, like ${dashClassifier?}</li> * <li>user-defined properties from the command line</li> @@ -288,11 +316,10 @@ public final class AssemblyFormatUtils * <li>environment variables.</li> * </ol> */ - public static String evaluateFileNameMapping( String expression, Artifact artifact, MavenProject mainProject, - MavenProject moduleProject, - Artifact moduleArtifact, - MavenProject artifactProject, - AssemblerConfigurationSource configSource ) + public static String evaluateFileNameMapping( final String expression, final Artifact artifact, + final MavenProject mainProject, final MavenProject moduleProject, + final Artifact moduleArtifact, final MavenProject artifactProject, + final AssemblerConfigurationSource configSource ) throws AssemblyFormattingException { String value = expression; @@ -301,22 +328,27 @@ public final class AssemblyFormatUtils // [jdcasey; 16-Aug-1007] This is fixed in SVN, just waiting for it to pass out of legacy. artifact.isSnapshot(); - StringSearchInterpolator interpolator = new StringSearchInterpolator(); + final StringSearchInterpolator interpolator = new StringSearchInterpolator(); if ( moduleArtifact != null ) { // 1A interpolator.addValueSource( new PrefixedObjectValueSource( "module.", moduleArtifact ) ); - + // 1B interpolator.addValueSource( new PrefixedObjectValueSource( "module.", moduleArtifact.getArtifactHandler() ) ); - interpolator.addValueSource( new PrefixedObjectValueSource( "module.handler.", moduleArtifact.getArtifactHandler() ) ); + interpolator.addValueSource( new PrefixedObjectValueSource( "module.handler.", + moduleArtifact.getArtifactHandler() ) ); } - + // 1C if ( moduleProject != null ) { interpolator.addValueSource( new PrefixedObjectValueSource( "module.", moduleProject ) ); + if ( moduleProject.getArtifact() != null ) + { + interpolator.addValueSource( new PrefixedObjectValueSource( "module.", moduleProject.getArtifact() ) ); + } } // 2A @@ -330,22 +362,27 @@ public final class AssemblyFormatUtils if ( artifactProject != null ) { interpolator.addValueSource( new PrefixedObjectValueSource( "artifact.", artifactProject ) ); + if ( artifactProject.getArtifact() != null ) + { + interpolator.addValueSource( new PrefixedObjectValueSource( "artifact.", artifactProject.getArtifact() ) ); + } } if ( mainProject != null ) { // 3 // 4 - interpolator.addValueSource( new PrefixedObjectValueSource( InterpolationConstants.PROJECT_PREFIXES, mainProject, true ) ); + interpolator.addValueSource( new PrefixedObjectValueSource( InterpolationConstants.PROJECT_PREFIXES, + mainProject, true ) ); } - Properties specialRules = new Properties(); + final Properties specialRules = new Properties(); - String classifier = artifact.getClassifier(); + final String classifier = artifact.getClassifier(); if ( classifier != null ) { - specialRules.setProperty( "dashClassifier?", "-" + classifier ); - specialRules.setProperty( "dashClassifier", "-" + classifier ); + specialRules.setProperty( "dashClassifier?", "-" + classifier ); + specialRules.setProperty( "dashClassifier", "-" + classifier ); } else { @@ -368,11 +405,11 @@ public final class AssemblyFormatUtils { userProperties = session.getExecutionProperties(); } - catch ( NoSuchMethodError nsmer ) + catch ( final NoSuchMethodError nsmer ) { // OK, so user is using Maven <= 2.0.8. No big deal. } - + if ( userProperties != null ) { // 6 @@ -380,11 +417,13 @@ public final class AssemblyFormatUtils } } } - + if ( mainProject != null ) { // 7 - interpolator.addValueSource( new PrefixedPropertiesValueSource( InterpolationConstants.PROJECT_PROPERTIES_PREFIXES, mainProject.getProperties(), true ) ); + interpolator.addValueSource( new PrefixedPropertiesValueSource( + InterpolationConstants.PROJECT_PROPERTIES_PREFIXES, + mainProject.getProperties(), true ) ); } Properties commandLineProperties = System.getProperties(); @@ -396,38 +435,42 @@ public final class AssemblyFormatUtils } } - catch ( NoSuchMethodError nsmer ) + catch ( final NoSuchMethodError nsmer ) { // OK, so user is using Maven <= 2.0.8. No big deal. } - + // 8 interpolator.addValueSource( new PropertiesBasedValueSource( commandLineProperties ) ); try { // 9 - interpolator.addValueSource( new PrefixedPropertiesValueSource( Collections.singletonList( "env." ), CommandLineUtils.getSystemEnvVars( false ), true ) ); + interpolator.addValueSource( new PrefixedPropertiesValueSource( Collections.singletonList( "env." ), + CommandLineUtils.getSystemEnvVars( false ), + true ) ); } - catch ( IOException e ) + catch ( final IOException e ) { - throw new AssemblyFormattingException( "Failed to retrieve OS environment variables. Reason: " + e.getMessage(), e ); + throw new AssemblyFormattingException( "Failed to retrieve OS environment variables. Reason: " + + e.getMessage(), e ); } try { value = interpolator.interpolate( value ); } - catch ( InterpolationException e ) + catch ( final InterpolationException e ) { - throw new AssemblyFormattingException( "Failed to interpolate output filename mapping. Reason: " + e.getMessage(), e ); + throw new AssemblyFormattingException( "Failed to interpolate output filename mapping. Reason: " + + e.getMessage(), e ); } value = StringUtils.replace( value, "//", "/" ); value = StringUtils.replace( value, "\\\\", "\\" ); value = StringUtils.replace( value, "./", "" ); value = StringUtils.replace( value, ".\\", "" ); - + return value; }