You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2007/07/14 01:15:51 UTC
svn commit: r556178 - in
/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly:
archive/DefaultAssemblyArchiver.java
filter/ComponentsXmlArchiverFileFilter.java
Author: jdcasey
Date: Fri Jul 13 16:15:50 2007
New Revision: 556178
URL: http://svn.apache.org/viewvc?view=rev&rev=556178
Log:
Updating the components.xml filter to implement FileSelector.
Modified:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/DefaultAssemblyArchiver.java
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java
Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/DefaultAssemblyArchiver.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/DefaultAssemblyArchiver.java?view=diff&rev=556178&r1=556177&r2=556178
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/DefaultAssemblyArchiver.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/DefaultAssemblyArchiver.java Fri Jul 13 16:15:50 2007
@@ -120,13 +120,13 @@
/**
* Creates the necessary archiver to build the distribution file.
- *
+ *
* @param format
* Archive format
- * @param includeBaseDir
+ * @param includeBaseDir
* @param configSource
- * @param finalName
- * @param string
+ * @param finalName
+ * @param string
* @return archiver Archiver generated
* @throws org.codehaus.plexus.archiver.ArchiverException
* @throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException
@@ -147,7 +147,7 @@
}
else
{
- archiver = this.archiverManager.getArchiver( format );
+ archiver = archiverManager.getArchiver( format );
}
configureArchiverFilters( archiver, componentsXmlFilter );
@@ -207,7 +207,7 @@
protected Archiver createWarArchiver()
throws NoSuchArchiverException
{
- WarArchiver warArchiver = (WarArchiver) this.archiverManager.getArchiver( "war" );
+ WarArchiver warArchiver = (WarArchiver) archiverManager.getArchiver( "war" );
warArchiver.setIgnoreWebxml( false ); // See MNG-1274
return warArchiver;
@@ -216,7 +216,7 @@
protected Archiver createTarArchiver( String format, String tarLongFileMode )
throws NoSuchArchiverException, ArchiverException
{
- TarArchiver tarArchiver = (TarArchiver) this.archiverManager.getArchiver( "tar" );
+ TarArchiver tarArchiver = (TarArchiver) archiverManager.getArchiver( "tar" );
int index = format.indexOf( '.' );
if ( index >= 0 )
{
Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java?view=diff&rev=556178&r1=556177&r2=556178
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java Fri Jul 13 16:15:50 2007
@@ -33,6 +33,8 @@
import org.codehaus.plexus.archiver.ArchiveFilterException;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.components.io.fileselectors.FileInfo;
+import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
@@ -46,62 +48,43 @@
*/
public class ComponentsXmlArchiverFileFilter
extends AbstractArchiveFinalizer
- implements ArchiveFileFilter
+ implements ArchiveFileFilter, FileSelector
{
// [jdcasey] Switched visibility to protected to allow testing. Also, because this class isn't final, it should allow
// some minimal access to the components accumulated for extending classes.
protected Map components;
-
+
private boolean excludeOverride = false;
public static final String COMPONENTS_XML_PATH = "META-INF/plexus/components.xml";
-
+
public boolean include( InputStream dataStream, String entryName )
throws ArchiveFilterException
{
- if ( excludeOverride )
+ try
{
- return true;
+ return isIncluded( dataStream, entryName );
}
-
- String entry = entryName;
-
- if ( entry.startsWith( "/" ) )
+ catch ( XmlPullParserException e )
{
- entry = entry.substring( 1 );
+ throw new ArchiveFilterException( "Error reading components from stream: " + e.getMessage(), e );
}
-
- if ( ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH.equals( entry ) )
+ catch ( IOException e )
{
- try
- {
- addComponentsXml( new InputStreamReader( dataStream ) );
- }
- catch ( XmlPullParserException e )
- {
- throw new ArchiveFilterException( "Error reading components from stream: " + e.getMessage(), e );
- }
- catch ( IOException e )
- {
- throw new ArchiveFilterException( "Error reading components from stream: " + e.getMessage(), e );
- }
-
- return false;
+ throw new ArchiveFilterException( "Error reading components from stream: " + e.getMessage(), e );
}
-
- return true;
}
-
+
protected void addComponentsXml( Reader componentsReader )
throws XmlPullParserException, IOException
{
Xpp3Dom newDom = Xpp3DomBuilder.build( componentsReader );
-
+
if ( newDom != null )
{
newDom = newDom.getChild( "components" );
}
-
+
if ( newDom != null )
{
Xpp3Dom[] children = newDom.getChildren();
@@ -121,7 +104,7 @@
}
}
}
-
+
// public void addComponentsXml( File componentsXml )
// throws IOException, XmlPullParserException
// {
@@ -129,7 +112,7 @@
// try
// {
// fileReader = new FileReader( componentsXml );
-//
+//
// addComponentsXml( fileReader );
// }
// finally
@@ -165,11 +148,11 @@
{
IOUtil.close( fileWriter );
}
-
+
excludeOverride = true;
-
+
archiver.addFile( f, COMPONENTS_XML_PATH );
-
+
excludeOverride = false;
}
}
@@ -189,12 +172,53 @@
public List getVirtualFiles()
{
- if ( components != null && !components.isEmpty() )
+ if ( ( components != null ) && !components.isEmpty() )
{
return Collections.singletonList( COMPONENTS_XML_PATH );
}
-
+
return null;
+ }
+
+ private boolean isIncluded( InputStream dataStream, String entryName )
+ throws XmlPullParserException, IOException
+ {
+ if ( excludeOverride )
+ {
+ return true;
+ }
+
+ String entry = entryName;
+
+ if ( entry.startsWith( "/" ) )
+ {
+ entry = entry.substring( 1 );
+ }
+
+ if ( ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH.equals( entry ) )
+ {
+ addComponentsXml( new InputStreamReader( dataStream ) );
+
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean isSelected( FileInfo fileInfo )
+ throws IOException
+ {
+ try
+ {
+ return isIncluded( fileInfo.getContents(), fileInfo.getName() );
+ }
+ catch ( XmlPullParserException e )
+ {
+ IOException error = new IOException( "Error finalizing component-set for archive. Reason: " + e.getMessage() );
+ error.initCause( e );
+
+ throw error;
+ }
}
}