diff --git a/maven-plugins/maven-assemble-plugin/build.sh b/maven-plugins/maven-assemble-plugin/build.sh index 29e03bde66..63b1975890 100755 --- a/maven-plugins/maven-assemble-plugin/build.sh +++ b/maven-plugins/maven-assemble-plugin/build.sh @@ -5,4 +5,5 @@ # m2 plugin:descriptor -m2 modello:xpp3-reader modello:xpp3-writer modello:java resources:resources compiler:compile resources:testResources compiler:testCompile surefire:test jar:jar install:install +m2 modello:xpp3-reader modello:xpp3-writer modello:java resources:resources compiler:compile resources:testResources compiler:testCompile surefire:test jar:jar +cp target/maven-assemble-plugin-1.0-SNAPSHOT.jar $HOME/repository-m2/org.apache.maven.plugins/maven-plugins diff --git a/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java b/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java index a21bc54873..2eccdd2cdc 100755 --- a/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java +++ b/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java @@ -25,9 +25,13 @@ import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.archiver.tar.TarArchiver; import org.codehaus.plexus.archiver.zip.ZipArchiver; +import org.codehaus.plexus.util.IOUtil; import java.io.File; import java.io.FileReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.Iterator; /** @@ -35,19 +39,28 @@ import java.util.Iterator; * @version $Id$ * @goal assemble * @description assemble an application bundle or distribution + * @parameter name="basedir" type="String" required="true" validator="" expression="#basedir" description="" * @parameter name="outputDirectory" type="java.io.File" required="true" validator="" expression="#project.build.directory" description="" - * @parameter name="descriptor" type="java.io.File" required="true" validator="" expression="#maven.assemble.descriptor" description="" + * @parameter name="descriptor" type="java.io.File" required="false" validator="" expression="#maven.assemble.descriptor" description="" * @parameter name="finalName" type="String" required="true" validator="" expression="#project.build.finalName" description="" + * @parameter name="descriptorId" type="String" required="false" validator="" expression="#maven.assemble.descriptorId" description="" */ public class AssembleMojo extends AbstractPlugin { private static final String[] EMPTY_STRING_ARRAY = {}; - private File outputDirectory; + private String basedir; + + /** + * @todo use java.io.File + */ + private String outputDirectory; private File descriptor; + private String descriptorId; + private String finalName; public void execute() @@ -67,92 +80,131 @@ public class AssembleMojo private void doExecute() throws Exception { - AssemblyXpp3Reader reader = new AssemblyXpp3Reader(); - Assembly assembly = reader.read( new FileReader( descriptor ) ); + Reader r = null; - // TODO: include dependencies marked for distribution under certain formats - // TODO: have a default set of descriptors that can be used instead of the file - // TODO: how, might we plugin this into an installer, such as NSIS? - // TODO: allow file mode specifications? - - String fullName = finalName + "-" + assembly.getId(); - - for ( Iterator i = assembly.getFormats().iterator(); i.hasNext(); ) + if ( descriptor != null ) { - String format = (String) i.next(); - - String filename = fullName + "." + format; - - // TODO: use component roles? Can we do that in a mojo? - Archiver archiver; - if ( format.startsWith( "tar" ) ) + r = new FileReader( descriptor ); + } + else if ( descriptorId != null ) + { + InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" ); + if ( resourceAsStream == null ) { - TarArchiver tarArchiver = new TarArchiver(); - archiver = tarArchiver; - int index = format.indexOf( '.' ); - if ( index >= 0 ) + // TODO: better exception + throw new Exception( "Descriptor with ID '" + descriptorId + "' not found" ); + } + r = new InputStreamReader( resourceAsStream ); + } + else + { + // TODO: better exception + throw new Exception( "You must specify descriptor or descriptorId" ); + } + + try + { + AssemblyXpp3Reader reader = new AssemblyXpp3Reader(); + Assembly assembly = reader.read( r ); + + // TODO: include dependencies marked for distribution under certain formats + // TODO: how, might we plugin this into an installer, such as NSIS? + // TODO: allow file mode specifications? + + String fullName = finalName + "-" + assembly.getId(); + + for ( Iterator i = assembly.getFormats().iterator(); i.hasNext(); ) + { + String format = (String) i.next(); + + String filename = fullName + "." + format; + + // TODO: use component roles? Can we do that in a mojo? + Archiver archiver; + if ( format.startsWith( "tar" ) ) { - // TODO: this needs a cleanup in plexus archiver - use a real typesafe enum - TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod(); - // TODO: this should accept gz and bz2 as well so we can skip over the switch - String compression = format.substring( index + 1 ); - if ( compression.equals( "gz" ) ) + TarArchiver tarArchiver = new TarArchiver(); + archiver = tarArchiver; + int index = format.indexOf( '.' ); + if ( index >= 0 ) { - tarCompressionMethod.setValue( "gzip" ); + // TODO: this needs a cleanup in plexus archiver - use a real typesafe enum + TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod(); + // TODO: this should accept gz and bz2 as well so we can skip over the switch + String compression = format.substring( index + 1 ); + if ( compression.equals( "gz" ) ) + { + tarCompressionMethod.setValue( "gzip" ); + } + else if ( compression.equals( "bz2" ) ) + { + tarCompressionMethod.setValue( "bzip2" ); + } + else + { + // TODO: better handling + throw new IllegalArgumentException( "Unknown compression format: " + compression ); + } + tarArchiver.setCompression( tarCompressionMethod ); } - else if ( compression.equals( "bz2" ) ) + } + else if ( format.startsWith( "zip" ) ) + { + archiver = new ZipArchiver(); + } + else if ( format.startsWith( "jar" ) ) + { + // TODO: use MavenArchiver for manifest? + archiver = new JarArchiver(); + } + else + { + // TODO: better handling + throw new IllegalArgumentException( "Unknown format: " + format ); + } + + for ( Iterator j = assembly.getFilesets().iterator(); j.hasNext(); ) + { + FileSet fileset = (FileSet) j.next(); + String directory = fileset.getDirectory(); + String output = fileset.getOutputDirectory(); + if ( directory == null ) { - tarCompressionMethod.setValue( "bzip2" ); + directory = basedir; + if ( output == null ) + { + output = "/"; + } } else { - // TODO: better handling - throw new IllegalArgumentException( "Unknown compression format: " + compression ); + if ( output == null ) + { + output = directory; + } + } + if ( !output.endsWith( "/" ) && !output.endsWith( "\\" ) ) + { + // TODO: shouldn't archiver do this? + output += '/'; } - tarArchiver.setCompression( tarCompressionMethod ); - } - } - else if ( format.startsWith( "zip" ) ) - { - archiver = new ZipArchiver(); - } - else if ( format.startsWith( "jar" ) ) - { - // TODO: use MavenArchiver for manifest? - archiver = new JarArchiver(); - } - else - { - // TODO: better handling - throw new IllegalArgumentException( "Unknown format: " + format ); - } - for ( Iterator j = assembly.getFilesets().iterator(); j.hasNext(); ) - { - FileSet fileset = (FileSet) j.next(); - String directory = fileset.getDirectory(); - String output = fileset.getOutputDirectory(); - if ( output == null ) - { - output = directory; - } - if ( !output.endsWith( "/" ) && !output.endsWith( "\\" ) ) - { - // TODO: shouldn't archiver do this? - output += '/'; + String[] includes = (String[]) fileset.getIncludes().toArray( EMPTY_STRING_ARRAY ); + if ( includes.length == 0 ) + { + includes = null; + } + String[] excludes = (String[]) fileset.getExcludes().toArray( EMPTY_STRING_ARRAY ); + archiver.addDirectory( new File( directory ), output, includes, excludes ); } - String[] includes = (String[]) fileset.getIncludes().toArray( EMPTY_STRING_ARRAY ); - if ( includes.length == 0 ) - { - includes = null; - } - String[] excludes = (String[]) fileset.getExcludes().toArray( EMPTY_STRING_ARRAY ); - archiver.addDirectory( new File( directory ), output, includes, excludes ); + archiver.setDestFile( new File( outputDirectory, filename ) ); + archiver.createArchive(); } - - archiver.setDestFile( new File( outputDirectory, filename ) ); - archiver.createArchive(); + } + finally + { + IOUtil.close( r ); } } } diff --git a/maven-plugins/maven-assemble-plugin/src/main/resources/assemblies/bin.xml b/maven-plugins/maven-assemble-plugin/src/main/resources/assemblies/bin.xml new file mode 100644 index 0000000000..1a3e7ddeff --- /dev/null +++ b/maven-plugins/maven-assemble-plugin/src/main/resources/assemblies/bin.xml @@ -0,0 +1,26 @@ + + bin + + tar.gz + tar.bz2 + zip + + + + + README* + LICENSE* + NOTICE* + + + + + + target + / + + *.jar + + + +