Search in sources :

Example 11 with Path

use of org.eclipse.che.ide.resource.Path 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 12 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class RefactoringUpdater method updateAfterRefactoring.

/**
     * Iterates over each refactoring change and according to change type performs specific update operation.
     * i.e. for {@code ChangeName#UPDATE} updates only opened editors, for {@code ChangeName#MOVE or ChangeName#RENAME_COMPILATION_UNIT}
     * updates only new paths and opened editors, for {@code ChangeName#RENAME_PACKAGE} reloads package structure and restore expansion.
     *
     * @param changes
     *         applied changes
     */
public void updateAfterRefactoring(List<ChangeInfo> changes) {
    if (changes == null || changes.isEmpty()) {
        return;
    }
    ExternalResourceDelta[] deltas = new ExternalResourceDelta[0];
    final List<String> pathChanged = new ArrayList<>();
    for (ChangeInfo change : changes) {
        final ExternalResourceDelta delta;
        final Path newPath = Path.valueOf(change.getPath());
        final Path oldPath = !isNullOrEmpty(change.getOldPath()) ? Path.valueOf(change.getOldPath()) : Path.EMPTY;
        switch(change.getName()) {
            case MOVE:
            case RENAME_COMPILATION_UNIT:
                delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
                registerRemovedFile(change);
                break;
            case RENAME_PACKAGE:
                delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
                break;
            case UPDATE:
                if (!isFileRemoved(change.getPath(), changes)) {
                    pathChanged.add(change.getPath());
                    registerRemovedFile(change);
                }
            default:
                continue;
        }
        final int index = deltas.length;
        deltas = Arrays.copyOf(deltas, index + 1);
        deltas[index] = delta;
    }
    //here we need to remove file for file that moved or renamed JDT lib sent it to
    for (int i = 0; i < deltas.length; i++) {
        if (pathChanged.contains(deltas[i].getToPath().toString())) {
            pathChanged.remove(deltas[i].getToPath().toString());
        }
        if (pathChanged.contains(deltas[i].getFromPath().toString())) {
            pathChanged.remove(deltas[i].getFromPath().toString());
        }
    }
    if (deltas.length > 0) {
        appContext.getWorkspaceRoot().synchronize(deltas).then(new Operation<ResourceDelta[]>() {

            @Override
            public void apply(final ResourceDelta[] appliedDeltas) throws OperationException {
                for (ResourceDelta delta : appliedDeltas) {
                    eventBus.fireEvent(new RevealResourceEvent(delta.getToPath()));
                }
                for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
                    final String path = editorPartPresenter.getEditorInput().getFile().getLocation().toString();
                    if (pathChanged.contains(path)) {
                        eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
                    }
                }
                setActiveEditor();
            }
        });
    } else {
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

            @Override
            public void execute() {
                for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
                    eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
                }
                setActiveEditor();
            }
        });
    }
}
Also used : ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) Path(org.eclipse.che.ide.resource.Path) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) Scheduler(com.google.gwt.core.client.Scheduler) ArrayList(java.util.ArrayList) ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 13 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class ConvertFolderToProjectAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    Resource folder = getSelectedItem();
    if (folder == null) {
        return;
    }
    Path location = folder.getLocation();
    if (location == null) {
        return;
    }
    MutableProjectConfig mutableProjectConfig = new MutableProjectConfig();
    mutableProjectConfig.setPath(location.toString());
    mutableProjectConfig.setName(folder.getName());
    projectConfigWizard.show(mutableProjectConfig);
}
Also used : Path(org.eclipse.che.ide.resource.Path) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 14 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class FullTextSearchAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource[] resources = appContext.getResources();
    final Path searchPath;
    if (resources == null || resources.length == 0 || resources.length > 1) {
        searchPath = Path.ROOT;
    } else {
        if (resources[0] instanceof Container) {
            searchPath = resources[0].getLocation();
        } else {
            final Container parent = resources[0].getParent();
            searchPath = parent != null ? parent.getLocation() : Path.ROOT;
        }
    }
    presenter.showDialog(searchPath);
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 15 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class GitServiceClientImpl method remove.

@Override
public Promise<Void> remove(DevMachine devMachine, Path project, Path[] items, boolean cached) {
    String params = "?projectPath=" + project.toString();
    if (items != null) {
        for (Path item : items) {
            params += "&items=" + item.toString();
        }
    }
    params += "&cached=" + String.valueOf(cached);
    String url = appContext.getDevMachine().getWsAgentBaseUrl() + REMOVE + params;
    return asyncRequestFactory.createDeleteRequest(url).loader(loader).send();
}
Also used : Path(org.eclipse.che.ide.resource.Path)

Aggregations

Path (org.eclipse.che.ide.resource.Path)72 Resource (org.eclipse.che.ide.api.resources.Resource)27 Operation (org.eclipse.che.api.promises.client.Operation)15 OperationException (org.eclipse.che.api.promises.client.OperationException)15 PromiseError (org.eclipse.che.api.promises.client.PromiseError)13 ArrayList (java.util.ArrayList)11 Project (org.eclipse.che.ide.api.resources.Project)11 Promise (org.eclipse.che.api.promises.client.Promise)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)10 List (java.util.List)8 Test (org.junit.Test)7 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)6 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)6 Optional (com.google.common.base.Optional)5 Function (org.eclipse.che.api.promises.client.Function)5 FunctionException (org.eclipse.che.api.promises.client.FunctionException)5 Container (org.eclipse.che.ide.api.resources.Container)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 HashMap (java.util.HashMap)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4