Search in sources :

Example 11 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class RunClassContextTestAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
    notificationManager.notify(notification);
    final Selection<?> selection = selectionAgent.getSelection();
    final Object possibleNode = selection.getHeadElement();
    if (possibleNode instanceof FileNode) {
        VirtualFile file = ((FileNode) possibleNode).getData();
        final Project project = appContext.getRootProject();
        String fqn = JavaUtil.resolveFQN(file);
        Map<String, String> parameters = new HashMap<>();
        parameters.put("fqn", fqn);
        parameters.put("runClass", "true");
        parameters.put("updateClasspath", "true");
        Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
        testResultPromise.then(new Operation<TestResult>() {

            @Override
            public void apply(TestResult result) throws OperationException {
                notification.setStatus(SUCCESS);
                if (result.isSuccess()) {
                    notification.setTitle("Test runner executed successfully");
                    notification.setContent("All tests are passed");
                } else {
                    notification.setTitle("Test runner executed successfully with test failures.");
                    notification.setContent(result.getFailureCount() + " test(s) failed.\n");
                }
                presenter.handleResponse(result);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError exception) throws OperationException {
                final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
                notification.setContent(errorMessage);
                notification.setStatus(FAIL);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) HashMap(java.util.HashMap) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) TestResult(org.eclipse.che.api.testing.shared.TestResult) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) FileNode(org.eclipse.che.ide.resources.tree.FileNode) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 12 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class RunClassTestAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditorPartPresenter editorPart = editorAgent.getActiveEditor();
    final VirtualFile file = editorPart.getEditorInput().getFile();
    String fqn = JavaUtil.resolveFQN(file);
    Map<String, String> parameters = new HashMap<>();
    parameters.put("fqn", fqn);
    parameters.put("runClass", "true");
    parameters.put("updateClasspath", "true");
    delegate.doRunTests(e, parameters);
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) HashMap(java.util.HashMap) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 13 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class DebuggerTest method testAddBreakpoint.

@Test
public void testAddBreakpoint() throws Exception {
    MockSettings mockSettings = new MockSettingsImpl<>().defaultAnswer(RETURNS_SMART_NULLS).extraInterfaces(Resource.class);
    Project project = mock(Project.class);
    when(optional.isPresent()).thenReturn(true);
    when(optional.get()).thenReturn(project);
    when(project.getPath()).thenReturn(PATH);
    VirtualFile virtualFile = mock(VirtualFile.class, mockSettings);
    Path path = mock(Path.class);
    when(path.toString()).thenReturn(PATH);
    when(virtualFile.getLocation()).thenReturn(path);
    when(virtualFile.toString()).thenReturn(PATH);
    Resource resource = (Resource) virtualFile;
    when(resource.getRelatedProject()).thenReturn(optional);
    doReturn(promiseVoid).when(service).addBreakpoint(SESSION_ID, breakpointDto);
    doReturn(promiseVoid).when(promiseVoid).then((Operation<Void>) any());
    when(locationDto.withLineNumber(LINE_NUMBER + 1)).thenReturn(locationDto);
    when(locationDto.withResourcePath(PATH)).thenReturn(locationDto);
    when(locationDto.withResourceProjectPath(PATH)).thenReturn(locationDto);
    when(locationDto.withTarget(anyString())).thenReturn(locationDto);
    when(breakpointDto.withLocation(locationDto)).thenReturn(breakpointDto);
    when(breakpointDto.withEnabled(true)).thenReturn(breakpointDto);
    debugger.addBreakpoint(virtualFile, LINE_NUMBER);
    verify(locationDto).withLineNumber(LINE_NUMBER + 1);
    verify(locationDto).withTarget(FQN);
    verify(locationDto).withResourcePath(PATH);
    verify(locationDto).withResourceProjectPath(PATH);
    verify(breakpointDto).withLocation(locationDto);
    verify(breakpointDto).withEnabled(true);
    verify(promiseVoid).then(operationVoidCaptor.capture());
    operationVoidCaptor.getValue().apply(null);
    verify(observer).onBreakpointAdded(breakpointCaptor.capture());
    assertEquals(breakpointCaptor.getValue(), TEST_BREAKPOINT);
    verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture());
    operationPromiseErrorCaptor.getValue().apply(promiseError);
    verify(promiseError).getMessage();
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) VariablePath(org.eclipse.che.api.debug.shared.model.VariablePath) Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) Resource(org.eclipse.che.ide.api.resources.Resource) MockSettings(org.mockito.MockSettings) BaseTest(org.eclipse.che.plugin.debugger.ide.BaseTest) Test(org.junit.Test)

Example 14 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class OpenDeclarationFinder method openDeclaration.

public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
        navigationService.findDeclaration(project.get().getLocation(), fqn, offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(project.get().getLocation(), result);
                }
            }
        });
    } else if (file instanceof JarFileNode) {
        navigationService.findDeclaration(((JarFileNode) file).getProjectLocation(), file.getLocation().toString().replace('/', '.'), offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(((JarFileNode) file).getProject(), result);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 15 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class OpenDeclarationFinder method handleDescriptor.

private void handleDescriptor(final Path projectPath, final OpenDeclarationDescriptor descriptor) {
    final EditorPartPresenter openedEditor = editorAgent.getOpenedEditor(Path.valueOf(descriptor.getPath()));
    if (openedEditor != null) {
        editorAgent.openEditor(openedEditor.getEditorInput().getFile(), new OpenEditorCallbackImpl() {

            @Override
            public void onEditorOpened(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }

            @Override
            public void onEditorActivated(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }
        });
        return;
    }
    if (descriptor.isBinary()) {
        navigationService.getEntry(projectPath, descriptor.getLibId(), descriptor.getPath()).then(new Operation<JarEntry>() {

            @Override
            public void apply(final JarEntry entry) throws OperationException {
                navigationService.getContent(projectPath, descriptor.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {

                    @Override
                    public void apply(ClassContent content) throws OperationException {
                        final VirtualFile file = javaNodeFactory.newJarFileNode(entry, descriptor.getLibId(), projectPath, null);
                        editorAgent.openEditor(file, new OpenEditorCallbackImpl() {

                            @Override
                            public void onEditorOpened(final EditorPartPresenter editor) {
                                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                    @Override
                                    public void execute() {
                                        if (editor instanceof TextEditor) {
                                            ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                            editor.activate();
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    } else {
        appContext.getWorkspaceRoot().getFile(descriptor.getPath()).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> file) throws OperationException {
                if (file.isPresent()) {
                    editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {

                        @Override
                        public void onEditorOpened(final EditorPartPresenter editor) {
                            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                @Override
                                public void execute() {
                                    if (editor instanceof TextEditor) {
                                        ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                        editor.activate();
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)48 Project (org.eclipse.che.ide.api.resources.Project)21 Resource (org.eclipse.che.ide.api.resources.Resource)19 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)18 OperationException (org.eclipse.che.api.promises.client.OperationException)15 Operation (org.eclipse.che.api.promises.client.Operation)14 PromiseError (org.eclipse.che.api.promises.client.PromiseError)9 File (org.eclipse.che.ide.api.resources.File)8 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)6 Test (org.junit.Test)6 Optional (com.google.common.base.Optional)5 Scheduler (com.google.gwt.core.client.Scheduler)4 HashMap (java.util.HashMap)4 EditorInput (org.eclipse.che.ide.api.editor.EditorInput)4 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)4 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 Path (org.eclipse.che.ide.resource.Path)4 Breakpoint (org.eclipse.che.ide.api.debug.Breakpoint)3 JarFileNode (org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode)3