protected void createTestProject(String archetypeArtifactId, String archetypeVersion) throws Exception {
MavenProject project = getMavenProject();
FileUtils.deleteDirectory(getTestFile("target/" + project.getArtifactId()));
Archetype archetype = (Archetype) lookup(Archetype.ROLE);
String localRepoPath = System.getProperty( "localRepoPath" );
if (StringUtils.isEmpty(localRepoPath)) {
localRepoPath = System.getProperty("user.home") + System.getProperty("file.separator") +
".m2" + System.getProperty("file.separator") + "repository";
}
String mavenRepoLocal = "file://" + localRepoPath;
ArtifactRepositoryLayout layout =
(ArtifactRepositoryLayout) container.lookup(ArtifactRepositoryLayout.ROLE, "default");
ArtifactRepository localRepository = new DefaultArtifactRepository("local", mavenRepoLocal, layout);
List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
String archetypeGroupId = "org.appfuse.archetypes";
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
request.setGroupId(project.getGroupId()).setArtifactId(project.getArtifactId()).setVersion("1.0-SNAPSHOT");
request.setArchetypeGroupId(archetypeGroupId).setArchetypeArtifactId(archetypeArtifactId);
request.setArchetypeVersion(archetypeVersion);
request.setLocalRepository(localRepository);
request.setRemoteArtifactRepositories(remoteRepositories);
request.setOutputDirectory(getTestFile("target").getAbsolutePath());
archetype.generateProjectFromArchetype(request);
}