Search in sources :

Example 31 with IFolder

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());
}
Also used : Path(org.eclipse.core.runtime.Path) IResourceProxyVisitor(org.eclipse.core.resources.IResourceProxyVisitor) IResourceProxy(org.eclipse.core.resources.IResourceProxy) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) Test(org.testng.annotations.Test) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest)

Example 32 with IFolder

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();
}
Also used : IFolder(org.eclipse.core.resources.IFolder) Test(org.testng.annotations.Test) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest)

Example 33 with IFolder

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();
}
Also used : IFolder(org.eclipse.core.resources.IFolder) Test(org.testng.annotations.Test) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest)

Example 34 with IFolder

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());
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IFolder(org.eclipse.core.resources.IFolder)

Example 35 with IFolder

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);
}
Also used : IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)299 IFile (org.eclipse.core.resources.IFile)129 IPath (org.eclipse.core.runtime.IPath)90 IProject (org.eclipse.core.resources.IProject)77 CoreException (org.eclipse.core.runtime.CoreException)72 IResource (org.eclipse.core.resources.IResource)66 Path (org.eclipse.core.runtime.Path)47 IContainer (org.eclipse.core.resources.IContainer)45 File (java.io.File)43 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 InputStream (java.io.InputStream)18 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)17 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15