Search in sources :

Example 6 with ClasspathEntryDto

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

the class ClasspathService method convertClasspathEntriesToDTO.

private List<ClasspathEntryDto> convertClasspathEntriesToDTO(IJavaProject javaProject, IClasspathEntry[] entries) throws JavaModelException {
    List<ClasspathEntryDto> entriesDTO = new ArrayList<>(entries.length);
    for (IClasspathEntry entry : entries) {
        ClasspathEntryDto entryDTO = DtoFactory.getInstance().createDto(ClasspathEntryDto.class);
        entryDTO.withEntryKind(entry.getEntryKind()).withPath(entry.getPath().toOSString());
        if (IClasspathEntry.CPE_CONTAINER == entry.getEntryKind()) {
            IClasspathEntry[] subEntries = JavaCore.getClasspathContainer(entry.getPath(), javaProject).getClasspathEntries();
            entryDTO.withExpandedEntries(convertClasspathEntriesToDTO(javaProject, subEntries));
        }
        entriesDTO.add(entryDTO);
    }
    return entriesDTO;
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto)

Example 7 with ClasspathEntryDto

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

the class ClasspathResolver method updateClasspath.

/** Concatenates classpath entries and update classpath file. */
public Promise<Void> updateClasspath() {
    final Resource resource = appContext.getResource();
    checkState(resource != null);
    final Optional<Project> optProject = resource.getRelatedProject();
    checkState(optProject.isPresent());
    final List<ClasspathEntryDto> entries = new ArrayList<>();
    for (String path : libs) {
        entries.add(dtoFactory.createDto(ClasspathEntryDto.class).withPath(path).withEntryKind(LIBRARY));
    }
    for (ClasspathEntryDto container : containers) {
        entries.add(container);
    }
    for (String path : sources) {
        entries.add(dtoFactory.createDto(ClasspathEntryDto.class).withPath(path).withEntryKind(SOURCE));
    }
    for (String path : projects) {
        entries.add(dtoFactory.createDto(ClasspathEntryDto.class).withPath(path).withEntryKind(PROJECT));
    }
    final Project project = optProject.get();
    Promise<Void> promise = classpathUpdater.setRawClasspath(project.getLocation().toString(), entries);
    promise.then(new Operation<Void>() {

        @Override
        public void apply(Void arg) throws OperationException {
            project.synchronize().then(new Operation<Resource[]>() {

                @Override
                public void apply(Resource[] arg) throws OperationException {
                    eventBus.fireEvent(new ClasspathChangedEvent(project.getLocation().toString(), entries));
                }
            });
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify("Problems with updating classpath", arg.getMessage(), FAIL, EMERGE_MODE);
        }
    });
    return promise;
}
Also used : Resource(org.eclipse.che.ide.api.resources.Resource) ArrayList(java.util.ArrayList) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 8 with ClasspathEntryDto

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

the class ClasspathResolver method resolveClasspathEntries.

/** Reads and parses classpath entries. */
public void resolveClasspathEntries(List<ClasspathEntryDto> entries) {
    libs = new HashSet<>();
    containers = new HashSet<>();
    sources = new HashSet<>();
    projects = new HashSet<>();
    for (ClasspathEntryDto entry : entries) {
        switch(entry.getEntryKind()) {
            case ClasspathEntryKind.LIBRARY:
                libs.add(entry.getPath());
                break;
            case ClasspathEntryKind.CONTAINER:
                containers.add(entry);
                break;
            case ClasspathEntryKind.SOURCE:
                sources.add(entry.getPath());
                break;
            case ClasspathEntryKind.PROJECT:
                projects.add(WORKSPACE_PATH + entry.getPath());
                break;
            default:
        }
    }
}
Also used : ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto)

Example 9 with ClasspathEntryDto

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

the class ProjectClasspathPresenter method show.

/** Show dialog. */
public void show() {
    final Resource[] resources = appContext.getResources();
    Preconditions.checkState(resources != null && resources.length == 1);
    final Optional<Project> project = resources[0].getRelatedProject();
    Preconditions.checkState(isJavaProject(project.get()));
    classpathContainer.getClasspathEntries(project.get().getLocation().toString()).then(new Operation<List<ClasspathEntryDto>>() {

        @Override
        public void apply(List<ClasspathEntryDto> arg) throws OperationException {
            classpathResolver.resolveClasspathEntries(arg);
            if (propertiesMap == null) {
                propertiesMap = new HashMap<>();
                for (ClasspathPagePresenter page : classpathPages) {
                    Set<ClasspathPagePresenter> pages = propertiesMap.get(page.getCategory());
                    if (pages == null) {
                        pages = new HashSet<>();
                        propertiesMap.put(page.getCategory(), pages);
                    }
                    pages.add(page);
                }
                view.setPages(propertiesMap);
            }
            view.show();
            view.selectPage(propertiesMap.entrySet().iterator().next().getValue().iterator().next());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify("Problems with getting classpath", arg.getMessage(), FAIL, EMERGE_MODE);
        }
    });
}
Also used : Resource(org.eclipse.che.ide.api.resources.Resource) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) JavaUtil.isJavaProject(org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject) PromiseError(org.eclipse.che.api.promises.client.PromiseError) List(java.util.List) ClasspathPagePresenter(org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.pages.ClasspathPagePresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 10 with ClasspathEntryDto

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

the class ClasspathMacro 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> libs = classpathResolver.getLibs();
            StringBuilder classpath = new StringBuilder();
            for (String lib : libs) {
                classpath.append(lib).append(':');
            }
            for (ClasspathEntryDto container : classpathResolver.getContainers()) {
                if (!JRE_CONTAINER.equals(container.getPath())) {
                    addLibsFromContainer(container, classpath);
                }
            }
            if (classpath.toString().isEmpty()) {
                classpath.append(appContext.getProjectsRoot().toString()).append(projectPath).append(':');
            }
            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)

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