brett 2005/03/30 07:41:23
Modified:
maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble
AssembleMojo.java
maven-plugins/maven-assemble-plugin build.sh
Added: maven-plugins/maven-assemble-plugin/src/main/resources/assemblies
bin.xml
Log:
standard assemly - bin
Revision Changes Path
1.5 +123 -71
maven-components/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java
Index: AssembleMojo.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AssembleMojo.java 21 Mar 2005 07:59:28 -0000 1.4
+++ AssembleMojo.java 30 Mar 2005 15:41:23 -0000 1.5
@@ -25,9 +25,13 @@
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 @@
* @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 @@
private void doExecute()
throws Exception
{
- AssemblyXpp3Reader reader = new AssemblyXpp3Reader();
- Assembly assembly = reader.read( new FileReader( descriptor ) );
-
- // 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?
+ Reader r = null;
- String fullName = finalName + "-" + assembly.getId();
+ if ( descriptor != null )
+ {
+ r = new FileReader( descriptor );
+ }
+ else if ( descriptorId != null )
+ {
+ InputStream resourceAsStream = getClass().getResourceAsStream(
"/assemblies/" + descriptorId + ".xml" );
+ if ( resourceAsStream == null )
+ {
+ // 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" );
+ }
- for ( Iterator i = assembly.getFormats().iterator(); i.hasNext(); )
+ try
{
- String format = (String) i.next();
+ AssemblyXpp3Reader reader = new AssemblyXpp3Reader();
+ Assembly assembly = reader.read( r );
- String filename = fullName + "." + format;
+ // 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?
- // TODO: use component roles? Can we do that in a mojo?
- Archiver archiver;
- if ( format.startsWith( "tar" ) )
+ String fullName = finalName + "-" + assembly.getId();
+
+ for ( Iterator i = assembly.getFormats().iterator();
i.hasNext(); )
{
- TarArchiver tarArchiver = new TarArchiver();
- archiver = tarArchiver;
- int index = format.indexOf( '.' );
- if ( index >= 0 )
+ 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" ) )
- {
- tarCompressionMethod.setValue( "bzip2" );
- }
- else
- {
- // TODO: better handling
- throw new IllegalArgumentException( "Unknown
compression format: " + compression );
- }
- 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 )
+ else if ( format.startsWith( "zip" ) )
{
- output = directory;
+ archiver = new ZipArchiver();
}
- if ( !output.endsWith( "/" ) && !output.endsWith( "\\" ) )
+ else if ( format.startsWith( "jar" ) )
{
- // TODO: shouldn't archiver do this?
- output += '/';
+ // TODO: use MavenArchiver for manifest?
+ archiver = new JarArchiver();
+ }
+ else
+ {
+ // TODO: better handling
+ throw new IllegalArgumentException( "Unknown format: " +
format );
}
- String[] includes = (String[])
fileset.getIncludes().toArray( EMPTY_STRING_ARRAY );
- if ( includes.length == 0 )
+ for ( Iterator j = assembly.getFilesets().iterator();
j.hasNext(); )
{
- includes = null;
+ FileSet fileset = (FileSet) j.next();
+ String directory = fileset.getDirectory();
+ String output = fileset.getOutputDirectory();
+ if ( directory == null )
+ {
+ directory = basedir;
+ if ( output == null )
+ {
+ output = "/";
+ }
+ }
+ else
+ {
+ 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[] 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 );
}
}
}
1.1
maven-components/maven-plugins/maven-assemble-plugin/src/main/resources/assemblies/bin.xml
Index: bin.xml
===================================================================
<assembly>
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<filesets>
<fileset>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileset>
<!-- TODO: docs? -->
<fileset>
<!-- TODO: use expresssions instead: ${project.build.directory},
${project.build.finalName} -->
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileset>
</filesets>
</assembly>
1.2 +2 -1
maven-components/maven-plugins/maven-assemble-plugin/build.sh
Index: build.sh
===================================================================
RCS file:
/home/cvs/maven-components/maven-plugins/maven-assemble-plugin/build.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build.sh 18 Mar 2005 01:14:11 -0000 1.1
+++ build.sh 30 Mar 2005 15:41:23 -0000 1.2
@@ -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