Adjusting to recent NB trunk changes.
authorJan Lahoda <jlahoda@netbeans.org>
Sun, 28 Apr 2013 21:55:14 +0200
changeset 9524c4b5ec2c7de
parent 951 b00f220fd939
child 953 d4587f6e7b02
Adjusting to recent NB trunk changes.
cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
     1.1 --- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java	Sun Apr 28 09:28:28 2013 +0200
     1.2 +++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java	Sun Apr 28 21:55:14 2013 +0200
     1.3 @@ -269,16 +269,17 @@
     1.4              }
     1.5  
     1.6              Preferences settingsFromConfigFile;
     1.7 -            Preferences hintSettings;
     1.8 +            Preferences hintSettingsPreferences;
     1.9 +            HintsSettings hintSettings;
    1.10              boolean apply;
    1.11  
    1.12              if (parsed.has(configFile)) {
    1.13                  settingsFromConfigFile = XMLHintPreferences.from(parsed.valueOf(configFile));
    1.14 -                hintSettings = settingsFromConfigFile.node("settings");
    1.15 +                hintSettings = HintsSettings.createPreferencesBasedHintsSettings(hintSettingsPreferences = settingsFromConfigFile.node("settings"), false, null);
    1.16                  apply = settingsFromConfigFile.getBoolean("apply", false);
    1.17              } else {
    1.18                  settingsFromConfigFile = null;
    1.19 -                hintSettings = NbPreferences.root().node("tempSettings");
    1.20 +                hintSettings = HintsSettings.createPreferencesBasedHintsSettings(hintSettingsPreferences = NbPreferences.root().node("tempSettings"), false, null);
    1.21                  apply = false;
    1.22              }
    1.23  
    1.24 @@ -297,10 +298,10 @@
    1.25                  assert hintFileFO != null;
    1.26                  hints = PatternConvertor.create(hintFileFO.asText());
    1.27                  for (HintDescription hd : hints) {
    1.28 -                    HintsSettings.setEnabled(hintSettings.node(hd.getMetadata().id), true);
    1.29 +                    hintSettings.setEnabled(hd.getMetadata(), true);
    1.30                  }
    1.31              } else {
    1.32 -                hints = readHints(sourceCP, binaryCP, hintSettings, settingsFromConfigFile != null ? settingsFromConfigFile.getBoolean("runDeclarative", true) : true);
    1.33 +                hints = readHints(sourceCP, binaryCP, hintSettings, hintSettingsPreferences, settingsFromConfigFile != null ? settingsFromConfigFile.getBoolean("runDeclarative", true) : true);
    1.34              }
    1.35  
    1.36              if (parsed.has(config) && !parsed.has(hint)) {
    1.37 @@ -318,7 +319,7 @@
    1.38                      return 1;
    1.39                  }
    1.40  
    1.41 -                Preferences prefs = hintSettings.node(hd.getMetadata().id);
    1.42 +                Preferences prefs = hintSettings.getHintPreferences(hd.getMetadata());
    1.43  
    1.44                  boolean stop = false;
    1.45  
    1.46 @@ -368,14 +369,12 @@
    1.47                      MainLookup.register(toRegister);
    1.48                  }
    1.49  
    1.50 -                setHintPreferences(hintSettings);
    1.51 -                
    1.52                  ProgressHandleWrapper progress = parsed.has("progress") ? new ProgressHandleWrapper(new ConsoleProgressHandleAbstraction(), 1) : new ProgressHandleWrapper(1);
    1.53  
    1.54                  if (apply) {
    1.55 -                    apply(hints, rootFolders.toArray(new Folder[0]), progress, parsed.valueOf(out));
    1.56 +                    apply(hints, rootFolders.toArray(new Folder[0]), progress, hintSettings, parsed.valueOf(out));
    1.57                  } else {
    1.58 -                    findOccurrences(hints, rootFolders.toArray(new Folder[0]), progress, parsed.valueOf(out));
    1.59 +                    findOccurrences(hints, rootFolders.toArray(new Folder[0]), progress, hintSettings, parsed.valueOf(out));
    1.60                  }
    1.61              } catch (Throwable e) {
    1.62                  e.printStackTrace();
    1.63 @@ -398,53 +397,6 @@
    1.64          return 0;
    1.65      }
    1.66  
    1.67 -    private static void setHintPreferences(final Preferences prefs) {
    1.68 -        HintsSettings.setPreferencesOverride(new Map<String, Preferences>() {
    1.69 -            @Override public int size() {
    1.70 -                throw new UnsupportedOperationException("Not supported yet.");
    1.71 -            }
    1.72 -            @Override public boolean isEmpty() {
    1.73 -                throw new UnsupportedOperationException("Not supported yet.");
    1.74 -            }
    1.75 -            @Override public boolean containsKey(Object key) {
    1.76 -                throw new UnsupportedOperationException("Not supported yet.");
    1.77 -            }
    1.78 -            @Override public boolean containsValue(Object value) {
    1.79 -                throw new UnsupportedOperationException("Not supported yet.");
    1.80 -            }
    1.81 -            @Override public Preferences get(Object key) {
    1.82 -                Preferences res = prefs.node((String) key);
    1.83 -
    1.84 -                if (res.get("enabled", null) == null) {
    1.85 -                    res.putBoolean("enabled", false);
    1.86 -                }
    1.87 -                
    1.88 -                return res;
    1.89 -            }
    1.90 -            @Override public Preferences put(String key, Preferences value) {
    1.91 -                throw new UnsupportedOperationException("Not supported yet.");
    1.92 -            }
    1.93 -            @Override public Preferences remove(Object key) {
    1.94 -                throw new UnsupportedOperationException("Not supported yet.");
    1.95 -            }
    1.96 -            @Override public void putAll(Map<? extends String, ? extends Preferences> m) {
    1.97 -                throw new UnsupportedOperationException("Not supported yet.");
    1.98 -            }
    1.99 -            @Override public void clear() {
   1.100 -                throw new UnsupportedOperationException("Not supported yet.");
   1.101 -            }
   1.102 -            @Override public Set<String> keySet() {
   1.103 -                throw new UnsupportedOperationException("Not supported yet.");
   1.104 -            }
   1.105 -            @Override public Collection<Preferences> values() {
   1.106 -                throw new UnsupportedOperationException("Not supported yet.");
   1.107 -            }
   1.108 -            @Override public Set<Entry<String, Preferences>> entrySet() {
   1.109 -                throw new UnsupportedOperationException("Not supported yet.");
   1.110 -            }
   1.111 -        });
   1.112 -    }
   1.113 -
   1.114      private static Map<HintMetadata, Collection<? extends HintDescription>> listHints(ClassPath sourceFrom, ClassPath binaryFrom) {
   1.115          Map<HintMetadata, Collection<? extends HintDescription>> result = new HashMap<HintMetadata, Collection<? extends HintDescription>>();
   1.116  
   1.117 @@ -455,44 +407,44 @@
   1.118          return result;
   1.119      }
   1.120      
   1.121 -    private static Iterable<? extends HintDescription> findHints(ClassPath sourceFrom, ClassPath binaryFrom, String name, Preferences toEnableIn) {
   1.122 +    private static Iterable<? extends HintDescription> findHints(ClassPath sourceFrom, ClassPath binaryFrom, String name, HintsSettings toEnableIn) {
   1.123          List<HintDescription> descs = new LinkedList<HintDescription>();
   1.124  
   1.125          for (Entry<HintMetadata, Collection<? extends HintDescription>> e : listHints(sourceFrom, binaryFrom).entrySet()) {
   1.126              if (e.getKey().displayName.equals(name)) {
   1.127                  descs.addAll(e.getValue());
   1.128 -                HintsSettings.setEnabled(toEnableIn.node(e.getKey().id), true);
   1.129 +                toEnableIn.setEnabled(e.getKey(), true);
   1.130              }
   1.131          }
   1.132  
   1.133          return descs;
   1.134      }
   1.135  
   1.136 -    private static Iterable<? extends HintDescription> allHints(ClassPath sourceFrom, ClassPath binaryFrom, Preferences toEnableIn) {
   1.137 +    private static Iterable<? extends HintDescription> allHints(ClassPath sourceFrom, ClassPath binaryFrom, HintsSettings toEnableIn) {
   1.138          List<HintDescription> descs = new LinkedList<HintDescription>();
   1.139  
   1.140          for (Entry<HintMetadata, Collection<? extends HintDescription>> e : listHints(sourceFrom, binaryFrom).entrySet()) {
   1.141              if (e.getKey().kind != Kind.INSPECTION) continue;
   1.142              if (!e.getKey().enabled) continue;
   1.143              descs.addAll(e.getValue());
   1.144 -            HintsSettings.setEnabled(toEnableIn.node(e.getKey().id), true);
   1.145 +            toEnableIn.setEnabled(e.getKey(), true);
   1.146          }
   1.147  
   1.148          return descs;
   1.149      }
   1.150  
   1.151 -    private static Iterable<? extends HintDescription> readHints(ClassPath sourceFrom, ClassPath binaryFrom, Preferences toEnableIn, boolean declarativeEnabledByDefault) {
   1.152 +    private static Iterable<? extends HintDescription> readHints(ClassPath sourceFrom, ClassPath binaryFrom, HintsSettings toEnableIn, Preferences toEnableInPreferencesHack, boolean declarativeEnabledByDefault) {
   1.153          Map<HintMetadata, ? extends Collection<? extends HintDescription>> hardcoded = RulesManager.getInstance().readHints(null, Arrays.<ClassPath>asList(), null);
   1.154          Map<HintMetadata, ? extends Collection<? extends HintDescription>> all = RulesManager.getInstance().readHints(null, Arrays.asList(sourceFrom, binaryFrom), null);
   1.155          List<HintDescription> descs = new LinkedList<HintDescription>();
   1.156  
   1.157          for (Entry<HintMetadata, ? extends Collection<? extends HintDescription>> entry: all.entrySet()) {
   1.158              if (hardcoded.containsKey(entry.getKey())) {
   1.159 -                if (HintsSettings.isEnabledWithDefault(toEnableIn.node(entry.getKey().id), false)) {
   1.160 +                if (toEnableIn.isEnabled(entry.getKey())) {
   1.161                      descs.addAll(entry.getValue());
   1.162                  }
   1.163              } else {
   1.164 -                if (HintsSettings.isEnabledWithDefault(toEnableIn.node(entry.getKey().id), declarativeEnabledByDefault)) {
   1.165 +                if (/*XXX: hack*/toEnableInPreferencesHack.node(entry.getKey().id).getBoolean("enabled", declarativeEnabledByDefault)) {
   1.166                      descs.addAll(entry.getValue());
   1.167                  }
   1.168              }
   1.169 @@ -508,7 +460,7 @@
   1.170          System.setProperty("RepositoryUpdate.increasedLogLevel", "OFF");
   1.171      }
   1.172      
   1.173 -    private static void findOccurrences(Iterable<? extends HintDescription> descs, Folder[] sourceRoot, ProgressHandleWrapper progress, File out) throws IOException {
   1.174 +    private static void findOccurrences(Iterable<? extends HintDescription> descs, Folder[] sourceRoot, ProgressHandleWrapper progress, HintsSettings settings, File out) throws IOException {
   1.175          final Map<String, String> id2DisplayName = new HashMap<String, String>();
   1.176  
   1.177          for (HintDescription hd : descs) {
   1.178 @@ -518,7 +470,7 @@
   1.179          }
   1.180  
   1.181          ProgressHandleWrapper w = progress.startNextPartWithEmbedding(1, 1);
   1.182 -        BatchResult occurrences = BatchSearch.findOccurrences(descs, Scopes.specifiedFoldersScope(sourceRoot), w);
   1.183 +        BatchResult occurrences = BatchSearch.findOccurrences(descs, Scopes.specifiedFoldersScope(sourceRoot), w, settings);
   1.184  
   1.185          List<MessageImpl> problems = new LinkedList<MessageImpl>();
   1.186          BatchSearch.getVerifiedSpans(occurrences, progress, new VerifiedSpansCallBack() {
   1.187 @@ -582,9 +534,9 @@
   1.188          put("!=", "not_equals");
   1.189      }};
   1.190  
   1.191 -    private static void apply(Iterable<? extends HintDescription> descs, Folder[] sourceRoot, ProgressHandleWrapper progress, File out) throws IOException {
   1.192 +    private static void apply(Iterable<? extends HintDescription> descs, Folder[] sourceRoot, ProgressHandleWrapper progress, HintsSettings settings, File out) throws IOException {
   1.193          ProgressHandleWrapper w = progress.startNextPartWithEmbedding(1, 1);
   1.194 -        BatchResult occurrences = BatchSearch.findOccurrences(descs, Scopes.specifiedFoldersScope(sourceRoot), w);
   1.195 +        BatchResult occurrences = BatchSearch.findOccurrences(descs, Scopes.specifiedFoldersScope(sourceRoot), w, settings);
   1.196  
   1.197          List<MessageImpl> problems = new LinkedList<MessageImpl>();
   1.198          Collection<ModificationResult> diffs = BatchUtilities.applyFixes(occurrences, w, new AtomicBoolean(), problems);