Search in sources :

Example 1 with Build

use of org.eclipse.che.ide.maven.tools.Build in project che by eclipse.

the class MavenModelReader method doRead.

private ModelReadingResult doRead(File pom) {
    List<MavenProjectProblem> problems = new ArrayList<>();
    Set<String> enabledProfiles = new HashSet<>();
    MavenModel result = new MavenModel();
    fillModelByDefaults(result);
    Model model = null;
    try {
        model = Model.readFrom(pom);
    } catch (IOException e) {
        problems.add(MavenProjectProblem.newProblem(pom.getPath(), e.getMessage(), MavenProblemType.SYNTAX));
    }
    if (model == null) {
        return new ModelReadingResult(result, problems, enabledProfiles);
    }
    final MavenKey parentKey;
    if (model.getParent() == null) {
        parentKey = result.getParent().getMavenKey();
    } else {
        Parent modelParent = model.getParent();
        parentKey = new MavenKey(modelParent.getGroupId(), modelParent.getArtifactId(), modelParent.getVersion());
        MavenParent parent = new MavenParent(parentKey, modelParent.getRelativePath());
        result.setParent(parent);
    }
    final MavenKey mavenKey = new MavenKey(getNotNull(model.getGroupId(), parentKey.getGroupId()), model.getArtifactId(), getNotNull(model.getVersion(), parentKey.getVersion()));
    result.setMavenKey(mavenKey);
    if (model.getPackaging() != null) {
        result.setPackaging(model.getPackaging());
    }
    result.setName(model.getName());
    final List<String> modules = model.getModules();
    if (modules != null) {
        result.setModules(new ArrayList<>(model.getModules()));
    }
    Map<String, String> properties = model.getProperties();
    Properties prop = new Properties();
    if (properties != null) {
        prop.putAll(properties);
    }
    result.setProperties(prop);
    final Build build = model.getBuild();
    if (build != null) {
        final String sourceDirectory = build.getSourceDirectory();
        if (sourceDirectory != null) {
            result.getBuild().setSources(singletonList(sourceDirectory));
        }
        final String testSourceDirectory = build.getTestSourceDirectory();
        if (testSourceDirectory != null) {
            result.getBuild().setTestSources(singletonList(testSourceDirectory));
        }
        result.getBuild().setResources(convertResources(build.getResources()));
    }
    //TODO add profiles
    return new ModelReadingResult(result, problems, enabledProfiles);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenParent(org.eclipse.che.maven.data.MavenParent) Parent(org.eclipse.che.ide.maven.tools.Parent) ArrayList(java.util.ArrayList) MavenParent(org.eclipse.che.maven.data.MavenParent) IOException(java.io.IOException) Properties(java.util.Properties) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenBuild(org.eclipse.che.maven.data.MavenBuild) Build(org.eclipse.che.ide.maven.tools.Build) Model(org.eclipse.che.ide.maven.tools.Model) MavenModel(org.eclipse.che.maven.data.MavenModel) HashSet(java.util.HashSet)

Example 2 with Build

use of org.eclipse.che.ide.maven.tools.Build 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

Build (org.eclipse.che.ide.maven.tools.Build)2 Model (org.eclipse.che.ide.maven.tools.Model)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)1 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)1 Parent (org.eclipse.che.ide.maven.tools.Parent)1 MavenBuild (org.eclipse.che.maven.data.MavenBuild)1 MavenKey (org.eclipse.che.maven.data.MavenKey)1 MavenModel (org.eclipse.che.maven.data.MavenModel)1 MavenParent (org.eclipse.che.maven.data.MavenParent)1 MavenProjectProblem (org.eclipse.che.maven.data.MavenProjectProblem)1