use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class ClasspathBuilderTest method elementShouldBeAddedAsLibToClasspathFromLibFolder.
@Test
public void elementShouldBeAddedAsLibToClasspathFromLibFolder() throws Exception {
Path jarPath = new Path(LIBRARY + "/a.jar");
library.add(LIBRARY);
IFolder libraryFolder1 = mock(IFolder.class);
IResourceProxy iResourceProxy = mock(IResourceProxy.class);
IResource iResource = mock(IResource.class);
when(iProject.getFolder(LIBRARY)).thenReturn(libraryFolder1);
when(libraryFolder1.exists()).thenReturn(true);
when(iResourceProxy.getType()).thenReturn(IResource.FILE);
when(iResourceProxy.requestFullPath()).thenReturn(jarPath);
when(iResourceProxy.requestResource()).thenReturn(iResource);
when(iResource.getLocation()).thenReturn(jarPath);
classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
ArgumentCaptor<IResourceProxyVisitor> resourceProxyVisitorArgumentCaptor = ArgumentCaptor.forClass(IResourceProxyVisitor.class);
verify(libraryFolder1).accept(resourceProxyVisitorArgumentCaptor.capture(), eq(IContainer.INCLUDE_PHANTOMS));
resourceProxyVisitorArgumentCaptor.getValue().visit(iResourceProxy);
verify(iResourceProxy).getType();
assertEquals(jarPath, iResource.getLocation());
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class ClasspathBuilderTest method libraryFolderShouldNotBeAddedIfItIsNotExist.
@Test
public void libraryFolderShouldNotBeAddedIfItIsNotExist() throws Exception {
library.add(LIBRARY);
IFolder libraryFolder1 = mock(IFolder.class);
when(iProject.getFolder(LIBRARY)).thenReturn(libraryFolder1);
when(libraryFolder1.exists()).thenReturn(false);
classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
verifyIfOnlyJREContainerInClasspath();
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class ClasspathBuilderTest method folderShouldNotBeAddedToClasspathIfItNotExist.
@Test
public void folderShouldNotBeAddedToClasspathIfItNotExist() throws Exception {
IFolder sourceFolder1 = mock(IFolder.class);
when(iProject.getFolder(SOURCE_FOLDER1)).thenReturn(sourceFolder1);
when(sourceFolder1.exists()).thenReturn(false);
sourceFolders.add(SOURCE_FOLDER1);
classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
verify(iProject).getFolder(anyString());
verifyIfOnlyJREContainerInClasspath();
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class ClasspathBuilder method addJars.
private void addJars(IJavaProject project, List<String> library, final List<IClasspathEntry> classpathEntries) {
if (library == null || library.isEmpty()) {
return;
}
for (String libFolder : library) {
if (libFolder.isEmpty()) {
continue;
}
IFolder libraryFolder = project.getProject().getFolder(libFolder);
if (!libraryFolder.exists()) {
return;
}
try {
libraryFolder.accept(proxy -> {
if (IResource.FILE != proxy.getType()) {
return true;
}
IPath path = proxy.requestFullPath();
if (!path.toString().endsWith(".jar")) {
return false;
}
IClasspathEntry libEntry = JavaCore.newLibraryEntry(proxy.requestResource().getLocation(), null, null);
classpathEntries.add(libEntry);
return false;
}, IContainer.INCLUDE_PHANTOMS);
} catch (CoreException e) {
LOG.warn("Can't read folder structure: " + libraryFolder.getFullPath().toString());
}
}
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class JavaProjectHelper method removeSourceContainer.
/**
* Removes a source folder from a IJavaProject.
* @param jproject The parent project
* @param containerName Name of the source folder to remove
* @throws CoreException Remove failed
*/
public static void removeSourceContainer(IJavaProject jproject, String containerName) throws CoreException {
IFolder folder = jproject.getProject().getFolder(containerName);
removeFromClasspath(jproject, folder.getFullPath());
folder.delete(true, null);
}
Aggregations