Author: epunzalan Date: Tue Mar 21 01:22:26 2006 New Revision: 387467 URL: http://svn.apache.org/viewcvs?rev=387467&view=rev Log: PR: MASSEMBLY-29
Added <modules> in assembly descriptor so that the user can specify which module(s) files to include/exclude in the archive. Modules are added into the archive with their dir structure preserved Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java?rev=387467&r1=387466&r2=387467&view=diff ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java (original) +++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java Tue Mar 21 01:22:26 2006 @@ -36,7 +36,9 @@ import org.apache.maven.plugins.assembly.model.FileSet; import org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader; import org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader; +import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.wagon.PathUtils; import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; @@ -178,6 +180,13 @@ */ protected boolean appendAssemblyId; + /** + * @parameter expression="${reactorProjects}" + * @required + * @readonly + */ + private List reactorProjects; + private ComponentsXmlArchiverFileFilter componentsXmlFilter = new ComponentsXmlArchiverFileFilter(); /** @@ -291,6 +300,7 @@ throws ArchiverException, IOException, MojoExecutionException, MojoFailureException, XmlPullParserException { processDependencySets( archiver, assembly.getDependencySets(), assembly.isIncludeBaseDirectory() ); + processModules( archiver, assembly.getModules(), assembly.isIncludeBaseDirectory() ); processFileSets( archiver, assembly.getFileSets(), assembly.isIncludeBaseDirectory() ); processFileList( archiver, assembly.getFiles(), assembly.isIncludeBaseDirectory() ); @@ -329,6 +339,69 @@ archiver.createArchive(); return destFile; + } + + private void processModules( Archiver archiver, List modulesList, boolean includeBaseDirectory ) + throws IOException, ArchiverException, XmlPullParserException + { + if ( reactorProjects != null ) + { + List moduleFileSets = new ArrayList(); + + for ( Iterator modules = modulesList.iterator(); modules.hasNext(); ) + { + String module = (String) modules.next(); + + MavenProject reactorProject = getModuleFromReactor( module ); + + if ( reactorProject != null ) + { + FileSet moduleFileSet = new FileSet(); + + moduleFileSet.setDirectory( reactorProject.getBasedir().getAbsolutePath() ); + moduleFileSet.setOutputDirectory( module ); + + List excludesList = new ArrayList(); + excludesList.add( PathUtils.toRelative( reactorProject.getBasedir(), reactorProject.getBuild().getDirectory() ) + "/**" ); + excludesList.add( PathUtils.toRelative( reactorProject.getBasedir(), reactorProject.getBuild().getOutputDirectory() ) + "/**" ); + excludesList.add( PathUtils.toRelative( reactorProject.getBasedir(), reactorProject.getBuild().getTestOutputDirectory() ) + "/**" ); + excludesList.add( PathUtils.toRelative( reactorProject.getBasedir(), reactorProject.getReporting().getOutputDirectory() ) + "/**" ); + moduleFileSet.setExcludes( excludesList ); + + moduleFileSets.add( moduleFileSet ); + } + } + + processFileSets( archiver, moduleFileSets, includeBaseDirectory ); + } + } + + private MavenProject getModuleFromReactor( String module ) + { + MavenProject reactorProject = null; + + if ( reactorProjects != null ) + { + File executedProjectDir = getExecutedProject().getFile().getParentFile(); + File moduleDir = new File( executedProjectDir, module ); + String modulePath = moduleDir.getAbsolutePath(); + + for ( Iterator projects = reactorProjects.iterator(); projects.hasNext(); ) + { + MavenProject project = (MavenProject) projects.next(); + + String projectPath = project.getFile().getParentFile().getAbsolutePath(); + + if ( modulePath.equals( projectPath ) ) + { + reactorProject = project; + + break; + } + } + } + + return reactorProject; } protected List readAssemblies() Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo?rev=387467&r1=387466&r2=387467&view=diff ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo (original) +++ maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo Tue Mar 21 01:22:26 2006 @@ -92,6 +92,17 @@ <defaultValue>false</defaultValue> </field> <field> + <name>modules</name> + <version>1.0.0</version> + <association> + <type>String</type> + <multiplicity>*</multiplicity> + </association> + <description> + Specify which modules source files to include in the assembly + </description> + </field> + <field> <name>fileSets</name> <version>1.0.0</version> <association> @@ -99,7 +110,7 @@ <multiplicity>*</multiplicity> </association> <description> - Specify assembly parameters for groups of files. + Specify assembly parameters for groups of files. </description> </field> <field> @@ -136,12 +147,12 @@ File relative to basedir containing Component. </description> </field> - - + + </fields> </class> - - + + <class> <name>SetBase</name> <version>1.0.0</version> @@ -193,8 +204,8 @@ <![CDATA[ Similar to a UNIX permission. Format: (User)(Group)(Other) where each component is a sum of Read = 4, Write = 2, and Execute = 1. For example, - the default value of 0644 translates to User read-write, Group and Other - read-only. + the default value of 0644 translates to User read-write, Group and Other + read-only. <a href="http://www.onlamp.com/pub/a/bsd/2000/09/06/FreeBSD_Basics.html">(more on unix-style permissions)</a> ]]> </description> @@ -208,8 +219,8 @@ <![CDATA[ Similar to a UNIX permission. Format: (User)(Group)(Other) where each component is a sum of Read = 4, Write = 2, and Execute = 1. For example, - the default value of 0644 translates to User read-write, Group and Other - read-only. + the default value of 0644 translates to User read-write, Group and Other + read-only. <a href="http://www.onlamp.com/pub/a/bsd/2000/09/06/FreeBSD_Basics.html">(more on unix-style permissions)</a> ]]> </description> @@ -239,7 +250,7 @@ <description> <![CDATA[ Controls the line-endings of files in this fileSet. - Valid values: + Valid values: <ul> <li><b>"keep"</b> - Preserve all line endings</li> <li><b>"unix"</b> - Use Unix-style line endings</li>