o Fixed tabs -> spaces (sorry, makes diff hard to read) and some codingstyle

issues.

o Modified model: added a 'BaseSet' type as a basetype
  for DependencySet and FileSet; it contains fileMode and
  directoryMode to work with the new plexus-archiver.

o Bumped plexus-archiver version to 1.0-alpha-2-SNAPSHOT.

o Added support for actually using fileMode and directoryMode.
  (tested this with a modified maven-core assembly descriptor,
  not committed as a test though).



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@264888 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kenney Westerhof 2005-08-30 22:57:50 +00:00
parent e0457b0204
commit 6fdbe554dd
3 changed files with 412 additions and 369 deletions

View File

@ -44,7 +44,7 @@
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>1.0-alpha-1</version>
<version>1.0-alpha-2-SNAPSHOT</version>
</dependency>
</dependencies>
<developers>

View File

@ -36,6 +36,7 @@ import org.codehaus.plexus.archiver.tar.TarArchiver;
import org.codehaus.plexus.archiver.zip.ZipArchiver;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileReader;
@ -68,10 +69,12 @@ public class AssemblyMojo
* @parameter expression="${maven.assembly.descriptorId}"
*/
protected String descriptorId;
/**
* @parameter expression="${maven.assembly.descriptor}"
*/
protected File descriptor;
/**
* @parameter expression="${basedir}"
* @required
@ -94,8 +97,9 @@ public class AssemblyMojo
private MavenProjectHelper projectHelper;
public void execute() throws MojoExecutionException {
public void execute()
throws MojoExecutionException
{
try
{
doExecute();
@ -107,7 +111,9 @@ public class AssemblyMojo
}
}
private void doExecute() throws Exception {
private void doExecute()
throws ArchiverException, IOException, MojoExecutionException, XmlPullParserException
{
Reader r = null;
if ( descriptor != null )
@ -165,15 +171,28 @@ public class AssemblyMojo
}
}
private void processDependencySets(Archiver archiver, List dependencySets, boolean includeBaseDirectory) throws ArchiverException, IOException, Exception {
private void processDependencySets( Archiver archiver, List dependencySets, boolean includeBaseDirectory )
throws ArchiverException, IOException, MojoExecutionException
{
for ( Iterator i = dependencySets.iterator(); i.hasNext(); )
{
DependencySet dependencySet = (DependencySet) i.next();
String output = dependencySet.getOutputDirectory();
output = getOutputDirectory( output, includeBaseDirectory );
archiver.setDefaultDirectoryMode( Integer.parseInt(
dependencySet.getDirectoryMode(), 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 ) );
AndArtifactFilter filter = new AndArtifactFilter();
filter.add( new ScopeArtifactFilter( dependencySet.getScope() ) );
if ( !dependencySet.getIncludes().isEmpty() )
{
filter.add( new IncludesArtifactFilter( dependencySet.getIncludes() ) );
@ -191,10 +210,11 @@ public class AssemblyMojo
if ( filter.include( artifact ) )
{
String name = artifact.getFile().getName();
if ( dependencySet.isUnpack() )
{
// TODO: something like zipfileset in plexus-archiver
// archiver.addJar( )
// archiver.addJar( )
File tempLocation = new File( workDirectory, name.substring( 0, name.length() - 4 ) );
boolean process = false;
@ -225,12 +245,26 @@ public class AssemblyMojo
}
}
private void processFileSets(Archiver archiver, List fileSets, boolean includeBaseDirecetory) throws ArchiverException {
private void processFileSets( Archiver archiver, List fileSets, boolean includeBaseDirecetory )
throws ArchiverException
{
for ( Iterator i = fileSets.iterator(); i.hasNext(); )
{
FileSet fileSet = (FileSet) i.next();
String directory = fileSet.getDirectory();
String output = fileSet.getOutputDirectory();
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 ) );
if ( directory == null )
{
directory = basedir;
@ -263,8 +297,8 @@ public class AssemblyMojo
}
}
private String evaluateFileNameMapping( String expression, Artifact artifact )
throws Exception
private static String evaluateFileNameMapping( String expression, Artifact artifact )
throws MojoExecutionException
{
// this matches the last ${...} string
Pattern pat = Pattern.compile( "^(.*)\\$\\{([^\\}]+)\\}(.*)$" );
@ -276,7 +310,14 @@ public class AssemblyMojo
if ( mat.matches() )
{
left = evaluateFileNameMapping( mat.group( 1 ), artifact );
try
{
middle = ReflectionValueExtractor.evaluate( "dep." + mat.group( 2 ), artifact );
}
catch (Exception e)
{
throw new MojoExecutionException("Cannot evaluate filenameMapping", e);
}
right = mat.group( 3 );
if ( middle == null )
@ -300,7 +341,7 @@ public class AssemblyMojo
return expression;
}
private List getJarExcludes()
private static List getJarExcludes()
{
List l = new ArrayList( getDefaultExcludes() );
l.add( "META-INF/**" );
@ -340,7 +381,7 @@ public class AssemblyMojo
return output;
}
private Archiver createArchiver( String format )
private static Archiver createArchiver( String format )
throws ArchiverException
{
Archiver archiver;
@ -370,10 +411,6 @@ public class AssemblyMojo
}
tarArchiver.setCompression( tarCompressionMethod );
}
// TODO: should be able to do this on a file/dir basis
tarArchiver.getOptions().setDirMode( "0700" );
tarArchiver.getOptions().setMode( "0700" );
}
else if ( format.startsWith( "zip" ) )
{
@ -385,7 +422,6 @@ public class AssemblyMojo
JarArchiver jarArchiver = new JarArchiver();
jarArchiver.setCompress( true );
archiver = jarArchiver;
}
else
{
@ -395,7 +431,7 @@ public class AssemblyMojo
return archiver;
}
public List getDefaultExcludes()
public static List getDefaultExcludes()
{
List defaultExcludes = new ArrayList();
defaultExcludes.add( "**/*~" );

View File

@ -1,3 +1,5 @@
<?xml version="1.0"?>
<model>
<id>assembly</id>
<name>Assembly</name>
@ -53,15 +55,9 @@
</fields>
</class>
<class>
<name>FileSet</name>
<name>SetBase</name>
<version>1.0.0</version>
<fields>
<field>
<name>directory</name>
<version>1.0.0</version>
<type>String</type>
<required>true</required>
</field>
<field>
<name>outputDirectory</name>
<version>1.0.0</version>
@ -83,17 +79,38 @@
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>fileMode</name>
<version>1.0.0</version>
<type>String</type>
<defaultValue>0644</defaultValue>
</field>
<field>
<name>directoryMode</name>
<version>1.0.0</version>
<type>String</type>
<defaultValue>0755</defaultValue>
</field>
</fields>
</class>
<class>
<name>FileSet</name>
<version>1.0.0</version>
<superClass>SetBase</superClass>
<fields>
<field>
<name>directory</name>
<version>1.0.0</version>
<type>String</type>
<required>true</required>
</field>
</fields>
</class>
<class>
<name>DependencySet</name>
<version>1.0.0</version>
<superClass>SetBase</superClass>
<fields>
<field>
<name>outputDirectory</name>
<version>1.0.0</version>
<type>String</type>
</field>
<field>
<name>outputFileNameMapping</name>
<version>1.0.0</version>
@ -113,20 +130,10 @@
<required>true</required>
</field>
<field>
<name>includes</name>
<name>lineEndings</name>
<version>1.0.0</version>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>excludes</name>
<version>1.0.0</version>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<!-- native, cr, lf, crlf, ..? -->
</field>
</fields>
</class>