use of org.eclipse.che.plugin.maven.shared.MavenArchetype in project che by eclipse.
the class ArchetypeGenerationStrategy method generateProject.
@Override
public void generateProject(final Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
AttributeValue artifactId = attributes.get(ARTIFACT_ID);
AttributeValue groupId = attributes.get(GROUP_ID);
AttributeValue version = attributes.get(VERSION);
if (groupId == null || artifactId == null || version == null) {
throw new ServerException("Missed some required attribute (groupId, artifactId or version)");
}
String archetypeGroupId = null;
String archetypeArtifactId = null;
String archetypeVersion = null;
String archetypeRepository = null;
Map<String, String> archetypeProperties = new HashMap<>();
//TODO: remove prop 'type' now it use only for detecting generation strategy
options.remove("type");
for (Entry<String, String> entry : options.entrySet()) {
switch(entry.getKey()) {
case "archetypeGroupId":
archetypeGroupId = entry.getValue();
break;
case "archetypeArtifactId":
archetypeArtifactId = entry.getValue();
break;
case "archetypeVersion":
archetypeVersion = entry.getValue();
break;
case "archetypeRepository":
archetypeRepository = entry.getValue();
break;
default:
archetypeProperties.put(entry.getKey(), entry.getValue());
}
}
if (isNullOrEmpty(archetypeGroupId) || isNullOrEmpty(archetypeArtifactId) || isNullOrEmpty(archetypeVersion)) {
throw new ServerException("Missed some required option (archetypeGroupId, archetypeArtifactId or archetypeVersion)");
}
MavenArchetype mavenArchetype = new MavenArchetypeImpl(archetypeGroupId, archetypeArtifactId, archetypeVersion, archetypeRepository, archetypeProperties);
final MavenArtifact mavenArtifact = new MavenArtifact();
mavenArtifact.setGroupId(getFirst(groupId.getList(), projectPath.getName()));
mavenArtifact.setArtifactId(getFirst(artifactId.getList(), projectPath.getName()));
mavenArtifact.setVersion(getFirst(version.getList(), DEFAULT_VERSION));
archetypeGenerator.generateFromArchetype(vfs.getRoot().toIoFile(), mavenArchetype, mavenArtifact);
}
use of org.eclipse.che.plugin.maven.shared.MavenArchetype in project che by eclipse.
the class ArchetypeGeneratorTest method generateFromArchetype.
@Test
@Ignore
public void generateFromArchetype() throws Exception {
MavenArchetype mavenArchetype = mock(MavenArchetype.class);
when(mavenArchetype.getArtifactId()).thenReturn("tomee-webapp-archetype");
when(mavenArchetype.getGroupId()).thenReturn("org.apache.openejb.maven");
when(mavenArchetype.getVersion()).thenReturn("1.7.1");
File workDir = Files.createTempDirectory("workDir").toFile();
ArchetypeGenerator archetypeGenerator = new ArchetypeGenerator();
String artifactId = NameGenerator.generate("artifactId", 5);
String groupId = NameGenerator.generate("groupId", 5);
MavenArtifact mavenArtifact = new MavenArtifact();
mavenArtifact.setArtifactId(artifactId);
mavenArtifact.setGroupId(groupId);
mavenArtifact.setVersion("1.0-SNAPSHOT");
archetypeGenerator.generateFromArchetype(workDir, mavenArchetype, mavenArtifact);
String[] list = workDir.list();
List<String> strings = Arrays.asList(list);
Assert.assertTrue(strings.contains(artifactId));
}
Aggregations