49 * values are the defaults. If explicitly specified, the target value 50 * has to be greater than or equal to the source value. 51 */ 52 public class Versions { 53 54 protected JavaCompiler javacompiler; 55 protected int failedCases; 56 57 public Versions() throws IOException { 58 javacompiler = ToolProvider.getSystemJavaCompiler(); 59 genSourceFiles(); 60 failedCases = 0; 61 } 62 63 public static void main(String... args) throws IOException { 64 Versions versions = new Versions(); 65 versions.run(); 66 } 67 68 public static final Set<String> RETIRED_SOURCES = 69 Set.of("1.2", "1.3", "1.4", "1.5"); 70 71 public static final Set<String> VALID_SOURCES = 72 Set.of("1.6", "1.7", "1.8", "1.9", "1.10", "11", "12"); 73 74 public static final String LATEST_MAJOR_VERSION = "56.0"; 75 76 static enum SourceTarget { 77 SIX(true, "50.0", "6", Versions::checksrc16), 78 SEVEN(true, "51.0", "7", Versions::checksrc17), 79 EIGHT(true, "52.0", "8", Versions::checksrc18), 80 NINE(true, "53.0", "9", Versions::checksrc19), 81 TEN(true, "54.0", "10", Versions::checksrc110), 82 ELEVEN(false, "55.0", "11", Versions::checksrc111), 83 TWELVE(false, "56.0", "12", Versions::checksrc112); 84 85 private final boolean dotOne; 86 private final String classFileVer; 87 private final String target; 88 private final BiConsumer<Versions, String[]> checker; 89 90 private SourceTarget(boolean dotOne, String classFileVer, String target, 91 BiConsumer<Versions, String[]> checker) { 92 this.dotOne = dotOne; 93 this.classFileVer = classFileVer; 94 this.target = target; 95 this.checker = checker; 96 } 97 213 214 // add in args conforming to List requrements of JavaCompiler 215 for (String onearg : args) { 216 String[] fields = onearg.split(" "); 217 for (String onefield : fields) { 218 jcargs.add(onefield); 219 } 220 } 221 222 boolean creturn = compile("Base.java", jcargs); 223 if (!creturn) { 224 // compilation errors note and return.. assume no class file 225 System.err.println("check: Compilation Failed"); 226 System.err.println("\t classVersion:\t" + major); 227 System.err.println("\t arguments:\t" + jcargs); 228 failedCases++; 229 230 } else if (!checkClassFileVersion("Base.class", major)) { 231 failedCases++; 232 } 233 } 234 235 protected void checksrc16(String... args) { 236 printargs("checksrc16", args); 237 int asize = args.length; 238 String[] newargs = new String[asize + 1]; 239 System.arraycopy(args, 0, newargs, 0, asize); 240 newargs[asize] = "Base.java"; 241 pass(newargs); 242 newargs[asize] = "New17.java"; 243 fail(newargs); 244 } 245 246 protected void checksrc17(String... args) { 247 printargs("checksrc17", args); 248 int asize = args.length; 249 String[] newargs = new String[asize+1]; 250 System.arraycopy(args, 0, newargs,0 , asize); 251 newargs[asize] = "New17.java"; 252 pass(newargs); 253 newargs[asize] = "New18.java"; 254 fail(newargs); 255 } 256 257 protected void checksrc18(String... args) { 258 printargs("checksrc18", args); 259 int asize = args.length; 260 String[] newargs = new String[asize+1]; 261 System.arraycopy(args, 0, newargs,0 , asize); 262 newargs[asize] = "New17.java"; 263 pass(newargs); | 49 * values are the defaults. If explicitly specified, the target value 50 * has to be greater than or equal to the source value. 51 */ 52 public class Versions { 53 54 protected JavaCompiler javacompiler; 55 protected int failedCases; 56 57 public Versions() throws IOException { 58 javacompiler = ToolProvider.getSystemJavaCompiler(); 59 genSourceFiles(); 60 failedCases = 0; 61 } 62 63 public static void main(String... args) throws IOException { 64 Versions versions = new Versions(); 65 versions.run(); 66 } 67 68 public static final Set<String> RETIRED_SOURCES = 69 Set.of("1.2", "1.3", "1.4", "1.5" /*, 1.6 */); 70 71 public static final Set<String> VALID_SOURCES = 72 Set.of("1.7", "1.8", "1.9", "1.10", "11", "12"); 73 74 public static final String LATEST_MAJOR_VERSION = "56.0"; 75 76 static enum SourceTarget { 77 SEVEN(true, "51.0", "7", Versions::checksrc17), 78 EIGHT(true, "52.0", "8", Versions::checksrc18), 79 NINE(true, "53.0", "9", Versions::checksrc19), 80 TEN(true, "54.0", "10", Versions::checksrc110), 81 ELEVEN(false, "55.0", "11", Versions::checksrc111), 82 TWELVE(false, "56.0", "12", Versions::checksrc112); 83 84 private final boolean dotOne; 85 private final String classFileVer; 86 private final String target; 87 private final BiConsumer<Versions, String[]> checker; 88 89 private SourceTarget(boolean dotOne, String classFileVer, String target, 90 BiConsumer<Versions, String[]> checker) { 91 this.dotOne = dotOne; 92 this.classFileVer = classFileVer; 93 this.target = target; 94 this.checker = checker; 95 } 96 212 213 // add in args conforming to List requrements of JavaCompiler 214 for (String onearg : args) { 215 String[] fields = onearg.split(" "); 216 for (String onefield : fields) { 217 jcargs.add(onefield); 218 } 219 } 220 221 boolean creturn = compile("Base.java", jcargs); 222 if (!creturn) { 223 // compilation errors note and return.. assume no class file 224 System.err.println("check: Compilation Failed"); 225 System.err.println("\t classVersion:\t" + major); 226 System.err.println("\t arguments:\t" + jcargs); 227 failedCases++; 228 229 } else if (!checkClassFileVersion("Base.class", major)) { 230 failedCases++; 231 } 232 } 233 234 protected void checksrc17(String... args) { 235 printargs("checksrc17", args); 236 int asize = args.length; 237 String[] newargs = new String[asize+1]; 238 System.arraycopy(args, 0, newargs,0 , asize); 239 newargs[asize] = "New17.java"; 240 pass(newargs); 241 newargs[asize] = "New18.java"; 242 fail(newargs); 243 } 244 245 protected void checksrc18(String... args) { 246 printargs("checksrc18", args); 247 int asize = args.length; 248 String[] newargs = new String[asize+1]; 249 System.arraycopy(args, 0, newargs,0 , asize); 250 newargs[asize] = "New17.java"; 251 pass(newargs); |