ArchetypeManager archetype = (ArchetypeManager) lookup( ArchetypeManager.ROLE );
ArchetypeRegistryManager registryManager = (ArchetypeRegistryManager) lookup( ArchetypeRegistryManager.ROLE );
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
ArtifactRepository localRepository = registryManager.createRepository( new File( getBasedir(),
"target" + File.separator
+ "test-classes"
+ File.separator
+ "repositories"
+ File.separator
+ "local" ).toURI().toURL().toExternalForm(),
"local-repo" );
ArtifactRepository centralRepository = registryManager.createRepository( new File( getBasedir(),
"target" + File.separator
+ "test-classes"
+ File.separator
+ "repositories"
+ File.separator
+ "central" ).toURI().toURL().toExternalForm(),
"central-repo" );
// (1) create a project from scratch
// (2) create an archetype from the project
// (3) create our own archetype catalog properties in memory
// (4) create our own archetype catalog describing the archetype we just created
// (5) deploy the archetype we just created
// (6) create a project form the archetype we just created
// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
// (1) create a project from scratch
// File sourceProject = new File( getBasedir( ), "target/test-classes/projects/roundtrip-1-project" );
File workingProject = new File( getBasedir(),
"target" + File.separator + "test-classes" + File.separator + "projects"
+ File.separator + "roundtrip-multi" );
FileUtils.forceDelete( new File( workingProject, "target" ) );
// (2) create an archetype from the project
File pom = new File( workingProject, "pom.xml" );
MavenProject project = projectBuilder.build( pom, localRepository, null );
ArchetypeCreationRequest acr =
new ArchetypeCreationRequest().setProject( project ).setLocalRepository( localRepository ).setFiltereds(
Constants.DEFAULT_FILTERED_EXTENSIONS ).setLanguages( Constants.DEFAULT_LANGUAGES ).setPostPhase(
"package" );
ArchetypeCreationResult creationResult = archetype.createArchetypeFromProject( acr );
if ( creationResult.getCause() != null )
{
throw creationResult.getCause();
}
else
{
assertArchetypeCreated( workingProject );
}
// (3) create our own archetype catalog properties in memory
File catalogDirectory = new File( getBasedir(), "target" + File.separator + "catalog" );
File catalogFile = new File( catalogDirectory, "archetype-catalog.xml" );
File catalogProperties = new File( catalogDirectory, "archetype-catalog.properties" );
catalogDirectory.mkdirs();
Properties p = new Properties();
p.setProperty( "sources", "catalog" );
p.setProperty( "catalog.file", catalogFile.getAbsolutePath() );
OutputStream os = new FileOutputStream( catalogProperties );
p.store( os, "Generated catalog properties" );
// (5) install the archetype we just created
File generatedArchetypeDirectory = new File( project.getBasedir(),
"target" + File.separator + "generated-sources" + File.separator
+ "archetype" );
File generatedArchetypePom = new File( generatedArchetypeDirectory, "pom.xml" );
MavenProject generatedArchetypeProject = projectBuilder.build( generatedArchetypePom, localRepository, null );
File archetypeDirectory =
new File( generatedArchetypeDirectory, "src" + File.separator + "main" + File.separator + "resources" );
File archetypeArchive = archetype.archiveArchetype( archetypeDirectory, new File(