use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaModelManager method initializeContainer.
private IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath) throws JavaModelException {
ClasspathContainerInitializer initializer = containerInitializersCache.get(containerPath.segment(0));
IClasspathContainer container = null;
if (initializer != null) {
// avoid initialization cycles
containerPut(project, containerPath, CONTAINER_INITIALIZATION_IN_PROGRESS);
try {
initializer.initialize(containerPath, project);
// if (monitor != null)
// monitor.subTask(""); //$NON-NLS-1$
// retrieve value (if initialization was successful)
container = containerBeingInitializedGet(project, containerPath);
if (container == null && containerGet(project, containerPath) == null) {
// initializer failed to do its job: redirect to the failure container
container = initializer.getFailureContainer(containerPath, project);
// if (container == null) {
// if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
// verbose_container_null_failure_container(project, containerPath, initializer);
// return null; // break cycle
// }
// if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
// verbose_container_using_failure_container(project, containerPath, initializer);
containerPut(project, containerPath, container);
}
} catch (CoreException e) {
if (e instanceof JavaModelException) {
throw (JavaModelException) e;
} else {
throw new JavaModelException(e);
}
}
} else {
// create a dummy initializer and get the default failure container
container = (new ClasspathContainerInitializer() {
public void initialize(IPath path, IJavaProject javaProject) throws CoreException {
// not used
}
}).getFailureContainer(containerPath, project);
}
return container;
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaModelOperation method deleteEmptyPackageFragment.
/**
* Convenience method to delete an empty package fragment
*/
protected void deleteEmptyPackageFragment(IPackageFragment fragment, boolean forceFlag, IResource rootResource) throws JavaModelException {
IContainer resource = (IContainer) ((JavaElement) fragment).resource();
try {
resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
while (resource instanceof IFolder) {
// deleting a package: delete the parent if it is empty (e.g. deleting x.y where folder x doesn't have resources but y)
// without deleting the package fragment root
resource = resource.getParent();
if (!resource.equals(rootResource) && resource.members().length == 0) {
resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
}
}
} catch (CoreException e) {
throw new JavaModelException(e);
}
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class DeltaProcessor method createExternalArchiveDelta.
/*
* Check if external archives have changed for the given elements and create the corresponding deltas.
* Returns whether at least one delta was created.
*/
private boolean createExternalArchiveDelta(HashSet refreshedElements, IProgressMonitor monitor) {
HashMap externalArchivesStatus = new HashMap();
boolean hasDelta = false;
// find JARs to refresh
HashSet archivePathsToRefresh = new HashSet();
Iterator iterator = refreshedElements.iterator();
while (iterator.hasNext()) {
IJavaElement element = (IJavaElement) iterator.next();
switch(element.getElementType()) {
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
archivePathsToRefresh.add(element.getPath());
break;
case IJavaElement.JAVA_PROJECT:
JavaProject javaProject = (JavaProject) element;
if (!JavaProject.hasJavaNature(javaProject.getProject())) {
// project is not accessible or has lost its Java nature
break;
}
IClasspathEntry[] classpath;
try {
classpath = javaProject.getResolvedClasspath();
for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
archivePathsToRefresh.add(classpath[j].getPath());
}
}
} catch (JavaModelException e) {
// project doesn't exist -> ignore
}
break;
case IJavaElement.JAVA_MODEL:
// }
throw new UnsupportedOperationException();
}
}
// }
return hasDelta;
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaProject method writeFileEntries.
/**
* Writes the classpath in a sharable format (VCM-wise) only when necessary, that is, if it is semantically different
* from the existing one in file. Will never write an identical one.
*
* @param newClasspath IClasspathEntry[]
* @param newOutputLocation IPath
* @return boolean Return whether the .classpath file was modified.
* @throws JavaModelException
*/
public boolean writeFileEntries(IClasspathEntry[] newClasspath, IClasspathEntry[] referencedEntries, IPath newOutputLocation) throws JavaModelException {
if (!this.project.isAccessible())
return false;
Map unknownElements = new HashMap();
IClasspathEntry[][] fileEntries = readFileEntries(unknownElements);
if (fileEntries[0] != JavaProject.INVALID_CLASSPATH && areClasspathsEqual(newClasspath, newOutputLocation, fileEntries[0]) && (referencedEntries == null || areClasspathsEqual(referencedEntries, fileEntries[1]))) {
// no need to save it, it is the same
return false;
}
// actual file saving
try {
setSharedProperty(JavaProject.CLASSPATH_FILENAME, encodeClasspath(newClasspath, referencedEntries, newOutputLocation, true, unknownElements));
return true;
} catch (CoreException e) {
throw new JavaModelException(e);
}
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaProject method setOptions.
@Override
public void setOptions(Map newOptions) {
IEclipsePreferences projectPreferences = getEclipsePreferences();
if (projectPreferences == null)
return;
try {
if (newOptions == null) {
projectPreferences.clear();
} else {
Iterator entries = newOptions.entrySet().iterator();
JavaModelManager javaModelManager = getJavaModelManager();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
javaModelManager.storePreference(key, value, projectPreferences, newOptions);
}
// reset to default all options not in new map
// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
String[] pNames = projectPreferences.keys();
int ln = pNames.length;
for (int i = 0; i < ln; i++) {
String key = pNames[i];
if (!newOptions.containsKey(key)) {
// old preferences => remove from preferences table
projectPreferences.remove(key);
}
}
}
// persist options
projectPreferences.flush();
// flush cache immediately
try {
getPerProjectInfo().options = null;
} catch (JavaModelException e) {
// do nothing
}
} catch (BackingStoreException e) {
// problem with pref store - quietly ignore
}
}
Aggregations