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 2006/07/22 01:32:26 UTC
svn commit: r424492 - in /maven/plugins/branches/MASSEMBLY-124: ./
src/main/java/org/apache/maven/plugin/assembly/
src/main/java/org/apache/maven/plugin/assembly/filter/
src/main/java/org/apache/maven/plugin/assembly/interpolation/
src/main/java/org/ap...
Author: jdcasey
Date: Fri Jul 21 16:32:25 2006
New Revision: 424492
URL: http://svn.apache.org/viewvc?rev=424492&view=rev
Log:
Adding more unit tests.
Added:
maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/InvalidAssemblerConfigurationException.java (with props)
maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilterTest.java (with props)
maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/
maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java (with props)
maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java (with props)
Modified:
maven/plugins/branches/MASSEMBLY-124/pom.xml
maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java
maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolator.java
maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/AssemblyReader.java
maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReader.java
maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractAssemblyMojo.java
maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractDirectoryMojo.java
maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolatorTest.java
maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/utils/PropertiesInterpolationValueSourceTest.java
Modified: maven/plugins/branches/MASSEMBLY-124/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/pom.xml?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/pom.xml (original)
+++ maven/plugins/branches/MASSEMBLY-124/pom.xml Fri Jul 21 16:32:25 2006
@@ -38,6 +38,7 @@
<phase>generate-sources</phase>
<goals>
<goal>xpp3-reader</goal>
+ <goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xsd</goal>
</goals>
@@ -80,6 +81,7 @@
<configuration>
<excludes>
<exclude>**/BasicAbstractAssemblyMojoFeaturesTest*</exclude>
+ <exclude>**/testutils/*</exclude>
</excludes>
</configuration>
</plugin>
@@ -137,6 +139,24 @@
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
<version>1.2_Java1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ <version>1.0-FCS</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>saxpath</groupId>
+ <artifactId>saxpath</artifactId>
+ <version>1.0-FCS</version>
<scope>test</scope>
</dependency>
</dependencies>
Added: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/InvalidAssemblerConfigurationException.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/InvalidAssemblerConfigurationException.java?rev=424492&view=auto
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/InvalidAssemblerConfigurationException.java (added)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/InvalidAssemblerConfigurationException.java Fri Jul 21 16:32:25 2006
@@ -0,0 +1,18 @@
+package org.apache.maven.plugin.assembly;
+
+
+public class InvalidAssemblerConfigurationException
+ extends Exception
+{
+
+ public InvalidAssemblerConfigurationException( String message, Throwable error )
+ {
+ super( message, error );
+ }
+
+ public InvalidAssemblerConfigurationException( String message )
+ {
+ super( message );
+ }
+
+}
Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/InvalidAssemblerConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/InvalidAssemblerConfigurationException.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilter.java Fri Jul 21 16:32:25 2006
@@ -39,7 +39,9 @@
*/
public class ComponentsXmlArchiverFileFilter
{
- private Map components;
+ // [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;
public static final String COMPONENTS_XML_PATH = "META-INF/plexus/components.xml";
@@ -62,6 +64,7 @@
{
newDom = newDom.getChild( "components" );
}
+
if ( newDom != null )
{
Xpp3Dom[] children = newDom.getChildren();
Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolator.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolator.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolator.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolator.java Fri Jul 21 16:32:25 2006
@@ -22,6 +22,7 @@
import org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
@@ -57,6 +58,10 @@
ofnmBlacklistings.add( "groupId" );
ofnmBlacklistings.add( "artifactId" );
ofnmBlacklistings.add( "version" );
+
+ // TODO: We should be blacklisting these, but currently they're not supported by filename mapping interpolation.
+// ofnmBlacklistings.add( "build.finalName" );
+// ofnmBlacklistings.add( "finalName" );
blacklist.put( "outputFileNameMapping", ofnmBlacklistings );
@@ -206,7 +211,7 @@
catch ( Exception e )
{
Logger logger = getLogger();
- if ( logger != null )
+ if ( logger.isDebugEnabled() )
{
logger.debug( "Assembly descriptor interpolation cannot proceed with expression: " + wholeExpr +
". Skipping...", e );
@@ -235,5 +240,19 @@
}
}
return result;
+ }
+
+ protected Logger getLogger()
+ {
+ Logger logger = super.getLogger();
+
+ if ( logger == null )
+ {
+ logger = new ConsoleLogger( Logger.LEVEL_INFO, "interpolator-internal" );
+
+ enableLogging( logger );
+ }
+
+ return logger;
}
}
Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/AssemblyReader.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/AssemblyReader.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/AssemblyReader.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/AssemblyReader.java Fri Jul 21 16:32:25 2006
@@ -1,9 +1,12 @@
package org.apache.maven.plugin.assembly.io;
+import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
+import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugins.assembly.model.Assembly;
import java.io.File;
+import java.io.Reader;
import java.util.List;
@@ -11,12 +14,18 @@
{
public List readAssemblies( AssemblerConfigurationSource configSource )
- throws AssemblyReadException;
+ throws AssemblyReadException, InvalidAssemblerConfigurationException;
public Assembly getAssemblyForDescriptorReference( String ref, AssemblerConfigurationSource configSource )
- throws AssemblyReadException;
+ throws AssemblyReadException, InvalidAssemblerConfigurationException;
public Assembly getAssemblyFromDescriptorFile( File file, AssemblerConfigurationSource configSource )
- throws AssemblyReadException;
+ throws AssemblyReadException, InvalidAssemblerConfigurationException;
+
+ public Assembly readAssembly( Reader reader, String locationDescription, AssemblerConfigurationSource configSource )
+ throws AssemblyReadException, InvalidAssemblerConfigurationException;
+
+ public void includeSiteInAssembly( Assembly assembly, AssemblerConfigurationSource configSource )
+ throws MojoFailureException, InvalidAssemblerConfigurationException;
}
Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReader.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReader.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReader.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReader.java Fri Jul 21 16:32:25 2006
@@ -3,6 +3,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
+import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugin.assembly.interpolation.AssemblyInterpolationException;
import org.apache.maven.plugin.assembly.interpolation.AssemblyInterpolator;
import org.apache.maven.plugins.assembly.model.Assembly;
@@ -14,6 +15,8 @@
import org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -39,7 +42,7 @@
{
public List readAssemblies( AssemblerConfigurationSource configSource )
- throws AssemblyReadException
+ throws AssemblyReadException, InvalidAssemblerConfigurationException
{
List assemblies = new ArrayList();
@@ -111,7 +114,8 @@
return assemblies;
}
- public Assembly getAssemblyForDescriptorReference( String ref, AssemblerConfigurationSource configSource ) throws AssemblyReadException
+ public Assembly getAssemblyForDescriptorReference( String ref, AssemblerConfigurationSource configSource )
+ throws AssemblyReadException, InvalidAssemblerConfigurationException
{
InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + ref + ".xml" );
@@ -124,7 +128,7 @@
}
public Assembly getAssemblyFromDescriptorFile( File file, AssemblerConfigurationSource configSource )
- throws AssemblyReadException
+ throws AssemblyReadException, InvalidAssemblerConfigurationException
{
Reader r = null;
try
@@ -144,7 +148,7 @@
}
public Assembly readAssembly( Reader reader, String locationDescription, AssemblerConfigurationSource configSource )
- throws AssemblyReadException
+ throws AssemblyReadException, InvalidAssemblerConfigurationException
{
Assembly assembly;
@@ -181,10 +185,11 @@
if ( configSource.isSiteIncluded() || assembly.isIncludeSiteDirectory() )
{
+ includeSiteInAssembly( assembly, configSource );
}
mergeComponentsWithMainAssembly( assembly, configSource );
-
+
return assembly;
}
@@ -251,7 +256,7 @@
{
File basedir = configSource.getBasedir();
- File componentDescriptor = new File( basedir + "/" + filePath );
+ File componentDescriptor = new File( basedir, filePath );
Reader r;
try
@@ -298,14 +303,14 @@
return component;
}
- protected void includeSiteInAssembly( Assembly assembly, AssemblerConfigurationSource configSource )
- throws MojoFailureException
+ public void includeSiteInAssembly( Assembly assembly, AssemblerConfigurationSource configSource )
+ throws InvalidAssemblerConfigurationException
{
File siteDirectory = configSource.getSiteDirectory();
if ( !siteDirectory.exists() )
{
- throw new MojoFailureException(
+ throw new InvalidAssemblerConfigurationException(
"site did not exist in the target directory - please run site:site before creating the assembly" );
}
@@ -318,6 +323,19 @@
siteFileSet.setOutputDirectory( "/site" );
assembly.addFileSet( siteFileSet );
+ }
+
+ protected Logger getLogger()
+ {
+ Logger logger = super.getLogger();
+
+ if ( logger == null )
+ {
+ logger = new ConsoleLogger( Logger.LEVEL_INFO, "assemblyReader-internal" );
+ enableLogging( logger );
+ }
+
+ return logger;
}
}
Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractAssemblyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractAssemblyMojo.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractAssemblyMojo.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractAssemblyMojo.java Fri Jul 21 16:32:25 2006
@@ -22,6 +22,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
+import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugin.assembly.archive.AssemblyArchiver;
import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
@@ -237,6 +238,10 @@
catch ( AssemblyReadException e )
{
throw new MojoExecutionException( "Error reading assemblies: " + e.getMessage(), e );
+ }
+ catch ( InvalidAssemblerConfigurationException e )
+ {
+ throw new MojoFailureException( assemblyReader, e.getMessage(), "Mojo configuration is invalid: " + e.getMessage() );
}
// TODO: include dependencies marked for distribution under certain formats
Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractDirectoryMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractDirectoryMojo.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractDirectoryMojo.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/AbstractDirectoryMojo.java Fri Jul 21 16:32:25 2006
@@ -18,6 +18,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugin.assembly.archive.AssemblyArchiver;
import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
@@ -44,6 +45,10 @@
catch ( AssemblyReadException e )
{
throw new MojoExecutionException( "Error reading assembly descriptors: " + e.getMessage(), e );
+ }
+ catch ( InvalidAssemblerConfigurationException e )
+ {
+ throw new MojoFailureException( reader, e.getMessage(), "Mojo configuration is invalid: " + e.getMessage() );
}
for ( Iterator i = assemblies.iterator(); i.hasNext(); )
Added: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilterTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilterTest.java?rev=424492&view=auto
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilterTest.java (added)
+++ maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilterTest.java Fri Jul 21 16:32:25 2006
@@ -0,0 +1,394 @@
+package org.apache.maven.plugin.assembly.filter;
+
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+import org.jdom.Text;
+import org.jdom.input.SAXBuilder;
+import org.jdom.xpath.XPath;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class ComponentsXmlArchiverFileFilterTest
+ extends TestCase
+{
+ private ComponentsXmlArchiverFileFilter filter;
+
+ public void setUp()
+ {
+ filter = new ComponentsXmlArchiverFileFilter();
+ }
+
+ public void testAddComponentsXml_ShouldAddComponentWithoutRoleHint()
+ throws IOException, XmlPullParserException
+ {
+ File componentsXml = writeComponentsXml( Collections.singletonList( new ComponentDef( "role", null,
+ "org.apache.maven.Impl" ) ) );
+
+ filter.addComponentsXml( componentsXml );
+
+ assertFalse( filter.components.isEmpty() );
+
+ Xpp3Dom componentDom = (Xpp3Dom) filter.components.get( "role" );
+
+ assertEquals( "role", componentDom.getChild( "role" ).getValue() );
+ assertNull( componentDom.getChild( "role-hint" ) );
+ assertEquals( "org.apache.maven.Impl", componentDom.getChild( "implementation" ).getValue() );
+ }
+
+ public void testAddComponentsXml_ShouldAddComponentWithRoleHint()
+ throws IOException, XmlPullParserException
+ {
+ File componentsXml = writeComponentsXml( Collections.singletonList( new ComponentDef( "role", "hint",
+ "org.apache.maven.Impl" ) ) );
+
+ filter.addComponentsXml( componentsXml );
+
+ assertFalse( filter.components.isEmpty() );
+
+ Xpp3Dom componentDom = (Xpp3Dom) filter.components.get( "rolehint" );
+
+ assertEquals( "role", componentDom.getChild( "role" ).getValue() );
+ assertEquals( "hint", componentDom.getChild( "role-hint" ).getValue() );
+ assertEquals( "org.apache.maven.Impl", componentDom.getChild( "implementation" ).getValue() );
+ }
+
+ public void testAddComponentsXml_ShouldAddTwoComponentsWithRoleHints()
+ throws IOException, XmlPullParserException
+ {
+ List defs = new ArrayList();
+
+ defs.add( new ComponentDef( "role", "hint", "org.apache.maven.Impl" ) );
+ defs.add( new ComponentDef( "role", "hint2", "org.apache.maven.Impl2" ) );
+
+ File componentsXml = writeComponentsXml( defs );
+
+ filter.addComponentsXml( componentsXml );
+
+ assertFalse( filter.components.isEmpty() );
+
+ Xpp3Dom componentDom = (Xpp3Dom) filter.components.get( "rolehint" );
+
+ assertEquals( "role", componentDom.getChild( "role" ).getValue() );
+ assertEquals( "hint", componentDom.getChild( "role-hint" ).getValue() );
+ assertEquals( "org.apache.maven.Impl", componentDom.getChild( "implementation" ).getValue() );
+
+ componentDom = (Xpp3Dom) filter.components.get( "rolehint2" );
+
+ assertEquals( "role", componentDom.getChild( "role" ).getValue() );
+ assertEquals( "hint2", componentDom.getChild( "role-hint" ).getValue() );
+ assertEquals( "org.apache.maven.Impl2", componentDom.getChild( "implementation" ).getValue() );
+ }
+
+ public void testAddToArchive_ShouldWriteComponentWithoutHintToFile()
+ throws IOException, ArchiverException, JDOMException
+ {
+ Xpp3Dom dom = createComponentDom( new ComponentDef( "role", null, "impl" ) );
+
+ filter.components = new LinkedHashMap();
+ filter.components.put( "role", dom );
+
+ FileCatchingArchiver fca = new FileCatchingArchiver();
+
+ filter.addToArchive( fca );
+
+ assertEquals( ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName() );
+
+ SAXBuilder builder = new SAXBuilder( false );
+
+ Document doc = builder.build( fca.getFile() );
+
+ XPath role = XPath.newInstance( "//component[position()=1]/role/text()" );
+ XPath hint = XPath.newInstance( "//component[position()=1]/role-hint/text()" );
+ XPath implementation = XPath.newInstance( "//component[position()=1]/implementation/text()" );
+
+ assertEquals( "role", ((Text) role.selectSingleNode( doc )).getText() );
+ assertNull( hint.selectSingleNode( doc ) );
+ assertEquals( "impl", ((Text) implementation.selectSingleNode( doc )).getText() );
+ }
+
+ public void testAddToArchive_ShouldWriteComponentWithHintToFile()
+ throws IOException, ArchiverException, JDOMException
+ {
+ Xpp3Dom dom = createComponentDom( new ComponentDef( "role", "hint", "impl" ) );
+
+ filter.components = new LinkedHashMap();
+ filter.components.put( "rolehint", dom );
+
+ FileCatchingArchiver fca = new FileCatchingArchiver();
+
+ filter.addToArchive( fca );
+
+ assertEquals( ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName() );
+
+ SAXBuilder builder = new SAXBuilder( false );
+
+ Document doc = builder.build( fca.getFile() );
+
+ XPath role = XPath.newInstance( "//component[position()=1]/role/text()" );
+ XPath hint = XPath.newInstance( "//component[position()=1]/role-hint/text()" );
+ XPath implementation = XPath.newInstance( "//component[position()=1]/implementation/text()" );
+
+ assertEquals( "role", ((Text) role.selectSingleNode( doc )).getText() );
+ assertEquals( "hint", ((Text) hint.selectSingleNode( doc )).getText() );
+ assertEquals( "impl", ((Text) implementation.selectSingleNode( doc )).getText() );
+ }
+
+ public void testAddToArchive_ShouldWriteTwoComponentToFile()
+ throws IOException, ArchiverException, JDOMException
+ {
+ filter.components = new LinkedHashMap();
+
+ Xpp3Dom dom = createComponentDom( new ComponentDef( "role", "hint", "impl" ) );
+
+ filter.components.put( "rolehint", dom );
+
+ Xpp3Dom dom2 = createComponentDom( new ComponentDef( "role", "hint2", "impl" ) );
+
+ filter.components.put( "rolehint2", dom2 );
+
+ FileCatchingArchiver fca = new FileCatchingArchiver();
+
+ filter.addToArchive( fca );
+
+ assertEquals( ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName() );
+
+ SAXBuilder builder = new SAXBuilder( false );
+
+ Document doc = builder.build( fca.getFile() );
+
+ XPath role = XPath.newInstance( "//component[position()=1]/role/text()" );
+ XPath hint = XPath.newInstance( "//component[position()=1]/role-hint/text()" );
+ XPath implementation = XPath.newInstance( "//component[position()=1]/implementation/text()" );
+
+ assertEquals( "role", ((Text) role.selectSingleNode( doc )).getText() );
+ assertEquals( "hint", ((Text) hint.selectSingleNode( doc )).getText() );
+ assertEquals( "impl", ((Text) implementation.selectSingleNode( doc )).getText() );
+
+ XPath role2 = XPath.newInstance( "//component[position()=2]/role/text()" );
+ XPath hint2 = XPath.newInstance( "//component[position()=2]/role-hint/text()" );
+ XPath implementation2 = XPath.newInstance( "//component[position()=2]/implementation/text()" );
+
+ assertEquals( "role", ((Text) role2.selectSingleNode( doc )).getText() );
+ assertEquals( "hint2", ((Text) hint2.selectSingleNode( doc )).getText() );
+ assertEquals( "impl", ((Text) implementation2.selectSingleNode( doc )).getText() );
+
+ }
+
+ private Xpp3Dom createComponentDom( ComponentDef def )
+ {
+ Xpp3Dom dom = new Xpp3Dom( "component" );
+
+ Xpp3Dom role = new Xpp3Dom( "role" );
+ role.setValue( def.role );
+ dom.addChild( role );
+
+ String hint = def.roleHint;
+ if ( hint != null )
+ {
+ Xpp3Dom roleHint = new Xpp3Dom( "role-hint" );
+ roleHint.setValue( hint );
+ dom.addChild( roleHint );
+ }
+
+ Xpp3Dom impl = new Xpp3Dom( "implementation" );
+ impl.setValue( def.implementation );
+ dom.addChild( impl );
+
+ return dom;
+ }
+
+ private File writeComponentsXml( List componentDefs )
+ throws IOException
+ {
+ File file = File.createTempFile( "ComponentsXmlArchiverFileFilter.", ".unit-test" );
+ file.deleteOnExit();
+
+ FileWriter writer = null;
+
+ try
+ {
+ writer = new FileWriter( file );
+
+ PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter( writer );
+
+ xmlWriter.startElement( "component-set" );
+ xmlWriter.startElement( "components" );
+
+ for ( Iterator it = componentDefs.iterator(); it.hasNext(); )
+ {
+ ComponentDef def = (ComponentDef) it.next();
+
+ xmlWriter.startElement( "component" );
+
+ xmlWriter.startElement( "role" );
+ xmlWriter.writeText( def.role );
+ xmlWriter.endElement();
+
+ String roleHint = def.roleHint;
+ if ( roleHint != null )
+ {
+ xmlWriter.startElement( "role-hint" );
+ xmlWriter.writeText( roleHint );
+ xmlWriter.endElement();
+ }
+
+ xmlWriter.startElement( "implementation" );
+ xmlWriter.writeText( def.implementation );
+ xmlWriter.endElement();
+
+ xmlWriter.endElement();
+ }
+
+ xmlWriter.endElement();
+ xmlWriter.endElement();
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+
+ return file;
+ }
+
+ private static final class ComponentDef
+ {
+ String role;
+
+ String roleHint;
+
+ String implementation;
+
+ ComponentDef( String role, String roleHint, String implementation )
+ {
+ this.role = role;
+ this.roleHint = roleHint;
+ this.implementation = implementation;
+
+ }
+ }
+
+ private static final class FileCatchingArchiver
+ implements Archiver
+ {
+
+ private File inputFile;
+
+ private String destFileName;
+
+ public void addDirectory( File directory )
+ throws ArchiverException
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void addDirectory( File directory, String prefix )
+ throws ArchiverException
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void addDirectory( File directory, String[] includes, String[] excludes )
+ throws ArchiverException
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void addDirectory( File directory, String prefix, String[] includes, String[] excludes )
+ throws ArchiverException
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void addFile( File inputFile, String destFileName )
+ throws ArchiverException
+ {
+ this.inputFile = inputFile;
+ this.destFileName = destFileName;
+ }
+
+ File getFile()
+ {
+ return inputFile;
+ }
+
+ String getDestFileName()
+ {
+ return destFileName;
+ }
+
+ public void addFile( File inputFile, String destFileName, int permissions )
+ throws ArchiverException
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void createArchive()
+ throws ArchiverException, IOException
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public int getDefaultDirectoryMode()
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public int getDefaultFileMode()
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public File getDestFile()
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public Map getFiles()
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public boolean getIncludeEmptyDirs()
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void setDefaultDirectoryMode( int mode )
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void setDefaultFileMode( int mode )
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void setDestFile( File destFile )
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void setIncludeEmptyDirs( boolean includeEmptyDirs )
+ {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ }
+
+}
Propchange: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/filter/ComponentsXmlArchiverFileFilterTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolatorTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolatorTest.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolatorTest.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/interpolation/AssemblyInterpolatorTest.java Fri Jul 21 16:32:25 2006
@@ -3,10 +3,14 @@
import org.apache.maven.model.Model;
import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.plugins.assembly.model.DependencySet;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import java.util.Properties;
import junit.framework.TestCase;
@@ -14,31 +18,186 @@
extends TestCase
{
- public void testDependencyOutputFileNameMappingsAreNotInterpolated()
+ private AssemblyInterpolator interpolator;
+
+ public void setUp()
+ throws IOException
+ {
+ interpolator = new AssemblyInterpolator();
+
+ interpolator.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
+ }
+
+ public void testBlacklistedExpressionsInDependencyOutputFileNameMappingsAreNotInterpolated()
throws IOException, AssemblyInterpolationException
{
- AssemblyInterpolator interpolator = new AssemblyInterpolator();
+ Model model = new Model();
+ model.setArtifactId( "artifact-id" );
+ model.setGroupId( "group.id" );
+ model.setVersion( "1" );
+ model.setPackaging( "jar" );
+
+ Assembly assembly = new Assembly();
+
+ // artifactId is blacklisted, but packaging is not.
+ String outputFileNameMapping = "${artifactId}.${packaging}";
+
+ DependencySet set = new DependencySet();
+ set.setOutputFileNameMapping( outputFileNameMapping );
+ assembly.addDependencySet( set );
+
+ Assembly outputAssembly = interpolator.interpolate( assembly, model, Collections.EMPTY_MAP );
+
+ List outputDependencySets = outputAssembly.getDependencySets();
+ assertEquals( 1, outputDependencySets.size() );
+
+ DependencySet outputSet = (DependencySet) outputDependencySets.get( 0 );
+
+ assertEquals( "${artifactId}.jar", outputSet.getOutputFileNameMapping() );
+ }
+
+ public void testBlacklistedExpressionsInDependencySetOutputDirectoryIsNotInterpolated()
+ throws IOException, AssemblyInterpolationException
+ {
Model model = new Model();
model.setArtifactId( "artifact-id" );
model.setGroupId( "group.id" );
model.setVersion( "1" );
+ model.setPackaging( "jar" );
Assembly assembly = new Assembly();
+ String outputDirectory = "${artifactId}.${packaging}";
+
DependencySet set = new DependencySet();
- set.setOutputFileNameMapping( "${artifactId}.${extension}" );
+ set.setOutputDirectory( outputDirectory );
assembly.addDependencySet( set );
Assembly outputAssembly = interpolator.interpolate( assembly, model, Collections.EMPTY_MAP );
-
+
List outputDependencySets = outputAssembly.getDependencySets();
assertEquals( 1, outputDependencySets.size() );
-
+
DependencySet outputSet = (DependencySet) outputDependencySets.get( 0 );
-
- assertEquals( set.getOutputFileNameMapping(), outputSet.getOutputFileNameMapping() );
+
+ assertEquals( "${artifactId}.jar", outputSet.getOutputDirectory() );
+ }
+
+ public void testShouldResolveModelGroupIdInAssemblyId()
+ throws AssemblyInterpolationException
+ {
+ Model model = new Model();
+ model.setArtifactId( "artifact-id" );
+ model.setGroupId( "group.id" );
+ model.setVersion( "1" );
+ model.setPackaging( "jar" );
+
+ Assembly assembly = new Assembly();
+
+ assembly.setId( "assembly.${groupId}" );
+
+ Assembly result = interpolator.interpolate( assembly, model, Collections.EMPTY_MAP );
+
+ assertEquals( "assembly.group.id", result.getId() );
+ }
+
+ public void testShouldResolveModelPropertyBeforeModelGroupIdInAssemblyId()
+ throws AssemblyInterpolationException
+ {
+ Model model = new Model();
+ model.setArtifactId( "artifact-id" );
+ model.setGroupId( "group.id" );
+ model.setVersion( "1" );
+ model.setPackaging( "jar" );
+
+ Properties props = new Properties();
+ props.setProperty( "groupId", "other.id" );
+
+ model.setProperties( props );
+
+ Assembly assembly = new Assembly();
+
+ assembly.setId( "assembly.${groupId}" );
+
+ Assembly result = interpolator.interpolate( assembly, model, Collections.EMPTY_MAP );
+
+ assertEquals( "assembly.other.id", result.getId() );
+ }
+
+ public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId()
+ throws AssemblyInterpolationException
+ {
+ Model model = new Model();
+ model.setArtifactId( "artifact-id" );
+ model.setGroupId( "group.id" );
+ model.setVersion( "1" );
+ model.setPackaging( "jar" );
+
+ Properties props = new Properties();
+ props.setProperty( "groupId", "other.id" );
+
+ model.setProperties( props );
+
+ Assembly assembly = new Assembly();
+
+ assembly.setId( "assembly.${groupId}" );
+
+ Assembly result = interpolator.interpolate( assembly, model, Collections.singletonMap( "groupId",
+ "still.another.id" ) );
+
+ assertEquals( "assembly.still.another.id", result.getId() );
+ }
+
+ public void testShouldResolveEnvarHOMEValueInDependencySetOutputDirectory()
+ throws IOException, AssemblyInterpolationException
+ {
+ Model model = new Model();
+ model.setArtifactId( "artifact-id" );
+ model.setGroupId( "group.id" );
+ model.setVersion( "1" );
+ model.setPackaging( "jar" );
+
+ Assembly assembly = new Assembly();
+
+ Properties envars = CommandLineUtils.getSystemEnvVars();
+
+ String homeValue = envars.getProperty( "PATH" );
+
+ String outputDirectory = "${env.PATH}";
+
+ DependencySet set = new DependencySet();
+ set.setOutputDirectory( outputDirectory );
+
+ assembly.addDependencySet( set );
+
+ Assembly outputAssembly = interpolator.interpolate( assembly, model, Collections.EMPTY_MAP );
+
+ List outputDependencySets = outputAssembly.getDependencySets();
+ assertEquals( 1, outputDependencySets.size() );
+
+ DependencySet outputSet = (DependencySet) outputDependencySets.get( 0 );
+
+ assertEquals( homeValue, outputSet.getOutputDirectory() );
+ }
+
+ public void testShouldNotTouchUnresolvedExpression()
+ throws AssemblyInterpolationException
+ {
+ Model model = new Model();
+ model.setArtifactId( "artifact-id" );
+ model.setGroupId( "group.id" );
+ model.setVersion( "1" );
+ model.setPackaging( "jar" );
+
+ Assembly assembly = new Assembly();
+
+ assembly.setId( "assembly.${unresolved}" );
+
+ Assembly result = interpolator.interpolate( assembly, model, Collections.EMPTY_MAP );
+
+ assertEquals( "assembly.${unresolved}", result.getId() );
}
}
Added: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java?rev=424492&view=auto
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java (added)
+++ maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java Fri Jul 21 16:32:25 2006
@@ -0,0 +1,719 @@
+package org.apache.maven.plugin.assembly.io;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
+import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
+import org.apache.maven.plugin.assembly.testutils.MockManager;
+import org.apache.maven.plugin.assembly.testutils.TestFileManager;
+import org.apache.maven.plugins.assembly.model.Assembly;
+import org.apache.maven.plugins.assembly.model.Component;
+import org.apache.maven.plugins.assembly.model.DependencySet;
+import org.apache.maven.plugins.assembly.model.FileItem;
+import org.apache.maven.plugins.assembly.model.FileSet;
+import org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer;
+import org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+import org.easymock.MockControl;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class DefaultAssemblyReaderTest
+ extends TestCase
+{
+
+ private TestFileManager fileManager;
+
+ private MockManager mockManager;
+
+ private MockControl configSourceControl;
+
+ private AssemblerConfigurationSource configSource;
+
+ public void setUp()
+ {
+ fileManager = new TestFileManager( "assembly-reader.test." );
+ mockManager = new MockManager();
+
+ configSourceControl = MockControl.createControl( AssemblerConfigurationSource.class );
+ mockManager.add( configSourceControl );
+
+ configSource = (AssemblerConfigurationSource) configSourceControl.getMock();
+ }
+
+ public void tearDown()
+ throws IOException
+ {
+ fileManager.cleanUp();
+ }
+
+ public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent()
+ throws IOException
+ {
+ File siteDir = File.createTempFile( "assembly-reader.", ".test" );
+ siteDir.delete();
+
+ configSource.getSiteDirectory();
+ configSourceControl.setReturnValue( siteDir );
+
+ Assembly assembly = new Assembly();
+
+ mockManager.replayAll();
+
+ try
+ {
+ new DefaultAssemblyReader().includeSiteInAssembly( assembly, configSource );
+
+ fail( "Should fail when site directory is non-existent." );
+ }
+ catch ( InvalidAssemblerConfigurationException e )
+ {
+ // this should happen.
+ }
+
+ mockManager.verifyAll();
+ }
+
+ public void testIncludeSiteInAssembly_ShouldAddSiteDirFileSetWhenDirExists()
+ throws IOException, InvalidAssemblerConfigurationException
+ {
+ File siteDir = fileManager.createTempDir();
+
+ configSource.getSiteDirectory();
+ configSourceControl.setReturnValue( siteDir );
+
+ Assembly assembly = new Assembly();
+
+ mockManager.replayAll();
+
+ new DefaultAssemblyReader().includeSiteInAssembly( assembly, configSource );
+
+ List fileSets = assembly.getFileSets();
+
+ assertNotNull( fileSets );
+ assertEquals( 1, fileSets.size() );
+
+ FileSet fs = (FileSet) fileSets.get( 0 );
+
+ assertEquals( siteDir.getPath(), fs.getDirectory() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testReadComponent_ShouldReadComponentFromXml()
+ throws IOException, AssemblyReadException
+ {
+ Component component = new Component();
+
+ FileSet fileSet = new FileSet();
+ fileSet.setDirectory( "/dir" );
+
+ component.addFileSet( fileSet );
+
+ StringWriter sw = new StringWriter();
+
+ ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
+
+ componentWriter.write( sw, component );
+
+ Component result = new DefaultAssemblyReader().readComponent( new StringReader( sw.toString() ) );
+
+ List fileSets = result.getFileSets();
+
+ assertNotNull( fileSets );
+ assertEquals( 1, fileSets.size() );
+
+ FileSet fs = (FileSet) fileSets.get( 0 );
+
+ assertEquals( "/dir", fs.getDirectory() );
+ }
+
+ public void testGetComponentFromFile_ShouldReadComponent()
+ throws IOException, AssemblyReadException
+ {
+ Component component = new Component();
+
+ FileSet fileSet = new FileSet();
+ fileSet.setDirectory( "/dir" );
+
+ component.addFileSet( fileSet );
+
+ File componentFile = fileManager.createTempFile();
+
+ FileWriter writer = null;
+
+ try
+ {
+ writer = new FileWriter( componentFile );
+
+ ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
+
+ componentWriter.write( writer, component );
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+
+ File basedir = componentFile.getParentFile();
+ String filename = componentFile.getName();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir );
+
+ mockManager.replayAll();
+
+ Component result = new DefaultAssemblyReader().getComponentFromFile( filename, configSource );
+
+ List fileSets = result.getFileSets();
+
+ assertNotNull( fileSets );
+ assertEquals( 1, fileSets.size() );
+
+ FileSet fs = (FileSet) fileSets.get( 0 );
+
+ assertEquals( "/dir", fs.getDirectory() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testMergeComponentWithAssembly_ShouldAddOneFileSetToExistingListOfTwo()
+ {
+ Assembly assembly = new Assembly();
+
+ FileSet fs = new FileSet();
+ fs.setDirectory( "/dir" );
+
+ assembly.addFileSet( fs );
+
+ fs = new FileSet();
+ fs.setDirectory( "/other-dir" );
+ assembly.addFileSet( fs );
+
+ fs = new FileSet();
+ fs.setDirectory( "/third-dir" );
+
+ Component component = new Component();
+
+ component.addFileSet( fs );
+
+ new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
+
+ List fileSets = assembly.getFileSets();
+
+ assertNotNull( fileSets );
+ assertEquals( 3, fileSets.size() );
+
+ FileSet rfs1 = (FileSet) fileSets.get( 0 );
+ assertEquals( "/dir", rfs1.getDirectory() );
+
+ FileSet rfs2 = (FileSet) fileSets.get( 1 );
+ assertEquals( "/other-dir", rfs2.getDirectory() );
+
+ FileSet rfs3 = (FileSet) fileSets.get( 2 );
+ assertEquals( "/third-dir", rfs3.getDirectory() );
+
+ }
+
+ public void testMergeComponentWithAssembly_ShouldAddOneFileItemToExistingListOfTwo()
+ {
+ Assembly assembly = new Assembly();
+
+ FileItem fi = new FileItem();
+ fi.setSource( "file" );
+
+ assembly.addFile( fi );
+
+ fi = new FileItem();
+ fi.setSource( "file2" );
+
+ assembly.addFile( fi );
+
+ fi = new FileItem();
+ fi.setSource( "file3" );
+
+ Component component = new Component();
+
+ component.addFile( fi );
+
+ new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
+
+ List fileItems = assembly.getFiles();
+
+ assertNotNull( fileItems );
+ assertEquals( 3, fileItems.size() );
+
+ FileItem rf1 = (FileItem) fileItems.get( 0 );
+ assertEquals( "file", rf1.getSource() );
+
+ FileItem rf2 = (FileItem) fileItems.get( 1 );
+ assertEquals( "file2", rf2.getSource() );
+
+ FileItem rf3 = (FileItem) fileItems.get( 2 );
+ assertEquals( "file3", rf3.getSource() );
+
+ }
+
+ public void testMergeComponentWithAssembly_ShouldAddOneDependencySetToExistingListOfTwo()
+ {
+ Assembly assembly = new Assembly();
+
+ DependencySet ds = new DependencySet();
+ ds.setScope( Artifact.SCOPE_RUNTIME );
+
+ assembly.addDependencySet( ds );
+
+ ds = new DependencySet();
+ ds.setScope( Artifact.SCOPE_COMPILE );
+
+ assembly.addDependencySet( ds );
+
+ Component component = new Component();
+
+ ds = new DependencySet();
+ ds.setScope( Artifact.SCOPE_SYSTEM );
+
+ component.addDependencySet( ds );
+
+ new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
+
+ List depSets = assembly.getDependencySets();
+
+ assertNotNull( depSets );
+ assertEquals( 3, depSets.size() );
+
+ assertEquals( Artifact.SCOPE_RUNTIME, ((DependencySet) depSets.get( 0 )).getScope() );
+ assertEquals( Artifact.SCOPE_COMPILE, ((DependencySet) depSets.get( 1 )).getScope() );
+ assertEquals( Artifact.SCOPE_SYSTEM, ((DependencySet) depSets.get( 2 )).getScope() );
+ }
+
+ // FIXME: Deep merging should take place...
+ // public void
+ // testMergeComponentWithAssembly_ShouldMergeOneFileSetToOneOfExistingTwo()
+ // {
+ // Assembly assembly = new Assembly();
+ //
+ // FileSet fs = new FileSet();
+ // fs.setDirectory( "/dir" );
+ // fs.addInclude( "**/test.txt" );
+ //
+ // assembly.addFileSet( fs );
+ //
+ // fs = new FileSet();
+ // fs.setDirectory( "/other-dir" );
+ // assembly.addFileSet( fs );
+ //
+ // fs = new FileSet();
+ // fs.setDirectory( "/dir" );
+ // fs.addInclude( "**/components.txt" );
+ //
+ // Component component = new Component();
+ //
+ // component.addFileSet( fs );
+ //
+ // new DefaultAssemblyReader().mergeComponentWithAssembly( component,
+ // assembly );
+ //
+ // List fileSets = assembly.getFileSets();
+ //
+ // assertNotNull( fileSets );
+ // assertEquals( 2, fileSets.size() );
+ //
+ // FileSet rfs1 = (FileSet) fileSets.get( 0 );
+ // assertEquals( "/dir", rfs1.getDirectory() );
+ //
+ // List includes = rfs1.getIncludes();
+ //
+ // assertNotNull( includes );
+ // assertEquals( 2, includes.size() );
+ // assertTrue( includes.contains( "**/test.txt" ) );
+ // assertTrue( includes.contains( "**/components.txt" ) );
+ //
+ // FileSet rfs2 = (FileSet) fileSets.get( 1 );
+ // assertEquals( "/other-dir", rfs2.getDirectory() );
+ //
+ // }
+
+ public void testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly()
+ throws IOException, AssemblyReadException
+ {
+ Component component = new Component();
+
+ FileSet fileSet = new FileSet();
+ fileSet.setDirectory( "/dir" );
+
+ component.addFileSet( fileSet );
+
+ File componentFile = fileManager.createTempFile();
+
+ FileWriter writer = null;
+
+ try
+ {
+ writer = new FileWriter( componentFile );
+
+ ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
+
+ componentWriter.write( writer, component );
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+
+ String filename = componentFile.getName();
+
+ Assembly assembly = new Assembly();
+ assembly.addComponentDescriptor( filename );
+
+ File basedir = componentFile.getParentFile();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir );
+
+ mockManager.replayAll();
+
+ new DefaultAssemblyReader().mergeComponentsWithMainAssembly( assembly, configSource );
+
+ List fileSets = assembly.getFileSets();
+
+ assertNotNull( fileSets );
+ assertEquals( 1, fileSets.size() );
+
+ FileSet fs = (FileSet) fileSets.get( 0 );
+
+ assertEquals( "/dir", fs.getDirectory() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testReadAssembly_ShouldReadAssemblyWithoutComponentsInterpolationOrSiteDirInclusion()
+ throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
+ {
+ Assembly assembly = new Assembly();
+ assembly.setId( "test" );
+
+ StringWriter sw = new StringWriter();
+ AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+
+ assemblyWriter.write( sw, assembly );
+
+ StringReader sr = new StringReader( sw.toString() );
+
+ File basedir = fileManager.createTempDir();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir );
+
+ Model model = new Model();
+ model.setGroupId( "group" );
+ model.setArtifactId( "artifact" );
+ model.setVersion( "version" );
+
+ MavenProject project = new MavenProject( model );
+
+ configSource.getProject();
+ configSourceControl.setReturnValue( project );
+
+ configSource.isSiteIncluded();
+ configSourceControl.setReturnValue( false );
+
+ mockManager.replayAll();
+
+ Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
+
+ assertEquals( assembly.getId(), result.getId() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromAssemblyWithoutComponentsOrInterpolation()
+ throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
+ {
+ Assembly assembly = new Assembly();
+ assembly.setId( "test" );
+
+ assembly.setIncludeSiteDirectory( true );
+
+ StringWriter sw = new StringWriter();
+ AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+
+ assemblyWriter.write( sw, assembly );
+
+ StringReader sr = new StringReader( sw.toString() );
+
+ File siteDir = fileManager.createTempDir();
+
+ configSource.getSiteDirectory();
+ configSourceControl.setReturnValue( siteDir );
+
+ File basedir = fileManager.createTempDir();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir );
+
+ Model model = new Model();
+ model.setGroupId( "group" );
+ model.setArtifactId( "artifact" );
+ model.setVersion( "version" );
+
+ MavenProject project = new MavenProject( model );
+
+ configSource.getProject();
+ configSourceControl.setReturnValue( project );
+
+ configSource.isSiteIncluded();
+ configSourceControl.setReturnValue( false );
+
+ mockManager.replayAll();
+
+ Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
+
+ assertEquals( assembly.getId(), result.getId() );
+
+ List fileSets = result.getFileSets();
+
+ assertEquals( 1, fileSets.size() );
+
+ assertEquals( "/site", ((FileSet) fileSets.get( 0 )).getOutputDirectory() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromConfigWithoutComponentsOrInterpolation()
+ throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
+ {
+ Assembly assembly = new Assembly();
+ assembly.setId( "test" );
+
+ StringWriter sw = new StringWriter();
+ AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+
+ assemblyWriter.write( sw, assembly );
+
+ StringReader sr = new StringReader( sw.toString() );
+
+ File siteDir = fileManager.createTempDir();
+
+ configSource.getSiteDirectory();
+ configSourceControl.setReturnValue( siteDir );
+
+ File basedir = fileManager.createTempDir();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir );
+
+ Model model = new Model();
+ model.setGroupId( "group" );
+ model.setArtifactId( "artifact" );
+ model.setVersion( "version" );
+
+ MavenProject project = new MavenProject( model );
+
+ configSource.getProject();
+ configSourceControl.setReturnValue( project );
+
+ configSource.isSiteIncluded();
+ configSourceControl.setReturnValue( true );
+
+ mockManager.replayAll();
+
+ Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
+
+ assertEquals( assembly.getId(), result.getId() );
+
+ List fileSets = result.getFileSets();
+
+ assertEquals( 1, fileSets.size() );
+
+ assertEquals( "/site", ((FileSet) fileSets.get( 0 )).getOutputDirectory() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation()
+ throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
+ {
+ File componentsFile = fileManager.createTempFile();
+
+ File basedir = componentsFile.getParentFile();
+ String componentsFilename = componentsFile.getName();
+
+ Component component = new Component();
+
+ FileSet fs = new FileSet();
+ fs.setDirectory( "/dir" );
+
+ component.addFileSet( fs );
+
+ FileWriter fw = null;
+
+ try
+ {
+ fw = new FileWriter( componentsFile );
+ new ComponentXpp3Writer().write( fw, component );
+ }
+ finally
+ {
+ IOUtil.close( fw );
+ }
+
+ Assembly assembly = new Assembly();
+ assembly.setId( "test" );
+
+ assembly.addComponentDescriptor( componentsFilename );
+
+ StringWriter sw = new StringWriter();
+ AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+
+ assemblyWriter.write( sw, assembly );
+
+ StringReader sr = new StringReader( sw.toString() );
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir, MockControl.ONE_OR_MORE );
+
+ Model model = new Model();
+ model.setGroupId( "group" );
+ model.setArtifactId( "artifact" );
+ model.setVersion( "version" );
+
+ MavenProject project = new MavenProject( model );
+
+ configSource.getProject();
+ configSourceControl.setReturnValue( project );
+
+ configSource.isSiteIncluded();
+ configSourceControl.setReturnValue( false );
+
+ mockManager.replayAll();
+
+ Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
+
+ assertEquals( assembly.getId(), result.getId() );
+
+ List fileSets = result.getFileSets();
+
+ assertEquals( 1, fileSets.size() );
+
+ assertEquals( "/dir", ((FileSet) fileSets.get( 0 )).getDirectory() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testReadAssembly_ShouldReadAssemblyWithInterpolationWithoutComponentsOrSiteDirInclusion()
+ throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
+ {
+ Assembly assembly = new Assembly();
+ assembly.setId( "${groupId}-assembly" );
+
+ StringWriter sw = new StringWriter();
+ AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+
+ assemblyWriter.write( sw, assembly );
+
+ StringReader sr = new StringReader( sw.toString() );
+
+ File basedir = fileManager.createTempDir();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir );
+
+ Model model = new Model();
+ model.setGroupId( "group" );
+ model.setArtifactId( "artifact" );
+ model.setVersion( "version" );
+
+ MavenProject project = new MavenProject( model );
+
+ configSource.getProject();
+ configSourceControl.setReturnValue( project );
+
+ configSource.isSiteIncluded();
+ configSourceControl.setReturnValue( false );
+
+ mockManager.replayAll();
+
+ Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
+
+ assertEquals( "group-assembly", result.getId() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testGetAssemblyFromDescriptorFile_ShouldReadAssembly()
+ throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
+ {
+ Assembly assembly = new Assembly();
+ assembly.setId( "test" );
+
+ FileSet fs = new FileSet();
+ fs.setDirectory( "/dir" );
+
+ assembly.addFileSet( fs );
+
+ File assemblyFile = fileManager.createTempFile();
+
+ File basedir = assemblyFile.getParentFile();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir, MockControl.ONE_OR_MORE );
+
+ configSource.getProject();
+ configSourceControl.setReturnValue( new MavenProject( new Model() ), MockControl.ONE_OR_MORE );
+
+ configSource.isSiteIncluded();
+ configSourceControl.setReturnValue( false );
+
+ FileWriter writer = null;
+ try
+ {
+ writer = new FileWriter( assemblyFile );
+ new AssemblyXpp3Writer().write( writer, assembly );
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+
+ mockManager.replayAll();
+
+ Assembly result = new DefaultAssemblyReader().getAssemblyFromDescriptorFile( assemblyFile, configSource );
+
+ assertEquals( assembly.getId(), result.getId() );
+
+ mockManager.verifyAll();
+ }
+
+ public void testGetAssemblyForDescriptorReference_ShouldReadBinaryAssemblyRef()
+ throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
+ {
+ File basedir = fileManager.createTempDir();
+
+ configSource.getBasedir();
+ configSourceControl.setReturnValue( basedir, MockControl.ONE_OR_MORE );
+
+ configSource.getProject();
+ configSourceControl.setReturnValue( new MavenProject( new Model() ), MockControl.ONE_OR_MORE );
+
+ configSource.isSiteIncluded();
+ configSourceControl.setReturnValue( false );
+
+ mockManager.replayAll();
+
+ Assembly result = new DefaultAssemblyReader().getAssemblyForDescriptorReference( "bin", configSource );
+
+ assertEquals( "bin", result.getId() );
+
+ mockManager.verifyAll();
+ }
+
+}
Propchange: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java?rev=424492&view=auto
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java (added)
+++ maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java Fri Jul 21 16:32:25 2006
@@ -0,0 +1,80 @@
+package org.apache.maven.plugin.assembly.testutils;
+
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class TestFileManager
+{
+
+ public static final String TEMP_DIR_PATH = System.getProperty( "java.io.tempdir" );
+
+ private List filesToDelete = new ArrayList();
+
+ private final String baseFilename;
+
+ public TestFileManager( String baseFilename )
+ {
+ this.baseFilename = baseFilename;
+ }
+
+ public void markForDeletion( File toDelete )
+ {
+ filesToDelete.add( toDelete );
+ }
+
+ public synchronized File createTempDir()
+ {
+ try
+ {
+ Thread.sleep( 20 );
+ }
+ catch ( InterruptedException e )
+ {
+ }
+
+ File dir = new File( TEMP_DIR_PATH, baseFilename + System.currentTimeMillis() );
+
+ dir.mkdirs();
+ markForDeletion( dir );
+
+ return dir;
+ }
+
+ public synchronized File createTempFile()
+ throws IOException
+ {
+ File tempFile = File.createTempFile( baseFilename, "" );
+ tempFile.deleteOnExit();
+
+ return tempFile;
+ }
+
+ public void cleanUp()
+ throws IOException
+ {
+ for ( Iterator it = filesToDelete.iterator(); it.hasNext(); )
+ {
+ File file = (File) it.next();
+
+ if ( file.exists() )
+ {
+ if ( file.isDirectory() )
+ {
+ FileUtils.deleteDirectory( file );
+ }
+ else
+ {
+ file.delete();
+ }
+ }
+
+ it.remove();
+ }
+ }
+
+}
Propchange: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/utils/PropertiesInterpolationValueSourceTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/utils/PropertiesInterpolationValueSourceTest.java?rev=424492&r1=424491&r2=424492&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/utils/PropertiesInterpolationValueSourceTest.java (original)
+++ maven/plugins/branches/MASSEMBLY-124/src/test/java/org/apache/maven/plugin/assembly/utils/PropertiesInterpolationValueSourceTest.java Fri Jul 21 16:32:25 2006
@@ -16,6 +16,14 @@
assertEquals( "value", new PropertiesInterpolationValueSource( props ).getValue( "key" ) );
}
+
+ public void testShouldRetrievePropertyValueForKeyWithDot()
+ {
+ Properties props = new Properties();
+ props.setProperty( "key.with.dot", "value" );
+
+ assertEquals( "value", new PropertiesInterpolationValueSource( props ).getValue( "key.with.dot" ) );
+ }
public void testShouldRetrieveNullValueForMissingKey()
{