1 11 package org.eclipse.core.internal.resources; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.lang.reflect.Method ; 15 import org.eclipse.core.filesystem.EFS; 16 import org.eclipse.core.filesystem.IFileStore; 17 import org.eclipse.core.internal.localstore.HistoryStore2; 18 import org.eclipse.core.internal.localstore.IHistoryStore; 19 import org.eclipse.core.internal.properties.IPropertyManager; 20 import org.eclipse.core.internal.properties.PropertyManager2; 21 import org.eclipse.core.resources.ResourcesPlugin; 22 import org.eclipse.core.runtime.IPath; 23 24 30 public class ResourcesCompatibilityHelper { 31 private static final String COMPATIBILITY_CLASS = "org.eclipse.core.internal.resources.ResourcesCompatibility"; private static final String CONVERT_HISTORY_STORE = ResourcesPlugin.PI_RESOURCES + ".convertHistory"; private static final String CONVERT_PROPERTY_STORE = ResourcesPlugin.PI_RESOURCES + ".convertProperties"; private static final String ENABLE_NEW_HISTORY_STORE = ResourcesPlugin.PI_RESOURCES + ".newHistory"; private static final String ENABLE_NEW_PROPERTY_STORE = ResourcesPlugin.PI_RESOURCES + ".newProperties"; 37 41 public static IHistoryStore createHistoryStore(IPath location, int limit) { 42 boolean newImpl = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(ENABLE_NEW_HISTORY_STORE)); 44 boolean convert = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(CONVERT_HISTORY_STORE)); 46 try { 47 return createHistoryStore(location, limit, newImpl, convert, true); 48 } catch (ClassNotFoundException e) { 49 } catch (NoSuchMethodException e) { 51 if (Workspace.DEBUG) 53 e.printStackTrace(); 54 } catch (IllegalAccessException e) { 55 if (Workspace.DEBUG) 57 e.printStackTrace(); 58 } catch (InvocationTargetException e) { 59 Throwable target = e.getTargetException(); 61 if (target instanceof RuntimeException ) 62 throw (RuntimeException ) target; 63 throw (Error ) target; 64 } 65 IFileStore store = EFS.getLocalFileSystem().getStore(location); 67 return new HistoryStore2((Workspace) ResourcesPlugin.getWorkspace(), store, limit); 68 } 69 70 public static IHistoryStore createHistoryStore(IPath location, int limit, boolean newImpl, boolean convert, boolean rename) throws ClassNotFoundException , NoSuchMethodException , IllegalAccessException , InvocationTargetException { 71 Class clazz = Class.forName(COMPATIBILITY_CLASS); 72 Method createMethod = clazz.getDeclaredMethod("createHistoryStore", new Class [] {IPath.class, int.class, boolean.class, boolean.class, boolean.class}); return (IHistoryStore) createMethod.invoke(null, new Object [] {location, new Integer (limit), Boolean.valueOf(newImpl), Boolean.valueOf(convert), Boolean.valueOf(rename)}); 74 } 75 76 public static IPropertyManager createPropertyManager(boolean newImpl, boolean convert) throws ClassNotFoundException , NoSuchMethodException , IllegalAccessException , InvocationTargetException { 77 Class clazz = Class.forName(COMPATIBILITY_CLASS); 78 Method createMethod = clazz.getDeclaredMethod("createPropertyManager", new Class [] {boolean.class, boolean.class}); return (IPropertyManager) createMethod.invoke(null, new Object [] {Boolean.valueOf(newImpl), Boolean.valueOf(convert)}); 80 } 81 82 86 public static IPropertyManager createPropertyManager() { 87 boolean newImpl = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(ENABLE_NEW_PROPERTY_STORE)); 89 boolean convert = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(CONVERT_PROPERTY_STORE)); 91 try { 92 return createPropertyManager(newImpl, convert); 93 } catch (ClassNotFoundException e) { 94 } catch (NoSuchMethodException e) { 96 if (Workspace.DEBUG) 98 e.printStackTrace(); 99 } catch (IllegalAccessException e) { 100 if (Workspace.DEBUG) 102 e.printStackTrace(); 103 } catch (InvocationTargetException e) { 104 Throwable target = e.getTargetException(); 106 if (target instanceof RuntimeException ) 107 throw (RuntimeException ) target; 108 throw (Error ) target; 109 } 110 return new PropertyManager2((Workspace) ResourcesPlugin.getWorkspace()); 112 } 113 } 114 | Popular Tags |