1 11 package org.eclipse.core.internal.properties; 12 13 import java.io.File ; 14 import org.eclipse.core.internal.indexing.IndexCursor; 15 import org.eclipse.core.internal.localstore.BucketTree; 16 import org.eclipse.core.internal.resources.CompatibilityMessages; 17 import org.eclipse.core.internal.resources.Workspace; 18 import org.eclipse.core.resources.*; 19 import org.eclipse.core.runtime.*; 20 21 public class PropertyStoreConverter { 22 class ConversionVisitor implements IVisitor { 23 private IPath basePath; 24 private BucketTree target; 25 private boolean worked; 26 27 public ConversionVisitor(IPath basePath, BucketTree target) { 28 this.target = target; 29 this.basePath = basePath; 30 } 31 32 public boolean hasWorked() { 33 return worked; 34 } 35 36 public boolean requiresValue(ResourceName resourceName, QualifiedName propertyName) { 37 return true; 39 } 40 41 public void visit(ResourceName resourceName, StoredProperty property, IndexCursor cursor) throws CoreException { 42 IPath fullPath = basePath.append(resourceName.getPath()); 43 target.loadBucketFor(fullPath); 44 ((PropertyBucket) target.getCurrent()).setProperty(fullPath, property.getName(), property.getStringValue()); 46 worked = true; 47 } 48 } 49 50 57 public IStatus convertProperties(Workspace workspace, final PropertyManager2 destination) { 58 File versionFile = destination.getVersionFile(); 62 if (versionFile.isFile()) 63 return Status.OK_STATUS; 65 final boolean[] worked = {false}; 66 final PropertyManager source = new PropertyManager(workspace); 67 try { 68 workspace.getRoot().accept(new IResourceVisitor() { 70 public boolean visit(org.eclipse.core.resources.IResource resource) throws CoreException { 71 ConversionVisitor propertyConverter = new ConversionVisitor(resource.getFullPath(), destination.getTree()); 72 PropertyStore store = source.getPropertyStore(resource, false); 73 if (store == null) 74 return true; 75 store.recordsDeepMatching(new ResourceName("", resource.getProjectRelativePath()), propertyConverter); source.closePropertyStore(resource); 77 worked[0] = worked[0] || propertyConverter.hasWorked(); 78 return true; 79 } 80 }, IResource.DEPTH_ONE, IResource.NONE); 81 destination.getTree().getCurrent().save(); 83 } catch (CoreException e) { 84 String conversionFailed = CompatibilityMessages.properties_conversionFailed; 86 return new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_READ_METADATA, new IStatus[] {e.getStatus()}, conversionFailed, null); 87 } 88 if (!worked[0]) 89 return Status.OK_STATUS; 91 String conversionOk = CompatibilityMessages.properties_conversionSucceeded; 94 return new Status(IStatus.INFO, ResourcesPlugin.PI_RESOURCES, IStatus.OK, conversionOk, null); 95 } 96 } 97 | Popular Tags |