Search in sources :

Example 1 with MavenArchetypeImpl

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);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) ServerException(org.eclipse.che.api.core.ServerException) MavenArchetypeImpl(org.eclipse.che.plugin.maven.generator.archetype.MavenArchetypeImpl) HashMap(java.util.HashMap) MavenArchetype(org.eclipse.che.plugin.maven.shared.MavenArchetype) MavenArtifact(org.eclipse.che.ide.maven.tools.MavenArtifact)

Aggregations

HashMap (java.util.HashMap)1 ServerException (org.eclipse.che.api.core.ServerException)1 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)1 MavenArtifact (org.eclipse.che.ide.maven.tools.MavenArtifact)1 MavenArchetypeImpl (org.eclipse.che.plugin.maven.generator.archetype.MavenArchetypeImpl)1 MavenArchetype (org.eclipse.che.plugin.maven.shared.MavenArchetype)1