Search in sources :

Example 1 with MavenModel

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

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

the class MavenProject method setModel.

private MavenProjectModifications setModel(MavenModelReaderResult readerResult, boolean clearArtifacts, boolean clearProfiles) {
    Info newInfo = info.clone();
    newInfo.problems = readerResult.getProblems();
    newInfo.activeProfiles = readerResult.getActiveProfiles();
    MavenModel model = readerResult.getMavenModel();
    newInfo.mavenKey = model.getMavenKey();
    if (model.getParent() != null) {
        newInfo.parentKey = model.getParent().getMavenKey();
    }
    newInfo.packaging = model.getPackaging();
    newInfo.name = model.getName();
    newInfo.sources = model.getBuild().getSources();
    newInfo.testSources = model.getBuild().getTestSources();
    newInfo.resources = model.getBuild().getResources();
    newInfo.testResources = model.getBuild().getTestResources();
    newInfo.properties = model.getProperties();
    newInfo.filters = model.getBuild().getFilters();
    Set<MavenRemoteRepository> remoteRepositories = new HashSet<>();
    Set<MavenArtifact> extensions = new HashSet<>();
    Set<MavenArtifact> dependencies = new HashSet<>();
    Set<MavenPlugin> plugins = new HashSet<>();
    Set<MavenKey> unresolvedArtifacts = new HashSet<>();
    if (!clearArtifacts) {
        if (info.remoteRepositories != null) {
            remoteRepositories.addAll(info.remoteRepositories);
        }
        if (info.extensions != null) {
            extensions.addAll(info.extensions);
        }
        if (info.dependencies != null) {
            dependencies.addAll(info.dependencies);
        }
        if (info.plugins != null) {
            plugins.addAll(info.plugins);
        }
        if (info.unresolvedArtifacts != null) {
            unresolvedArtifacts.addAll(info.unresolvedArtifacts);
        }
    }
    remoteRepositories.addAll(model.getRemoteRepositories());
    extensions.addAll(model.getExtensions());
    dependencies.addAll(model.getDependencies());
    plugins.addAll(model.getPlugins());
    unresolvedArtifacts.addAll(readerResult.getUnresolvedArtifacts());
    newInfo.remoteRepositories = new ArrayList<>(remoteRepositories);
    newInfo.extensions = new ArrayList<>(extensions);
    newInfo.dependencies = new ArrayList<>(dependencies);
    newInfo.plugins = new ArrayList<>(plugins);
    newInfo.unresolvedArtifacts = unresolvedArtifacts;
    newInfo.modulesNameToPath = collectModulesNameAndPath(model);
    return setInfo(newInfo);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenPlugin(org.eclipse.che.maven.data.MavenPlugin) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) HashSet(java.util.HashSet)

Example 3 with MavenModel

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

the class MavenServerManagerTest method testMultimoduleProjectModuleHasDependencyOnAnotherModule.

@Test
public void testMultimoduleProjectModuleHasDependencyOnAnotherModule() throws Exception {
    MavenServerResult resolveProject = mavenServer.resolveProject(new File(MavenServerManagerTest.class.getResource("/multimoduleProject/test/pom.xml").getFile()), Collections.emptyList(), Collections.emptyList());
    assertNotNull(resolveProject);
    MavenProjectInfo projectInfo = resolveProject.getProjectInfo();
    assertNotNull(projectInfo);
    MavenModel mavenModel = projectInfo.getMavenModel();
    assertNotNull(mavenModel);
    assertThat(mavenModel.getPackaging()).isEqualTo("jar");
    assertThat(mavenModel.getModules()).isEmpty();
    assertThat(mavenModel.getDependencies()).isNotEmpty().hasSize(6);
    mavenModel.getDependencies().forEach(mavenArtifact -> System.out.println(mavenArtifact.getFile().getAbsolutePath()));
}
Also used : MavenServerResult(org.eclipse.che.maven.server.MavenServerResult) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenProjectInfo(org.eclipse.che.maven.server.MavenProjectInfo) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with MavenModel

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

the class MavenServerManagerTest method testResolveMultimoduleProjectModulePom.

@Test
public void testResolveMultimoduleProjectModulePom() throws Exception {
    MavenServerResult resolveProject = mavenServer.resolveProject(new File(MavenServerManagerTest.class.getResource("/multimoduleProject/subModule/pom.xml").getFile()), Collections.emptyList(), Collections.emptyList());
    assertNotNull(resolveProject);
    MavenProjectInfo projectInfo = resolveProject.getProjectInfo();
    assertNotNull(projectInfo);
    MavenModel mavenModel = projectInfo.getMavenModel();
    assertNotNull(mavenModel);
    assertThat(mavenModel.getPackaging()).isEqualTo("jar");
    assertThat(mavenModel.getModules()).isEmpty();
    assertThat(mavenModel.getDependencies()).isNotEmpty().hasSize(3);
}
Also used : MavenServerResult(org.eclipse.che.maven.server.MavenServerResult) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenProjectInfo(org.eclipse.che.maven.server.MavenProjectInfo) File(java.io.File) Test(org.testng.annotations.Test)

Example 5 with MavenModel

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

the class MavenServerManagerTest method testProjectHasDependencies.

@Test
public void testProjectHasDependencies() throws Exception {
    MavenServerResult resolveProject = mavenServer.resolveProject(new File(MavenServerManagerTest.class.getResource("/FirstProject/pom.xml").getFile()), Collections.emptyList(), Collections.emptyList());
    assertNotNull(resolveProject);
    MavenProjectInfo projectInfo = resolveProject.getProjectInfo();
    assertNotNull(projectInfo);
    MavenModel mavenModel = projectInfo.getMavenModel();
    assertNotNull(mavenModel);
    List<MavenArtifact> dependencies = mavenModel.getDependencies();
    assertFalse(dependencies.isEmpty());
    assertEquals(26, dependencies.size());
}
Also used : MavenServerResult(org.eclipse.che.maven.server.MavenServerResult) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenProjectInfo(org.eclipse.che.maven.server.MavenProjectInfo) File(java.io.File) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Test(org.testng.annotations.Test)

Aggregations

MavenModel (org.eclipse.che.maven.data.MavenModel)13 File (java.io.File)7 MavenKey (org.eclipse.che.maven.data.MavenKey)6 Test (org.testng.annotations.Test)6 MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)4 MavenProjectInfo (org.eclipse.che.maven.server.MavenProjectInfo)4 MavenServerResult (org.eclipse.che.maven.server.MavenServerResult)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 MavenParent (org.eclipse.che.maven.data.MavenParent)3 Properties (java.util.Properties)2 Model (org.apache.maven.model.Model)2 Parent (org.apache.maven.model.Parent)2 MavenBuild (org.eclipse.che.maven.data.MavenBuild)2 MavenProjectProblem (org.eclipse.che.maven.data.MavenProjectProblem)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RemoteException (java.rmi.RemoteException)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1