Search in sources :

Example 11 with ClasspathEntryDto

use of org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto in project che by eclipse.

the class SourcepathMacro method expand.

@Override
public Promise<String> expand() {
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length != 1) {
        return promises.resolve("");
    }
    final Resource resource = resources[0];
    final Optional<Project> project = resource.getRelatedProject();
    if (!JavaUtil.isJavaProject(project.get())) {
        return promises.resolve("");
    }
    final String projectPath = project.get().getLocation().toString();
    return classpathContainer.getClasspathEntries(projectPath).then(new Function<List<ClasspathEntryDto>, String>() {

        @Override
        public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
            classpathResolver.resolveClasspathEntries(arg);
            Set<String> sources = classpathResolver.getSources();
            StringBuilder classpath = new StringBuilder();
            for (String source : sources) {
                classpath.append(source.substring(projectPath.length() + 1)).append(':');
            }
            if (classpath.toString().isEmpty()) {
                classpath.append(appContext.getProjectsRoot().toString()).append(projectPath);
            }
            return classpath.toString();
        }
    });
}
Also used : Set(java.util.Set) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List)

Example 12 with ClasspathEntryDto

use of org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto in project che by eclipse.

the class MarkDirAsSourceAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final Resource resource = appContext.getResource();
    checkState(resource instanceof Container, "Parent should be a container");
    final Optional<Project> project = resource.getRelatedProject();
    checkState(project.isPresent());
    classpathService.getClasspath(project.get().getLocation().toString()).then(new Operation<List<ClasspathEntryDto>>() {

        @Override
        public void apply(List<ClasspathEntryDto> arg) throws OperationException {
            classpathResolver.resolveClasspathEntries(arg);
            classpathResolver.getSources().add(resource.getLocation().toString());
            classpathResolver.updateClasspath();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify("Can't get classpath", arg.getMessage(), FAIL, EMERGE_MODE);
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) JavaUtil.isJavaProject(org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject) Container(org.eclipse.che.ide.api.resources.Container) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 13 with ClasspathEntryDto

use of org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto in project che by eclipse.

the class UnmarkDirAsSourceAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final Resource resource = appContext.getResource();
    checkState(resource instanceof Container, "Parent should be a container");
    final Optional<Project> project = resource.getRelatedProject();
    checkState(project.isPresent());
    classpathService.getClasspath(project.get().getLocation().toString()).then(new Operation<List<ClasspathEntryDto>>() {

        @Override
        public void apply(List<ClasspathEntryDto> arg) throws OperationException {
            classpathResolver.resolveClasspathEntries(arg);
            classpathResolver.getSources().remove(resource.getLocation().toString());
            classpathResolver.updateClasspath();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify("Can't get classpath", arg.getMessage(), FAIL, EMERGE_MODE);
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) JavaUtil.isJavaProject(org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject) Container(org.eclipse.che.ide.api.resources.Container) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 14 with ClasspathEntryDto

use of org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto in project che by eclipse.

the class SourceEntryPresenter method go.

@Override
public void go(AcceptsOneWidget container) {
    final Resource resource = appContext.getResource();
    Preconditions.checkState(resource != null);
    final Optional<Project> project = resource.getRelatedProject();
    isPlainJava = JAVAC.equals(project.get().getType());
    setReadOnlyMod();
    container.setWidget(view);
    if (!categories.isEmpty()) {
        view.renderNodes();
        return;
    }
    classpathContainer.getClasspathEntries(project.get().getLocation().toString()).then(new Operation<List<ClasspathEntryDto>>() {

        @Override
        public void apply(List<ClasspathEntryDto> entries) throws OperationException {
            categories.clear();
            for (ClasspathEntryDto entry : entries) {
                if (SOURCE == entry.getEntryKind()) {
                    categories.put(entry.getPath(), entry);
                }
            }
            view.setData(categories);
            view.renderNodes();
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) List(java.util.List) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 15 with ClasspathEntryDto

use of org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto in project che by eclipse.

the class ClasspathMacroTest method classpathShouldBeBuiltWith2ExternalLibrariesAnd2LibrariesFromContainer.

@Test
public void classpathShouldBeBuiltWith2ExternalLibrariesAnd2LibrariesFromContainer() throws Exception {
    String lib1 = "lib1.jar";
    String lib2 = "lib2.jar";
    List<ClasspathEntryDto> entries = new ArrayList<>();
    Set<String> libs = new HashSet<>();
    libs.add(lib1);
    libs.add(lib2);
    ClasspathEntryDto container = mock(ClasspathEntryDto.class);
    ClasspathEntryDto cLib1 = mock(ClasspathEntryDto.class);
    ClasspathEntryDto cLib2 = mock(ClasspathEntryDto.class);
    when(container.getPath()).thenReturn("containerPath");
    when(container.getExpandedEntries()).thenReturn(asList(cLib1, cLib2));
    when(cLib1.getPath()).thenReturn("cLib1.jar");
    when(cLib1.getEntryKind()).thenReturn(LIBRARY);
    when(cLib2.getPath()).thenReturn("cLib2.jar");
    when(cLib2.getEntryKind()).thenReturn(LIBRARY);
    Set<ClasspathEntryDto> containers = new HashSet<>();
    containers.add(container);
    when(classpathContainer.getClasspathEntries(anyString())).thenReturn(classpathEntriesPromise);
    when(classpathResolver.getLibs()).thenReturn(libs);
    when(classpathResolver.getContainers()).thenReturn(containers);
    classpathMacro.expand();
    verify(classpathEntriesPromise).then(classpathEntriesCapture.capture());
    String classpath = classpathEntriesCapture.getValue().apply(entries);
    verify(classpathResolver).resolveClasspathEntries(entries);
    assertEquals("lib2.jar:lib1.jar:cLib1.jar:cLib2.jar:", classpath);
}
Also used : ArrayList(java.util.ArrayList) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ClasspathEntryDto (org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto)16 ArrayList (java.util.ArrayList)8 Project (org.eclipse.che.ide.api.resources.Project)8 Resource (org.eclipse.che.ide.api.resources.Resource)8 List (java.util.List)7 OperationException (org.eclipse.che.api.promises.client.OperationException)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 Operation (org.eclipse.che.api.promises.client.Operation)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)3 Collections.singletonList (java.util.Collections.singletonList)2 Set (java.util.Set)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 Container (org.eclipse.che.ide.api.resources.Container)2 Path (org.eclipse.che.ide.resource.Path)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 ClasspathPagePresenter (org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.pages.ClasspathPagePresenter)1 IPath (org.eclipse.core.runtime.IPath)1