You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2005/10/19 20:25:06 UTC

svn commit: r326629 - in /maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly: AssemblyMojo.java ComponentsXmlArchiverFileFilter.java DirectoryMojo.java DownloadReport.java

Author: brett
Date: Wed Oct 19 11:25:03 2005
New Revision: 326629

URL: http://svn.apache.org/viewcvs?rev=326629&view=rev
Log:
PR: MNG-458
merge components.xml files

Added:
    maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/ComponentsXmlArchiverFileFilter.java   (with props)
Modified:
    maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java
    maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java
    maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DownloadReport.java

Modified: maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java?rev=326629&r1=326628&r2=326629&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java Wed Oct 19 11:25:03 2005
@@ -51,6 +51,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
@@ -133,6 +134,8 @@
      */
     private boolean includeSite;
 
+    private ComponentsXmlArchiverFileFilter componentsXmlFilter = new ComponentsXmlArchiverFileFilter();
+
     /**
      * Create the binary distribution.
      *
@@ -145,7 +148,6 @@
 
         // 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 = getDistributionName( assembly );
 
@@ -174,6 +176,10 @@
             {
                 throw new MojoExecutionException( "Error creating assembly: " + e.getMessage(), e );
             }
+            catch ( XmlPullParserException e )
+            {
+                throw new MojoExecutionException( "Error creating assembly: " + e.getMessage(), e );
+            }
 
             projectHelper.attachArtifact( project, format, assembly.getId(), destFile );
         }
@@ -196,12 +202,14 @@
     }
 
     protected File createArchive( Archiver archiver, Assembly assembly, String filename )
-        throws ArchiverException, IOException, MojoExecutionException, MojoFailureException
+        throws ArchiverException, IOException, MojoExecutionException, MojoFailureException, XmlPullParserException
     {
         File destFile;
         processDependencySets( archiver, assembly.getDependencySets(), assembly.isIncludeBaseDirectory() );
         processFileSets( archiver, assembly.getFileSets(), assembly.isIncludeBaseDirectory() );
 
+        componentsXmlFilter.addToArchive( archiver );
+
         destFile = new File( outputDirectory, filename );
         archiver.setDestFile( destFile );
         archiver.createArchive();
@@ -274,7 +282,7 @@
      * @param includeBaseDirectory
      */
     protected void processDependencySets( Archiver archiver, List dependencySets, boolean includeBaseDirectory )
-        throws ArchiverException, IOException, MojoExecutionException, MojoFailureException
+        throws ArchiverException, IOException, MojoExecutionException, MojoFailureException, XmlPullParserException
     {
         for ( Iterator i = dependencySets.iterator(); i.hasNext(); )
         {
@@ -286,10 +294,9 @@
 
             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() ) );
@@ -338,22 +345,38 @@
                             }
                             catch ( NoSuchArchiverException e )
                             {
-                                throw new MojoExecutionException( "Unable to obtain unarchiver for file '"
-                                    + artifact.getFile() + "'" );
+                                throw new MojoExecutionException(
+                                    "Unable to obtain unarchiver for file '" + artifact.getFile() + "'" );
                             }
                         }
-                        archiver.addDirectory( tempLocation, output, null, FileUtils.getDefaultExcludes() );
+
+                        addDirectory( archiver, tempLocation, output, null, FileUtils.getDefaultExcludesAsList() );
                     }
                     else
                     {
-                        archiver.addFile( artifact.getFile(), output
-                            + evaluateFileNameMapping( dependencySet.getOutputFileNameMapping(), artifact ) );
+                        archiver.addFile( artifact.getFile(), output +
+                            evaluateFileNameMapping( dependencySet.getOutputFileNameMapping(), artifact ) );
                     }
                 }
             }
         }
     }
 
+    private void addDirectory( Archiver archiver, File directory, String output, String[] includes, List excludes )
+        throws IOException, XmlPullParserException, ArchiverException
+    {
+        // TODO: more robust set of filters on added files in the archiver
+        File componentsXml = new File( directory, ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH );
+        if ( componentsXml.exists() )
+        {
+            componentsXmlFilter.addComponentsXml( componentsXml );
+            excludes = new ArrayList( excludes );
+            excludes.add( ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH );
+        }
+
+        archiver.addDirectory( directory, output, includes, (String[]) excludes.toArray( EMPTY_STRING_ARRAY ) );
+    }
+
     /**
      * Process Files that will be included in the distribution.
      *
@@ -363,7 +386,7 @@
      * @throws ArchiverException
      */
     protected void processFileSets( Archiver archiver, List fileSets, boolean includeBaseDirecetory )
-        throws ArchiverException
+        throws ArchiverException, IOException, XmlPullParserException
     {
         for ( Iterator i = fileSets.iterator(); i.hasNext(); )
         {
@@ -386,11 +409,10 @@
             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() ) );
+                .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 )
             {
@@ -429,7 +451,7 @@
                 archiveBaseDir = tmpDir;
             }
 
-            archiver.addDirectory( archiveBaseDir, output, includes, excludes );
+            addDirectory( archiver, archiveBaseDir, output, includes, excludesList );
         }
     }
 
@@ -489,7 +511,7 @@
     /**
      * Get the Output Directory by parsing the String output directory.
      *
-     * @param output The string representation of the 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 )
@@ -591,7 +613,7 @@
     }
 
     private void copySetReplacingLineEndings( File archiveBaseDir, File tmpDir, String[] includes, String[] excludes,
-                                             String lineEnding )
+                                              String lineEnding )
         throws ArchiverException
     {
         DirectoryScanner scanner = new DirectoryScanner();
@@ -659,7 +681,7 @@
         if ( !siteDirectory.exists() )
         {
             throw new MojoExecutionException(
-                                              "site did not exist in the target directory - please run site:site before creating the assembly" );
+                "site did not exist in the target directory - please run site:site before creating the assembly" );
         }
 
         getLog().info( "Adding site directory to assembly : " + siteDirectory );

Added: maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/ComponentsXmlArchiverFileFilter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/ComponentsXmlArchiverFileFilter.java?rev=326629&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/ComponentsXmlArchiverFileFilter.java (added)
+++ maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/ComponentsXmlArchiverFileFilter.java Wed Oct 19 11:25:03 2005
@@ -0,0 +1,116 @@
+package org.apache.maven.plugin.assembly;
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.Xpp3DomWriter;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.FileWriter;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+
+/*
+ * 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.
+ */
+
+/**
+ * Components XML file filter.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class ComponentsXmlArchiverFileFilter
+{
+    private Map components;
+
+    public static final String COMPONENTS_XML_PATH = "META-INF/plexus/components.xml";
+
+    public void addComponentsXml( File componentsXml )
+        throws IOException, XmlPullParserException
+    {
+        FileReader fileReader = null;
+        Xpp3Dom newDom;
+        try
+        {
+            fileReader = new FileReader( componentsXml );
+            newDom = Xpp3DomBuilder.build( fileReader );
+        }
+        finally
+        {
+            IOUtil.close( fileReader );
+        }
+
+        if ( newDom != null )
+        {
+            newDom = newDom.getChild( "components" );
+        }
+        if ( newDom != null )
+        {
+            Xpp3Dom[] children = newDom.getChildren();
+            for ( int i = 0; i < children.length; i++ )
+            {
+                Xpp3Dom component = children[i];
+
+                if ( components == null )
+                {
+                    components = new LinkedHashMap();
+                }
+
+                String role = component.getChild( "role" ).getValue();
+                Xpp3Dom child = component.getChild( "role-hint" );
+                String roleHint = child != null ? child.getValue() : "";
+                components.put( role + roleHint, component );
+            }
+        }
+    }
+
+    public void addToArchive( Archiver archiver )
+        throws IOException, ArchiverException
+    {
+        if ( components != null )
+        {
+            File f = File.createTempFile( "maven-assembly-plugin", "tmp" );
+            f.deleteOnExit();
+
+            FileWriter fileWriter = new FileWriter( f );
+            try
+            {
+                Xpp3Dom dom = new Xpp3Dom( "component-set" );
+                Xpp3Dom componentDom = new Xpp3Dom( "components" );
+                dom.addChild( componentDom );
+
+                for ( Iterator i = components.values().iterator(); i.hasNext(); )
+                {
+                    Xpp3Dom component = (Xpp3Dom) i.next();
+                    componentDom.addChild( component );
+                }
+
+                Xpp3DomWriter.write( fileWriter, dom );
+            }
+            finally
+            {
+                IOUtil.close( fileWriter );
+            }
+            archiver.addFile( f, COMPONENTS_XML_PATH );
+        }
+    }
+}

Propchange: maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/ComponentsXmlArchiverFileFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/ComponentsXmlArchiverFileFilter.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java?rev=326629&r1=326628&r2=326629&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java Wed Oct 19 11:25:03 2005
@@ -22,6 +22,7 @@
 import org.apache.maven.plugins.assembly.model.Assembly;
 import org.codehaus.plexus.archiver.Archiver;
 import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.IOException;
 
@@ -53,6 +54,10 @@
             throw new MojoExecutionException( "Error creating assembly", e );
         }
         catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error creating assembly", e );
+        }
+        catch ( XmlPullParserException e )
         {
             throw new MojoExecutionException( "Error creating assembly", e );
         }

Modified: maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DownloadReport.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DownloadReport.java?rev=326629&r1=326628&r2=326629&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DownloadReport.java (original)
+++ maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DownloadReport.java Wed Oct 19 11:25:03 2005
@@ -41,10 +41,9 @@
 /**
  * Generates the Download report.
  *
- * @goal download
- *
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  * @version $Id $
+ * @goal download
  */
 public class DownloadReport
     extends AbstractMavenReport
@@ -56,9 +55,7 @@
     private String outputDirectory;
 
     /**
-     * @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
-     * @required
-     * @readonly
+     * @component
      */
     private SiteRenderer siteRenderer;
 
@@ -218,15 +215,14 @@
                 if ( o.getChild( "finalName" ) == null )
                 {
                     throw new IllegalArgumentException(
-                                                        "The 'finalName' parameter is required for the configuration of the maven-assembly-plugin." );
+                        "The 'finalName' parameter is required for the configuration of the maven-assembly-plugin." );
                 }
-                String finalName = o.getChild( "finalName" ).getValue();
-                assemblyMojo.finalName = finalName;
+                assemblyMojo.finalName = o.getChild( "finalName" ).getValue();
 
                 if ( ( o.getChild( "descriptor" ) == null ) && ( o.getChild( "descriptorId" ) == null ) )
                 {
-                    throw new IllegalArgumentException( "The 'descriptor' or the 'descriptorId' parameter is "
-                        + "required for the configuration of the maven-assembly-plugin." );
+                    throw new IllegalArgumentException( "The 'descriptor' or the 'descriptorId' parameter is " +
+                        "required for the configuration of the maven-assembly-plugin." );
                 }
                 if ( o.getChild( "descriptor" ) != null )
                 {
@@ -239,11 +235,10 @@
                 }
                 if ( o.getChild( "descriptorId" ) != null )
                 {
-                    String descriptorId = o.getChild( "descriptorId" ).getValue();
-                    assemblyMojo.descriptorId = descriptorId;
+                    assemblyMojo.descriptorId = o.getChild( "descriptorId" ).getValue();
                 }
 
-                Assembly assembly = null;
+                Assembly assembly;
                 try
                 {
                     assembly = assemblyMojo.readAssembly();
@@ -291,9 +286,8 @@
 
         StringBuffer sb = null;
 
-        getLog().info(
-                       "The property distributionManagement.downloadUrl is not set in the pom.xml. "
-                           + "Copying distribution files in a relative directory ('" + downloadDirectory + "')." );
+        getLog().info( "The property distributionManagement.downloadUrl is not set in the pom.xml. " +
+            "Copying distribution files in a relative directory ('" + downloadDirectory + "')." );
 
         for ( Iterator it2 = distributionFileNames.iterator(); it2.hasNext(); )
         {
@@ -316,10 +310,8 @@
 
         if ( sb != null )
         {
-            getLog().warn(
-                           "The " + ( distributionFileNames.size() > 1 ? "files" : "file" ) + " "
-                               + sb.substring( 0, sb.length() - 2 )
-                               + " did not exist. - Please run assembly:assembly before." );
+            getLog().warn( "The " + ( distributionFileNames.size() > 1 ? "files" : "file" ) + " " +
+                sb.substring( 0, sb.length() - 2 ) + " did not exist. - Please run assembly:assembly before." );
             distributionFileNames = null;
         }
     }
@@ -336,7 +328,6 @@
         private List distributionFileNames = null;
 
         /**
-         *
          * @param sink
          * @param project
          * @param locale
@@ -344,7 +335,7 @@
          * @param distributionFileNames
          */
         public DownloadRenderer( Sink sink, MavenProject project, Locale locale, String downloadUrl,
-                                List distributionFileNames )
+                                 List distributionFileNames )
         {
             super( sink );
 
@@ -362,11 +353,10 @@
          */
         public String getTitle()
         {
-            return getBundle( locale ).getString( "report.download.title" )
-                + " "
-                + ( StringUtils.isEmpty( project.getName() ) ? project.getGroupId() + ":" + project.getArtifactId()
-                                                            : project.getName() ) + " "
-                + ( StringUtils.isEmpty( project.getVersion() ) ? "" : project.getVersion() );
+            return getBundle( locale ).getString( "report.download.title" ) + " " + (
+                StringUtils.isEmpty( project.getName() ) ? project.getGroupId() + ":" + project.getArtifactId()
+                    : project.getName() ) + " " +
+                ( StringUtils.isEmpty( project.getVersion() ) ? "" : project.getVersion() );
         }
 
         /**