Search in sources :

Example 1 with MavenParent

use of org.eclipse.che.maven.data.MavenParent in project che by eclipse.

the class MavenModelUtil method convertModel.

public static MavenModel convertModel(Model model, List<String> sources, List<String> testSources, Collection<Artifact> dependencies, Collection<Artifact> extensions, File localRepo) {
    MavenModel result = new MavenModel();
    result.setMavenKey(new MavenKey(model.getGroupId(), model.getArtifactId(), model.getVersion()));
    Parent parent = model.getParent();
    if (parent != null) {
        result.setParent(new MavenParent(new MavenKey(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()), parent.getRelativePath()));
    }
    result.setName(model.getName());
    result.setPackaging(model.getPackaging());
    result.setProperties(model.getProperties() != null ? model.getProperties() : new Properties());
    result.setModules(model.getModules());
    result.setPlugins(convertPlugins(model));
    Map<Artifact, MavenArtifact> convertedArtifacts = new HashMap<>();
    result.setExtensions(convertArtifacts(extensions, convertedArtifacts, localRepo));
    result.setDependencies(convertArtifacts(dependencies, convertedArtifacts, localRepo));
    result.setRemoteRepositories(convertRepositories(model.getRepositories()));
    result.setProfiles(convertProfiles(model.getProfiles()));
    convertBuild(result.getBuild(), model.getBuild(), sources, testSources);
    return result;
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenModel(org.eclipse.che.maven.data.MavenModel) Parent(org.apache.maven.model.Parent) MavenParent(org.eclipse.che.maven.data.MavenParent) HashMap(java.util.HashMap) MavenParent(org.eclipse.che.maven.data.MavenParent) Properties(java.util.Properties) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with MavenParent

use of org.eclipse.che.maven.data.MavenParent 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 3 with MavenParent

use of org.eclipse.che.maven.data.MavenParent in project che by eclipse.

the class MavenModelReader method fillModelByDefaults.

private void fillModelByDefaults(MavenModel model) {
    model.setMavenKey(new MavenKey("unknown", "unknown", "unknown"));
    final MavenKey parentKey = new MavenKey("unknown", "unknown", "unknown");
    model.setParent(new MavenParent(parentKey, "../pom.xml"));
    model.setPackaging("jar");
    model.setModules(emptyList());
    final MavenBuild build = model.getBuild();
    build.setSources(singletonList(DEFAULT_SOURCE_FOLDER));
    build.setTestSources(singletonList(DEFAULT_TEST_SOURCE_FOLDER));
    build.setResources(singletonList(new MavenResource(DEFAULT_RESOURCES_FOLDER, false, null, Collections.emptyList(), Collections.emptyList())));
    build.setTestResources(singletonList(new MavenResource(DEFAULT_TEST_RESOURCES_FOLDER, false, null, Collections.emptyList(), Collections.emptyList())));
}
Also used : MavenBuild(org.eclipse.che.maven.data.MavenBuild) MavenKey(org.eclipse.che.maven.data.MavenKey) MavenResource(org.eclipse.che.maven.data.MavenResource) MavenParent(org.eclipse.che.maven.data.MavenParent)

Aggregations

MavenKey (org.eclipse.che.maven.data.MavenKey)3 MavenParent (org.eclipse.che.maven.data.MavenParent)3 Properties (java.util.Properties)2 MavenBuild (org.eclipse.che.maven.data.MavenBuild)2 MavenModel (org.eclipse.che.maven.data.MavenModel)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Artifact (org.apache.maven.artifact.Artifact)1 Parent (org.apache.maven.model.Parent)1 Build (org.eclipse.che.ide.maven.tools.Build)1 Model (org.eclipse.che.ide.maven.tools.Model)1 Parent (org.eclipse.che.ide.maven.tools.Parent)1 MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)1 MavenProjectProblem (org.eclipse.che.maven.data.MavenProjectProblem)1 MavenResource (org.eclipse.che.maven.data.MavenResource)1