1 11 package org.eclipse.pde.internal.core.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.core.natures.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_BUILD = "compilers.p.build"; 67 public static final String P_INCOMPATIBLE_ENV = "compilers.incompatible-environment"; 69 public static final String P_MISSING_EXPORT_PKGS = "compilers.p.missing-packages"; 71 public static final String P_DEPRECATED = "compilers.p.deprecated"; 73 public static final String S_CREATE_DOCS = "compilers.s.create-docs"; 75 public static final String S_DOC_FOLDER = "compilers.s.doc-folder"; 77 public static final String S_OPEN_TAGS = "compilers.s.open-tags"; 79 public static final String F_UNRESOLVED_PLUGINS = "compilers.f.unresolved-plugins"; 81 public static final String F_UNRESOLVED_FEATURES = "compilers.f.unresolved-features"; 83 private static final String [][] fFlags = { 84 { P_UNRESOLVED_IMPORTS, 85 P_INCOMPATIBLE_ENV, 86 P_UNRESOLVED_EX_POINTS, 87 P_NO_REQUIRED_ATT, 88 P_UNKNOWN_ELEMENT, 89 P_UNKNOWN_ATTRIBUTE, 90 P_DEPRECATED, 91 P_UNKNOWN_CLASS, 92 P_UNKNOWN_RESOURCE, 93 P_NOT_EXTERNALIZED, 94 P_BUILD, 95 P_MISSING_EXPORT_PKGS}, 96 { S_CREATE_DOCS, 97 S_DOC_FOLDER, 98 S_OPEN_TAGS }, 99 { F_UNRESOLVED_PLUGINS, 100 F_UNRESOLVED_FEATURES }}; 101 102 public static int getFlagType(String flagId) { 103 if (flagId.equals(S_CREATE_DOCS)) 104 return BOOLEAN; 105 if (flagId.equals(S_DOC_FOLDER)) 106 return STRING; 107 return MARKER; 108 } 109 110 public static int getFlag(IProject project, String flagId) { 111 try { 112 return Integer.parseInt(getString(project, flagId)); 113 } catch (NumberFormatException nfe) { 114 return 0; 115 } 116 } 117 118 public static boolean getBoolean(IProject project, String flagId) { 119 return Boolean.valueOf(getString(project, flagId)).booleanValue(); 120 } 121 122 130 public static String getString(IProject project, String flagId) { 131 IPreferencesService service = Platform.getPreferencesService(); 132 IScopeContext[] contexts = project == null ? null 133 : new IScopeContext[] { new ProjectScope(project) }; 134 return service.getString(PDE.PLUGIN_ID, flagId, "", project == null ? null : contexts); 136 } 137 138 public static int getDefaultFlag(String flagId) { 139 return new DefaultScope().getNode(PDE.PLUGIN_ID).getInt(flagId, 0); 140 } 141 142 public static String getDefaultString(String flagId) { 143 return new DefaultScope().getNode(PDE.PLUGIN_ID).get(flagId, ""); } 145 146 public static boolean getDefaultBoolean(String flagId) { 147 return new DefaultScope().getNode(PDE.PLUGIN_ID).getBoolean(flagId, 148 false); 149 } 150 151 public static void setFlag(String flagId, int value) { 152 if (getDefaultFlag(flagId) == value) 153 new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId); 154 else 155 new InstanceScope().getNode(PDE.PLUGIN_ID).putInt(flagId, value); 156 } 157 158 public static void setFlag(IProject project, String flagId, int value) { 159 setString(project, flagId, Integer.toString(value)); 160 } 161 162 public static void setBoolean(String flagId, boolean value) { 163 if (getDefaultBoolean(flagId) == value) 164 new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId); 165 else 166 new InstanceScope().getNode(PDE.PLUGIN_ID) 167 .putBoolean(flagId, value); 168 } 169 170 public static void setBoolean(IProject project, String flagId, boolean value) { 171 setString(project, flagId, Boolean.toString(value)); 172 } 173 174 public static void setString(String flagId, String value) { 175 if (getDefaultString(flagId).equals(value)) 176 new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId); 177 else 178 new InstanceScope().getNode(PDE.PLUGIN_ID).put(flagId, value); 179 } 180 181 188 public static void setString(IProject project, String flagId, String value) { 189 if (project == null) 190 return; 191 Preferences preferences = new ProjectScope(project) 192 .getNode(PDE.PLUGIN_ID); 193 preferences.put(flagId, value); 194 try { 195 preferences.flush(); 196 } catch (BackingStoreException bse) { 197 } 198 } 199 200 206 public static void clear(IProject project, String flagId) { 207 if (project == null) 208 return; 209 Preferences preferences = new ProjectScope(project) 210 .getNode(PDE.PLUGIN_ID); 211 preferences.remove(flagId); 212 try { 213 preferences.flush(); 214 } catch (BackingStoreException bse) { 215 } 216 } 217 218 public static void initializeDefaults() { 219 Preferences node = new DefaultScope().getNode(PDE.PLUGIN_ID); 220 node.putInt(P_UNRESOLVED_IMPORTS, ERROR); 221 node.putInt(P_UNRESOLVED_EX_POINTS, ERROR); 222 node.putInt(P_NO_REQUIRED_ATT, ERROR); 223 node.putInt(P_UNKNOWN_ELEMENT, WARNING); 224 node.putInt(P_UNKNOWN_ATTRIBUTE, WARNING); 225 node.putInt(P_DEPRECATED, WARNING); 226 node.putInt(P_UNKNOWN_CLASS, WARNING); 227 node.putInt(P_UNKNOWN_RESOURCE, WARNING); 228 node.putInt(P_NOT_EXTERNALIZED, IGNORE); 229 node.putInt(P_BUILD, WARNING); 230 node.putInt(P_INCOMPATIBLE_ENV, WARNING); 231 node.putInt(P_MISSING_EXPORT_PKGS, IGNORE); 232 233 node.putBoolean(S_CREATE_DOCS, false); 234 node.put(S_DOC_FOLDER, "doc"); node.putInt(S_OPEN_TAGS, WARNING); 236 237 node.putInt(F_UNRESOLVED_PLUGINS, WARNING); 238 node.putInt(F_UNRESOLVED_FEATURES, WARNING); 239 } 240 241 public static String [] getFlags(int group) { 242 return fFlags[group]; 243 } 244 245 248 public static void save() { 249 try { 250 new InstanceScope().getNode(PDE.PLUGIN_ID).flush(); 251 } catch (BackingStoreException e) { 252 } 253 } 254 } 255 | Popular Tags |