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