PR: MNG-458

merge components.xml files


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@326629 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-19 18:25:03 +00:00
parent aa51fda6a5
commit 60cfb93baf
4 changed files with 182 additions and 49 deletions

View File

@ -51,6 +51,7 @@ import java.io.IOException;
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 @@ public class AssemblyMojo
*/
private boolean includeSite;
private ComponentsXmlArchiverFileFilter componentsXmlFilter = new ComponentsXmlArchiverFileFilter();
/**
* Create the binary distribution.
*
@ -145,7 +148,6 @@ public class AssemblyMojo
// 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 @@ public class AssemblyMojo
{
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 @@ public class AssemblyMojo
}
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 @@ public class AssemblyMojo
* @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 @@ public class AssemblyMojo
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 @@ public class AssemblyMojo
}
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 @@ public class AssemblyMojo
* @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 @@ public class AssemblyMojo
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 @@ public class AssemblyMojo
archiveBaseDir = tmpDir;
}
archiver.addDirectory( archiveBaseDir, output, includes, excludes );
addDirectory( archiver, archiveBaseDir, output, includes, excludesList );
}
}
@ -489,7 +511,7 @@ public class AssemblyMojo
/**
* 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 @@ public class AssemblyMojo
}
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 @@ public class AssemblyMojo
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 );

View File

@ -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 );
}
}
}

View File

@ -22,6 +22,7 @@ import org.apache.maven.plugin.assembly.archiver.DirectoryArchiver;
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;
@ -56,6 +57,10 @@ public class DirectoryMojo
{
throw new MojoExecutionException( "Error creating assembly", e );
}
catch ( XmlPullParserException e )
{
throw new MojoExecutionException( "Error creating assembly", e );
}
}
}

View File

@ -41,10 +41,9 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* 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 @@ public class DownloadReport
private String outputDirectory;
/**
* @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
* @required
* @readonly
* @component
*/
private SiteRenderer siteRenderer;
@ -218,15 +215,14 @@ public class DownloadReport
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 @@ public class DownloadReport
}
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 @@ public class DownloadReport
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 @@ public class DownloadReport
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 @@ public class DownloadReport
private List distributionFileNames = null;
/**
*
* @param sink
* @param project
* @param locale
@ -344,7 +335,7 @@ public class DownloadReport
* @param distributionFileNames
*/
public DownloadRenderer( Sink sink, MavenProject project, Locale locale, String downloadUrl,
List distributionFileNames )
List distributionFileNames )
{
super( sink );
@ -362,11 +353,10 @@ public class DownloadReport
*/
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() );
}
/**