// check if the build state version number has changed since last session
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=98969)
if (monitor != null)
monitor.subTask(Messages.javamodel_getting_build_state_number);
QualifiedName qName = new QualifiedName(JavaCore.PLUGIN_ID, "stateVersionNumber"); //$NON-NLS-1$
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String versionNumber = null;
try {
versionNumber = root.getPersistentProperty(qName);
} catch (CoreException e) {
// could not read version number: consider it is new
}
final JavaModel model = manager.getJavaModel();
String newVersionNumber = Byte.toString(State.VERSION);
if (!newVersionNumber.equals(versionNumber)) {
// build state version number has changed: touch every projects to force a rebuild
if (JavaBuilder.DEBUG)
System.out.println("Build state version number has changed"); //$NON-NLS-1$
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor progressMonitor2) throws CoreException {
IJavaProject[] projects = null;
try {
projects = model.getJavaProjects();
} catch (JavaModelException e) {
// could not get Java projects: ignore
}
if (projects != null) {
for (int i = 0, length = projects.length; i < length; i++) {
IJavaProject project = projects[i];
try {
if (JavaBuilder.DEBUG)
System.out.println("Touching " + project.getElementName()); //$NON-NLS-1$
project.getProject().touch(progressMonitor2);
} catch (CoreException e) {
// could not touch this project: ignore
}
}
}
}
};
if (monitor != null)
monitor.subTask(Messages.javamodel_building_after_upgrade);
try {
ResourcesPlugin.getWorkspace().run(runnable, monitor);
} catch (CoreException e) {
// could not touch all projects
}
try {
root.setPersistentProperty(qName, newVersionNumber);
} catch (CoreException e) {
Util.log(e, "Could not persist build state version number"); //$NON-NLS-1$
}
}