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 2010/09/21 22:33:04 UTC
svn commit: r999610 - in /maven/plugins/trunk/maven-assembly-plugin: ./
src/main/java/org/apache/maven/plugin/assembly/archive/
src/main/java/org/apache/maven/plugin/assembly/filter/
Author: jdcasey
Date: Tue Sep 21 20:33:04 2010
New Revision: 999610
URL: http://svn.apache.org/viewvc?rev=999610&view=rev
Log:
[MASSEMBLY-209][MASSEMBLY-360] Adding line-oriented aggregators for spring files in META-INF and META-INF/services/* ...these still need tests.
Added:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AbstractLineAggregatingHandler.java (with props)
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfServicesHandler.java (with props)
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfSpringHandler.java (with props)
Modified:
maven/plugins/trunk/maven-assembly-plugin/pom.xml
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/DefaultAssemblyArchiver.java
Modified: maven/plugins/trunk/maven-assembly-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/pom.xml?rev=999610&r1=999609&r2=999610&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-assembly-plugin/pom.xml Tue Sep 21 20:33:04 2010
@@ -199,6 +199,13 @@ under the License.
<version>3.8.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-annotations</artifactId>
+ <version>1.5.4</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<repositories>
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?rev=999610&r1=999609&r2=999610&view=diff
==============================================================================
--- 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 Tue Sep 21 20:33:04 2010
@@ -31,6 +31,7 @@ import org.apache.maven.plugin.assembly.
import org.apache.maven.plugin.assembly.artifact.DependencyResolver;
import org.apache.maven.plugin.assembly.filter.ComponentsXmlArchiverFileFilter;
import org.apache.maven.plugin.assembly.filter.ContainerDescriptorHandler;
+import org.apache.maven.plugin.assembly.filter.MetaInfServicesHandler;
import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugin.assembly.interpolation.AssemblyExpressionEvaluator;
import org.apache.maven.plugin.assembly.model.Assembly;
@@ -234,7 +235,7 @@ public class DefaultAssemblyArchiver
}
List handlers = new ArrayList();
- boolean foundPlexus = false;
+ List<String> hints = new ArrayList<String>();
if ( ( requestedContainerDescriptorHandlers != null ) && !requestedContainerDescriptorHandlers.isEmpty() )
{
@@ -260,22 +261,33 @@ public class DefaultAssemblyArchiver
}
handlers.add( handler );
-
- if ( "plexus".equals( hint ) )
- {
- foundPlexus = true;
- }
+ hints.add( hint );
}
}
- if ( !foundPlexus )
+ addBuiltInContainerDescriptorHandlers( hints, handlers );
+
+ return handlers;
+ }
+
+ private void addBuiltInContainerDescriptorHandlers( final List<String> hints, final List handlers )
+ {
+ if ( !hints.contains( "plexus" ) )
{
handlers.add( new ComponentsXmlArchiverFileFilter() );
}
- return handlers;
- }
+ if ( !hints.contains( "metaInf-services" ) )
+ {
+ handlers.add( new MetaInfServicesHandler() );
+ }
+ if ( !hints.contains( "metaInf-spring" ) )
+ {
+ handlers.add( new MetaInfServicesHandler() );
+ }
+ }
+
/**
* Creates the necessary archiver to build the distribution file.
*
Added: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AbstractLineAggregatingHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AbstractLineAggregatingHandler.java?rev=999610&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AbstractLineAggregatingHandler.java (added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AbstractLineAggregatingHandler.java Tue Sep 21 20:33:04 2010
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2010 John Casey.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.apache.maven.plugin.assembly.filter;
+
+import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.components.io.fileselectors.FileInfo;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public abstract class AbstractLineAggregatingHandler
+ implements ContainerDescriptorHandler
+{
+
+ private Map<String, StringWriter> catalog = new HashMap<String, StringWriter>();
+
+ private Map<String, List<String>> files = new HashMap<String, List<String>>();
+
+ protected abstract String getOutputPathPrefix( final FileInfo fileInfo );
+
+ protected abstract boolean fileMatches( final FileInfo fileInfo );
+
+ public void finalizeArchiveCreation( final Archiver archiver ) throws ArchiverException
+ {
+ for ( final Map.Entry<String, StringWriter> entry : catalog.entrySet() )
+ {
+ final String name = entry.getKey();
+ final String fname = new File( name ).getName();
+
+ Writer writer = null;
+ File f;
+ try
+ {
+ f = File.createTempFile( "assembly-" + fname, ".tmp" );
+ f.deleteOnExit();
+
+ writer = new FileWriter( f );
+ writer.write( entry.getValue().toString() );
+ }
+ catch ( final IOException e )
+ {
+ throw new ArchiverException( "Error adding aggregated content for: " + fname
+ + " to finalize archive creation. Reason: " + e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+ }
+ }
+
+ public void finalizeArchiveExtraction( final UnArchiver unArchiver ) throws ArchiverException
+ {
+ }
+
+ public List<String> getVirtualFiles()
+ {
+ return new ArrayList<String>( catalog.keySet() );
+ }
+
+ public boolean isSelected( final FileInfo fileInfo ) throws IOException
+ {
+ String name = fileInfo.getName();
+ name = AssemblyFileUtils.normalizePath( name );
+ name = name.replace( File.separatorChar, '/' );
+
+ name = getOutputPathPrefix( fileInfo ) + new File( name ).getName();
+
+ if ( fileInfo.isFile() && fileMatches( fileInfo ) )
+ {
+ StringWriter writer = catalog.get( name );
+ if ( writer == null )
+ {
+ writer = new StringWriter();
+ catalog.put( name, writer );
+ }
+
+ readLines( fileInfo, new PrintWriter( writer ) );
+
+ List<String> aggregated = files.get( name );
+ if ( aggregated == null )
+ {
+ aggregated = new ArrayList<String>();
+ files.put( name, aggregated );
+ }
+
+ aggregated.add( fileInfo.getName() );
+
+ return false;
+ }
+
+ return true;
+ }
+
+ protected void readLines( final FileInfo fileInfo, final PrintWriter writer ) throws IOException
+ {
+ BufferedReader reader = null;
+ try
+ {
+ reader = new BufferedReader( new InputStreamReader( fileInfo.getContents() ) ); // platform encoding
+ String line = null;
+ while ( ( line = reader.readLine() ) != null )
+ {
+ writer.println( line );
+ }
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+ }
+
+ protected final Map<String, StringWriter> getCatalog()
+ {
+ return catalog;
+ }
+
+ protected final Map<String, List<String>> getFiles()
+ {
+ return files;
+ }
+
+ protected final void setCatalog( final Map<String, StringWriter> catalog )
+ {
+ this.catalog = catalog;
+ }
+
+ protected final void setFiles( final Map<String, List<String>> files )
+ {
+ this.files = files;
+ }
+
+}
Propchange: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AbstractLineAggregatingHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfServicesHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfServicesHandler.java?rev=999610&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfServicesHandler.java (added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfServicesHandler.java Tue Sep 21 20:33:04 2010
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 John Casey.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.apache.maven.plugin.assembly.filter;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.components.io.fileselectors.FileInfo;
+
+@Component( role = ContainerDescriptorHandler.class, hint = "metaInf-services" )
+public class MetaInfServicesHandler
+ extends AbstractLineAggregatingHandler
+{
+
+ private static final String SERVICES_PATH_PREFIX = "/META-INF/services/";
+
+ @Override
+ protected String getOutputPathPrefix( final FileInfo fileInfo )
+ {
+ return SERVICES_PATH_PREFIX;
+ }
+
+ @Override
+ protected boolean fileMatches( final FileInfo fileInfo )
+ {
+ return fileInfo.getName().startsWith( SERVICES_PATH_PREFIX )
+ || fileInfo.getName().startsWith( "META-INF/services" );
+ }
+
+}
Propchange: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfServicesHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfSpringHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfSpringHandler.java?rev=999610&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfSpringHandler.java (added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfSpringHandler.java Tue Sep 21 20:33:04 2010
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 John Casey.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.apache.maven.plugin.assembly.filter;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.components.io.fileselectors.FileInfo;
+
+@Component( role = ContainerDescriptorHandler.class, hint = "metaInf-spring" )
+public class MetaInfSpringHandler
+ extends AbstractLineAggregatingHandler
+{
+
+ private static final String SPRING_PATH_PREFIX = "/META-INF";
+
+ @Override
+ protected String getOutputPathPrefix( final FileInfo fileInfo )
+ {
+ return SPRING_PATH_PREFIX;
+ }
+
+ @Override
+ protected boolean fileMatches( final FileInfo fileInfo )
+ {
+ return fileInfo.getName().startsWith( "/META-INF/spring." )
+ || fileInfo.getName().startsWith( "META-INF/spring." );
+ }
+
+}
Propchange: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/MetaInfSpringHandler.java
------------------------------------------------------------------------------
svn:eol-style = native