use of org.eclipse.che.plugin.maven.generator.archetype.MavenArchetypeImpl 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);
}
Aggregations