Search in sources :

Example 6 with MavenArtifact

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

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

the class WorkspaceTest method testUpdateProject.

@Test
public void testUpdateProject() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + "    <dependency>" + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>" + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>";
    createTestProject("test", pom);
    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();
    MavenProject mavenProject = mavenProjectManager.findMavenProject(test);
    List<MavenArtifact> dependencies = mavenProject.getDependencies();
    assertThat(dependencies).isNotNull().hasSize(2);
    assertThat(dependencies).onProperty("artifactId").contains("junit", "hamcrest-core");
    assertThat(dependencies).onProperty("groupId").contains("junit", "org.hamcrest");
    assertThat(dependencies).onProperty("version").contains("4.12", "1.3");
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Example 8 with MavenArtifact

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

the class WorkspaceTest method testUpdateProjectThatHasDependencyInWorkspace.

@Test
public void testUpdateProjectThatHasDependencyInWorkspace() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + "    <dependency>" + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>" + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>";
    createTestProject("test1", pom);
    String pom2 = "<groupId>test2</groupId>" + "<artifactId>testArtifact2</artifactId>" + "<version>2</version>" + "<dependencies>" + "    <dependency>" + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>" + "        <version>4.12</version>" + "    </dependency>" + "    <dependency>" + "        <groupId>test</groupId>" + "        <artifactId>testArtifact</artifactId>" + "        <version>42</version>" + "    </dependency>" + "</dependencies>";
    createTestProject("test2", pom2);
    IProject project1 = ResourcesPlugin.getWorkspace().getRoot().getProject("test1");
    IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject("test2");
    mavenWorkspace.update(Arrays.asList(project1, project2));
    mavenWorkspace.waitForUpdate();
    MavenProject mavenProject = mavenProjectManager.findMavenProject(project2);
    List<MavenArtifact> dependencies = mavenProject.getDependencies();
    assertThat(dependencies).isNotNull().hasSize(3);
    assertThat(dependencies).onProperty("artifactId").contains("junit", "hamcrest-core", "testArtifact");
    assertThat(dependencies).onProperty("groupId").contains("junit", "org.hamcrest", "test");
    assertThat(dependencies).onProperty("version").contains("4.12", "1.3", "42");
    List<File> depFiles = dependencies.stream().map(MavenArtifact::getFile).collect(Collectors.toList());
    List<String> paths = depFiles.stream().map(File::getAbsolutePath).collect(Collectors.toList());
    assertThat(paths).contains(new java.io.File(root, "test1/pom.xml").getAbsolutePath());
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Example 9 with MavenArtifact

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

Example 10 with MavenArtifact

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

the class ClasspathManager method getClasspath.

private IClasspathEntry[] getClasspath(MavenProject mavenProject) {
    ClasspathHelper helper = new ClasspathHelper(true);
    List<MavenArtifact> dependencies = mavenProject.getDependencies();
    for (MavenArtifact dependency : dependencies) {
        File file = dependency.getFile();
        if (file == null) {
            continue;
        }
        ClasspathEntryHelper entry;
        if (file.getPath().endsWith("pom.xml")) {
            String path = file.getParentFile().getPath();
            entry = helper.addProjectEntry(new Path(path.substring(workspacePath.length())));
        } else {
            entry = helper.addLibraryEntry(new Path(file.getPath()));
        }
        if (entry != null) {
            MavenArtifactKey artifactKey = new MavenArtifactKey(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getExtension(), dependency.getClassifier());
            entry.setArtifactKey(artifactKey);
            attachSources(entry);
        }
    }
    return helper.getEntries();
}
Also used : Path(org.eclipse.core.runtime.Path) MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) IClassFile(org.eclipse.jdt.core.IClassFile) File(java.io.File)

Aggregations

MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)15 Test (org.testng.annotations.Test)8 MavenArtifactKey (org.eclipse.che.maven.data.MavenArtifactKey)6 File (java.io.File)4 MavenModel (org.eclipse.che.maven.data.MavenModel)4 MavenKey (org.eclipse.che.maven.data.MavenKey)3 MavenProject (org.eclipse.che.plugin.maven.server.core.project.MavenProject)3 IProject (org.eclipse.core.resources.IProject)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Artifact (org.apache.maven.artifact.Artifact)2 MavenRemoteRepository (org.eclipse.che.maven.data.MavenRemoteRepository)2 MavenServerWrapper (org.eclipse.che.plugin.maven.server.MavenServerWrapper)2 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)2 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 Singleton (com.google.inject.Singleton)1 Proxy (java.lang.reflect.Proxy)1 Collections (java.util.Collections)1