Search in sources :

Example 1 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)

Example 2 with MavenArtifact

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

the class MavenProjectManager method findDependentProjects.

public List<MavenProject> findDependentProjects(List<MavenProject> projects) {
    readLock.lock();
    try {
        List<MavenProject> result = new ArrayList<>();
        Set<MavenKey> mavenKeys = projects.stream().map(MavenProject::getMavenKey).collect(Collectors.toSet());
        Set<String> paths = projects.stream().map(project -> project.getProject().getFullPath().toOSString()).collect(Collectors.toSet());
        for (MavenProject project : projectToMavenProjectMap.values()) {
            boolean isAdd = false;
            for (String path : project.getModulesPath()) {
                if (paths.contains(path)) {
                    isAdd = true;
                    break;
                }
            }
            if (!isAdd) {
                for (MavenArtifact artifact : project.getDependencies()) {
                    if (contains(mavenKeys, artifact.getArtifactId(), artifact.getGroupId(), artifact.getVersion())) {
                        isAdd = true;
                        break;
                    }
                }
            }
            if (isAdd) {
                result.add(project);
            }
        }
        return result;
    } finally {
        readLock.unlock();
    }
}
Also used : MavenServerManager(org.eclipse.che.plugin.maven.server.MavenServerManager) MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) Proxy(java.lang.reflect.Proxy) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Map(java.util.Map) LinkedList(java.util.LinkedList) Set(java.util.Set) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MavenProjectModifications(org.eclipse.che.plugin.maven.server.core.project.MavenProjectModifications) Provider(com.google.inject.Provider) MavenKey(org.eclipse.che.maven.data.MavenKey) List(java.util.List) Lock(java.util.concurrent.locks.Lock) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenWorkspaceCache(org.eclipse.che.maven.data.MavenWorkspaceCache) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MavenKey(org.eclipse.che.maven.data.MavenKey) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact)

Example 3 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 4 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 5 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)

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