View | Details | Raw Unified | Return to bug 104536
Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-31 / +50 lines)
Lines 974-979 Link Here
974
	public long[] times;
974
	public long[] times;
975
	public int timesCounter;
975
	public int timesCounter;
976
	public boolean verbose = false;
976
	public boolean verbose = false;
977
	
978
	private File javaHomeCache;
979
	private boolean javaHomeChecked;
980
	private boolean didSpecifyTarget;
981
	private boolean didSpecifySource;
982
	private boolean didSpecifyCompliance;	
977
983
978
	public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished) {
984
	public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished) {
979
		this(outWriter, errWriter, systemExitWhenFinished, null);
985
		this(outWriter, errWriter, systemExitWhenFinished, null);
Lines 988-994 Link Here
988
				Object key = iter.next();
994
				Object key = iter.next();
989
				this.options.put(key, customDefaultOptions.get(key));
995
				this.options.put(key, customDefaultOptions.get(key));
990
			}
996
			}
997
			if (customDefaultOptions.get(CompilerOptions.OPTION_Source) != null) {
998
				this.didSpecifySource = true;
999
			} else {
1000
				this.didSpecifySource = false;
1001
			}
1002
			if (customDefaultOptions.get(CompilerOptions.OPTION_TargetPlatform) != null) {
1003
				this.didSpecifyTarget = true;
1004
			} else {
1005
				this.didSpecifyTarget = false;
1006
			}
1007
		} else {
1008
			this.didSpecifySource = false;
1009
			this.didSpecifyTarget = false;
991
		}
1010
		}
1011
		/*
1012
		 * We don't set the compliance even if it could be set in the custom options to allow the user to specify
1013
		 * a compliance in the compilerarg.
1014
		 */ 
1015
		this.didSpecifyCompliance = false;		
992
	}
1016
	}
993
	
1017
	
994
	/*
1018
	/*
Lines 1220-1229 Link Here
1220
		boolean printUsageRequired = false;
1244
		boolean printUsageRequired = false;
1221
		boolean printVersionRequired = false;
1245
		boolean printVersionRequired = false;
1222
		
1246
		
1223
		boolean didSpecifySource = false;
1224
		boolean didSpecifyCompliance = false;
1225
		boolean didSpecifyDefaultEncoding = false;
1247
		boolean didSpecifyDefaultEncoding = false;
1226
		boolean didSpecifyTarget = false;
1227
		boolean didSpecifyDeprecation = false;
1248
		boolean didSpecifyDeprecation = false;
1228
		boolean didSpecifyWarnings = false;
1249
		boolean didSpecifyWarnings = false;
1229
		boolean useEnableJavadoc = false;
1250
		boolean useEnableJavadoc = false;
Lines 1363-1393 Link Here
1363
				continue;
1384
				continue;
1364
			}
1385
			}
1365
			if (currentArg.equals("-1.3")) { //$NON-NLS-1$
1386
			if (currentArg.equals("-1.3")) { //$NON-NLS-1$
1366
				if (didSpecifyCompliance) {
1387
				if (this.didSpecifyCompliance) {
1367
					throw new InvalidInputException(
1388
					throw new InvalidInputException(
1368
						Main.bind("configure.duplicateCompliance", currentArg));//$NON-NLS-1$
1389
						Main.bind("configure.duplicateCompliance", currentArg));//$NON-NLS-1$
1369
				}
1390
				}
1370
				didSpecifyCompliance = true;
1391
				this.didSpecifyCompliance = true;
1371
				this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3);
1392
				this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3);
1372
				mode = Default;
1393
				mode = Default;
1373
				continue;
1394
				continue;
1374
			}
1395
			}
1375
			if (currentArg.equals("-1.4")) { //$NON-NLS-1$
1396
			if (currentArg.equals("-1.4")) { //$NON-NLS-1$
1376
				if (didSpecifyCompliance) {
1397
				if (this.didSpecifyCompliance) {
1377
					throw new InvalidInputException(
1398
					throw new InvalidInputException(
1378
						Main.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$
1399
						Main.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$
1379
				}
1400
				}
1380
				didSpecifyCompliance = true;
1401
				this.didSpecifyCompliance = true;
1381
				this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
1402
				this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
1382
				mode = Default;
1403
				mode = Default;
1383
				continue;
1404
				continue;
1384
			}
1405
			}
1385
			if (currentArg.equals("-1.5") || currentArg.equals("-5") || currentArg.equals("-5.0")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1406
			if (currentArg.equals("-1.5") || currentArg.equals("-5") || currentArg.equals("-5.0")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1386
				if (didSpecifyCompliance) {
1407
				if (this.didSpecifyCompliance) {
1387
					throw new InvalidInputException(
1408
					throw new InvalidInputException(
1388
						Main.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$
1409
						Main.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$
1389
				}
1410
				}
1390
				didSpecifyCompliance = true;
1411
				this.didSpecifyCompliance = true;
1391
				this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
1412
				this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
1392
				mode = Default;
1413
				mode = Default;
1393
				continue;
1414
				continue;
Lines 1927-1937 Link Here
1927
			}
1948
			}
1928
1949
1929
			if (mode == TargetSetting) {
1950
			if (mode == TargetSetting) {
1930
				if (didSpecifyTarget) {
1951
				if (this.didSpecifyTarget) {
1931
					throw new InvalidInputException(
1952
					throw new InvalidInputException(
1932
						Main.bind("configure.duplicateTarget", currentArg));//$NON-NLS-1$
1953
						Main.bind("configure.duplicateTarget", currentArg));//$NON-NLS-1$
1933
				}				
1954
				}				
1934
				didSpecifyTarget = true;
1955
				this.didSpecifyTarget = true;
1935
				if (currentArg.equals("1.1")) { //$NON-NLS-1$
1956
				if (currentArg.equals("1.1")) { //$NON-NLS-1$
1936
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
1957
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
1937
				} else if (currentArg.equals("1.2")) { //$NON-NLS-1$
1958
				} else if (currentArg.equals("1.2")) { //$NON-NLS-1$
Lines 1940-1952 Link Here
1940
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3);
1961
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3);
1941
				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
1962
				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
1942
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
1963
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
1943
					if (didSpecifyCompliance && CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) < ClassFileConstants.JDK1_4) {
1964
					if (this.didSpecifyCompliance && CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) < ClassFileConstants.JDK1_4) {
1944
						throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForTarget", (String)this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_4)); //$NON-NLS-1$
1965
						throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForTarget", (String)this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_4)); //$NON-NLS-1$
1945
					}
1966
					}
1946
					this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
1967
					this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
1947
				} else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
1968
				} else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
1948
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1969
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1949
					if (didSpecifyCompliance && CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) < ClassFileConstants.JDK1_5) {
1970
					if (this.didSpecifyCompliance && CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) < ClassFileConstants.JDK1_5) {
1950
						throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForTarget", (String)this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_5)); //$NON-NLS-1$
1971
						throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForTarget", (String)this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_5)); //$NON-NLS-1$
1951
					}
1972
					}
1952
					this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
1973
					this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
Lines 1987-1997 Link Here
1987
				continue;
2008
				continue;
1988
			}
2009
			}
1989
			if (mode == InsideSource) {
2010
			if (mode == InsideSource) {
1990
				if (didSpecifySource) {
2011
				if (this.didSpecifySource) {
1991
					throw new InvalidInputException(
2012
					throw new InvalidInputException(
1992
						Main.bind("configure.duplicateSource", currentArg));//$NON-NLS-1$
2013
						Main.bind("configure.duplicateSource", currentArg));//$NON-NLS-1$
1993
				}				
2014
				}				
1994
				didSpecifySource = true;
2015
				this.didSpecifySource = true;
1995
				if (currentArg.equals("1.3")) { //$NON-NLS-1$
2016
				if (currentArg.equals("1.3")) { //$NON-NLS-1$
1996
					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2017
					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
1997
				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
2018
				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
Lines 2319-2350 Link Here
2319
			this.destinationPath = null;
2340
			this.destinationPath = null;
2320
		}
2341
		}
2321
		
2342
		
2322
		if (didSpecifyCompliance) {
2343
		if (this.didSpecifyCompliance) {
2323
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
2344
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
2324
			if (CompilerOptions.VERSION_1_3.equals(version)) {
2345
			if (CompilerOptions.VERSION_1_3.equals(version)) {
2325
				if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2346
				if (!this.didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2326
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
2347
				if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
2327
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
2348
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
2328
				if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2349
				if (!this.didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2329
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
2350
				if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
2330
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2351
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2331
				if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
2352
				if (!this.didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
2332
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
2353
				if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
2333
			}
2354
			}
2334
		}
2355
		}
2335
		if (didSpecifySource) {
2356
		if (this.didSpecifySource) {
2336
			Object version = this.options.get(CompilerOptions.OPTION_Source);
2357
			Object version = this.options.get(CompilerOptions.OPTION_Source);
2337
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
2358
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
2338
				if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
2359
				if (!this.didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
2339
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
2360
				if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
2340
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2361
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2341
				if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
2362
				if (!this.didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
2342
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
2363
				if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
2343
			}
2364
			}
2344
		}
2365
		}
2345
2366
2346
		// check and set compliance/source/target compatibilities
2367
		// check and set compliance/source/target compatibilities
2347
		if (didSpecifyTarget) {
2368
		if (this.didSpecifyTarget) {
2348
			// target must be 1.5 if source is 1.5
2369
			// target must be 1.5 if source is 1.5
2349
			if (CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Source)) >= ClassFileConstants.JDK1_5
2370
			if (CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Source)) >= ClassFileConstants.JDK1_5
2350
					&& CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_TargetPlatform)) < ClassFileConstants.JDK1_5){ 
2371
					&& CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_TargetPlatform)) < ClassFileConstants.JDK1_5){ 
Lines 2372-2378 Link Here
2372
				throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForSource", (String)this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_4)); //$NON-NLS-1$
2393
				throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForSource", (String)this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_4)); //$NON-NLS-1$
2373
		}
2394
		}
2374
		// set default target according to compliance & sourcelevel.
2395
		// set default target according to compliance & sourcelevel.
2375
		if (!didSpecifyTarget) {
2396
		if (!this.didSpecifyTarget) {
2376
			if (this.options.get(CompilerOptions.OPTION_Compliance).equals(CompilerOptions.VERSION_1_3)) {
2397
			if (this.options.get(CompilerOptions.OPTION_Compliance).equals(CompilerOptions.VERSION_1_3)) {
2377
				this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
2398
				this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
2378
			} else if (this.options.get(CompilerOptions.OPTION_Compliance).equals(CompilerOptions.VERSION_1_4)) {
2399
			} else if (this.options.get(CompilerOptions.OPTION_Compliance).equals(CompilerOptions.VERSION_1_4)) {
Lines 2465-2472 Link Here
2465
		}
2486
		}
2466
	}
2487
	}
2467
2488
2468
	private File javaHomeCache;
2469
	private boolean javaHomeChecked;
2470
	private File getJavaHome() {
2489
	private File getJavaHome() {
2471
		if (!javaHomeChecked) {
2490
		if (!javaHomeChecked) {
2472
			javaHomeChecked = true;
2491
			javaHomeChecked = true;

Return to bug 104536