From 244f6070e8f4a4ec0a89899b97e5a47b5a0eee3e Mon Sep 17 00:00:00 2001 From: Trygve Laugstol Date: Thu, 6 Jan 2005 13:40:44 +0000 Subject: [PATCH] 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 --- .../maven/archetype/DefaultArchetype.java | 33 ++++++++++++++++--- .../ArchetypeDescriptorBuilder.java | 6 ++-- .../ArchetypeDescriptorBuilderTest.java | 28 ++++++++++++---- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/DefaultArchetype.java b/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/DefaultArchetype.java index 816d9280b7..c8fa453a1a 100644 --- a/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/DefaultArchetype.java +++ b/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/DefaultArchetype.java @@ -87,7 +87,7 @@ public class DefaultArchetype } // ---------------------------------------------------------------------- - // + // Load the descriptor // ---------------------------------------------------------------------- String outputDirectory = (String) parameters.get( "outputDirectory" ); @@ -124,6 +124,10 @@ public class DefaultArchetype throw new ArchetypeDescriptorException( "Error reading the " + ARCHETYPE_DESCRIPTOR + " descriptor.", e ); } + // ---------------------------------------------------------------------- + // Set up the Velocity context + // ---------------------------------------------------------------------- + Context context = new VelocityContext(); context.put( "package", packageName ); @@ -137,17 +141,25 @@ public class DefaultArchetype context.put( key, value ); } + // ---------------------------------------------------------------------- + // Process the templates + // ---------------------------------------------------------------------- + ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader( archetypeJarLoader ); try { - processTemplate( outputDirectory, context, ARCHETYPE_POM, null ); + processTemplate( outputDirectory, context, ARCHETYPE_POM, false, null ); processSources( outputDirectory, context, descriptor.getSources(), packageName ); + processResources( outputDirectory, context, descriptor.getResources(), packageName ); + processSources( outputDirectory, context, descriptor.getTestSources(), packageName ); + + processResources( outputDirectory, context, descriptor.getTestResources(), packageName ); } catch ( Exception e ) { @@ -170,16 +182,27 @@ public class DefaultArchetype { 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 { File f; - if ( packageName != null ) + if ( packageInFileName && packageName != null ) { String path = packageName.replace( '.', '/' ); diff --git a/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilder.java b/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilder.java index e2a72724c7..129aa08c51 100644 --- a/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilder.java +++ b/maven-archetype/maven-archetype-core/src/main/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilder.java @@ -52,7 +52,7 @@ public class ArchetypeDescriptorBuilder if ( resources != null ) { - Xpp3Dom[] resourceList = resources.getChildren( "source" ); + Xpp3Dom[] resourceList = resources.getChildren( "resource" ); 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 ) { - Xpp3Dom[] testResourceList = sources.getChildren( "source" ); + Xpp3Dom[] testResourceList = testResources.getChildren( "resource" ); for ( int i = 0; i < testResourceList.length; i++ ) { diff --git a/maven-archetype/maven-archetype-core/src/test/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilderTest.java b/maven-archetype/maven-archetype-core/src/test/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilderTest.java index ac4aa98253..e084f0dc70 100644 --- a/maven-archetype/maven-archetype-core/src/test/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilderTest.java +++ b/maven-archetype/maven-archetype-core/src/test/java/org/apache/maven/archetype/descriptor/ArchetypeDescriptorBuilderTest.java @@ -38,16 +38,16 @@ public class ArchetypeDescriptorBuilderTest " source1" + " " + " " + - " source0" + - " source1" + + " resource0" + + " resource1" + " " + " " + - " source0" + - " source1" + + " testSource0" + + " testSource1" + " " + " " + - " source0" + - " source1" + + " testResource0" + + " testResource1" + " " + ""; @@ -59,10 +59,26 @@ public class ArchetypeDescriptorBuilderTest assertEquals( 2, descriptor.getSources().size() ); + assertEquals( "source0", descriptor.getSources().get( 0 ) ); + + assertEquals( "source1", descriptor.getSources().get( 1 ) ); + assertEquals( 2, descriptor.getResources().size() ); + assertEquals( "resource0", descriptor.getResources().get( 0 ) ); + + assertEquals( "resource1", descriptor.getResources().get( 1 ) ); + assertEquals( 2, descriptor.getTestSources().size() ); + assertEquals( "testSource0", descriptor.getTestSources().get( 0 ) ); + + assertEquals( "testSource1", descriptor.getTestSources().get( 1 ) ); + assertEquals( 2, descriptor.getTestResources().size() ); + + assertEquals( "testResource0", descriptor.getTestResources().get( 0 ) ); + + assertEquals( "testResource1", descriptor.getTestResources().get( 1 ) ); } }