ArtifactRepository remoteRepository = new DefaultArtifactRepository( "remote", mavenRepoRemote, layout );
remoteRepositories.add( remoteRepository );
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest()
.setPackage( "org.apache.maven.quickstart" )
.setGroupId( "maven" )
.setArtifactId( "quickstart" )
.setVersion( "1.0-alpha-1-SNAPSHOT" )
.setArchetypeGroupId( "org.apache.maven.archetypes" )
.setArchetypeArtifactId( "maven-archetype-quickstart" )
.setArchetypeVersion( "1.0-alpha-1-SNAPSHOT" )
.setLocalRepository( localRepository )
.setRemoteArtifactRepositories( remoteRepositories )
.setOutputDirectory( getTestFile( "target" ).getAbsolutePath() );
//parameters.put( "name", "jason" );
archetype.createArchetype( request, remoteRepository );
// ----------------------------------------------------------------------
// Set up the Velocity context
// ----------------------------------------------------------------------
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put( "basedir", request.getOutputDirectory() );
parameters.put( "package", request.getPackage() );
parameters.put( "packageName", request.getPackage() );
parameters.put( "groupId", request.getGroupId() );
parameters.put( "artifactId", request.getArtifactId() );
parameters.put( "version", request.getVersion() );
Context context = new VelocityContext();
for ( Map.Entry<String, Object> entry : parameters.entrySet() )
{
context.put( entry.getKey(), entry.getValue() );
}
// ----------------------------------------------------------------------
// Validate POM generation
// ----------------------------------------------------------------------
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class.getName() );
Artifact archetypeArtifact = artifactFactory.createArtifact( request.getArchetypeGroupId(), request.getArchetypeArtifactId(),
request.getArchetypeVersion(), Artifact.SCOPE_RUNTIME, "jar" );
StringWriter writer = new StringWriter();
ClassLoader old = Thread.currentThread().getContextClassLoader();