Search in sources :

Example 6 with MavenModel

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

the class ProjectResolverTest method testProjectHasDependencies.

@Test
public void testProjectHasDependencies() throws Exception {
    MavenServerResult resolveProject = mavenServer.resolveProject(new File(MavenServerTest.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 : MavenModel(org.eclipse.che.maven.data.MavenModel) File(java.io.File) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Test(org.testng.annotations.Test)

Example 7 with MavenModel

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

the class MavenModelUtil method convertToMavenModel.

public static Model convertToMavenModel(MavenModel model) {
    Model result = new Model();
    result.setArtifactId(model.getMavenKey().getArtifactId());
    result.setGroupId(model.getMavenKey().getGroupId());
    result.setVersion(model.getMavenKey().getVersion());
    result.setPackaging(model.getPackaging());
    result.setName(model.getName());
    if (model.getParent() != null) {
        Parent parent = new Parent();
        MavenKey parentKey = model.getParent().getMavenKey();
        parent.setArtifactId(parentKey.getArtifactId());
        parent.setGroupId(parentKey.getGroupId());
        parent.setVersion(parentKey.getVersion());
        parent.setRelativePath(model.getParent().getRelativePath());
        result.setParent(parent);
    }
    result.setProperties(model.getProperties());
    result.setModules(model.getModules());
    result.setBuild(new Build());
    MavenBuild modelBuild = model.getBuild();
    convertToMavenBuildBase(modelBuild, result.getBuild());
    result.getBuild().setSourceDirectory(modelBuild.getSources().get(0));
    result.getBuild().setTestSourceDirectory(modelBuild.getTestSources().get(0));
    result.setProfiles(convertToMavenProfiles(model.getProfiles()));
    return result;
}
Also used : MavenBuild(org.eclipse.che.maven.data.MavenBuild) MavenKey(org.eclipse.che.maven.data.MavenKey) Parent(org.apache.maven.model.Parent) MavenParent(org.eclipse.che.maven.data.MavenParent) MavenBuild(org.eclipse.che.maven.data.MavenBuild) Build(org.apache.maven.model.Build) MavenModel(org.eclipse.che.maven.data.MavenModel) Model(org.apache.maven.model.Model)

Example 8 with MavenModel

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

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

the class MavenServerImpl method interpolateModel.

public static MavenModel interpolateModel(MavenModel model, File projectDir) throws RemoteException {
    Model result = MavenModelUtil.convertToMavenModel(model);
    result = internalInterpolate(result, projectDir);
    return MavenModelUtil.convertModel(result);
}
Also used : Model(org.apache.maven.model.Model) MavenModel(org.eclipse.che.maven.data.MavenModel)

Example 10 with MavenModel

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

the class MavenServerImpl method createResult.

private MavenServerResult createResult(File pom, MavenResult mavenResult) throws RemoteException {
    List<MavenProjectProblem> problems = new ArrayList<>();
    Set<MavenKey> unresolvedArtifacts = new HashSet<>();
    validate(pom, mavenResult.getExceptions(), problems);
    MavenProject project = mavenResult.getMavenProject();
    if (project == null) {
        return new MavenServerResult(null, problems, unresolvedArtifacts);
    }
    MavenModel model = null;
    try {
        DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult();
        org.eclipse.aether.graph.DependencyNode dependencyNode = null;
        if (resolutionResult != null) {
            dependencyNode = resolutionResult.getDependencyGraph();
        }
        List<org.eclipse.aether.graph.DependencyNode> dependencyNodes = null;
        if (dependencyNode != null) {
            dependencyNodes = dependencyNode.getChildren();
        }
        model = MavenModelUtil.convertProjectToModel(project, dependencyNodes, new File(localRepo.getBasedir()));
    } catch (Exception e) {
        validate(project.getFile(), Collections.singletonList(e), problems);
    }
    List<String> activeProfiles = getActiveProfiles(project);
    MavenProjectInfo projectInfo = new MavenProjectInfo(model, null, activeProfiles);
    return new MavenServerResult(projectInfo, problems, unresolvedArtifacts);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) ArrayList(java.util.ArrayList) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionException(org.apache.maven.MavenExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) MavenProject(org.apache.maven.project.MavenProject) MavenModel(org.eclipse.che.maven.data.MavenModel) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

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