Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-1964: add libraries from containers for building classpath #2047

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
@Singleton
public class ClasspathContainer implements ClasspathChangedEvent.ClasspathChangedHandler {
public static String JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER";

private final ClasspathServiceClient classpathServiceClient;

private Map<String, Promise<List<ClasspathEntryDto>>> classpathes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import java.util.List;
import java.util.Set;

import static org.eclipse.che.ide.ext.java.client.command.ClasspathContainer.JRE_CONTAINER;
import static org.eclipse.che.ide.ext.java.shared.ClasspathEntryKind.LIBRARY;

/**
* Provides project's classpath.
*
Expand Down Expand Up @@ -88,6 +91,12 @@ public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
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(':');
}
Expand All @@ -97,4 +106,12 @@ public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
});
}

private void addLibsFromContainer(ClasspathEntryDto container, StringBuilder classpath) {
for (ClasspathEntryDto entry : container.getExpandedEntries()) {
if (LIBRARY == entry.getEntryKind()) {
classpath.append(entry.getPath()).append(':');
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ public void onClick(ClickEvent event) {

root.setWidget(element);

element.getElement().getParentElement().getStyle().setMargin(1, PX);

itemCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
import java.util.Map;
import java.util.Set;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.ext.java.shared.ClasspathEntryKind.LIBRARY;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -117,6 +120,43 @@ public void classpathShouldBeBuiltWith2Libraries() throws Exception {
assertEquals("lib2.jar:lib1.jar:", classpath);
}

@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);

classpathProvider.getValue();

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

@Test
public void defaultValueOfClasspathShouldBeBuilt() throws Exception {
List<ClasspathEntryDto> entries = new ArrayList<>();
Expand Down
4 changes: 0 additions & 4 deletions plugins/plugin-ssh-key/che-plugin-ssh-key-ide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
Expand Down