Search in sources :

Example 1 with ResourceChangedEvent

use of org.eclipse.che.jdt.core.resources.ResourceChangedEvent in project che by eclipse.

the class BaseTest method createTestProject.

protected FolderEntry createTestProject() throws ServerException, NotFoundException, ConflictException, ForbiddenException {
    String classpath = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<classpath>\n" + "\t<classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER\"/>\n" + "</classpath>";
    FolderEntry parent = projectManager.getProjectsRoot().createFolder("project");
    parent.createFolder("bin");
    parent.createFolder("src");
    FolderEntry codenvyFolder = parent.createFolder(".che");
    FolderEntry libFolder = parent.createFolder("lib");
    libFolder.createFile("a.jar", "text".getBytes());
    codenvyFolder.createFile("classpath", classpath.getBytes());
    projectRegistry.setProjectType(parent.getPath().toString(), PlainJavaProjectConstants.JAVAC_PROJECT_ID, false);
    //inform DeltaProcessingStat about new project
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(new ResourceChangedEvent(root, new ProjectCreatedEvent("", parent.getPath().toString())));
    return parent;
}
Also used : ProjectCreatedEvent(org.eclipse.che.api.project.server.ProjectCreatedEvent) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent)

Example 2 with ResourceChangedEvent

use of org.eclipse.che.jdt.core.resources.ResourceChangedEvent in project che by eclipse.

the class ProjectListeners method handleEvent.

public void handleEvent(ProjectItemModifiedEvent event) {
    final String eventPath = event.getPath();
    if (!isJavaProject(event.getProject())) {
        return;
    }
    try {
        JavaModelManager.getJavaModelManager().deltaState.resourceChanged(new ResourceChangedEvent(workspace, event));
    } catch (Throwable t) {
        //catch all exceptions that may be happened
        LOG.error("Can't update java model in " + eventPath, t);
    }
    if (event.getType() == ProjectItemModifiedEvent.EventType.UPDATED) {
        ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
        ITextFileBuffer fileBuffer = manager.getTextFileBuffer(new Path(eventPath), LocationKind.IFILE);
        if (fileBuffer != null) {
            try {
                fileBuffer.revert(new NullProgressMonitor());
            } catch (CoreException e) {
                LOG.error("Can't read file content: " + eventPath, e);
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent)

Example 3 with ResourceChangedEvent

use of org.eclipse.che.jdt.core.resources.ResourceChangedEvent in project che by eclipse.

the class DeltaProcessingTest method testAddClass.

@Test
public void testAddClass() throws Exception {
    File workspace = new File(BaseTest.class.getResource("/projects").getFile());
    ResourceChangedEvent event = new ResourceChangedEvent(workspace, new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED, "projects", "test", "/test/src/main/java/org/eclipse/che/test/NewClass.java", false));
    NameEnvironmentAnswer answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.NewClass".toCharArray()));
    assertThat(answer).isNull();
    FileOutputStream outputStream = new FileOutputStream(new File(workspace, "/test/src/main/java/org/eclipse/che/test/NewClass.java"));
    outputStream.write("package org.eclipse.che.test;\n public class NewClass{}\n".getBytes());
    outputStream.close();
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.NewClass".toCharArray()));
    assertThat(answer).isNotNull();
}
Also used : NameEnvironmentAnswer(org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) FileOutputStream(java.io.FileOutputStream) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) File(java.io.File) Test(org.junit.Test)

Example 4 with ResourceChangedEvent

use of org.eclipse.che.jdt.core.resources.ResourceChangedEvent in project che by eclipse.

the class DeltaProcessingTest method testRemoveClass.

@Test
public void testRemoveClass() throws Exception {
    ResourceChangedEvent event = new ResourceChangedEvent(new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.DELETED, "projects", "test", "/test/src/main/java/org/eclipse/che/test/MyClass.java", false));
    NameEnvironmentAnswer answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNotNull();
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNull();
}
Also used : NameEnvironmentAnswer(org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) File(java.io.File) Test(org.junit.Test)

Example 5 with ResourceChangedEvent

use of org.eclipse.che.jdt.core.resources.ResourceChangedEvent in project che by eclipse.

the class DeltaProcessingTest method testRemoveFolder.

@Test
public void testRemoveFolder() throws Exception {
    ResourceChangedEvent event = new ResourceChangedEvent(new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.DELETED, "projects", "test", "/test/src/main/java/org/eclipse/che/test", true));
    NameEnvironmentAnswer answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNotNull();
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNull();
}
Also used : NameEnvironmentAnswer(org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) File(java.io.File) Test(org.junit.Test)

Aggregations

ResourceChangedEvent (org.eclipse.che.jdt.core.resources.ResourceChangedEvent)7 File (java.io.File)4 ProjectItemModifiedEvent (org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent)4 NameEnvironmentAnswer (org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer)3 Test (org.junit.Test)3 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)2 ProjectCreatedEvent (org.eclipse.che.api.project.server.ProjectCreatedEvent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IType (org.eclipse.jdt.core.IType)1