Adding ability to dump hint ids to a file.
1.1 --- a/javahints.generate/src/org/netbeans/modules/javahints/generate/OptionProcessorImpl.java Mon Oct 22 14:58:05 2012 +0200
1.2 +++ b/javahints.generate/src/org/netbeans/modules/javahints/generate/OptionProcessorImpl.java Mon Oct 22 14:58:29 2012 +0200
1.3 @@ -51,6 +51,8 @@
1.4 import java.util.Map;
1.5 import java.util.Set;
1.6 import org.netbeans.api.sendopts.CommandException;
1.7 +import org.netbeans.modules.java.hints.providers.spi.HintMetadata;
1.8 +import org.netbeans.modules.java.hints.spiimpl.RulesManager;
1.9 import org.netbeans.spi.sendopts.Env;
1.10 import org.netbeans.spi.sendopts.Option;
1.11 import org.netbeans.spi.sendopts.OptionProcessor;
1.12 @@ -66,7 +68,8 @@
1.13 public class OptionProcessorImpl extends OptionProcessor {
1.14
1.15 private static final Option GENERATE_WIKI = Option.requiredArgument('g', "generate-wiki-text-and-exit");
1.16 - private static final Set<Option> OPTIONS = new HashSet<Option>(Arrays.asList(GENERATE_WIKI));
1.17 + private static final Option DUMP_HINTS = Option.requiredArgument('d', "dump-hint-ids-and-exit");
1.18 + private static final Set<Option> OPTIONS = new HashSet<Option>(Arrays.asList(GENERATE_WIKI, DUMP_HINTS));
1.19
1.20 @Override
1.21 protected Set<Option> getOptions() {
1.22 @@ -75,14 +78,16 @@
1.23
1.24 @Override
1.25 protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException {
1.26 + boolean exit = false;
1.27 if (optionValues.containsKey(GENERATE_WIKI)) {
1.28 + exit = true;
1.29 +
1.30 OutputStream out = null;
1.31 try {
1.32 String targetFilePath = optionValues.get(GENERATE_WIKI)[0];
1.33 File target = new File(env.getCurrentDirectory(), targetFilePath);
1.34 out = new BufferedOutputStream(new FileOutputStream(target));
1.35 out.write(GenerateHintWiki.generateWiki().getBytes("UTF-8"));
1.36 - LifecycleManager.getDefault().exit();
1.37 } catch (IOException ex) {
1.38 Exceptions.printStackTrace(ex);
1.39 } finally {
1.40 @@ -93,6 +98,31 @@
1.41 }
1.42 }
1.43 }
1.44 + if (optionValues.containsKey(DUMP_HINTS)) {
1.45 + exit = true;
1.46 +
1.47 + OutputStream out = null;
1.48 + try {
1.49 + String targetFilePath = optionValues.get(DUMP_HINTS)[0];
1.50 + File target = new File(env.getCurrentDirectory(), targetFilePath);
1.51 + out = new BufferedOutputStream(new FileOutputStream(target));
1.52 + for (HintMetadata hm : RulesManager.getInstance().readHints(null, null, null).keySet()) {
1.53 + out.write(hm.id.getBytes("UTF-8"));
1.54 + out.write("\n".getBytes("UTF-8"));
1.55 + }
1.56 + } catch (IOException ex) {
1.57 + Exceptions.printStackTrace(ex);
1.58 + } finally {
1.59 + try {
1.60 + out.close();
1.61 + } catch (IOException ex) {
1.62 + Exceptions.printStackTrace(ex);
1.63 + }
1.64 + }
1.65 + }
1.66 +
1.67 + if (exit)
1.68 + LifecycleManager.getDefault().exit();
1.69 }
1.70
1.71 }