Search in sources :

Example 11 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 12 with MavenProject

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

the class MavenWebSocketCommunication method sendUpdateMassage.

@Override
public void sendUpdateMassage(Set<MavenProject> updated, List<MavenProject> removed) {
    ProjectsUpdateMessage dto = DtoFactory.newDto(ProjectsUpdateMessage.class);
    List<String> updatedPaths = updated.stream().map(project -> project.getProject().getFullPath().toOSString()).collect(Collectors.toList());
    dto.setUpdatedProjects(updatedPaths);
    List<String> removedPaths = removed.stream().map(project -> project.getProject().getFullPath().toOSString()).collect(Collectors.toList());
    dto.setDeletedProjects(removedPaths);
    send(DtoFactory.getInstance().toJsonElement(dto).getAsJsonObject(), MessageType.UPDATE);
}
Also used : JsonObject(com.google.gson.JsonObject) Logger(org.slf4j.Logger) MavenAttributes(org.eclipse.che.plugin.maven.shared.MavenAttributes) ChannelBroadcastMessage(org.everrest.websockets.message.ChannelBroadcastMessage) LoggerFactory(org.slf4j.LoggerFactory) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) EncodeException(javax.websocket.EncodeException) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) List(java.util.List) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ProjectsUpdateMessage(org.eclipse.che.plugin.maven.shared.dto.ProjectsUpdateMessage) WSConnectionContext(org.everrest.websockets.WSConnectionContext) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Singleton(com.google.inject.Singleton) ProjectsUpdateMessage(org.eclipse.che.plugin.maven.shared.dto.ProjectsUpdateMessage)

Example 13 with MavenProject

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

the class MavenWorkspace method runResolve.

private void runResolve() {
    //TODO synchronise on projectsToResolve change
    Set<MavenProject> needResolve = new HashSet<>(projectsToResolve);
    projectsToResolve.clear();
    for (MavenProject mavenProject : needResolve) {
        resolveExecutor.submitTask(new MavenProjectResolveTask(mavenProject, manager, () -> {
            addSourcesFromBuildHelperPlugin(mavenProject);
            classpathManager.updateClasspath(mavenProject);
        }));
    }
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) HashSet(java.util.HashSet)

Example 14 with MavenProject

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

the class MavenWorkspace method updateJavaProject.

private void updateJavaProject(MavenProject project) {
    IJavaProject javaProject = JavaCore.create(project.getProject());
    try {
        ClasspathHelper helper = new ClasspathHelper(javaProject);
        project.getSources().stream().map(s -> project.getProject().getFullPath().append(s)).forEach(helper::addSourceEntry);
        project.getTestSources().stream().map(s -> project.getProject().getFullPath().append(s)).forEach(helper::addSourceEntry);
        //add maven classpath container
        helper.addContainerEntry(new Path(MavenClasspathContainer.CONTAINER_ID));
        //add JRE classpath container
        helper.addContainerEntry(new Path(JREContainerInitializer.JRE_CONTAINER));
        javaProject.setRawClasspath(helper.getEntries(), null);
    } catch (JavaModelException e) {
        LOG.error("Can't update Java project classpath", e);
    }
}
Also used : ClasspathHelper(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper) JavaModelException(org.eclipse.jdt.core.JavaModelException) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MAVEN_ID(org.eclipse.che.plugin.maven.shared.MavenAttributes.MAVEN_ID) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Constants(org.eclipse.che.ide.ext.java.shared.Constants) JREContainerInitializer(org.eclipse.che.jdt.core.launching.JREContainerInitializer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) Map(java.util.Map) ConflictException(org.eclipse.che.api.core.ConflictException) ClasspathHelper(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper) EventService(org.eclipse.che.api.core.notification.EventService) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Logger(org.slf4j.Logger) IJavaProject(org.eclipse.jdt.core.IJavaProject) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) JavaCore(org.eclipse.jdt.core.JavaCore) JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus) ProjectDeletedEvent(org.eclipse.che.api.project.server.ProjectDeletedEvent) MavenAttributes(org.eclipse.che.plugin.maven.shared.MavenAttributes) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) NotFoundException(org.eclipse.che.api.core.NotFoundException) MavenProjectModifications(org.eclipse.che.plugin.maven.server.core.project.MavenProjectModifications) Provider(com.google.inject.Provider) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Path(org.eclipse.core.runtime.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) IJavaModelStatusConstants(org.eclipse.jdt.core.IJavaModelStatusConstants) Element(org.jdom.Element) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 15 with MavenProject

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

the class WorkspaceTest method testImportMultimoduleProjectDeleteAndImportAgain.

@Test
public void testImportMultimoduleProjectDeleteAndImportAgain() throws Exception {
    String pom = "<groupId>com.codenvy.workspacebf11inh2ze5i06bk</groupId>\n" + "<artifactId>multimodule</artifactId>\n" + "   <packaging>pom</packaging>\n" + "   <version>1.0-SNAPSHOT</version>\n" + "   <properties>\n" + "      <maven.compiler.source>1.6</maven.compiler.source>\n" + "      <maven.compiler.target>1.6</maven.compiler.target>\n" + "   </properties>\n" + "   <modules>\n" + "      <module>my-lib</module>\n" + "      <module>my-webapp</module>\n" + "   </modules>";
    createTestProject("parent", pom);
    String myLibPom = " <parent>\n" + "<groupId>com.codenvy.workspacebf11inh2ze5i06bk</groupId>\n" + "<artifactId>multimodule</artifactId>\n" + "    <version>1.0-SNAPSHOT</version>\n" + "  </parent>\n" + "  <artifactId>my-lib</artifactId>\n" + "  <version>1.0-SNAPSHOT</version>\n" + "  <packaging>jar</packaging>\n" + "\n" + "  <name>sample-lib</name>\n" + "\n" + "  <properties>\n" + "    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n" + "  </properties>\n" + "\n" + "  <dependencies>\n" + "    <dependency>\n" + "      <groupId>junit</groupId>\n" + "      <artifactId>junit</artifactId>\n" + "      <version>3.8.1</version>\n" + "      <scope>test</scope>\n" + "    </dependency>\n" + "  </dependencies>";
    createTestProject("parent/my-lib", myLibPom);
    String myWebApp = " <parent>\n" + "<groupId>com.codenvy.workspacebf11inh2ze5i06bk</groupId>\n" + "<artifactId>multimodule</artifactId>\n" + "    <version>1.0-SNAPSHOT</version>\n" + "  </parent>\n" + "  <artifactId>my-webapp</artifactId>\n" + "  <packaging>war</packaging>\n" + "  <version>1.0</version>\n" + "  <name>SpringDemo</name>\n" + "  <properties>\n" + "    <maven.compiler.source>1.8</maven.compiler.source>\n" + "    <maven.compiler.target>1.8</maven.compiler.target>\n" + "  </properties>\n" + "  <dependencies>\n" + "      <dependency>\n" + "<groupId>com.codenvy.workspacebf11inh2ze5i06bk</groupId>\n" + "         <artifactId>my-lib</artifactId>\n" + "         <version>1.0-SNAPSHOT</version>\n" + "      </dependency>\n" + "      <dependency>\n" + "         <groupId>javax.servlet</groupId>\n" + "         <artifactId>servlet-api</artifactId>\n" + "         <version>2.5</version>\n" + "         <scope>provided</scope>\n" + "      </dependency>\n" + "      <dependency>\n" + "         <groupId>org.springframework</groupId>\n" + "         <artifactId>spring-webmvc</artifactId>\n" + "         <version>3.0.5.RELEASE</version>\n" + "      </dependency>\n" + "      <dependency>\n" + "         <groupId>junit</groupId>\n" + "         <artifactId>junit</artifactId>\n" + "         <version>3.8.1</version>\n" + "         <scope>test</scope>\n" + "      </dependency>\n" + "  </dependencies>\n" + "  <build>\n" + "    <finalName>greeting</finalName>\n" + "  </build>";
    createTestProject("parent/my-webapp", myWebApp);
    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("parent");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();
    MavenProject mavenProject = mavenProjectManager.findMavenProject(test);
    assertThat(mavenProject).isNotNull();
    pm.delete("parent");
    createTestProject("parent2", pom);
    createTestProject("parent2/my-lib", myLibPom);
    createTestProject("parent2/my-webapp", myWebApp);
    IProject test2 = ResourcesPlugin.getWorkspace().getRoot().getProject("parent2");
    mavenWorkspace.update(Collections.singletonList(test2));
    mavenWorkspace.waitForUpdate();
    MavenProject mavenProject2 = mavenProjectManager.findMavenProject(test2);
    assertThat(mavenProject2).isNotNull();
}
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)

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