1 11 package org.eclipse.pde.internal.builders; 12 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.ProjectScope; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.core.runtime.preferences.DefaultScope; 17 import org.eclipse.core.runtime.preferences.IPreferencesService; 18 import org.eclipse.core.runtime.preferences.IScopeContext; 19 import org.eclipse.core.runtime.preferences.InstanceScope; 20 import org.eclipse.pde.internal.PDE; 21 import org.osgi.service.prefs.BackingStoreException; 22 import org.osgi.service.prefs.Preferences; 23 24 public class CompilerFlags { 25 public static final int ERROR = 0; 26 27 public static final int WARNING = 1; 28 29 public static final int IGNORE = 2; 30 31 public static final int MARKER = 0; 32 33 public static final int BOOLEAN = 1; 34 35 public static final int STRING = 2; 36 37 public static final int PLUGIN_FLAGS = 0; 38 39 public static final int SCHEMA_FLAGS = 1; 40 41 public static final int FEATURE_FLAGS = 2; 42 43 public static final int SITE_FLAGS = 3; 44 45 public static final String USE_PROJECT_PREF = "compilers.use-project"; 48 public static final String P_UNRESOLVED_IMPORTS = "compilers.p.unresolved-import"; 51 public static final String P_UNRESOLVED_EX_POINTS = "compilers.p.unresolved-ex-points"; 53 public static final String P_UNKNOWN_ELEMENT = "compilers.p.unknown-element"; 55 public static final String P_UNKNOWN_ATTRIBUTE = "compilers.p.unknown-attribute"; 57 public static final String P_UNKNOWN_CLASS = "compilers.p.unknown-class"; 59 public static final String P_UNKNOWN_RESOURCE = "compilers.p.unknown-resource"; 61 public static final String P_NO_REQUIRED_ATT = "compilers.p.no-required-att"; 63 public static final String P_NOT_EXTERNALIZED = "compilers.p.not-externalized-att"; 65 public static final String P_DEPRECATED = "compilers.p.deprecated"; 67 public static final String S_CREATE_DOCS = "compilers.s.create-docs"; 69 public static final String S_DOC_FOLDER = "compilers.s.doc-folder"; 71 public static final String S_OPEN_TAGS = "compilers.s.open-tags"; 73 public static final String F_UNRESOLVED_PLUGINS = "compilers.f.unresolved-plugins"; 75 public static final String F_UNRESOLVED_FEATURES = "compilers.f.unresolved-features"; 77 private static final String [][] fFlags = { 78 { P_UNRESOLVED_IMPORTS, P_UNRESOLVED_EX_POINTS, P_NO_REQUIRED_ATT, 79 P_UNKNOWN_ELEMENT, P_UNKNOWN_ATTRIBUTE, P_DEPRECATED, 80 P_UNKNOWN_CLASS, P_UNKNOWN_RESOURCE, P_NOT_EXTERNALIZED }, 81 { S_CREATE_DOCS, S_DOC_FOLDER, S_OPEN_TAGS }, 82 { F_UNRESOLVED_PLUGINS, F_UNRESOLVED_FEATURES }, {} }; 83 84 public static int getFlagType(String flagId) { 85 if (flagId.equals(S_CREATE_DOCS)) 86 return BOOLEAN; 87 if (flagId.equals(S_DOC_FOLDER)) 88 return STRING; 89 return MARKER; 90 } 91 92 public static int getFlag(IProject project, String flagId) { 93 try { 94 return Integer.parseInt(getString(project, flagId)); 95 } catch (NumberFormatException nfe) { 96 return 0; 97 } 98 } 99 100 public static boolean getBoolean(IProject project, String flagId) { 101 return Boolean.valueOf(getString(project, flagId)).booleanValue(); 102 } 103 104 112 public static String getString(IProject project, String flagId) { 113 IPreferencesService service = Platform.getPreferencesService(); 114 IScopeContext[] contexts = project == null ? null 115 : new IScopeContext[] { new ProjectScope(project) }; 116 return service.getString(PDE.PLUGIN_ID, flagId, "", project == null ? null : contexts); 118 } 119 120 public static int getDefaultFlag(String flagId) { 121 return new DefaultScope().getNode(PDE.PLUGIN_ID).getInt(flagId, 0); 122 } 123 124 public static String getDefaultString(String flagId) { 125 return new DefaultScope().getNode(PDE.PLUGIN_ID).get(flagId, ""); } 127 128 public static boolean getDefaultBoolean(String flagId) { 129 return new DefaultScope().getNode(PDE.PLUGIN_ID).getBoolean(flagId, 130 false); 131 } 132 133 public static void setFlag(String flagId, int value) { 134 if (getDefaultFlag(flagId) == value) 135 new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId); 136 else 137 new InstanceScope().getNode(PDE.PLUGIN_ID).putInt(flagId, value); 138 } 139 140 public static void setFlag(IProject project, String flagId, int value) { 141 setString(project, flagId, Integer.toString(value)); 142 } 143 144 public static void setBoolean(String flagId, boolean value) { 145 if (getDefaultBoolean(flagId) == value) 146 new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId); 147 else 148 new InstanceScope().getNode(PDE.PLUGIN_ID) 149 .putBoolean(flagId, value); 150 } 151 152 public static void setBoolean(IProject project, String flagId, boolean value) { 153 setString(project, flagId, Boolean.toString(value)); 154 } 155 156 public static void setString(String flagId, String value) { 157 if (getDefaultString(flagId).equals(value)) 158 new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId); 159 else 160 new InstanceScope().getNode(PDE.PLUGIN_ID).put(flagId, value); 161 } 162 163 170 public static void setString(IProject project, String flagId, String value) { 171 if (project == null) 172 return; 173 Preferences preferences = new ProjectScope(project) 174 .getNode(PDE.PLUGIN_ID); 175 preferences.put(flagId, value); 176 try { 177 preferences.flush(); 178 } catch (BackingStoreException bse) { 179 } 180 } 181 182 188 public static void clear(IProject project, String flagId) { 189 if (project == null) 190 return; 191 Preferences preferences = new ProjectScope(project) 192 .getNode(PDE.PLUGIN_ID); 193 preferences.remove(flagId); 194 try { 195 preferences.flush(); 196 } catch (BackingStoreException bse) { 197 } 198 } 199 200 public static void initializeDefaults() { 201 Preferences node = new DefaultScope().getNode(PDE.PLUGIN_ID); 202 node.putInt(P_UNRESOLVED_IMPORTS, ERROR); 203 node.putInt(P_UNRESOLVED_EX_POINTS, ERROR); 204 node.putInt(P_NO_REQUIRED_ATT, ERROR); 205 node.putInt(P_UNKNOWN_ELEMENT, WARNING); 206 node.putInt(P_UNKNOWN_ATTRIBUTE, WARNING); 207 node.putInt(P_DEPRECATED, WARNING); 208 node.putInt(P_UNKNOWN_CLASS, IGNORE); 209 node.putInt(P_UNKNOWN_RESOURCE, IGNORE); 210 node.putInt(P_NOT_EXTERNALIZED, IGNORE); 211 212 node.putBoolean(S_CREATE_DOCS, false); 213 node.put(S_DOC_FOLDER, "doc"); node.putInt(S_OPEN_TAGS, WARNING); 215 216 node.putInt(F_UNRESOLVED_PLUGINS, WARNING); 217 node.putInt(F_UNRESOLVED_FEATURES, WARNING); 218 } 219 220 public static String [] getFlags(int group) { 221 return fFlags[group]; 222 } 223 224 227 public static void save() { 228 try { 229 new InstanceScope().getNode(PDE.PLUGIN_ID).flush(); 230 } catch (BackingStoreException e) { 231 } 232 } 233 } 234 | Popular Tags |