break;
case IJavaElement.JAVA_MODEL :
Iterator projectNames = this.state.getOldJavaProjecNames().iterator();
while (projectNames.hasNext()) {
String projectName = (String) projectNames.next();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (!JavaProject.hasJavaNature(project)) {
// project is not accessible or has lost its Java nature
continue;
}
javaProject = (JavaProject) JavaCore.create(project);
try {
classpath = javaProject.getResolvedClasspath();
} catch (JavaModelException e2) {
// project doesn't exist -> ignore
continue;
}
for (int k = 0, cpLength = classpath.length; k < cpLength; k++){
if (classpath[k].getEntryKind() == IClasspathEntry.CPE_LIBRARY){
archivePathsToRefresh.add(classpath[k].getPath());
}
}
}
break;
}
}
// perform refresh
Iterator projectNames = this.state.getOldJavaProjecNames().iterator();
IWorkspaceRoot wksRoot = ResourcesPlugin.getWorkspace().getRoot();
while (projectNames.hasNext()) {
if (monitor != null && monitor.isCanceled()) break;
String projectName = (String) projectNames.next();
IProject project = wksRoot.getProject(projectName);
if (!JavaProject.hasJavaNature(project)) {
// project is not accessible or has lost its Java nature
continue;
}
JavaProject javaProject = (JavaProject) JavaCore.create(project);
IClasspathEntry[] entries;
try {
entries = javaProject.getResolvedClasspath();
} catch (JavaModelException e1) {
// project does not exist -> ignore
continue;
}
for (int j = 0; j < entries.length; j++){
if (entries[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath entryPath = entries[j].getPath();
if (!archivePathsToRefresh.contains(entryPath)) continue; // not supposed to be refreshed
String status = (String)externalArchivesStatus.get(entryPath);
if (status == null){
// compute shared status
Object targetLibrary = JavaModel.getTarget(wksRoot, entryPath, true);
if (targetLibrary == null){ // missing JAR
if (this.state.getExternalLibTimeStamps().remove(entryPath) != null){
externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
// the jar was physically removed: remove the index
this.manager.indexManager.removeIndex(entryPath);
}
} else if (targetLibrary instanceof File){ // external JAR
File externalFile = (File)targetLibrary;
// check timestamp to figure if JAR has changed in some way
Long oldTimestamp =(Long) this.state.getExternalLibTimeStamps().get(entryPath);
long newTimeStamp = getTimeStamp(externalFile);
if (oldTimestamp != null){
if (newTimeStamp == 0){ // file doesn't exist
externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
this.state.getExternalLibTimeStamps().remove(entryPath);
// remove the index
this.manager.indexManager.removeIndex(entryPath);
} else if (oldTimestamp.longValue() != newTimeStamp){
externalArchivesStatus.put(entryPath, EXTERNAL_JAR_CHANGED);
this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp));
// first remove the index so that it is forced to be re-indexed
this.manager.indexManager.removeIndex(entryPath);
// then index the jar
this.manager.indexManager.indexLibrary(entryPath, project.getProject());
} else {
externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
}
} else {
if (newTimeStamp == 0){ // jar still doesn't exist
externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
} else {
externalArchivesStatus.put(entryPath, EXTERNAL_JAR_ADDED);
this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp));
// index the new jar
this.manager.indexManager.indexLibrary(entryPath, project.getProject());
}
}
} else { // internal JAR
externalArchivesStatus.put(entryPath, INTERNAL_JAR_IGNORE);
}