#21: adding --hint-file command line option, allowing to specify a file with the rules to apply.
1.1 --- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java Mon Oct 01 08:59:20 2012 -0700
1.2 +++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java Tue Oct 09 08:18:39 2012 -0700
1.3 @@ -83,6 +83,7 @@
1.4 import org.netbeans.api.java.source.ModificationResult;
1.5 import org.netbeans.core.startup.MainLookup;
1.6 import org.netbeans.modules.jackpot30.ui.settings.XMLHintPreferences;
1.7 +import org.netbeans.modules.java.hints.jackpot.spi.PatternConvertor;
1.8 import org.netbeans.modules.java.hints.providers.spi.HintDescription;
1.9 import org.netbeans.modules.java.hints.providers.spi.HintMetadata;
1.10 import org.netbeans.modules.java.hints.spiimpl.MessageImpl;
1.11 @@ -147,6 +148,7 @@
1.12 ArgumentAcceptingOptionSpec<String> hint = parser.accepts("hint", "hint name").withRequiredArg().ofType(String.class);
1.13 ArgumentAcceptingOptionSpec<String> config = parser.accepts("config", "configurations").withRequiredArg().ofType(String.class);
1.14 ArgumentAcceptingOptionSpec<String> source = parser.accepts("source", "source level").withRequiredArg().ofType(String.class).defaultsTo(SOURCE_LEVEL_DEFAULT);
1.15 + ArgumentAcceptingOptionSpec<File> hintFile = parser.accepts("hint-file", "file with rules that should be performed").withRequiredArg().ofType(File.class);
1.16
1.17 parser.accepts("list", "list all known hints");
1.18 parser.accepts("progress", "show progress");
1.19 @@ -281,10 +283,21 @@
1.20
1.21 if (parsed.has(hint)) {
1.22 if (settingsFromConfigFile != null) {
1.23 - System.err.println("cannot specify --hint and --configFile together");
1.24 + System.err.println("cannot specify --hint and --config-file together");
1.25 return 1;
1.26 }
1.27 hints = findHints(sourceCP, binaryCP, parsed.valueOf(hint), hintSettings);
1.28 + } else if (parsed.has(hintFile)) {
1.29 + if (settingsFromConfigFile != null) {
1.30 + System.err.println("cannot specify --hint-file and --config-file together");
1.31 + return 1;
1.32 + }
1.33 + FileObject hintFileFO = FileUtil.toFileObject(parsed.valueOf(hintFile));
1.34 + assert hintFileFO != null;
1.35 + hints = PatternConvertor.create(hintFileFO.asText());
1.36 + for (HintDescription hd : hints) {
1.37 + HintsSettings.setEnabled(hintSettings.node(hd.getMetadata().id), true);
1.38 + }
1.39 } else {
1.40 hints = readHints(sourceCP, binaryCP, hintSettings, settingsFromConfigFile != null ? settingsFromConfigFile.getBoolean("runDeclarative", true) : true);
1.41 }
2.1 --- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java Mon Oct 01 08:59:20 2012 -0700
2.2 +++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java Tue Oct 09 08:18:39 2012 -0700
2.3 @@ -257,6 +257,35 @@
2.4 "1.6",
2.5 "--no-apply");
2.6 }
2.7 +
2.8 + public void testHintFile() throws Exception {
2.9 + String golden =
2.10 + "package test;\n" +
2.11 + "public class Test {\n" +
2.12 + " private void test(java.util.Collection c) {\n" +
2.13 + " boolean b = c.size() == 0;\n" +
2.14 + " }\n" +
2.15 + "}\n";
2.16 +
2.17 + doRunCompiler(golden,
2.18 + "",
2.19 + null,
2.20 + "src/test/Test.java",
2.21 + "package test;\n" +
2.22 + "public class Test {\n" +
2.23 + " private void test(java.util.Collection c) {\n" +
2.24 + " boolean b = c.isEmpty();\n" +
2.25 + " }\n" +
2.26 + "}\n",
2.27 + "test-rule.hint",
2.28 + "$var.isEmpty() => $var.size() == 0;;",
2.29 + null,
2.30 + "--hint-file",
2.31 + "${workdir}/test-rule.hint",
2.32 + "--source",
2.33 + "1.6",
2.34 + "--apply");
2.35 + }
2.36
2.37 private void doRunCompiler(String golden, String stdOut, String stdErr, String... fileContentAndExtraOptions) throws Exception {
2.38 List<String> fileAndContent = new LinkedList<String>();