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