mirror of
https://github.com/apache/maven.git
synced 2025-02-21 17:40:48 +00:00
PR: MNG-926
Submitted by: Johnny R. Ruiz III Reviewed by: Brett Porter assembly plugin documentation git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@290859 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2ebee0b9c8
commit
ef26e75576
maven-plugins/maven-assembly-plugin/src
main/java/org/apache/maven/plugin/assembly
site
@ -16,6 +16,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -26,11 +29,8 @@
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
|
||||
/**
|
||||
* Base routines for assembly and unpack goals
|
||||
* Base routines for assembly and unpack goals.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
@ -40,87 +40,119 @@ public abstract class AbstractUnpackingMojo
|
||||
static protected final String[] EMPTY_STRING_ARRAY = {};
|
||||
|
||||
/**
|
||||
* The output directory of the assembled distribution file.
|
||||
*
|
||||
* @parameter expression="${project.build.directory}"
|
||||
* @required
|
||||
*/
|
||||
protected File outputDirectory;
|
||||
|
||||
/**
|
||||
* The filename of the assembled distribution file.
|
||||
*
|
||||
* @parameter expression="${project.build.finalName}"
|
||||
* @required
|
||||
*/
|
||||
protected String finalName;
|
||||
|
||||
/**
|
||||
* Project dependencies.
|
||||
*
|
||||
* @parameter expression="${project.artifacts}"
|
||||
* @readonly
|
||||
*/
|
||||
protected Set dependencies;
|
||||
|
||||
/**
|
||||
* Directory to unpack JARs into if needed
|
||||
* @parameter expression="${project.build.directory}/assembly/work"
|
||||
* @required
|
||||
*/
|
||||
protected File workDirectory;
|
||||
* Directory to unpack JARs into if needed
|
||||
*
|
||||
* @parameter expression="${project.build.directory}/assembly/work"
|
||||
* @required
|
||||
*/
|
||||
protected File workDirectory;
|
||||
|
||||
protected void unpack(File file, File location) throws IOException {
|
||||
String fileName = file.getAbsolutePath().toLowerCase().trim();
|
||||
// Should be checking for '.' too?
|
||||
// Not doing this to be consistent with existing code
|
||||
if ( fileName.endsWith( "jar" ) )
|
||||
{
|
||||
unpackJar( file, location );
|
||||
}
|
||||
else if( fileName.endsWith( "zip" ) )
|
||||
{
|
||||
unpackZip( file, location );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Unpacks the archive file.
|
||||
*
|
||||
* @param file File to be unpacked.
|
||||
* @param location Location where to put the unpacked files.
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void unpack( File file, File location )
|
||||
throws IOException
|
||||
{
|
||||
String fileName = file.getAbsolutePath().toLowerCase().trim();
|
||||
// Should be checking for '.' too?
|
||||
// Not doing this to be consistent with existing code
|
||||
if ( fileName.endsWith( "jar" ) )
|
||||
{
|
||||
unpackJar( file, location );
|
||||
}
|
||||
else if ( fileName.endsWith( "zip" ) )
|
||||
{
|
||||
unpackZip( file, location );
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackJar( File file, File tempLocation )
|
||||
throws IOException
|
||||
{
|
||||
if ( !file.getAbsolutePath().toLowerCase().trim().endsWith( "jar" ) )
|
||||
{
|
||||
getLog().warn( "Trying to unpack a non-jar file " + file.getAbsolutePath() + " - IGNORING" );
|
||||
return;
|
||||
}
|
||||
|
||||
JarFile jar = new JarFile( file );
|
||||
for ( Enumeration e = jar.entries(); e.hasMoreElements(); )
|
||||
{
|
||||
JarEntry entry = (JarEntry) e.nextElement();
|
||||
|
||||
if ( !entry.isDirectory() )
|
||||
{
|
||||
File outFile = new File( tempLocation, entry.getName() );
|
||||
outFile.getParentFile().mkdirs();
|
||||
IOUtil.copy( jar.getInputStream( entry ), new FileOutputStream( outFile ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Unpacks the Jar file.
|
||||
*
|
||||
* @param file File to be unpack/unjar.
|
||||
* @param tempLocation Location where to put the unpacked files.
|
||||
* @throws IOException
|
||||
*/
|
||||
private void unpackJar( File file, File tempLocation )
|
||||
throws IOException
|
||||
{
|
||||
if ( !file.getAbsolutePath().toLowerCase().trim().endsWith( "jar" ) )
|
||||
{
|
||||
getLog().warn( "Trying to unpack a non-jar file " + file.getAbsolutePath() + " - IGNORING" );
|
||||
return;
|
||||
}
|
||||
|
||||
private void unpackZip(File file, File tempLocation) throws IOException {
|
||||
if ( !file.getAbsolutePath().toLowerCase().trim().endsWith( "zip" ) )
|
||||
{
|
||||
getLog().warn( "Trying to unpack a non-zip file " + file.getAbsolutePath() + " - IGNORING" );
|
||||
return;
|
||||
}
|
||||
|
||||
ZipFile zip = new ZipFile( file );
|
||||
for ( Enumeration e = zip.entries(); e.hasMoreElements(); )
|
||||
{
|
||||
ZipEntry entry = (ZipEntry) e.nextElement();
|
||||
|
||||
if ( !entry.isDirectory() )
|
||||
{
|
||||
File outFile = new File( tempLocation, entry.getName() );
|
||||
outFile.getParentFile().mkdirs();
|
||||
IOUtil.copy( zip.getInputStream( entry ), new FileOutputStream( outFile ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
JarFile jar = new JarFile( file );
|
||||
for ( Enumeration e = jar.entries(); e.hasMoreElements(); )
|
||||
{
|
||||
JarEntry entry = (JarEntry) e.nextElement();
|
||||
|
||||
if ( !entry.isDirectory() )
|
||||
{
|
||||
File outFile = new File( tempLocation, entry.getName() );
|
||||
outFile.getParentFile().mkdirs();
|
||||
IOUtil.copy( jar.getInputStream( entry ), new FileOutputStream( outFile ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks the Zip file.
|
||||
*
|
||||
* @param file Zip file to be unpacked.
|
||||
* @param tempLocation Location where to unpack the files.
|
||||
* @throws IOException
|
||||
*/
|
||||
private void unpackZip( File file, File tempLocation )
|
||||
throws IOException
|
||||
{
|
||||
if ( !file.getAbsolutePath().toLowerCase().trim().endsWith( "zip" ) )
|
||||
{
|
||||
getLog().warn( "Trying to unpack a non-zip file " + file.getAbsolutePath() + " - IGNORING" );
|
||||
return;
|
||||
}
|
||||
|
||||
ZipFile zip = new ZipFile( file );
|
||||
for ( Enumeration e = zip.entries(); e.hasMoreElements(); )
|
||||
{
|
||||
ZipEntry entry = (ZipEntry) e.nextElement();
|
||||
|
||||
if ( !entry.isDirectory() )
|
||||
{
|
||||
File outFile = new File( tempLocation, entry.getName() );
|
||||
outFile.getParentFile().mkdirs();
|
||||
IOUtil.copy( zip.getInputStream( entry ), new FileOutputStream( outFile ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
221
maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java
221
maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java
@ -71,23 +71,31 @@ public class AssemblyMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* Predefined Assembly Descriptor Id's. You can select bin, jar-with-dependencies, or src.
|
||||
*
|
||||
* @parameter expression="${maven.assembly.descriptorId}"
|
||||
*/
|
||||
protected String descriptorId;
|
||||
|
||||
/**
|
||||
* Assembly XML Descriptor file. This must be the path to your customized descriptor file.
|
||||
*
|
||||
* @parameter expression="${maven.assembly.descriptor}"
|
||||
*/
|
||||
protected File descriptor;
|
||||
|
||||
/**
|
||||
* Base directory of the project.
|
||||
*
|
||||
* @parameter expression="${basedir}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private String basedir;
|
||||
|
||||
|
||||
/**
|
||||
* The Maven Project.
|
||||
*
|
||||
* @parameter expression="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
@ -95,6 +103,8 @@ public class AssemblyMojo
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* Maven ProjectHelper
|
||||
*
|
||||
* @parameter expression="${component.org.apache.maven.project.MavenProjectHelper}"
|
||||
* @required
|
||||
* @readonly
|
||||
@ -102,13 +112,19 @@ public class AssemblyMojo
|
||||
private MavenProjectHelper projectHelper;
|
||||
|
||||
/**
|
||||
* Temporary directory that contain the files to be assembled.
|
||||
*
|
||||
* @parameter expression="${project.build.directory}/archive-tmp"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private File tempRoot;
|
||||
|
||||
|
||||
/**
|
||||
* Create the binary distribution.
|
||||
*
|
||||
* @throws MojoExecutionException
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
@ -123,11 +139,16 @@ public void execute()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the binary distribution.
|
||||
*
|
||||
* @throws ArchiverException, IOException, MojoExecutionException, XmlPullParserException
|
||||
*/
|
||||
private void doExecute()
|
||||
throws ArchiverException, IOException, MojoExecutionException, XmlPullParserException
|
||||
{
|
||||
Reader r = null;
|
||||
|
||||
|
||||
if ( descriptor != null )
|
||||
{
|
||||
r = new FileReader( descriptor );
|
||||
@ -146,35 +167,35 @@ else if ( descriptorId != null )
|
||||
// TODO: better exception
|
||||
throw new MojoExecutionException( "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 plug 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 = createArchiver( format );
|
||||
|
||||
|
||||
processFileSets( archiver, assembly.getFileSets(), assembly.isIncludeBaseDirectory() );
|
||||
processDependencySets( archiver, assembly.getDependencySets(), assembly.isIncludeBaseDirectory() );
|
||||
|
||||
|
||||
File destFile = new File( outputDirectory, filename );
|
||||
archiver.setDestFile( destFile );
|
||||
archiver.createArchive();
|
||||
|
||||
projectHelper.attachArtifact(project, format, format + "-assembly", destFile );
|
||||
|
||||
projectHelper.attachArtifact( project, format, format + "-assembly", destFile );
|
||||
}
|
||||
}
|
||||
finally
|
||||
@ -183,6 +204,14 @@ else if ( descriptorId != null )
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes Dependency Sets
|
||||
*
|
||||
* @param archiver
|
||||
* @param dependencySets
|
||||
* @param includeBaseDirectory
|
||||
* @throws ArchiverException, IOException, MojoExecutionException
|
||||
*/
|
||||
private void processDependencySets( Archiver archiver, List dependencySets, boolean includeBaseDirectory )
|
||||
throws ArchiverException, IOException, MojoExecutionException
|
||||
{
|
||||
@ -192,15 +221,13 @@ private void processDependencySets( Archiver archiver, List dependencySets, bool
|
||||
String output = dependencySet.getOutputDirectory();
|
||||
output = getOutputDirectory( output, includeBaseDirectory );
|
||||
|
||||
archiver.setDefaultDirectoryMode( Integer.parseInt(
|
||||
dependencySet.getDirectoryMode(), 8 ) );
|
||||
archiver.setDefaultDirectoryMode( Integer.parseInt( dependencySet.getDirectoryMode(), 8 ) );
|
||||
|
||||
archiver.setDefaultFileMode( Integer.parseInt(
|
||||
dependencySet.getFileMode(), 8 ) );
|
||||
archiver.setDefaultFileMode( Integer.parseInt( dependencySet.getFileMode(), 8 ) );
|
||||
|
||||
getLog().debug("DependencySet["+output+"]" +
|
||||
" dir perms: " + Integer.toString( archiver.getDefaultDirectoryMode(), 8 ) +
|
||||
" file perms: " + Integer.toString( archiver.getDefaultFileMode(), 8 ) );
|
||||
getLog().debug( "DependencySet[" + output + "]" + " dir perms: " +
|
||||
Integer.toString( archiver.getDefaultDirectoryMode(), 8 ) + " file perms: " +
|
||||
Integer.toString( archiver.getDefaultFileMode(), 8 ) );
|
||||
|
||||
AndArtifactFilter filter = new AndArtifactFilter();
|
||||
filter.add( new ScopeArtifactFilter( dependencySet.getScope() ) );
|
||||
@ -222,7 +249,7 @@ private void processDependencySets( Archiver archiver, List dependencySets, bool
|
||||
if ( filter.include( artifact ) )
|
||||
{
|
||||
String name = artifact.getFile().getName();
|
||||
|
||||
|
||||
if ( dependencySet.isUnpack() )
|
||||
{
|
||||
// TODO: something like zipfileset in plexus-archiver
|
||||
@ -254,10 +281,17 @@ else if ( artifact.getFile().lastModified() > tempLocation.lastModified() )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process Files that will be included in the distribution.
|
||||
*
|
||||
* @param archiver
|
||||
* @param fileSets
|
||||
* @param includeBaseDirecetory
|
||||
* @throws ArchiverException
|
||||
*/
|
||||
private void processFileSets( Archiver archiver, List fileSets, boolean includeBaseDirecetory )
|
||||
throws ArchiverException
|
||||
{
|
||||
@ -268,24 +302,22 @@ private void processFileSets( Archiver archiver, List fileSets, boolean includeB
|
||||
String output = fileSet.getOutputDirectory();
|
||||
|
||||
String lineEnding = getLineEndingCharacters( fileSet.getLineEnding() );
|
||||
|
||||
|
||||
File tmpDir = null;
|
||||
|
||||
|
||||
if ( lineEnding != null )
|
||||
{
|
||||
tmpDir = FileUtils.createTempFile( "", "", tempRoot );
|
||||
tmpDir.mkdirs();
|
||||
}
|
||||
|
||||
archiver.setDefaultDirectoryMode( Integer.parseInt(
|
||||
fileSet.getDirectoryMode(), 8 ) );
|
||||
|
||||
archiver.setDefaultFileMode( Integer.parseInt(
|
||||
fileSet.getFileMode(), 8 ) );
|
||||
|
||||
getLog().debug("FileSet["+output+"]" +
|
||||
" dir perms: " + Integer.toString( archiver.getDefaultDirectoryMode(), 8 ) +
|
||||
" file perms: " + Integer.toString( archiver.getDefaultFileMode(), 8 ) +
|
||||
archiver.setDefaultDirectoryMode( Integer.parseInt( fileSet.getDirectoryMode(), 8 ) );
|
||||
|
||||
archiver.setDefaultFileMode( Integer.parseInt( fileSet.getFileMode(), 8 ) );
|
||||
|
||||
getLog().debug( "FileSet[" + output + "]" + " dir perms: " +
|
||||
Integer.toString( archiver.getDefaultDirectoryMode(), 8 ) + " file perms: " +
|
||||
Integer.toString( archiver.getDefaultFileMode(), 8 ) +
|
||||
( fileSet.getLineEnding() == null ? "" : " lineEndings: " + fileSet.getLineEnding() ) );
|
||||
|
||||
if ( directory == null )
|
||||
@ -304,7 +336,7 @@ private void processFileSets( Archiver archiver, List fileSets, boolean includeB
|
||||
}
|
||||
}
|
||||
output = getOutputDirectory( output, includeBaseDirecetory );
|
||||
|
||||
|
||||
String[] includes = (String[]) fileSet.getIncludes().toArray( EMPTY_STRING_ARRAY );
|
||||
if ( includes.length == 0 )
|
||||
{
|
||||
@ -315,10 +347,9 @@ private void processFileSets( Archiver archiver, List fileSets, boolean includeB
|
||||
List excludesList = fileSet.getExcludes();
|
||||
excludesList.addAll( getDefaultExcludes() );
|
||||
String[] excludes = (String[]) excludesList.toArray( EMPTY_STRING_ARRAY );
|
||||
|
||||
|
||||
|
||||
File archiveBaseDir = new File( directory );
|
||||
|
||||
|
||||
if ( lineEnding != null )
|
||||
{
|
||||
copySetReplacingLineEndings( archiveBaseDir, tmpDir, includes, excludes, lineEnding );
|
||||
@ -330,16 +361,23 @@ private void processFileSets( Archiver archiver, List fileSets, boolean includeB
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates Filename Mapping
|
||||
*
|
||||
* @param expression
|
||||
* @param artifact
|
||||
* @return expression
|
||||
*/
|
||||
private static String evaluateFileNameMapping( String expression, Artifact artifact )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
// this matches the last ${...} string
|
||||
Pattern pat = Pattern.compile( "^(.*)\\$\\{([^\\}]+)\\}(.*)$" );
|
||||
Matcher mat = pat.matcher( expression );
|
||||
|
||||
String left,right;
|
||||
|
||||
String left, right;
|
||||
Object middle;
|
||||
|
||||
|
||||
if ( mat.matches() )
|
||||
{
|
||||
left = evaluateFileNameMapping( mat.group( 1 ), artifact );
|
||||
@ -347,12 +385,12 @@ private static String evaluateFileNameMapping( String expression, Artifact artif
|
||||
{
|
||||
middle = ReflectionValueExtractor.evaluate( "dep." + mat.group( 2 ), artifact );
|
||||
}
|
||||
catch (Exception e)
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new MojoExecutionException("Cannot evaluate filenameMapping", e);
|
||||
throw new MojoExecutionException( "Cannot evaluate filenameMapping", e );
|
||||
}
|
||||
right = mat.group( 3 );
|
||||
|
||||
|
||||
if ( middle == null )
|
||||
{
|
||||
// TODO: There should be a more generic way dealing with that. Having magic words is not good at all.
|
||||
@ -367,20 +405,31 @@ private static String evaluateFileNameMapping( String expression, Artifact artif
|
||||
middle = "${" + mat.group( 2 ) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return left + middle + right;
|
||||
}
|
||||
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the files to be excluded and put it into list.
|
||||
*
|
||||
* @return l List of filename patterns to be excluded.
|
||||
*/
|
||||
private static List getJarExcludes()
|
||||
{
|
||||
List l = new ArrayList( getDefaultExcludes() );
|
||||
l.add( "META-INF/**" );
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Output Directory by parsing the String output directory.
|
||||
*
|
||||
* @param output The string representation of the output directory.
|
||||
* @param includeBaseDirectory True if base directory is to be included in the assembled file.
|
||||
*/
|
||||
private String getOutputDirectory( String output, boolean includeBaseDirectory )
|
||||
{
|
||||
if ( output == null )
|
||||
@ -392,7 +441,7 @@ private String getOutputDirectory( String output, boolean includeBaseDirectory )
|
||||
// TODO: shouldn't archiver do this?
|
||||
output += '/';
|
||||
}
|
||||
|
||||
|
||||
if ( includeBaseDirectory )
|
||||
{
|
||||
if ( output.startsWith( "/" ) )
|
||||
@ -413,7 +462,14 @@ private String getOutputDirectory( String output, boolean includeBaseDirectory )
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the necessary archiver to build the distribution file.
|
||||
*
|
||||
* @param format Archive format
|
||||
* @return archiver Archiver generated
|
||||
* @throws ArchiverException
|
||||
*/
|
||||
private static Archiver createArchiver( String format )
|
||||
throws ArchiverException
|
||||
{
|
||||
@ -463,7 +519,12 @@ else if ( format.startsWith( "jar" ) )
|
||||
}
|
||||
return archiver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert into the exclude list the default excludes file pattern.
|
||||
*
|
||||
* @return defaultExcludes List containing the default patterns of files to be excluded.
|
||||
*/
|
||||
public static List getDefaultExcludes()
|
||||
{
|
||||
List defaultExcludes = new ArrayList();
|
||||
@ -472,40 +533,40 @@ public static List getDefaultExcludes()
|
||||
defaultExcludes.add( "**/.#*" );
|
||||
defaultExcludes.add( "**/%*%" );
|
||||
defaultExcludes.add( "**/._*" );
|
||||
|
||||
|
||||
// CVS
|
||||
defaultExcludes.add( "**/CVS" );
|
||||
defaultExcludes.add( "**/CVS/**" );
|
||||
defaultExcludes.add( "**/.cvsignore" );
|
||||
|
||||
|
||||
// SCCS
|
||||
defaultExcludes.add( "**/SCCS" );
|
||||
defaultExcludes.add( "**/SCCS/**" );
|
||||
|
||||
|
||||
// Visual SourceSafe
|
||||
defaultExcludes.add( "**/vssver.scc" );
|
||||
|
||||
|
||||
// Subversion
|
||||
defaultExcludes.add( "**/.svn" );
|
||||
defaultExcludes.add( "**/.svn/**" );
|
||||
|
||||
|
||||
// Mac
|
||||
defaultExcludes.add( "**/.DS_Store" );
|
||||
|
||||
|
||||
return defaultExcludes;
|
||||
}
|
||||
|
||||
|
||||
private void copyReplacingLineEndings( File source, File dest, String lineEndings )
|
||||
throws IOException
|
||||
{
|
||||
getLog().debug( "Copying while replacing line endings: " + source + " to " + dest );
|
||||
|
||||
BufferedReader in = new BufferedReader( new FileReader ( source ) );
|
||||
BufferedWriter out = new BufferedWriter ( new FileWriter( dest ) );
|
||||
|
||||
BufferedReader in = new BufferedReader( new FileReader( source ) );
|
||||
BufferedWriter out = new BufferedWriter( new FileWriter( dest ) );
|
||||
|
||||
String line;
|
||||
|
||||
while ( ( line = in.readLine()) != null )
|
||||
|
||||
while ( ( line = in.readLine() ) != null )
|
||||
{
|
||||
out.write( line );
|
||||
out.write( lineEndings );
|
||||
@ -514,8 +575,9 @@ private void copyReplacingLineEndings( File source, File dest, String lineEnding
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
private void copySetReplacingLineEndings( File archiveBaseDir, File tmpDir, String[] includes, String[] excludes, String lineEnding )
|
||||
|
||||
private void copySetReplacingLineEndings( File archiveBaseDir, File tmpDir, String[] includes, String[] excludes,
|
||||
String lineEnding )
|
||||
throws ArchiverException
|
||||
{
|
||||
DirectoryScanner scanner = new DirectoryScanner();
|
||||
@ -523,36 +585,34 @@ private void copySetReplacingLineEndings( File archiveBaseDir, File tmpDir, Stri
|
||||
scanner.setIncludes( includes );
|
||||
scanner.setExcludes( excludes );
|
||||
scanner.scan();
|
||||
|
||||
|
||||
String [] dirs = scanner.getIncludedDirectories();
|
||||
|
||||
for ( int j = 0; j < dirs.length; j ++)
|
||||
|
||||
for ( int j = 0; j < dirs.length; j ++ )
|
||||
{
|
||||
new File( tempRoot, dirs[j] ).mkdirs();
|
||||
}
|
||||
|
||||
|
||||
String [] files = scanner.getIncludedFiles();
|
||||
|
||||
for ( int j = 0; j < files.length; j ++)
|
||||
|
||||
for ( int j = 0; j < files.length; j ++ )
|
||||
{
|
||||
File targetFile = new File( tmpDir, files[j] );
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
targetFile.getParentFile().mkdirs();
|
||||
|
||||
copyReplacingLineEndings( new File( archiveBaseDir, files[j] ), targetFile, lineEnding );
|
||||
}
|
||||
catch (IOException e)
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ArchiverException("Error copying file '" +
|
||||
files[j] + "' to '" + targetFile + "'", e);
|
||||
throw new ArchiverException( "Error copying file '" + files[j] + "' to '" + targetFile + "'", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String getLineEndingCharacters( String lineEnding )
|
||||
throws ArchiverException
|
||||
{
|
||||
@ -572,13 +632,12 @@ else if ( lineEnding.equals( "unix" ) || lineEnding.equals( "lf" ) )
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArchiverException( "Illlegal lineEnding specified: '" +
|
||||
lineEnding + "'");
|
||||
throw new ArchiverException( "Illlegal lineEnding specified: '" + lineEnding + "'" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return lineEnding;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
55
maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java
55
maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java
@ -1,11 +1,11 @@
|
||||
package org.apache.maven.plugin.assembly;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
@ -33,27 +33,40 @@
|
||||
public class UnpackMojo
|
||||
extends AbstractUnpackingMojo
|
||||
{
|
||||
/**
|
||||
* Unpacks the archive file.
|
||||
*
|
||||
* @throws MojoExecutionException
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
doExecute();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
// TODO: don't catch exception
|
||||
throw new MojoExecutionException( "Error unpacking", e );
|
||||
}
|
||||
}
|
||||
|
||||
public void execute() throws MojoExecutionException {
|
||||
try
|
||||
{
|
||||
doExecute();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
// TODO: don't catch exception
|
||||
throw new MojoExecutionException( "Error unpacking", e );
|
||||
}
|
||||
}
|
||||
|
||||
private void doExecute() throws Exception {
|
||||
/**
|
||||
* Unpacks the project dependencies.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private void doExecute()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
for ( Iterator j = dependencies.iterator(); j.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) j.next();
|
||||
|
||||
String name = artifact.getFile().getName();
|
||||
|
||||
|
||||
File tempLocation = new File( workDirectory, name.substring( 0, name.length() - 4 ) );
|
||||
boolean process = false;
|
||||
if ( !tempLocation.exists() )
|
||||
@ -68,9 +81,9 @@ else if ( artifact.getFile().lastModified() > tempLocation.lastModified() )
|
||||
|
||||
if ( process )
|
||||
{
|
||||
File file = artifact.getFile();
|
||||
unpack(file, tempLocation);
|
||||
File file = artifact.getFile();
|
||||
unpack( file, tempLocation );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
------
|
||||
Maven 2 Assembly Plugin
|
||||
------
|
||||
Johnny R. Ruiz III
|
||||
<jruiz@exist.com>
|
||||
------
|
||||
September 20, 2005
|
||||
|
||||
Pre-defined Descriptor Files
|
||||
|
||||
*bin.xml descriptorId:bin
|
||||
|
||||
------
|
||||
<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>
|
||||
<fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>*.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
------
|
||||
|
||||
*jar-with-dependencies.xml descriptorId:jar-with-dependencies
|
||||
|
||||
-----
|
||||
<assembly>
|
||||
<id>jar-with-dependencies</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/classes</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<unpack>true</unpack>
|
||||
<scope>runtime</scope>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
||||
-----
|
||||
|
||||
*src.xml descriptorId:xml
|
||||
|
||||
-----
|
||||
<assembly>
|
||||
<id>src</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>
|
||||
<include>pom.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>src</directory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
-----
|
||||
|
||||
|
||||
|
||||
|
72
maven-plugins/maven-assembly-plugin/src/site/apt/howto.apt
Normal file
72
maven-plugins/maven-assembly-plugin/src/site/apt/howto.apt
Normal file
@ -0,0 +1,72 @@
|
||||
------
|
||||
Maven 2 Assembly Plugin
|
||||
------
|
||||
Johnny R. Ruiz III
|
||||
<jruiz@exist.com>
|
||||
------
|
||||
September 20, 2005
|
||||
|
||||
How to Use
|
||||
|
||||
These is a brief example on how to use the assembly:assembly goal and assembly:unpack goal.
|
||||
|
||||
To use the assembly:assembly goal, you must define the descriptor file that you are going to use or
|
||||
define the descriptorId from the predefined {{{descriptor.html}descriptor ids}}.
|
||||
|
||||
|
||||
* How To use assembly:assembly using a customized descriptor file.
|
||||
|
||||
-----
|
||||
m2 assembly:assembly -Dmaven.assembly.descriptor=path/to/descriptor.xml
|
||||
-----
|
||||
|
||||
|
||||
* How to use assembly:assembly using predefined descriptor ids.
|
||||
|
||||
----
|
||||
|
||||
m2 assembly:assembly -Dmaven.assembly.descriptorId=bin
|
||||
|
||||
or m2 assembly:assembly -Dmaven.assembly.descriptorId=jar-with-dependencies
|
||||
|
||||
or m2 assembly:assembly -Dmaven.assembly.descriptorId=src
|
||||
|
||||
-----
|
||||
|
||||
* How to configure assembly:assembly plugin in pom.xml
|
||||
|
||||
You can also configure this plugin inside your pom.xml. To run use "m2 assembly:assembly".
|
||||
|
||||
-------------------
|
||||
<project>
|
||||
...
|
||||
<build>
|
||||
...
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.0-beta-1</version>
|
||||
<configuration>
|
||||
<descriptor>path/to/descriptor.xml</descriptor>
|
||||
<finalName>final_name</finalName>
|
||||
<outputDirectory>output/directory</outputDirectory>
|
||||
<workDirectory>target/assembly/work</workDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
...
|
||||
</build>
|
||||
...
|
||||
</project>
|
||||
-------------------
|
||||
|
||||
* How to use assembly:unpack
|
||||
|
||||
After running this goal, all dependencies will be extracted at the specified "\<workDirectory\>".
|
||||
|
||||
-----
|
||||
m2 assembly:unpack
|
||||
-----
|
||||
|
||||
For full documentation, click {{{index.html}here}}.
|
||||
|
@ -0,0 +1,23 @@
|
||||
------
|
||||
Maven 2 Assembly Plugin
|
||||
------
|
||||
Johnny R. Ruiz III
|
||||
<jruiz@exist.com>
|
||||
------
|
||||
September 20, 2005
|
||||
|
||||
Introduction
|
||||
|
||||
This plugin is the Maven2 version of Maven1's Distribution Plugin.
|
||||
|
||||
This plugin provides the capability to create a binary distribution and source distribution.
|
||||
Currently it can create distribution format such as: zip format, tar.bz, tar.gz2, jar format.
|
||||
The goal to do this is "assembly:assembly".
|
||||
|
||||
It also provides the capability to extract all project dependencies on certain working directory.
|
||||
The goal to do this is "assembly:unpack".
|
||||
|
||||
To learn how to use the plugin, click {{{howto.html}here}}.
|
||||
|
||||
|
||||
|
42
maven-plugins/maven-assembly-plugin/src/site/site.xml
Normal file
42
maven-plugins/maven-assembly-plugin/src/site/site.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
<project name="Maven Assembly Plugin">
|
||||
<bannerLeft>
|
||||
<name>Maven Assembly Plugin</name>
|
||||
<src>http://maven.apache.org/images/apache-maven-project.png</src>
|
||||
<href>http://maven.apache.org/</href>
|
||||
</bannerLeft>
|
||||
<bannerRight>
|
||||
<src>http://maven.apache.org/images/maven-small.gif</src>
|
||||
</bannerRight>
|
||||
<body>
|
||||
<links>
|
||||
<item name="Maven 2" href="http://maven.apache.org/maven2/"/>
|
||||
</links>
|
||||
|
||||
<menu name="Overview">
|
||||
<item name="Introduction" href="introduction.html"/>
|
||||
<item name="How to Use" href="howto.html"/>
|
||||
<item name="Predefined Descriptors" href="descriptor.html"/>
|
||||
</menu>
|
||||
${reports}
|
||||
</body>
|
||||
</project>
|
Loading…
x
Reference in New Issue
Block a user