mirror of https://github.com/apache/maven.git
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:
parent
f5052b6d5a
commit
244f6070e8
|
@ -87,7 +87,7 @@ public void createArchetype( String archetypeGroupId, String archetypeArtifactId
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// Load the descriptor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String outputDirectory = (String) parameters.get( "outputDirectory" );
|
||||
|
@ -124,6 +124,10 @@ public void createArchetype( String archetypeGroupId, String archetypeArtifactId
|
|||
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 void createArchetype( String archetypeGroupId, String archetypeArtifactId
|
|||
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 @@ protected void processSources( String outputDirectory, Context context, List sou
|
|||
{
|
||||
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( '.', '/' );
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public ArchetypeDescriptor build( Reader reader )
|
|||
|
||||
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 ArchetypeDescriptor build( Reader reader )
|
|||
}
|
||||
}
|
||||
|
||||
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++ )
|
||||
{
|
||||
|
|
|
@ -38,16 +38,16 @@ public void testBuilder()
|
|||
" <source>source1</source>" +
|
||||
" </sources>" +
|
||||
" <resources>" +
|
||||
" <source>source0</source>" +
|
||||
" <source>source1</source>" +
|
||||
" <resource>resource0</resource>" +
|
||||
" <resource>resource1</resource>" +
|
||||
" </resources>" +
|
||||
" <testSources>" +
|
||||
" <source>source0</source>" +
|
||||
" <source>source1</source>" +
|
||||
" <source>testSource0</source>" +
|
||||
" <source>testSource1</source>" +
|
||||
" </testSources>" +
|
||||
" <testResources>" +
|
||||
" <source>source0</source>" +
|
||||
" <source>source1</source>" +
|
||||
" <resource>testResource0</resource>" +
|
||||
" <resource>testResource1</resource>" +
|
||||
" </testResources>" +
|
||||
"</archetype>";
|
||||
|
||||
|
@ -59,10 +59,26 @@ public void testBuilder()
|
|||
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue