Commits

Jan Lahoda committed 0a0b424

The command line tool now accepts --source cmd. line parameter. Ant task supports it as well.

  • Participants
  • Parent commits 6be26dc

Comments (0)

Files changed (4)

File cmdline/ant/src/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTask.java

         this.sourcepath = sourcepath;
     }
 
+    private String sourcelevel;
+
+    public void setSource(String sourcelevel) {
+        this.sourcelevel = sourcelevel;
+    }
+
     private Path classpath;
 
     public Path createClasspath() {
             cmdLine.addArguments(new String[] {"-no-apply"});
             cmdLine.addArguments(new String[] {"-sourcepath", srcPath.toString()});
             cmdLine.addArguments(new String[] {"-classpath", classpath.toString()});
+            if (sourcelevel != null) cmdLine.addArguments(new String[] {"--source", sourcelevel});
             cmdLine.addArguments(srcPath.list());
 
             Execute exec = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN));

File cmdline/tool/nbproject/genfiles.properties

 build.xml.stylesheet.CRC32=a56c6a5b@1.44
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=6d837aec
+nbproject/build-impl.xml.data.CRC32=73e63f71
 nbproject/build-impl.xml.script.CRC32=08f1fb11
 nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49

File cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java

 public class Main {
 
     private static final String OPTION_NO_APPLY = "no-apply";
+    private static final String SOURCE_LEVEL_DEFAULT = "1.7";
+    private static final String ACCEPTABLE_SOURCE_LEVEL_PATTERN = "(1\\.)?[2-9][0-9]*";
     
     public static void main(String... args) throws IOException, ClassNotFoundException {
         System.exit(compile(args));
         ArgumentAcceptingOptionSpec<File> out = parser.accepts("out", "output diff").withRequiredArg().ofType(File.class);
         ArgumentAcceptingOptionSpec<String> hint = parser.accepts("hint", "hint name").withRequiredArg().ofType(String.class);
         ArgumentAcceptingOptionSpec<String> config = parser.accepts("config", "configurations").withRequiredArg().ofType(String.class);
+        ArgumentAcceptingOptionSpec<String> source = parser.accepts("source", "source level").withRequiredArg().ofType(String.class).defaultsTo(SOURCE_LEVEL_DEFAULT);
 
         parser.accepts("list", "list all known hints");
         parser.accepts("progress", "show progress");
                 }
             }
 
+            String sourceLevel = parsed.valueOf(source);
+
+            if (!Pattern.compile(ACCEPTABLE_SOURCE_LEVEL_PATTERN).matcher(sourceLevel).matches()) {
+                System.err.println("unrecognized source level specification: " + sourceLevel);
+                return 1;
+            }
+            
             try {
                 MainLookup.register(new ClassPathProviderImpl(bootCP, compileCP, sourceCP));
                 MainLookup.register(new JavaPathRecognizer());
-                MainLookup.register(new SourceLevelQueryImpl(sourceCP, "1.7"));
+                MainLookup.register(new SourceLevelQueryImpl(sourceCP, sourceLevel));
                 
                 ProgressHandleWrapper progress = parsed.has("progress") ? new ProgressHandleWrapper(new ConsoleProgressHandleAbstraction(), 1) : new ProgressHandleWrapper(1);
 

File cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java

 import org.netbeans.junit.NbTestCase;
 import org.openide.filesystems.FileUtil;
 
-/**
+/**XXX: should also test error conditions
  *
  * @author lahvac
  */
                       "also-equals=false");
     }
 
+    public void testValidSourceLevel() throws Exception {
+        String golden =
+            "package test;\n" +
+            "public class Test {\n" +
+            "    private void test(java.util.Collection c) {\n" +
+            "        boolean b = c.isEmpty();\n" +
+            "    }\n" +
+            "}\n";
+
+        doRunCompiler(golden,
+                      null,
+                      null,
+                      "src/test/Test.java",
+                      "package test;\n" +
+                      "public class Test {\n" +
+                      "    private void test(java.util.Collection c) {\n" +
+                      "        boolean b = c.size() == 0;\n" +
+                      "    }\n" +
+                      "}\n",
+                      null,
+                      "--hint",
+                      "Usage of .size() == 0",
+                      "--source",
+                      "1.6");
+    }
+
     private void doRunCompiler(String golden, String stdOut, String stdErr, String... fileContentAndExtraOptions) throws Exception {
         List<String> fileAndContent = new LinkedList<String>();
         List<String> extraOptions = new LinkedList<String>();