mirror of https://github.com/apache/maven.git
standard assemly - bin
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163721 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6f8b171aaf
commit
0f861327fd
|
@ -5,4 +5,5 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
m2 plugin:descriptor
|
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
|
||||||
|
|
|
@ -25,9 +25,13 @@ import org.codehaus.plexus.archiver.Archiver;
|
||||||
import org.codehaus.plexus.archiver.jar.JarArchiver;
|
import org.codehaus.plexus.archiver.jar.JarArchiver;
|
||||||
import org.codehaus.plexus.archiver.tar.TarArchiver;
|
import org.codehaus.plexus.archiver.tar.TarArchiver;
|
||||||
import org.codehaus.plexus.archiver.zip.ZipArchiver;
|
import org.codehaus.plexus.archiver.zip.ZipArchiver;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,19 +39,28 @@ import java.util.Iterator;
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @goal assemble
|
* @goal assemble
|
||||||
* @description assemble an application bundle or distribution
|
* @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="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="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
|
public class AssembleMojo
|
||||||
extends AbstractPlugin
|
extends AbstractPlugin
|
||||||
{
|
{
|
||||||
private static final String[] EMPTY_STRING_ARRAY = {};
|
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 File descriptor;
|
||||||
|
|
||||||
|
private String descriptorId;
|
||||||
|
|
||||||
private String finalName;
|
private String finalName;
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
|
@ -67,92 +80,131 @@ public class AssembleMojo
|
||||||
private void doExecute()
|
private void doExecute()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
AssemblyXpp3Reader reader = new AssemblyXpp3Reader();
|
Reader r = null;
|
||||||
Assembly assembly = reader.read( new FileReader( descriptor ) );
|
|
||||||
|
|
||||||
// TODO: include dependencies marked for distribution under certain formats
|
if ( descriptor != null )
|
||||||
// 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(); )
|
|
||||||
{
|
{
|
||||||
String format = (String) i.next();
|
r = new FileReader( descriptor );
|
||||||
|
}
|
||||||
String filename = fullName + "." + format;
|
else if ( descriptorId != null )
|
||||||
|
{
|
||||||
// TODO: use component roles? Can we do that in a mojo?
|
InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" );
|
||||||
Archiver archiver;
|
if ( resourceAsStream == null )
|
||||||
if ( format.startsWith( "tar" ) )
|
|
||||||
{
|
{
|
||||||
TarArchiver tarArchiver = new TarArchiver();
|
// TODO: better exception
|
||||||
archiver = tarArchiver;
|
throw new Exception( "Descriptor with ID '" + descriptorId + "' not found" );
|
||||||
int index = format.indexOf( '.' );
|
}
|
||||||
if ( index >= 0 )
|
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 tarArchiver = new TarArchiver();
|
||||||
TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod();
|
archiver = tarArchiver;
|
||||||
// TODO: this should accept gz and bz2 as well so we can skip over the switch
|
int index = format.indexOf( '.' );
|
||||||
String compression = format.substring( index + 1 );
|
if ( index >= 0 )
|
||||||
if ( compression.equals( "gz" ) )
|
|
||||||
{
|
{
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
// TODO: better handling
|
if ( output == null )
|
||||||
throw new IllegalArgumentException( "Unknown compression format: " + compression );
|
{
|
||||||
|
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(); )
|
String[] includes = (String[]) fileset.getIncludes().toArray( EMPTY_STRING_ARRAY );
|
||||||
{
|
if ( includes.length == 0 )
|
||||||
FileSet fileset = (FileSet) j.next();
|
{
|
||||||
String directory = fileset.getDirectory();
|
includes = null;
|
||||||
String output = fileset.getOutputDirectory();
|
}
|
||||||
if ( output == null )
|
String[] excludes = (String[]) fileset.getExcludes().toArray( EMPTY_STRING_ARRAY );
|
||||||
{
|
archiver.addDirectory( new File( directory ), output, includes, excludes );
|
||||||
output = directory;
|
|
||||||
}
|
|
||||||
if ( !output.endsWith( "/" ) && !output.endsWith( "\\" ) )
|
|
||||||
{
|
|
||||||
// TODO: shouldn't archiver do this?
|
|
||||||
output += '/';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] includes = (String[]) fileset.getIncludes().toArray( EMPTY_STRING_ARRAY );
|
archiver.setDestFile( new File( outputDirectory, filename ) );
|
||||||
if ( includes.length == 0 )
|
archiver.createArchive();
|
||||||
{
|
|
||||||
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 ) );
|
finally
|
||||||
archiver.createArchive();
|
{
|
||||||
|
IOUtil.close( r );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<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>
|
Loading…
Reference in New Issue