use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.
the class JavaModelManager method containerGet.
public synchronized IClasspathContainer containerGet(IJavaProject project, IPath containerPath) {
// // check initialization in progress first
if (containerIsInitializationInProgress(project, containerPath)) {
return CONTAINER_INITIALIZATION_IN_PROGRESS;
}
Map projectContainers = (Map) this.containers.get(project);
if (projectContainers == null) {
return null;
}
IClasspathContainer container = (IClasspathContainer) projectContainers.get(containerPath);
return container;
}
use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.
the class JavaModelManager method containerPutIfInitializingWithSameEntries.
public boolean containerPutIfInitializingWithSameEntries(IPath containerPath, IJavaProject[] projects, IClasspathContainer[] respectiveContainers) {
int projectLength = projects.length;
if (projectLength != 1)
return false;
final IClasspathContainer container = respectiveContainers[0];
IJavaProject project = projects[0];
// // optimize only if initializing, otherwise we are in a regular setContainer(...) call
if (!containerIsInitializationInProgress(project, containerPath))
return false;
IClasspathContainer previousContainer = containerGetDefaultToPreviousSession(project, containerPath);
if (container == null) {
if (previousContainer == null) {
containerPut(project, containerPath, null);
return true;
}
return false;
}
final IClasspathEntry[] newEntries = container.getClasspathEntries();
if (previousContainer == null)
if (newEntries.length == 0) {
containerPut(project, containerPath, container);
return true;
} else {
if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
verbose_missbehaving_container(containerPath, projects, respectiveContainers, container, newEntries, null);
return false;
}
final IClasspathEntry[] oldEntries = previousContainer.getClasspathEntries();
if (oldEntries.length != newEntries.length) {
if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
verbose_missbehaving_container(containerPath, projects, respectiveContainers, container, newEntries, oldEntries);
return false;
}
for (int i = 0, length = newEntries.length; i < length; i++) {
if (newEntries[i] == null) {
if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
verbose_missbehaving_container(project, containerPath, newEntries);
return false;
}
if (!newEntries[i].equals(oldEntries[i])) {
if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
verbose_missbehaving_container(containerPath, projects, respectiveContainers, container, newEntries, oldEntries);
return false;
}
}
containerPut(project, containerPath, container);
return true;
}
use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.
the class JavaModelManager method getClasspathContainer.
public IClasspathContainer getClasspathContainer(final IPath containerPath, final IJavaProject project) throws JavaModelException {
IClasspathContainer container = containerGet(project, containerPath);
if (container == null) {
// if (batchContainerInitializations()) {
// // avoid deep recursion while initializing container on workspace restart
// // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=60437)
// try {
// container = initializeAllContainers(project, containerPath);
// } finally {
// batchInitializationFinished();
// }
// } else {
container = initializeContainer(project, containerPath);
// containerBeingInitializedRemove(project, containerPath);
SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container });
operation.runOperation(null);
// }
}
return container;
}
use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.
the class SetContainerOperation method executeOperation.
protected void executeOperation() throws JavaModelException {
checkCanceled();
try {
//$NON-NLS-1$
beginTask("", 1);
if (JavaModelManager.CP_RESOLVE_VERBOSE)
verbose_set_container();
if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED)
verbose_set_container_invocation_trace();
JavaModelManager manager = JavaModelManager.getJavaModelManager();
if (manager.containerPutIfInitializingWithSameEntries(this.containerPath, this.affectedProjects, this.respectiveContainers))
return;
final int projectLength = this.affectedProjects.length;
final IJavaProject[] modifiedProjects;
System.arraycopy(this.affectedProjects, 0, modifiedProjects = new IJavaProject[projectLength], 0, projectLength);
// filter out unmodified project containers
int remaining = 0;
for (int i = 0; i < projectLength; i++) {
if (isCanceled())
return;
JavaProject affectedProject = (JavaProject) this.affectedProjects[i];
IClasspathContainer newContainer = this.respectiveContainers[i];
// 30920 - prevent infinite loop
if (newContainer == null)
newContainer = JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS;
boolean found = false;
if (JavaProject.hasJavaNature(affectedProject.getProject())) {
IClasspathEntry[] rawClasspath = affectedProject.getRawClasspath();
for (int j = 0, cpLength = rawClasspath.length; j < cpLength; j++) {
IClasspathEntry entry = rawClasspath[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(this.containerPath)) {
found = true;
break;
}
}
}
if (!found) {
// filter out this project - does not reference the container path, or isnt't yet Java project
modifiedProjects[i] = null;
manager.containerPut(affectedProject, this.containerPath, newContainer);
continue;
}
IClasspathContainer oldContainer = manager.containerGet(affectedProject, this.containerPath);
if (oldContainer == JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS) {
oldContainer = null;
}
if ((oldContainer != null && oldContainer.equals(this.respectiveContainers[i])) || (oldContainer == this.respectiveContainers[i])) /*handle case where old and new containers are null (see bug 149043*/
{
// filter out this project - container did not change
modifiedProjects[i] = null;
continue;
}
remaining++;
manager.containerPut(affectedProject, this.containerPath, newContainer);
}
if (remaining == 0)
return;
// trigger model refresh
try {
for (int i = 0; i < projectLength; i++) {
if (isCanceled())
return;
JavaProject affectedProject = (JavaProject) modifiedProjects[i];
// was filtered out
if (affectedProject == null)
continue;
if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED)
verbose_update_project(affectedProject);
// force resolved classpath to be recomputed
ClasspathChange classpathChange = affectedProject.getPerProjectInfo().resetResolvedClasspath();
// if needed, generate delta, update project ref, create markers, ...
classpathChanged(classpathChange, i == 0);
if (this.canChangeResources) {
// touch project to force a build if needed
try {
affectedProject.getProject().touch(this.progressMonitor);
} catch (CoreException e) {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=148970
// if (!ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(affectedProject.getElementName()))
// throw e;
}
}
}
} catch (CoreException e) {
if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE)
verbose_failure(e);
if (e instanceof JavaModelException) {
throw (JavaModelException) e;
} else {
throw new JavaModelException(e);
}
} finally {
for (int i = 0; i < projectLength; i++) {
if (this.respectiveContainers[i] == null) {
// reset init in progress marker
manager.containerPut(this.affectedProjects[i], this.containerPath, null);
}
}
}
} finally {
done();
}
}
use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.
the class JavaSearchScope method add.
/**
* Add a path to current java search scope or all project fragment roots if null.
* Use project resolved classpath to retrieve and store access restriction on each classpath entry.
* Recurse if dependent projects are found.
* @param javaProject Project used to get resolved classpath entries
* @param pathToAdd Path to add in case of single element or null if user want to add all project package fragment roots
* @param includeMask Mask to apply on classpath entries
* @param projectsToBeAdded Set to avoid infinite recursion
* @param visitedProjects Set to avoid adding twice the same project
* @param referringEntry Project raw entry in referring project classpath
* @throws JavaModelException May happen while getting java model info
*/
void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException {
IProject project = javaProject.getProject();
if (!project.isAccessible() || !visitedProjects.add(project))
return;
IPath projectPath = project.getFullPath();
String projectPathString = projectPath.toString();
addEnclosingProjectOrJar(projectPath);
IClasspathEntry[] entries = javaProject.getResolvedClasspath();
IJavaModel model = javaProject.getJavaModel();
JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo();
for (int i = 0, length = entries.length; i < length; i++) {
IClasspathEntry entry = entries[i];
AccessRuleSet access = null;
ClasspathEntry cpEntry = (ClasspathEntry) entry;
if (referringEntry != null) {
// Source folder are implicitly exported.
if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
continue;
}
cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry);
// cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry);
}
access = cpEntry.getAccessRuleSet();
switch(entry.getEntryKind()) {
case IClasspathEntry.CPE_LIBRARY:
IClasspathEntry rawEntry = null;
Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries;
if (rootPathToRawEntries != null) {
rawEntry = (IClasspathEntry) rootPathToRawEntries.get(entry.getPath());
}
if (rawEntry == null)
break;
rawKind: switch(rawEntry.getEntryKind()) {
case IClasspathEntry.CPE_LIBRARY:
case IClasspathEntry.CPE_VARIABLE:
if ((includeMask & APPLICATION_LIBRARIES) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
//$NON-NLS-1$
add(projectPath.toString(), "", pathToString, false, /*not a package*/
access);
addEnclosingProjectOrJar(entry.getPath());
}
}
break;
case IClasspathEntry.CPE_CONTAINER:
IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject);
if (container == null)
break;
switch(container.getKind()) {
case IClasspathContainer.K_APPLICATION:
if ((includeMask & APPLICATION_LIBRARIES) == 0)
break rawKind;
break;
case IClasspathContainer.K_SYSTEM:
case IClasspathContainer.K_DEFAULT_SYSTEM:
if ((includeMask & SYSTEM_LIBRARIES) == 0)
break rawKind;
break;
default:
break rawKind;
}
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
//$NON-NLS-1$
add(projectPath.toString(), "", pathToString, false, /*not a package*/
access);
addEnclosingProjectOrJar(entry.getPath());
}
break;
}
break;
case IClasspathEntry.CPE_PROJECT:
if ((includeMask & REFERENCED_PROJECTS) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
JavaProject referencedProject = (JavaProject) model.getJavaProject(path.toOSString());
if (!projectsToBeAdded.contains(referencedProject)) {
// do not recurse if depending project was used to create the scope
add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry);
}
}
}
break;
case IClasspathEntry.CPE_SOURCE:
if ((includeMask & SOURCES) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
add(projectPath.toString(), Util.relativePath(path, projectPath.segmentCount()), projectPathString, false, /*not a package*/
access);
}
}
break;
}
}
}
Aggregations