Author: carlos Date: Thu Jan 19 18:08:36 2006 New Revision: 370694 URL: http://svn.apache.org/viewcvs?rev=370694&view=rev Log: Applied patches from 2.1 PR: MASSEMBLY-25
Modified: maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/mdo/descriptor.mdo Modified: maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java URL: http://svn.apache.org/viewcvs/maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java?rev=370694&r1=370693&r2=370694&view=diff ============================================================================== --- maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java (original) +++ maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java Thu Jan 19 18:08:36 2006 @@ -26,8 +26,11 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -77,9 +80,25 @@ extends AbstractUnpackingMojo { /** + * A list of descriptor files to generate from. + * + * @parameter + */ + private File[] descriptors; + + /** + * A list of built-in descriptor references to generate from. You can select from <code>bin</code>, + * <code>jar-with-dependencies</code>, or <code>src</code>. + * + * @parameter + */ + private String[] descriptorRefs; + + /** * Predefined Assembly Descriptor Id's. You can select bin, jar-with-dependencies, or src. * * @parameter expression="${descriptorId}" + * @deprecated Please use descriptorRefs instead */ protected String descriptorId; @@ -87,6 +106,7 @@ * Assembly XML Descriptor file. This must be the path to your customized descriptor file. * * @parameter expression="${descriptor}" + * @deprecated Please use descriptors instead */ protected File descriptor; @@ -136,6 +156,7 @@ * Set to true to include the site generated by site:site goal. * * @parameter expression="${includeSite}" default-value="false" + * @deprecated Please set this variable in the assembly descriptor instead */ private boolean includeSite; @@ -152,12 +173,22 @@ public void execute() throws MojoExecutionException, MojoFailureException { - Assembly assembly = readAssembly(); + List assemblies = readAssemblies(); // TODO: include dependencies marked for distribution under certain formats // TODO: how, might we plug this into an installer, such as NSIS? // TODO: allow file mode specifications? + for ( Iterator i = assemblies.iterator(); i.hasNext(); ) + { + Assembly assembly = (Assembly) i.next(); + createAssembly( assembly ); + } + } + + private void createAssembly( Assembly assembly ) + throws MojoExecutionException, MojoFailureException + { String fullName = finalName + "-" + assembly.getId(); for ( Iterator i = assembly.getFormats().iterator(); i.hasNext(); ) @@ -232,41 +263,91 @@ return destFile; } - protected Assembly readAssembly() + protected List readAssemblies() throws MojoFailureException, MojoExecutionException { - Reader r; + List assemblies = new ArrayList(); if ( descriptor != null ) { - try + assemblies.add( getAssembly( descriptor ) ); + } + + if ( descriptorId != null ) + { + assemblies.add( getAssembly( descriptorId ) ); + } + + if ( descriptors != null && descriptors.length > 0 ) + { + for ( int i = 0; i < descriptors.length; i++ ) { - r = new FileReader( descriptor ); + assemblies.add( getAssembly( descriptors[i] ) ); } - catch ( FileNotFoundException e ) + } + + if ( descriptorRefs != null && descriptorRefs.length > 0 ) + { + for ( int i = 0; i < descriptorRefs.length; i++ ) { - throw new MojoFailureException( "Unable to find descriptor: " + e.getMessage() ); + assemblies.add( getAssembly( descriptorRefs[i] ) ); } } - else if ( descriptorId != null ) + + if ( assemblies.isEmpty() ) { - InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" ); - if ( resourceAsStream == null ) + throw new MojoFailureException( "No assembly descriptors found." ); + } + + // check unique IDs + Set ids = new HashSet(); + for ( Iterator i = assemblies.iterator(); i.hasNext(); ) + { + Assembly assembly = (Assembly) i.next(); + if ( !ids.add( assembly.getId() ) ) { - throw new MojoFailureException( "Descriptor with ID '" + descriptorId + "' not found" ); + throw new MojoFailureException( "The assembly id " + assembly.getId() + " is used more than once." ); } - r = new InputStreamReader( resourceAsStream ); + } - else + return assemblies; + } + + private Assembly getAssembly( String ref ) + throws MojoFailureException, MojoExecutionException + { + InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + ref + ".xml" ); + if ( resourceAsStream == null ) { - throw new MojoFailureException( "You must specify descriptor or descriptorId" ); + throw new MojoFailureException( "Descriptor with ID '" + ref + "' not found" ); } + return getAssembly( new InputStreamReader( resourceAsStream ) ); + } + private Assembly getAssembly( File file ) + throws MojoFailureException, MojoExecutionException +{ + Reader r; + try + { + r = new FileReader( file ); + } + catch ( FileNotFoundException e ) + { + throw new MojoFailureException( "Unable to find descriptor: " + e.getMessage() ); + } + + return getAssembly( r ); +} + +private Assembly getAssembly( Reader reader ) + throws MojoExecutionException +{ Assembly assembly; try { - AssemblyXpp3Reader reader = new AssemblyXpp3Reader(); - assembly = reader.read( r ); + AssemblyXpp3Reader r = new AssemblyXpp3Reader(); + assembly = r.read( reader ); } catch ( IOException e ) { @@ -278,10 +359,10 @@ } finally { - IOUtil.close( r ); + IOUtil.close( reader ); } - if ( includeSite ) + if ( includeSite || assembly.isIncludeSiteDirectory() ) { includeSiteInAssembly( assembly ); } Modified: maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java URL: http://svn.apache.org/viewcvs/maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java?rev=370694&r1=370693&r2=370694&view=diff ============================================================================== --- maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java (original) +++ maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java Thu Jan 19 18:08:36 2006 @@ -16,6 +16,10 @@ * limitations under the License. */ +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.assembly.archiver.DirectoryArchiver; @@ -23,8 +27,6 @@ import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.ArchiverException; -import java.io.IOException; - /** * Assemble an application bundle or distribution. * @@ -39,7 +41,17 @@ public void execute() throws MojoExecutionException, MojoFailureException { - Assembly assembly = readAssembly(); + List assemblies = readAssemblies(); + for ( Iterator i = assemblies.iterator(); i.hasNext(); ) + { + Assembly assembly = (Assembly) i.next(); + createDirectory( assembly ); + } + } + + private void createDirectory( Assembly assembly ) + throws MojoExecutionException, MojoFailureException + { String fullName = finalName + "-" + assembly.getId(); Modified: maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/mdo/descriptor.mdo URL: http://svn.apache.org/viewcvs/maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/mdo/descriptor.mdo?rev=370694&r1=370693&r2=370694&view=diff ============================================================================== --- maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/mdo/descriptor.mdo (original) +++ maven/plugins/branches/maven-assembly-plugin-2.0.x/src/main/mdo/descriptor.mdo Thu Jan 19 18:08:36 2006 @@ -37,6 +37,11 @@ <defaultValue>true</defaultValue> </field> <field> + <name>includeSiteDirectory</name> + <type>boolean</type> + <defaultValue>false</defaultValue> + </field> + <field> <name>fileSets</name> <version>1.0.0</version> <association>