use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class DeltaProcessingState method getRootInfos.
private HashMap[] getRootInfos(boolean usePreviousSession) {
HashMap newRoots = new HashMap();
HashMap newOtherRoots = new HashMap();
HashMap newSourceAttachments = new HashMap();
HashMap newProjectDependencies = new HashMap();
IJavaModel model = manager.getJavaModel();
IJavaProject[] projects;
try {
projects = model.getJavaProjects();
} catch (JavaModelException e) {
// nothing can be done
return null;
}
for (int i = 0, length = projects.length; i < length; i++) {
JavaProject project = (JavaProject) projects[i];
IClasspathEntry[] classpath;
try {
// if (usePreviousSession) {
// PerProjectInfo perProjectInfo = project.getPerProjectInfo();
// project.resolveClasspath(perProjectInfo, true/*use previous session values*/, false/*don't add classpath change*/);
// classpath = perProjectInfo.resolvedClasspath;
// } else {
classpath = project.getResolvedClasspath();
// }
} catch (JavaModelException e) {
// continue with next project
continue;
}
for (int j = 0, classpathLength = classpath.length; j < classpathLength; j++) {
IClasspathEntry entry = classpath[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
// TODO (jerome) reuse handle
IJavaProject key = model.getJavaProject(entry.getPath().segment(0));
IJavaProject[] dependents = (IJavaProject[]) newProjectDependencies.get(key);
if (dependents == null) {
dependents = new IJavaProject[] { project };
} else {
int dependentsLength = dependents.length;
System.arraycopy(dependents, 0, dependents = new IJavaProject[dependentsLength + 1], 0, dependentsLength);
dependents[dependentsLength] = project;
}
newProjectDependencies.put(key, dependents);
continue;
}
// root path
IPath path = entry.getPath();
if (newRoots.get(path) == null) {
newRoots.put(path, new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind()));
} else {
ArrayList rootList = (ArrayList) newOtherRoots.get(path);
if (rootList == null) {
rootList = new ArrayList();
newOtherRoots.put(path, rootList);
}
rootList.add(new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind()));
}
// source attachment path
if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY)
continue;
String propertyString = null;
// try {
// propertyString = Util.getSourceAttachmentProperty(path);
// } catch (JavaModelException e) {
// e.printStackTrace();
// }
IPath sourceAttachmentPath;
if (propertyString != null) {
int index = propertyString.lastIndexOf(PackageFragmentRoot.ATTACHMENT_PROPERTY_DELIMITER);
sourceAttachmentPath = (index < 0) ? new Path(propertyString) : new Path(propertyString.substring(0, index));
} else {
sourceAttachmentPath = entry.getSourceAttachmentPath();
}
if (sourceAttachmentPath != null) {
newSourceAttachments.put(sourceAttachmentPath, path);
}
}
}
return new HashMap[] { newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies };
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaModelOperation method deleteResources.
/**
* Convenience method to delete resources
*/
protected void deleteResources(IResource[] resources, boolean forceFlag) throws JavaModelException {
if (resources == null || resources.length == 0)
return;
IProgressMonitor subProgressMonitor = getSubProgressMonitor(resources.length);
IWorkspace workspace = resources[0].getWorkspace();
try {
workspace.delete(resources, forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, subProgressMonitor);
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 JavaModelOperation method moveResources.
/**
* Convenience method to move resources
*/
protected void moveResources(IResource[] resources, IPath container) throws JavaModelException {
IProgressMonitor subProgressMonitor = null;
if (this.progressMonitor != null) {
subProgressMonitor = new SubProgressMonitor(this.progressMonitor, resources.length, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
try {
for (int i = 0, length = resources.length; i < length; i++) {
IResource resource = resources[i];
IPath destination = container.append(resource.getName());
if (root.findMember(destination) == null) {
resource.move(destination, false, subProgressMonitor);
}
}
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 JavaModelOperation method executeNestedOperation.
/**
* Convenience method to run an operation within this operation
*/
public void executeNestedOperation(JavaModelOperation operation, int subWorkAmount) throws JavaModelException {
IJavaModelStatus status = operation.verify();
if (!status.isOK()) {
throw new JavaModelException(status);
}
IProgressMonitor subProgressMonitor = getSubProgressMonitor(subWorkAmount);
// fix for 1FW7IKC, part (1)
try {
operation.setNested(true);
operation.run(subProgressMonitor);
} catch (CoreException ce) {
if (ce instanceof JavaModelException) {
throw (JavaModelException) ce;
} else {
// translate the core exception to a java model exception
if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
Throwable e = ce.getStatus().getException();
if (e instanceof JavaModelException) {
throw (JavaModelException) e;
}
}
throw new JavaModelException(ce);
}
}
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaModelOperation method createFolder.
/**
* Convenience method to create a folder
*/
protected void createFolder(IContainer parentFolder, String name, boolean forceFlag) throws JavaModelException {
IFolder folder = parentFolder.getFolder(new Path(name));
try {
// we should use true to create the file locally. Only VCM should use tru/false
folder.create(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, // local
true, getSubProgressMonitor(1));
setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
} catch (CoreException e) {
throw new JavaModelException(e);
}
}
Aggregations