< prev index next >

test/langtools/tools/javac/classfiles/ClassVersionChecker.java

Print this page
rev 48343 : imported patch JDK-8173382-classfile-version


   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 7157626 8001112 8188870
  27  * @summary Test major version for all legal combinations for -source and -target
  28  * @author sgoel
  29  *
  30  * @modules jdk.compiler
  31  */
  32 
  33 import java.io.*;
  34 import java.nio.*;
  35 import java.util.*;
  36 import java.util.regex.*;
  37 
  38 public class ClassVersionChecker {
  39 
  40     int errors;
  41     String[] jdk = {"", "1.6", "1.7", "1.8", "1.9", "1.10"};
  42     File javaFile = null;
  43 
  44     public static void main(String[] args) throws Throwable {
  45         new ClassVersionChecker().run();
  46     }
  47 
  48     void run() throws Exception {
  49         writeTestFile();
  50         /* Rules applicable for -source and -target combinations
  51          * 1. If both empty, version num is for the current release
  52          * 2. If source is not empty and target is empty, version is based on source
  53          * 3. If both non-empty, version is based on target
  54          */
  55 
  56         /* -source (0=>empty,1=>1.2,...) X -target (0=>empty,1=>1.2,...)
  57          * ver[0][0] => no -source or -target was given
  58          * -1 => invalid combinations
  59          */
  60         int[][] ver =
  61                 {{54, -1, -1, -1, -1, -1},
  62                  {54, 50, 51, 52, 53, 54},
  63                  {54, -1, 51, 52, 53, 54},
  64                  {54, -1, -1, 52, 53, 54},
  65                  {54, -1, -1, -1, 53, 54}};

  66 
  67         // Loop to run all possible combinations of source/target values
  68         for (int i = 0; i< ver.length; i++) {
  69             for (int j = 0 ; j< ver[i].length; j++) {
  70                 if(ver[i][j] != -1) {
  71                     logMsg("Index values for i = " + i + " j = " + j);
  72                     logMsg("Running for src = " + jdk[i] + " target = "+jdk[j] +" expected = " + ver[i][j]);
  73                     test(i,j, ver[i][j]);
  74                 }
  75             }
  76         }
  77 
  78         if (errors > 0)
  79             throw new Exception(errors + " errors found");
  80     }
  81 
  82     void test (int i, int j, int expected) {
  83         File classFile = compileTestFile(i, j, javaFile);
  84         short majorVer = getMajorVersion(classFile);
  85         checkVersion(majorVer, expected);




   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 7157626 8001112 8188870 8173382
  27  * @summary Test major version for all legal combinations for -source and -target
  28  * @author sgoel
  29  *
  30  * @modules jdk.compiler
  31  */
  32 
  33 import java.io.*;
  34 import java.nio.*;
  35 import java.util.*;
  36 import java.util.regex.*;
  37 
  38 public class ClassVersionChecker {
  39 
  40     int errors;
  41     String[] jdk = {"", "1.6", "1.7", "1.8", "1.9", "1.10", "11"};
  42     File javaFile = null;
  43 
  44     public static void main(String[] args) throws Throwable {
  45         new ClassVersionChecker().run();
  46     }
  47 
  48     void run() throws Exception {
  49         writeTestFile();
  50         /* Rules applicable for -source and -target combinations
  51          * 1. If both empty, version num is for the current release
  52          * 2. If source is not empty and target is empty, version is based on source
  53          * 3. If both non-empty, version is based on target
  54          */
  55 
  56         /* -source (0=>empty,1=>1.2,...) X -target (0=>empty,1=>1.2,...)
  57          * ver[0][0] => no -source or -target was given
  58          * -1 => invalid combinations
  59          */
  60         int[][] ver =
  61                 {{55, -1, -1, -1, -1, -1, -1},
  62                  {55, 50, 51, 52, 53, 54, 55},
  63                  {55, -1, 51, 52, 53, 54, 55},
  64                  {55, -1, -1, 52, 53, 54, 55},
  65                  {55, -1, -1, -1, 53, 54, 55},
  66                  {55, -1, -1, -1, -1, 54, 55}};
  67 
  68         // Loop to run all possible combinations of source/target values
  69         for (int i = 0; i< ver.length; i++) {
  70             for (int j = 0 ; j< ver[i].length; j++) {
  71                 if(ver[i][j] != -1) {
  72                     logMsg("Index values for i = " + i + " j = " + j);
  73                     logMsg("Running for src = " + jdk[i] + " target = "+jdk[j] +" expected = " + ver[i][j]);
  74                     test(i,j, ver[i][j]);
  75                 }
  76             }
  77         }
  78 
  79         if (errors > 0)
  80             throw new Exception(errors + " errors found");
  81     }
  82 
  83     void test (int i, int j, int expected) {
  84         File classFile = compileTestFile(i, j, javaFile);
  85         short majorVer = getMajorVersion(classFile);
  86         checkVersion(majorVer, expected);


< prev index next >