// Load the descriptor
// ----------------------------------------------------------------------
ArchetypeDescriptorBuilder builder = new ArchetypeDescriptorBuilder();
ArchetypeDescriptor descriptor;
URLClassLoader archetypeJarLoader;
InputStream is = null;
try
{
URL[] urls = new URL[1];
urls[0] = archetypeFile.toURL();
archetypeJarLoader = new URLClassLoader( urls );
is = getStream( ARCHETYPE_DESCRIPTOR, archetypeJarLoader );
if ( is == null )
{
is = getStream( ARCHETYPE_OLD_DESCRIPTOR, archetypeJarLoader );
}
if ( is == null )
{
throw new ArchetypeDescriptorException( "The " + ARCHETYPE_DESCRIPTOR + " descriptor cannot be found." );
}
descriptor = builder.build( new XmlStreamReader( is ) );
}
catch ( IOException e )
{
throw new ArchetypeDescriptorException( "Error reading the " + ARCHETYPE_DESCRIPTOR + " descriptor.", e );
}
catch ( XmlPullParserException e )
{
throw new ArchetypeDescriptorException( "Error reading the " + ARCHETYPE_DESCRIPTOR + " descriptor.", e );
}
finally
{
IOUtil.close( is );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
String artifactId = request.getArtifactId();
File parentPomFile = new File( request.getOutputDirectory(), ARCHETYPE_POM );
File outputDirectoryFile;
boolean creating;
File pomFile;
if ( parentPomFile.exists() && descriptor.isAllowPartial() && artifactId == null )
{
outputDirectoryFile = new File( request.getOutputDirectory() );
creating = false;
pomFile = parentPomFile;
}
else
{
if ( artifactId == null )
{
throw new ArchetypeTemplateProcessingException(
"Artifact ID must be specified when creating a new project from an archetype." );
}
outputDirectoryFile = new File( request.getOutputDirectory(), artifactId );
creating = true;
if ( outputDirectoryFile.exists() )
{
if ( descriptor.isAllowPartial() )
{
creating = false;
}
else
{