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;
}
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;
}
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:
}
}
}
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);
}
});
}
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();
}
});
}
Aggregations