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

View File

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