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);
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class JavaProjectHelper method addClassFolder.
/**
* Creates and adds a class folder to the class path.
* @param jproject The parent project
* @param containerName
* @param sourceAttachPath The source attachment path
* @param sourceAttachRoot The source attachment root path
* @return The handle of the created root
* @throws CoreException
*/
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath, IPath sourceAttachRoot) 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;
}
IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
addToClasspath(jproject, cpe);
return jproject.getPackageFragmentRoot(container);
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class IndexSelector method initializeIndexLocations.
/*
* Compute the list of paths which are keying index files.
*/
private void initializeIndexLocations() {
IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
IndexManager manager = JavaModelManager.getIndexManager();
// use a linked set to preserve the order during search: see bug 348507
LinkedHashSet locations = new LinkedHashSet();
IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
if (focus == null) {
for (int i = 0; i < projectsAndJars.length; i++) {
IPath path = projectsAndJars[i];
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
locations.add(manager.computeIndexLocation(path));
}
} else {
try {
// See whether the state builder might be used to reduce the number of index locations
// find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
int length = projectsAndJars.length;
JavaProject[] projectsCanSeeFocus = new JavaProject[length];
SimpleSet visitedProjects = new SimpleSet(length);
int projectIndex = 0;
SimpleSet externalLibsToCheck = new SimpleSet(length);
ObjectVector superTypes = new ObjectVector();
IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
char[][][] focusQualifiedNames = null;
boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
if (isAutoBuilding && focus instanceof IJavaProject) {
focusQualifiedNames = getQualifiedNames(superTypes);
}
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
for (int i = 0; i < length; i++) {
IPath path = projectsAndJars[i];
JavaProject project = (JavaProject) getJavaProject(path, model);
if (project != null) {
visitedProjects.add(project);
/*We are adding all modules to the locations for searching in each one.
Now the location contains not only current module and Jars on which depends, but also all modules from the workspace.*/
locations.add(manager.computeIndexLocation(path));
/*int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames);
if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) {
locations.add(manager.computeIndexLocation(path));
}
if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) {
projectsCanSeeFocus[projectIndex++] = project;
}*/
} else {
externalLibsToCheck.add(path);
}
}
for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
for (int j = entries.length; --j >= 0; ) {
IClasspathEntry entry = entries[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
if (externalLibsToCheck.remove(path) != null) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
locations.add(manager.computeIndexLocation(path));
}
}
}
}
// jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
if (externalLibsToCheck.elementSize > 0) {
IJavaProject[] allProjects = model.getJavaProjects();
for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
JavaProject project = (JavaProject) allProjects[i];
if (!visitedProjects.includes(project)) {
IClasspathEntry[] entries = project.getResolvedClasspath();
for (int j = entries.length; --j >= 0; ) {
IClasspathEntry entry = entries[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
if (externalLibsToCheck.remove(path) != null) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
locations.add(manager.computeIndexLocation(path));
}
}
}
}
}
}
} catch (JavaModelException e) {
// ignored
}
}
// Ensure no nulls
locations.remove(null);
this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class JavaSearchScope method toString.
public String toString() {
//$NON-NLS-1$
StringBuffer result = new StringBuffer("JavaSearchScope on ");
if (this.elements != null) {
//$NON-NLS-1$
result.append("[");
for (int i = 0, length = this.elements.size(); i < length; i++) {
JavaElement element = (JavaElement) this.elements.get(i);
//$NON-NLS-1$
result.append("\n\t");
result.append(element.toStringWithAncestors());
}
//$NON-NLS-1$
result.append("\n]");
} else {
if (this.pathsCount == 0) {
//$NON-NLS-1$
result.append("[empty scope]");
} else {
//$NON-NLS-1$
result.append("[");
String[] paths = new String[this.relativePaths.length];
int index = 0;
for (int i = 0; i < this.relativePaths.length; i++) {
String path = this.relativePaths[i];
if (path == null)
continue;
String containerPath;
if (ExternalFoldersManager.isInternalPathForExternalFolder(new Path(this.containerPaths[i]))) {
Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[i]));
containerPath = ((IFolder) target).getLocation().toOSString();
} else {
containerPath = this.containerPaths[i];
}
if (path.length() > 0) {
paths[index++] = containerPath + '/' + path;
} else {
paths[index++] = containerPath;
}
}
System.arraycopy(paths, 0, paths = new String[index], 0, index);
Util.sort(paths);
for (int i = 0; i < index; i++) {
//$NON-NLS-1$
result.append("\n\t");
result.append(paths[i]);
}
//$NON-NLS-1$
result.append("\n]");
}
}
return result.toString();
}
Aggregations