Search in sources :

Example 6 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class WorkspaceTest method testProjectNameUsedFromPom.

@Test
public void testProjectNameUsedFromPom() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + " <name>testName</name>" + "<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);
    String name = mavenProject.getName();
    assertThat(name).isNotNull().isNotEmpty().isEqualTo("testName");
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Example 7 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class ClasspathManagerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    Provider<ProjectRegistry> projectRegistryProvider = (Provider<ProjectRegistry>) mock(Provider.class);
    when(projectRegistryProvider.get()).thenReturn(projectRegistry);
    MavenServerManagerTest.MyMavenServerProgressNotifier mavenNotifier = new MavenServerManagerTest.MyMavenServerProgressNotifier();
    MavenTerminal terminal = (level, message, throwable) -> {
        System.out.println(message);
        if (throwable != null) {
            throwable.printStackTrace();
        }
    };
    localRepository = new File(new File("target/localRepo").getAbsolutePath());
    localRepository.mkdirs();
    mavenServerManager.setLocalRepository(localRepository);
    MavenWrapperManager wrapperManager = new MavenWrapperManager(mavenServerManager);
    mavenProjectManager = new MavenProjectManager(wrapperManager, mavenServerManager, terminal, mavenNotifier, new EclipseWorkspaceProvider());
    classpathManager = new ClasspathManager(root.getAbsolutePath(), wrapperManager, mavenProjectManager, terminal, mavenNotifier);
    mavenWorkspace = new MavenWorkspace(mavenProjectManager, mavenNotifier, new MavenExecutorService(), projectRegistryProvider, new MavenCommunication() {

        @Override
        public void sendUpdateMassage(Set<MavenProject> updated, List<MavenProject> removed) {
        }

        @Override
        public void sendNotification(NotificationMessage message) {
            System.out.println(message.toString());
        }

        @Override
        public void send(JsonObject object, MessageType type) {
        }
    }, classpathManager, eventService, new EclipseWorkspaceProvider());
}
Also used : MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) JsonObject(com.google.gson.JsonObject) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Assert.assertNull(org.testng.Assert.assertNull) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) Mock(org.mockito.Mock) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) Test(org.testng.annotations.Test) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) AfterMethod(org.testng.annotations.AfterMethod) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) IProject(org.eclipse.core.resources.IProject) BaseTest(org.eclipse.che.plugin.maven.server.BaseTest) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaCore(org.eclipse.jdt.core.JavaCore) BeforeMethod(org.testng.annotations.BeforeMethod) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Assert.assertNotNull(org.testng.Assert.assertNotNull) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) File(java.io.File) IoUtil(org.eclipse.che.commons.lang.IoUtil) IType(org.eclipse.jdt.core.IType) Provider(com.google.inject.Provider) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) List(java.util.List) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) Mockito.mock(org.mockito.Mockito.mock) MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Set(java.util.Set) JsonObject(com.google.gson.JsonObject) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) Provider(com.google.inject.Provider) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) List(java.util.List) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) File(java.io.File) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class MavenProjectManagerTest method testNotValidResolveProject.

@Test
public void testNotValidResolveProject() throws Exception {
    when(project.getFile(MavenConstants.POM_FILE_NAME)).thenReturn(pom);
    when(pom.getLocation()).thenReturn(new Path(MavenProjectManagerTest.class.getResource("/BadProject/pom.xml").getFile()));
    when(pom.getFullPath()).thenReturn(new Path("/BadProject/pom.xml"));
    when(project.getFullPath()).thenReturn(new Path("/BadProject"));
    projectManager.addListener(listener);
    MavenProject mavenProject = new MavenProject(project, workspace);
    mavenProject.read(project, manager);
    MavenKey mavenKey = mavenProject.getMavenKey();
    assertThat(mavenKey).isNotNull();
    projectManager.resolveMavenProject(project, mavenProject);
    verify(listener).projectResolved(any(), any());
    assertThat(mavenProject.getProblems()).isNotNull().isNotEmpty();
    mavenProject.getProblems().forEach(System.out::println);
}
Also used : Path(org.eclipse.core.runtime.Path) MavenKey(org.eclipse.che.maven.data.MavenKey) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) Test(org.testng.annotations.Test)

Example 9 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class MavenProjectManager method update.

public void update(List<IProject> projects, boolean recursive) {
    if (projects.isEmpty()) {
        return;
    }
    mavenNotifier.start();
    UpdateState state = new UpdateState();
    Deque<MavenProject> stack = new LinkedList<>();
    for (IProject project : projects) {
        MavenProject mavenProject = findMavenProject(project);
        if (mavenProject != null) {
            internalUpdate(mavenProject, findParentProject(mavenProject), false, recursive, state, stack);
        } else {
            internalAddMavenProject(project, recursive, state, stack);
        }
    }
    mavenNotifier.stop();
    state.fireUpdate();
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject)

Example 10 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject 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)

Aggregations

MavenProject (org.eclipse.che.plugin.maven.server.core.project.MavenProject)24 IProject (org.eclipse.core.resources.IProject)16 Test (org.testng.annotations.Test)13 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)9 MavenKey (org.eclipse.che.maven.data.MavenKey)7 List (java.util.List)6 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 Inject (com.google.inject.Inject)4 Provider (com.google.inject.Provider)4 Singleton (com.google.inject.Singleton)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 Collectors (java.util.stream.Collectors)4 Path (org.eclipse.core.runtime.Path)4 Map (java.util.Map)3 ProjectRegistry (org.eclipse.che.api.project.server.ProjectRegistry)3 MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)3 MavenTerminal (org.eclipse.che.maven.server.MavenTerminal)3