Search in sources :

Example 16 with AttributeValue

use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.

the class SimpleGeneratorStrategy method generateProject.

@Override
public void generateProject(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 (artifactId == null) {
        throw new ConflictException("Missed required attribute artifactId");
    }
    if (groupId == null) {
        throw new ConflictException("Missed required attribute groupId");
    }
    if (version == null) {
        throw new ConflictException("Missed required attribute version");
    }
    Model model = Model.createModel();
    model.setModelVersion("4.0.0");
    final FolderEntry baseFolder = new FolderEntry(vfs.getRoot().createFolder(projectPath.toString()));
    if (baseFolder.getChild("pom.xml") == null) {
        baseFolder.createFile("pom.xml", new byte[0]);
    }
    AttributeValue parentArtifactId = attributes.get(PARENT_ARTIFACT_ID);
    if (parentArtifactId != null) {
        model.setArtifactId(parentArtifactId.getString());
    }
    AttributeValue parentGroupId = attributes.get(PARENT_GROUP_ID);
    if (parentGroupId != null) {
        model.setGroupId(parentGroupId.getString());
    }
    AttributeValue parentVersion = attributes.get(PARENT_VERSION);
    if (parentVersion != null) {
        model.setVersion(parentVersion.getString());
    }
    model.setArtifactId(artifactId.getString());
    model.setGroupId(groupId.getString());
    model.setVersion(version.getString());
    AttributeValue packaging = attributes.get(PACKAGING);
    if (packaging != null) {
        model.setPackaging(packaging.getString());
    }
    AttributeValue sourceFolders = attributes.get(SOURCE_FOLDER);
    if (sourceFolders != null) {
        final String sourceFolder = sourceFolders.getString();
        baseFolder.createFolder(sourceFolder);
        if (!DEFAULT_SOURCE_FOLDER.equals(sourceFolder)) {
            model.setBuild(new Build().setSourceDirectory(sourceFolder));
        }
    }
    AttributeValue testSourceFolders = attributes.get(TEST_SOURCE_FOLDER);
    if (testSourceFolders != null) {
        final String testSourceFolder = testSourceFolders.getString();
        baseFolder.createFolder(testSourceFolder);
        if (!DEFAULT_TEST_SOURCE_FOLDER.equals(testSourceFolder)) {
            Build build = model.getBuild();
            if (build != null) {
                build.setTestSourceDirectory(testSourceFolder);
            } else {
                model.setBuild(new Build().setTestSourceDirectory(testSourceFolder));
            }
        }
    }
    model.writeTo(baseFolder.getChild("pom.xml").getVirtualFile());
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) ConflictException(org.eclipse.che.api.core.ConflictException) Build(org.eclipse.che.ide.maven.tools.Build) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) Model(org.eclipse.che.ide.maven.tools.Model)

Aggregations

AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)16 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Test (org.junit.Test)8 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)7 ProjectConfig (org.eclipse.che.api.core.model.project.ProjectConfig)5 File (java.io.File)2 Map (java.util.Map)2 ServerException (org.eclipse.che.api.core.ServerException)2 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)2 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)2 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1