< prev index next >

langtools/test/tools/javac/versions/Versions.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 8030610 8028546
  27  * @summary Check interpretation of -target and -source options
  28  * @modules java.compiler
  29  *          jdk.compiler
  30  * @run main Versions
  31  */
  32 
  33 import java.io.*;
  34 import java.nio.*;
  35 import java.nio.channels.*;
  36 
  37 import javax.tools.JavaCompiler;
  38 import javax.tools.ToolProvider;
  39 import javax.tools.JavaFileObject;
  40 import javax.tools.StandardJavaFileManager;
  41 import java.util.List;
  42 import java.util.ArrayList;
  43 import java.util.Arrays;
  44 
  45 
  46 public class Versions {
  47 
  48     protected JavaCompiler javacompiler;
  49     protected int failedCases;
  50 
  51     public Versions() throws IOException {
  52         javacompiler = ToolProvider.getSystemJavaCompiler();
  53         genSourceFiles();
  54         failedCases = 0;
  55     }
  56 
  57     public static void main(String... args) throws IOException {
  58         Versions versions = new Versions();
  59         versions.run();
  60     }
  61 
  62     void run() {
  63 
  64         String TC = "";
  65         System.out.println("Version.java: Starting");
  66 
  67         check("53.0");
  68         check("53.0", "-source 1.6");
  69         check("53.0", "-source 1.7");
  70         check("53.0", "-source 1.8");
  71         check("53.0", "-source 1.9");
  72         check("53.0", "-source 1.10");

  73 
  74         check_source_target("50.0", "6", "6");
  75         check_source_target("51.0", "6", "7");
  76         check_source_target("51.0", "7", "7");
  77         check_source_target("52.0", "6", "8");
  78         check_source_target("52.0", "7", "8");
  79         check_source_target("52.0", "8", "8");
  80         check_source_target("53.0", "6", "9");
  81         check_source_target("53.0", "7", "9");
  82         check_source_target("53.0", "8", "9");
  83         check_source_target("53.0", "9", "9");
  84         check_source_target("53.0", "10", "10");






  85 
  86         checksrc16("-source 1.6");
  87         checksrc16("-source 6");
  88         checksrc16("-source 1.6", "-target 1.6");
  89         checksrc16("-source 6", "-target 6");
  90         checksrc17("-source 1.7");
  91         checksrc17("-source 7");
  92         checksrc17("-source 1.7", "-target 1.7");
  93         checksrc17("-source 7", "-target 7");
  94         checksrc18("-source 1.8");
  95         checksrc18("-source 8");
  96         checksrc18("-source 1.8", "-target 1.8");
  97         checksrc18("-source 8", "-target 8");
  98         checksrc19("-source 1.9");
  99         checksrc19("-source 9");
 100         checksrc19("-source 1.9", "-target 1.9");
 101         checksrc19("-source 9", "-target 9");
 102 
 103         checksrc110();
 104         checksrc110("-source 1.10");
 105         checksrc110("-source 10");
 106         checksrc110("-source 1.10", "-target 1.10");
 107         checksrc110("-source 10", "-target 10");
 108         checksrc110("-target 1.10");
 109         checksrc110("-target 10");
 110 





 111         fail("-source 7", "-target 1.6", "Base.java");
 112         fail("-source 8", "-target 1.6", "Base.java");
 113         fail("-source 8", "-target 1.7", "Base.java");
 114         fail("-source 9", "-target 1.7", "Base.java");
 115         fail("-source 9", "-target 1.8", "Base.java");
 116         fail("-source 10", "-target 1.7", "Base.java");
 117         fail("-source 10", "-target 1.8", "Base.java");




 118 
 119         fail("-source 1.5", "-target 1.5", "Base.java");
 120         fail("-source 1.4", "-target 1.4", "Base.java");
 121         fail("-source 1.3", "-target 1.3", "Base.java");
 122         fail("-source 1.2", "-target 1.2", "Base.java");
 123 
 124         if (failedCases > 0) {
 125             System.err.println("failedCases = " + String.valueOf(failedCases));
 126             throw new Error("Test failed");
 127         }
 128 
 129     }
 130 
 131     protected void printargs(String fname,String... args) {
 132         System.out.printf("test: %s", fname);
 133         for (String onearg : args) {
 134             System.out.printf(" %s", onearg);
 135         }
 136         System.out.printf("\n", fname);
 137     }


 197 
 198     protected void checksrc18(String... args) {
 199         printargs("checksrc18", args);
 200         int asize = args.length;
 201         String[] newargs = new String[asize+1];
 202         System.arraycopy(args, 0, newargs,0 , asize);
 203         newargs[asize] = "New17.java";
 204         pass(newargs);
 205         newargs[asize] = "New18.java";
 206         pass(newargs);
 207     }
 208 
 209     protected void checksrc19(String... args) {
 210         printargs("checksrc19", args);
 211         checksrc18(args);
 212     }
 213 
 214     protected void checksrc110(String... args) {
 215         printargs("checksrc110", args);
 216         checksrc19(args);





 217     }
 218 
 219     protected void pass(String... args) {
 220         printargs("pass", args);
 221 
 222         List<String> jcargs = new ArrayList<String>();
 223         jcargs.add("-Xlint:-options");
 224 
 225         // add in args conforming to List requrements of JavaCompiler
 226         for (String onearg : args) {
 227             String[] fields = onearg.split(" ");
 228             for (String onefield : fields) {
 229                 jcargs.add(onefield);
 230             }
 231         }
 232 
 233         // empty list is error
 234         if (jcargs.isEmpty()) {
 235             System.err.println("error: test error in pass() - No arguments");
 236             System.err.println("\t arguments:\t" + jcargs);




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 8030610 8028546 8187296
  27  * @summary Check interpretation of -target and -source options
  28  * @modules java.compiler
  29  *          jdk.compiler
  30  * @run main Versions
  31  */
  32 
  33 import java.io.*;
  34 import java.nio.*;
  35 import java.nio.channels.*;
  36 
  37 import javax.tools.JavaCompiler;
  38 import javax.tools.ToolProvider;
  39 import javax.tools.JavaFileObject;
  40 import javax.tools.StandardJavaFileManager;
  41 import java.util.List;
  42 import java.util.ArrayList;
  43 import java.util.Arrays;
  44 
  45 
  46 public class Versions {
  47 
  48     protected JavaCompiler javacompiler;
  49     protected int failedCases;
  50 
  51     public Versions() throws IOException {
  52         javacompiler = ToolProvider.getSystemJavaCompiler();
  53         genSourceFiles();
  54         failedCases = 0;
  55     }
  56 
  57     public static void main(String... args) throws IOException {
  58         Versions versions = new Versions();
  59         versions.run();
  60     }
  61 
  62     void run() {
  63 
  64         String TC = "";
  65         System.out.println("Version.java: Starting");
  66 
  67         check("54.0");
  68         check("54.0", "-source 1.6");
  69         check("54.0", "-source 1.7");
  70         check("54.0", "-source 1.8");
  71         check("54.0", "-source 1.9");
  72         check("54.0", "-source 1.10");
  73         check("54.0", "-source 11");
  74 
  75         check_source_target("50.0", "6", "6");
  76         check_source_target("51.0", "6", "7");
  77         check_source_target("51.0", "7", "7");
  78         check_source_target("52.0", "6", "8");
  79         check_source_target("52.0", "7", "8");
  80         check_source_target("52.0", "8", "8");
  81         check_source_target("53.0", "6", "9");
  82         check_source_target("53.0", "7", "9");
  83         check_source_target("53.0", "8", "9");
  84         check_source_target("53.0", "9", "9");
  85         check_source_target("53.0", "10", "10");
  86         check_source_target("54.0", "6", "11");
  87         check_source_target("54.0", "7", "11");
  88         check_source_target("54.0", "8", "11");
  89         check_source_target("54.0", "9", "11");
  90         check_source_target("54.0", "10", "11");
  91         check_source_target("54.0", "11", "11");
  92 
  93         checksrc16("-source 1.6");
  94         checksrc16("-source 6");
  95         checksrc16("-source 1.6", "-target 1.6");
  96         checksrc16("-source 6", "-target 6");
  97         checksrc17("-source 1.7");
  98         checksrc17("-source 7");
  99         checksrc17("-source 1.7", "-target 1.7");
 100         checksrc17("-source 7", "-target 7");
 101         checksrc18("-source 1.8");
 102         checksrc18("-source 8");
 103         checksrc18("-source 1.8", "-target 1.8");
 104         checksrc18("-source 8", "-target 8");
 105         checksrc19("-source 1.9");
 106         checksrc19("-source 9");
 107         checksrc19("-source 1.9", "-target 1.9");
 108         checksrc19("-source 9", "-target 9");
 109 
 110         checksrc110();
 111         checksrc110("-source 1.10");
 112         checksrc110("-source 10");
 113         checksrc110("-source 1.10", "-target 1.10");
 114         checksrc110("-source 10", "-target 10");
 115         checksrc110("-target 1.10");
 116         checksrc110("-target 10");
 117 
 118         checksrc11();
 119         checksrc11("-source 11");
 120         checksrc11("-source 11", "-target 11");
 121         checksrc11("-target 11");
 122 
 123         fail("-source 7", "-target 1.6", "Base.java");
 124         fail("-source 8", "-target 1.6", "Base.java");
 125         fail("-source 8", "-target 1.7", "Base.java");
 126         fail("-source 9", "-target 1.7", "Base.java");
 127         fail("-source 9", "-target 1.8", "Base.java");
 128         fail("-source 10", "-target 1.7", "Base.java");
 129         fail("-source 10", "-target 1.8", "Base.java");
 130         fail("-source 11", "-target 1.7", "Base.java");
 131         fail("-source 11", "-target 1.8", "Base.java");
 132         fail("-source 11", "-target 1.9", "Base.java");
 133         fail("-source 11", "-target 1.10", "Base.java");
 134 
 135         fail("-source 1.5", "-target 1.5", "Base.java");
 136         fail("-source 1.4", "-target 1.4", "Base.java");
 137         fail("-source 1.3", "-target 1.3", "Base.java");
 138         fail("-source 1.2", "-target 1.2", "Base.java");
 139 
 140         if (failedCases > 0) {
 141             System.err.println("failedCases = " + String.valueOf(failedCases));
 142             throw new Error("Test failed");
 143         }
 144 
 145     }
 146 
 147     protected void printargs(String fname,String... args) {
 148         System.out.printf("test: %s", fname);
 149         for (String onearg : args) {
 150             System.out.printf(" %s", onearg);
 151         }
 152         System.out.printf("\n", fname);
 153     }


 213 
 214     protected void checksrc18(String... args) {
 215         printargs("checksrc18", args);
 216         int asize = args.length;
 217         String[] newargs = new String[asize+1];
 218         System.arraycopy(args, 0, newargs,0 , asize);
 219         newargs[asize] = "New17.java";
 220         pass(newargs);
 221         newargs[asize] = "New18.java";
 222         pass(newargs);
 223     }
 224 
 225     protected void checksrc19(String... args) {
 226         printargs("checksrc19", args);
 227         checksrc18(args);
 228     }
 229 
 230     protected void checksrc110(String... args) {
 231         printargs("checksrc110", args);
 232         checksrc19(args);
 233     }
 234 
 235     protected void checksrc11(String... args) {
 236         printargs("checksrc11", args);
 237         checksrc110(args);
 238     }
 239 
 240     protected void pass(String... args) {
 241         printargs("pass", args);
 242 
 243         List<String> jcargs = new ArrayList<String>();
 244         jcargs.add("-Xlint:-options");
 245 
 246         // add in args conforming to List requrements of JavaCompiler
 247         for (String onearg : args) {
 248             String[] fields = onearg.split(" ");
 249             for (String onefield : fields) {
 250                 jcargs.add(onefield);
 251             }
 252         }
 253 
 254         // empty list is error
 255         if (jcargs.isEmpty()) {
 256             System.err.println("error: test error in pass() - No arguments");
 257             System.err.println("\t arguments:\t" + jcargs);


< prev index next >