mirror of https://github.com/apache/maven.git
make the assembly mojo work, and use field type
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163637 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1f757e62d9
commit
e1f51a9ad4
|
@ -17,15 +17,14 @@ package org.apache.maven.plugin.assemble;
|
|||
*/
|
||||
|
||||
import org.apache.maven.plugin.AbstractPlugin;
|
||||
import org.apache.maven.plugin.PluginExecutionRequest;
|
||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||
import org.apache.maven.plugin.PluginExecutionException;
|
||||
import org.apache.maven.plugins.assemble.model.Assembly;
|
||||
import org.apache.maven.plugins.assemble.model.FileSet;
|
||||
import org.apache.maven.plugins.assemble.model.io.xpp3.AssemblyXpp3Reader;
|
||||
import org.codehaus.plexus.archiver.Archiver;
|
||||
import org.codehaus.plexus.archiver.jar.JarArchiver;
|
||||
import org.codehaus.plexus.archiver.zip.ZipArchiver;
|
||||
import org.codehaus.plexus.archiver.tar.TarArchiver;
|
||||
import org.codehaus.plexus.archiver.zip.ZipArchiver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
@ -36,8 +35,8 @@ import java.util.Iterator;
|
|||
* @version $Id$
|
||||
* @goal assemble
|
||||
* @description assemble an application bundle or distribution
|
||||
* @parameter name="outputDirectory" type="String" required="true" validator="" expression="#project.build.directory" description=""
|
||||
* @parameter name="descriptor" type="String" required="true" validator="" expression="#maven.assemble.descriptor" 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="finalName" type="String" required="true" validator="" expression="#project.build.finalName" description=""
|
||||
*/
|
||||
public class AssembleMojo
|
||||
|
@ -45,16 +44,31 @@ public class AssembleMojo
|
|||
{
|
||||
private static final String[] EMPTY_STRING_ARRAY = {};
|
||||
|
||||
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
|
||||
private File outputDirectory;
|
||||
|
||||
private File descriptor;
|
||||
|
||||
private String finalName;
|
||||
|
||||
public void execute()
|
||||
throws PluginExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
doExecute();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
// TODO: don't catch exception
|
||||
throw new PluginExecutionException( "Error creating assembly", e );
|
||||
}
|
||||
}
|
||||
|
||||
private void doExecute()
|
||||
throws Exception
|
||||
{
|
||||
// TODO: align all to basedir
|
||||
String outputDirectory = (String) request.getParameter( "outputDirectory" );
|
||||
String descriptor = (String) request.getParameter( "descriptor" );
|
||||
String finalName = (String) request.getParameter( "finalName" );
|
||||
|
||||
AssemblyXpp3Reader reader = new AssemblyXpp3Reader();
|
||||
Assembly assembly = reader.read( new FileReader( new File( descriptor ) ) );
|
||||
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
|
||||
|
@ -80,7 +94,21 @@ public class AssembleMojo
|
|||
{
|
||||
// TODO: this needs a cleanup in plexus archiver - use a real typesafe enum
|
||||
TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod();
|
||||
tarCompressionMethod.setValue( format.substring( index + 1 ) );
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +136,17 @@ public class AssembleMojo
|
|||
{
|
||||
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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue