Search in sources :

Example 66 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class ClasspathBuilderTest method sourceFoldersShouldBeAddedToClasspath.

@Test
public void sourceFoldersShouldBeAddedToClasspath() throws Exception {
    IFolder sourceFolder1 = mock(IFolder.class);
    IFolder sourceFolder2 = mock(IFolder.class);
    when(iProject.getFolder(SOURCE_FOLDER1)).thenReturn(sourceFolder1);
    when(iProject.getFolder(SOURCE_FOLDER2)).thenReturn(sourceFolder2);
    when(sourceFolder1.exists()).thenReturn(true);
    when(sourceFolder1.getFullPath()).thenReturn(new Path(SOURCE_FOLDER1));
    when(sourceFolder2.exists()).thenReturn(true);
    when(sourceFolder2.getFullPath()).thenReturn(new Path(SOURCE_FOLDER2));
    sourceFolders.add(SOURCE_FOLDER1);
    sourceFolders.add(SOURCE_FOLDER2);
    classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
    verify(iProject, times(2)).getFolder(anyString());
    ArgumentCaptor<IClasspathEntry[]> classpathEntriesCapture = ArgumentCaptor.forClass(IClasspathEntry[].class);
    verify(iJavaProject).setRawClasspath(classpathEntriesCapture.capture(), eq(null));
    List<IClasspathEntry> classpathEntries = asList(classpathEntriesCapture.getValue());
    assertEquals(3, classpathEntries.size());
    assertThat(classpathEntries).onProperty("path").containsOnly(new Path(JREContainerInitializer.JRE_CONTAINER), new Path(SOURCE_FOLDER1), new Path(SOURCE_FOLDER2));
}
Also used : Path(org.eclipse.core.runtime.Path) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IFolder(org.eclipse.core.resources.IFolder) Test(org.testng.annotations.Test) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest)

Example 67 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class ClasspathBuilderTest method verifyIfOnlyJREContainerInClasspath.

private void verifyIfOnlyJREContainerInClasspath() throws JavaModelException {
    ArgumentCaptor<IClasspathEntry[]> classpathEntriesCapture = ArgumentCaptor.forClass(IClasspathEntry[].class);
    verify(iJavaProject).setRawClasspath(classpathEntriesCapture.capture(), eq(null));
    List<IClasspathEntry> classpathEntries = asList(classpathEntriesCapture.getValue());
    assertEquals(1, classpathEntries.size());
    assertThat(classpathEntries).onProperty("path").containsOnly(new Path(JREContainerInitializer.JRE_CONTAINER));
}
Also used : Path(org.eclipse.core.runtime.Path) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 68 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class JavaProjectHelper method addLibrary.

/**
     * Adds a library entry with source attachment to a IJavaProject.
     * @param jproject The parent project
     * @param path The path of the library to add
     * @param sourceAttachPath The source attachment path
     * @param sourceAttachRoot The source attachment root path
     * @return The handle of the created root
     * @throws JavaModelException
     */
public static IPackageFragmentRoot addLibrary(IJavaProject jproject, IPath path, IPath sourceAttachPath, IPath sourceAttachRoot) throws JavaModelException {
    IClasspathEntry cpe = JavaCore.newLibraryEntry(path, sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    if (workspaceResource != null) {
        return jproject.getPackageFragmentRoot(workspaceResource);
    }
    return jproject.getPackageFragmentRoot(path.toString());
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IResource(org.eclipse.core.resources.IResource)

Example 69 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class JavaProjectHelper method addSourceContainer.

/**
     * Adds a source container to a IJavaProject.
     * @param jproject The parent project
     * @param containerName The name of the new source container
     * @param inclusionFilters Inclusion filters to set
     * @param exclusionFilters Exclusion filters to set
     * @param outputLocation The location where class files are written to, <b>null</b> for project output folder
     * @return The handle to the new source container
     * @throws CoreException Creation failed
     */
public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters, String outputLocation) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IPackageFragmentRoot root = jproject.getPackageFragmentRoot(container);
    IPath outputPath = null;
    if (outputLocation != null) {
        IFolder folder = project.getFolder(outputLocation);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        outputPath = folder.getFullPath();
    }
    IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, outputPath);
    addToClasspath(jproject, cpe);
    return root;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 70 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class RefactoringScopeFactory method addRelatedReferencing.

private static void addRelatedReferencing(IJavaProject focus, Set<IJavaProject> projects) throws CoreException {
    IProject[] referencingProjects = focus.getProject().getReferencingProjects();
    for (int i = 0; i < referencingProjects.length; i++) {
        IJavaProject candidate = JavaCore.create(referencingProjects[i]);
        if (candidate == null || projects.contains(candidate) || !candidate.exists())
            // break cycle
            continue;
        IClasspathEntry entry = getReferencingClassPathEntry(candidate, focus);
        if (entry != null) {
            projects.add(candidate);
            if (entry.isExported()) {
                addRelatedReferencing(candidate, projects);
                addRelatedReferenced(candidate, projects);
            }
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject)

Aggregations

IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)55 IJavaProject (org.eclipse.jdt.core.IJavaProject)44 ArrayList (java.util.ArrayList)35 Path (org.eclipse.core.runtime.Path)27 JavaModelException (org.eclipse.jdt.core.JavaModelException)23 IProject (org.eclipse.core.resources.IProject)20 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)16 File (java.io.File)15 IFolder (org.eclipse.core.resources.IFolder)13 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 CoreException (org.eclipse.core.runtime.CoreException)12 IJavaElement (org.eclipse.jdt.core.IJavaElement)12 JavaProject (org.eclipse.jdt.internal.core.JavaProject)11 IFile (org.eclipse.core.resources.IFile)10 IResource (org.eclipse.core.resources.IResource)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)7 URL (java.net.URL)7