1 11 package org.eclipse.core.internal.localstore; 12 13 import org.eclipse.core.internal.resources.CompatibilityMessages; 14 import org.eclipse.core.internal.resources.Workspace; 15 import org.eclipse.core.internal.utils.Policy; 16 import org.eclipse.core.resources.IResourceStatus; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.*; 19 20 public class HistoryStoreConverter { 21 27 public IStatus convertHistory(Workspace workspace, IPath location, int limit, final HistoryStore2 destination, boolean rename) { 28 if (!location.toFile().isDirectory()) 29 return Status.OK_STATUS; 31 IPath indexFile = location.append(HistoryStore.INDEX_FILE); 32 if (!indexFile.toFile().isFile()) 33 return Status.OK_STATUS; 35 long start = System.currentTimeMillis(); 37 final CoreException[] exception = new CoreException[1]; 38 final BucketTree tree = destination.getTree(); 39 final HistoryBucket currentBucket = (HistoryBucket) tree.getCurrent(); 40 HistoryStore source = new HistoryStore(workspace, location, limit); 41 source.accept(Path.ROOT, new IHistoryStoreVisitor() { 42 public boolean visit(HistoryStoreEntry state) { 43 try { 44 tree.loadBucketFor(state.getPath()); 45 } catch (CoreException e) { 46 exception[0] = e; 48 return false; 49 } 50 currentBucket.addBlob(state.getPath(), state.getUUID(), state.getLastModified()); 51 return true; 52 } 53 }, true); 54 try { 55 tree.getCurrent().save(); 57 source.shutdown(null); 59 } catch (CoreException e) { 60 exception[0] = e; 62 } 63 if (Policy.DEBUG_HISTORY) 64 Policy.debug("Time to convert local history: " + (System.currentTimeMillis() - start) + "ms."); if (exception[0] != null) { 66 String conversionFailed = CompatibilityMessages.history_conversionFailed; 68 Status failure = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_READ_METADATA, new IStatus[] {exception[0].getStatus()}, conversionFailed, null); 69 return failure; 71 } 72 if (rename) 76 indexFile.toFile().renameTo(indexFile.addFileExtension(Long.toString(System.currentTimeMillis())).toFile()); 77 String conversionOk = CompatibilityMessages.history_conversionSucceeded; 78 return new Status(IStatus.INFO, ResourcesPlugin.PI_RESOURCES, IStatus.OK, conversionOk, null); 80 } 81 } 82 | Popular Tags |