o Improving test case.

o Fixing proper reading of the resources sections.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163294 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Trygve Laugstol 2005-01-06 13:40:44 +00:00
parent f5052b6d5a
commit 244f6070e8
3 changed files with 53 additions and 14 deletions

View File

@ -87,7 +87,7 @@ public class DefaultArchetype
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// // Load the descriptor
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
String outputDirectory = (String) parameters.get( "outputDirectory" ); String outputDirectory = (String) parameters.get( "outputDirectory" );
@ -124,6 +124,10 @@ public class DefaultArchetype
throw new ArchetypeDescriptorException( "Error reading the " + ARCHETYPE_DESCRIPTOR + " descriptor.", e ); throw new ArchetypeDescriptorException( "Error reading the " + ARCHETYPE_DESCRIPTOR + " descriptor.", e );
} }
// ----------------------------------------------------------------------
// Set up the Velocity context
// ----------------------------------------------------------------------
Context context = new VelocityContext(); Context context = new VelocityContext();
context.put( "package", packageName ); context.put( "package", packageName );
@ -137,17 +141,25 @@ public class DefaultArchetype
context.put( key, value ); context.put( key, value );
} }
// ----------------------------------------------------------------------
// Process the templates
// ----------------------------------------------------------------------
ClassLoader old = Thread.currentThread().getContextClassLoader(); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( archetypeJarLoader ); Thread.currentThread().setContextClassLoader( archetypeJarLoader );
try try
{ {
processTemplate( outputDirectory, context, ARCHETYPE_POM, null ); processTemplate( outputDirectory, context, ARCHETYPE_POM, false, null );
processSources( outputDirectory, context, descriptor.getSources(), packageName ); processSources( outputDirectory, context, descriptor.getSources(), packageName );
processResources( outputDirectory, context, descriptor.getResources(), packageName );
processSources( outputDirectory, context, descriptor.getTestSources(), packageName ); processSources( outputDirectory, context, descriptor.getTestSources(), packageName );
processResources( outputDirectory, context, descriptor.getTestResources(), packageName );
} }
catch ( Exception e ) catch ( Exception e )
{ {
@ -170,16 +182,27 @@ public class DefaultArchetype
{ {
String template = (String) i.next(); String template = (String) i.next();
processTemplate( outputDirectory, context, template, packageName ); processTemplate( outputDirectory, context, template, true, packageName );
} }
} }
protected void processTemplate( String outputDirectory, Context context, String template, String packageName ) protected void processResources( String outputDirectory, Context context, List resources, String packageName )
throws Exception
{
for ( Iterator i = resources.iterator(); i.hasNext(); )
{
String template = (String) i.next();
processTemplate( outputDirectory, context, template, false, packageName );
}
}
protected void processTemplate( String outputDirectory, Context context, String template, boolean packageInFileName, String packageName )
throws Exception throws Exception
{ {
File f; File f;
if ( packageName != null ) if ( packageInFileName && packageName != null )
{ {
String path = packageName.replace( '.', '/' ); String path = packageName.replace( '.', '/' );

View File

@ -52,7 +52,7 @@ public class ArchetypeDescriptorBuilder
if ( resources != null ) if ( resources != null )
{ {
Xpp3Dom[] resourceList = resources.getChildren( "source" ); Xpp3Dom[] resourceList = resources.getChildren( "resource" );
for ( int i = 0; i < resourceList.length; i++ ) for ( int i = 0; i < resourceList.length; i++ )
{ {
@ -72,11 +72,11 @@ public class ArchetypeDescriptorBuilder
} }
} }
Xpp3Dom testResources = dom.getChild( "sources" ); Xpp3Dom testResources = dom.getChild( "testResources" );
if ( testResources != null ) if ( testResources != null )
{ {
Xpp3Dom[] testResourceList = sources.getChildren( "source" ); Xpp3Dom[] testResourceList = testResources.getChildren( "resource" );
for ( int i = 0; i < testResourceList.length; i++ ) for ( int i = 0; i < testResourceList.length; i++ )
{ {

View File

@ -38,16 +38,16 @@ public class ArchetypeDescriptorBuilderTest
" <source>source1</source>" + " <source>source1</source>" +
" </sources>" + " </sources>" +
" <resources>" + " <resources>" +
" <source>source0</source>" + " <resource>resource0</resource>" +
" <source>source1</source>" + " <resource>resource1</resource>" +
" </resources>" + " </resources>" +
" <testSources>" + " <testSources>" +
" <source>source0</source>" + " <source>testSource0</source>" +
" <source>source1</source>" + " <source>testSource1</source>" +
" </testSources>" + " </testSources>" +
" <testResources>" + " <testResources>" +
" <source>source0</source>" + " <resource>testResource0</resource>" +
" <source>source1</source>" + " <resource>testResource1</resource>" +
" </testResources>" + " </testResources>" +
"</archetype>"; "</archetype>";
@ -59,10 +59,26 @@ public class ArchetypeDescriptorBuilderTest
assertEquals( 2, descriptor.getSources().size() ); assertEquals( 2, descriptor.getSources().size() );
assertEquals( "source0", descriptor.getSources().get( 0 ) );
assertEquals( "source1", descriptor.getSources().get( 1 ) );
assertEquals( 2, descriptor.getResources().size() ); assertEquals( 2, descriptor.getResources().size() );
assertEquals( "resource0", descriptor.getResources().get( 0 ) );
assertEquals( "resource1", descriptor.getResources().get( 1 ) );
assertEquals( 2, descriptor.getTestSources().size() ); assertEquals( 2, descriptor.getTestSources().size() );
assertEquals( "testSource0", descriptor.getTestSources().get( 0 ) );
assertEquals( "testSource1", descriptor.getTestSources().get( 1 ) );
assertEquals( 2, descriptor.getTestResources().size() ); assertEquals( 2, descriptor.getTestResources().size() );
assertEquals( "testResource0", descriptor.getTestResources().get( 0 ) );
assertEquals( "testResource1", descriptor.getTestResources().get( 1 ) );
} }
} }