summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-09-12 22:22:34 (EDT)
committerpelder2007-09-12 22:22:34 (EDT)
commit54418eb6ce561850425f343fd436e51399633baf (patch)
tree31d7a5fa13935d97058120f45b7366105cc3c6b4
parent360d0381f74cd346df5f25de067d69f4543f8db9 (diff)
downloadorg.eclipse.jet-54418eb6ce561850425f343fd436e51399633baf.zip
org.eclipse.jet-54418eb6ce561850425f343fd436e51399633baf.tar.gz
org.eclipse.jet-54418eb6ce561850425f343fd436e51399633baf.tar.bz2
[201583] Clean-up old compiler state save areasv20070913
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java139
2 files changed, 97 insertions, 44 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
index 6f6d1d4..6f0f29a 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
@@ -259,7 +259,7 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
bundleManager = new JETBundleManager();
bundleManager.startup();
- savedStateManager = new SavedStateManager();
+ savedStateManager = new SavedStateManager(this);
savedStateManager.startup();
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java
index a3b3122..a944144 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java
@@ -16,11 +16,12 @@
*/
package org.eclipse.jet.internal;
+import java.io.File;
+import java.io.FilenameFilter;
import java.lang.ref.WeakReference;
-import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IProject;
@@ -32,6 +33,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
/**
* Manager for state saved and restored by the jet plugin
@@ -65,17 +67,27 @@ public class SavedStateManager implements ISaveParticipant
}
private ISavedState savedState;
- private List stateSavers = new ArrayList();
- private Map saversByProject = new HashMap();
- private final InternalJET2Platform plugin;
+ /**
+ * Map<IProject,WeakReference<IStateSaver>> that tracks which JET projects and their state savers
+ */
+ private final Map stateSaverByProject = new HashMap();
+
+
+ private final Plugin plugin;
+ /**
+ * Track the new save number is required. A Project or Full save will request a new save number
+ * if this value is true, and then set this flag to false.
+ * This flag will be reset to true at the end of a successful full save.
+ */
+ private boolean needNewSaveNumber = true;
/**
+ * @param plugin
*
*/
- public SavedStateManager()
+ public SavedStateManager(Plugin plugin)
{
- super();
- plugin = InternalJET2Platform.getDefault();
+ this.plugin = plugin;
}
/* (non-Javadoc)
@@ -83,6 +95,44 @@ public class SavedStateManager implements ISaveParticipant
*/
public void doneSaving(ISaveContext context)
{
+ if(context.getKind() == ISaveContext.FULL_SAVE) {
+ // delete the old saved state since it is not necessary any more
+ final int previousSaveNumber = context.getPreviousSaveNumber();
+
+ final Path saveDirectory = getSaveDirectory(previousSaveNumber);
+ final IPath location = plugin.getStateLocation().append(saveDirectory);
+ final File file = location.toFile();
+ if(file.exists()) {
+ deleteDirectory(file);
+ }
+
+ // check for directories to purge because of bug 201583...
+ final File stateDir = plugin.getStateLocation().toFile();
+ final String currentSaveDirectory = getSaveDirectory(context.getSaveNumber()).toString();
+ final File[] orphanedSaveDirs = stateDir.listFiles(new FilenameFilter() {
+
+ public boolean accept(File dir, String name)
+ {
+ return name.startsWith("save-") && !name.equals(currentSaveDirectory); //$NON-NLS-1$
+ }});
+ for (int i = 0; i < orphanedSaveDirs.length; i++)
+ {
+ deleteDirectory(orphanedSaveDirs[i]);
+ }
+ }
+ }
+
+ private void deleteDirectory(File dir) {
+ File[] files = dir.listFiles();
+ for (int i = 0; i < files.length; i++)
+ {
+ if(files[i].isDirectory()) {
+ deleteDirectory(files[i]);
+ } else {
+ files[i].delete();
+ }
+ }
+ dir.delete();
}
/* (non-Javadoc)
@@ -109,22 +159,21 @@ public class SavedStateManager implements ISaveParticipant
{
case ISaveContext.FULL_SAVE:
// save the plug-in state
- doSave(context, stateSavers);
+ doFullSave(context, stateSaverByProject.values());
break;
case ISaveContext.PROJECT_SAVE:
// get the project related to this save operation
IProject project = context.getProject();
- List projectSavers = (List)saversByProject.get(project);
- if(projectSavers != null) {
- doSave(context, projectSavers);
+ WeakReference ref = (WeakReference)stateSaverByProject.get(project);
+
+ if(ref != null) {
+ doProjectSave(context, (IStateSaver)ref.get());
}
+ // PROJECT_SAVE happens only when the project is closed, forget about this project
+ stateSaverByProject.remove(project);
break;
case ISaveContext.SNAPSHOT:
- // This operation needs to be really fast because
- // snapshots can be requested frequently by the
- // workspace.
- // TODO Is this fast enough?
- doSave(context, stateSavers);
+ // do nothing for snapshot saves...
break;
}
}
@@ -135,7 +184,7 @@ public class SavedStateManager implements ISaveParticipant
* @throws IllegalStateException
* @throws CoreException
*/
- private void doSave(ISaveContext context, List projectSavers) throws IllegalStateException, CoreException
+ private void doFullSave(ISaveContext context, Collection projectSavers) throws CoreException
{
for (Iterator i = projectSavers.iterator(); i.hasNext();)
{
@@ -143,17 +192,33 @@ public class SavedStateManager implements ISaveParticipant
final IStateSaver saver = (IStateSaver)ref.get();
if(saver != null)
{
- IPath logicalPath = getLogicalStatePath(saver);
-
- final IPath realPath = getActualPath(logicalPath, context.getSaveNumber());
- context.map(logicalPath, realPath);
-
- final IPath location = plugin.getStateLocation().append(realPath);
-
- saver.doSave(location);
- context.needSaveNumber();
+ doProjectSave(context, saver);
}
}
+
+ // reset this flag so that next full save or project save will request a new save number.
+ needNewSaveNumber = true;
+ }
+
+ /**
+ * @param context
+ * @param saver
+ * @throws CoreException
+ */
+ private void doProjectSave(ISaveContext context, final IStateSaver saver) throws CoreException
+ {
+ if(needNewSaveNumber) {
+ context.needSaveNumber();
+ needNewSaveNumber = false;
+ }
+ IPath logicalPath = getLogicalStatePath(saver);
+
+ final IPath realPath = getActualPath(logicalPath, context.getSaveNumber());
+ context.map(logicalPath, realPath);
+
+ final IPath location = plugin.getStateLocation().append(realPath);
+
+ saver.doSave(location);
}
/**
@@ -194,7 +259,7 @@ public class SavedStateManager implements ISaveParticipant
if(DEBUG) System.out.println("SavedStateManager.startup()"); //$NON-NLS-1$
try
{
- savedState = ResourcesPlugin.getWorkspace().addSaveParticipant(InternalJET2Platform.getDefault(), this);
+ savedState = ResourcesPlugin.getWorkspace().addSaveParticipant(plugin, this);
if(DEBUG && savedState != null) System.out.println(" found saved state: " + savedState.getSaveNumber()); //$NON-NLS-1$
}
catch (CoreException e)
@@ -206,33 +271,21 @@ public class SavedStateManager implements ISaveParticipant
public void shutdown()
{
if(DEBUG) System.out.println("SavedStateManager.shutdown()"); //$NON-NLS-1$
- ResourcesPlugin.getWorkspace().removeSaveParticipant(InternalJET2Platform.getDefault());
+ ResourcesPlugin.getWorkspace().removeSaveParticipant(plugin);
}
public IPath addSaveSaver(IStateSaver saver ,IProject project)
{
- stateSavers.add(new WeakReference(saver));
- rememberProjectSaver(project, saver);
+ stateSaverByProject.put(project, new WeakReference(saver));
IPath initialLocation = null;
if(savedState != null)
{
final int saveNumber = savedState.getSaveNumber();
final IPath realPath = getActualPath(getLogicalStatePath(saver), saveNumber);
- initialLocation = InternalJET2Platform.getDefault().getStateLocation().append(realPath);
+ initialLocation = plugin.getStateLocation().append(realPath);
}
if(DEBUG) System.out.println("SavedStateManager.addSaveSaver(): " + project + ", " + initialLocation); //$NON-NLS-1$//$NON-NLS-2$
return initialLocation;
}
-
- private void rememberProjectSaver(IProject project, IStateSaver saver)
- {
- // FIXME This method appears to do nothing. Is it even needed?
- List list = (List)saversByProject.get(project);
- if(list == null)
- {
- list = new ArrayList();
- }
- list.add(new WeakReference(saver));
- }
}