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

(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-321 / +386 lines)
Lines 1328-1333 Link Here
1328
}
1328
}
1329
1329
1330
/*
1330
/*
1331
Handle a single warning token.
1332
*/
1333
protected void handleWarningToken(String token, boolean isEnabling,
1334
		boolean useEnableJavadoc) throws InvalidInputException {
1335
	if (token.equals("constructorName")) { //$NON-NLS-1$
1336
		this.options.put(
1337
			CompilerOptions.OPTION_ReportMethodWithConstructorName,
1338
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1339
	} else if (token.equals("pkgDefaultMethod") || token.equals("packageDefaultMethod")/*backward compatible*/ ) { //$NON-NLS-1$ //$NON-NLS-2$
1340
		this.options.put(
1341
			CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod,
1342
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1343
	} else if (token.equals("maskedCatchBlock") || token.equals("maskedCatchBlocks")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1344
		this.options.put(
1345
			CompilerOptions.OPTION_ReportHiddenCatchBlock,
1346
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1347
	} else if (token.equals("deprecation")) { //$NON-NLS-1$
1348
		this.options.put(
1349
			CompilerOptions.OPTION_ReportDeprecation, 
1350
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1351
		this.options.put(
1352
			CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, 
1353
			CompilerOptions.DISABLED);
1354
		this.options.put(
1355
			CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, 
1356
			CompilerOptions.DISABLED);						
1357
	} else if (token.equals("allDeprecation")) { //$NON-NLS-1$
1358
		this.options.put(
1359
			CompilerOptions.OPTION_ReportDeprecation, 
1360
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1361
		this.options.put(
1362
			CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, 
1363
			isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1364
		this.options.put(
1365
			CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, 
1366
			isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1367
	} else if (token.equals("unusedLocal") || token.equals("unusedLocals")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1368
		this.options.put(
1369
			CompilerOptions.OPTION_ReportUnusedLocal, 
1370
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1371
	} else if (token.equals("unusedArgument") || token.equals("unusedArguments")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1372
		this.options.put(
1373
			CompilerOptions.OPTION_ReportUnusedParameter,
1374
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1375
	} else if (token.equals("unusedImport") || token.equals("unusedImports")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1376
		this.options.put(
1377
			CompilerOptions.OPTION_ReportUnusedImport,
1378
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1379
	} else if (token.equals("unusedPrivate")) { //$NON-NLS-1$
1380
		this.options.put(
1381
			CompilerOptions.OPTION_ReportUnusedPrivateMember,
1382
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1383
	} else if (token.equals("unusedLabel")) { //$NON-NLS-1$
1384
		this.options.put(
1385
			CompilerOptions.OPTION_ReportUnusedLabel,
1386
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1387
	} else if (token.equals("localHiding")) { //$NON-NLS-1$
1388
		this.options.put(
1389
			CompilerOptions.OPTION_ReportLocalVariableHiding,
1390
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1391
	} else if (token.equals("fieldHiding")) { //$NON-NLS-1$
1392
		this.options.put(
1393
			CompilerOptions.OPTION_ReportFieldHiding,
1394
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1395
	} else if (token.equals("specialParamHiding")) { //$NON-NLS-1$
1396
		this.options.put(
1397
			CompilerOptions.OPTION_ReportSpecialParameterHidingField,
1398
			isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1399
	} else if (token.equals("conditionAssign")) { //$NON-NLS-1$
1400
		this.options.put(
1401
			CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment,
1402
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1403
		} else if (token.equals("syntheticAccess") //$NON-NLS-1$
1404
				|| token.equals("synthetic-access")) { //$NON-NLS-1$
1405
		this.options.put(
1406
			CompilerOptions.OPTION_ReportSyntheticAccessEmulation,
1407
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1408
	} else if (token.equals("nls")) { //$NON-NLS-1$
1409
		this.options.put(
1410
			CompilerOptions.OPTION_ReportNonExternalizedStringLiteral,
1411
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1412
	} else if (token.equals("staticReceiver")) { //$NON-NLS-1$
1413
		this.options.put(
1414
			CompilerOptions.OPTION_ReportNonStaticAccessToStatic,
1415
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1416
	} else if (token.equals("indirectStatic")) { //$NON-NLS-1$
1417
		this.options.put(
1418
			CompilerOptions.OPTION_ReportIndirectStaticAccess,
1419
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1420
	} else if (token.equals("noEffectAssign")) { //$NON-NLS-1$
1421
		this.options.put(
1422
			CompilerOptions.OPTION_ReportNoEffectAssignment,
1423
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1424
	} else if (token.equals("intfNonInherited") || token.equals("interfaceNonInherited")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1425
		this.options.put(
1426
			CompilerOptions.OPTION_ReportIncompatibleNonInheritedInterfaceMethod,
1427
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1428
	} else if (token.equals("charConcat") || token.equals("noImplicitStringConversion")/*backward compatible*/) {//$NON-NLS-1$ //$NON-NLS-2$
1429
		this.options.put(
1430
			CompilerOptions.OPTION_ReportNoImplicitStringConversion,
1431
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1432
	} else if (token.equals("semicolon")) {//$NON-NLS-1$ 
1433
		this.options.put(
1434
			CompilerOptions.OPTION_ReportEmptyStatement,
1435
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1436
	} else if (token.equals("serial")) {//$NON-NLS-1$ 
1437
		this.options.put(
1438
			CompilerOptions.OPTION_ReportMissingSerialVersion,
1439
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1440
	} else if (token.equals("emptyBlock")) {//$NON-NLS-1$ 
1441
		this.options.put(
1442
			CompilerOptions.OPTION_ReportUndocumentedEmptyBlock,
1443
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1444
	} else if (token.equals("uselessTypeCheck")) {//$NON-NLS-1$ 
1445
		this.options.put(
1446
			CompilerOptions.OPTION_ReportUnnecessaryTypeCheck,
1447
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1448
	} else if (token.equals("unchecked") || token.equals("unsafe")) {//$NON-NLS-1$ //$NON-NLS-2$ 
1449
		this.options.put(
1450
			CompilerOptions.OPTION_ReportUncheckedTypeOperation,
1451
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1452
	} else if (token.equals("raw")) {//$NON-NLS-1$
1453
		this.options.put(
1454
			CompilerOptions.OPTION_ReportRawTypeReference,
1455
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1456
	} else if (token.equals("finalBound")) {//$NON-NLS-1$ 
1457
		this.options.put(
1458
			CompilerOptions.OPTION_ReportFinalParameterBound,
1459
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1460
	} else if (token.equals("suppress")) {//$NON-NLS-1$ 
1461
		this.options.put(
1462
			CompilerOptions.OPTION_SuppressWarnings,
1463
			isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1464
	} else if (token.equals("warningToken")) {//$NON-NLS-1$ 
1465
		this.options.put(
1466
			CompilerOptions.OPTION_ReportUnhandledWarningToken,
1467
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1468
	} else if (token.equals("unnecessaryElse")) {//$NON-NLS-1$ 
1469
		this.options.put(
1470
			CompilerOptions.OPTION_ReportUnnecessaryElse,
1471
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1472
	} else if (token.equals("javadoc")) {//$NON-NLS-1$ 
1473
		if (!useEnableJavadoc) {
1474
			this.options.put(
1475
				CompilerOptions.OPTION_DocCommentSupport,
1476
				isEnabling ? CompilerOptions.ENABLED: CompilerOptions.DISABLED);
1477
		}
1478
		// if disabling then it's not necessary to set other javadoc options
1479
		if (isEnabling) {
1480
			this.options.put(
1481
				CompilerOptions.OPTION_ReportInvalidJavadoc,
1482
				CompilerOptions.WARNING);
1483
			this.options.put(
1484
				CompilerOptions.OPTION_ReportInvalidJavadocTags,
1485
				CompilerOptions.ENABLED);
1486
			this.options.put(
1487
				CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef,
1488
				CompilerOptions.DISABLED);
1489
			this.options.put(
1490
				CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef,
1491
				CompilerOptions.DISABLED);
1492
			this.options.put(
1493
				CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility,
1494
				CompilerOptions.PRIVATE);
1495
			this.options.put(
1496
				CompilerOptions.OPTION_ReportMissingJavadocTags,
1497
				CompilerOptions.WARNING);
1498
			this.options.put(
1499
				CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility,
1500
				CompilerOptions.PRIVATE);
1501
		}
1502
	} else if (token.equals("allJavadoc")) { //$NON-NLS-1$
1503
		if (!useEnableJavadoc) {
1504
			this.options.put(
1505
				CompilerOptions.OPTION_DocCommentSupport,
1506
				isEnabling ? CompilerOptions.ENABLED: CompilerOptions.DISABLED);
1507
		}
1508
		// if disabling then it's not necessary to set other javadoc options
1509
		if (isEnabling) {
1510
			this.options.put(
1511
			CompilerOptions.OPTION_ReportInvalidJavadoc,
1512
			CompilerOptions.WARNING);
1513
			this.options.put(
1514
				CompilerOptions.OPTION_ReportInvalidJavadocTags,
1515
				CompilerOptions.ENABLED);
1516
			this.options.put(
1517
				CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility,
1518
				CompilerOptions.PRIVATE);
1519
			this.options.put(
1520
				CompilerOptions.OPTION_ReportMissingJavadocTags,
1521
				CompilerOptions.WARNING);
1522
			this.options.put(
1523
				CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility,
1524
				CompilerOptions.PRIVATE);
1525
			this.options.put(
1526
				CompilerOptions.OPTION_ReportMissingJavadocComments,
1527
				CompilerOptions.WARNING);
1528
		}
1529
	} else if (token.startsWith("tasks")) { //$NON-NLS-1$
1530
		String taskTags = ""; //$NON-NLS-1$
1531
		int start = token.indexOf('(');
1532
		int end = token.indexOf(')');
1533
		if (start >= 0 && end >= 0 && start < end){
1534
			taskTags = token.substring(start+1, end).trim();
1535
			taskTags = taskTags.replace('|',',');
1536
		}
1537
		if (taskTags.length() == 0){
1538
			throw new InvalidInputException(this.bind("configure.invalidTaskTag", token)); //$NON-NLS-1$
1539
		}
1540
		this.options.put(
1541
			CompilerOptions.OPTION_TaskTags,
1542
			isEnabling ? taskTags : "");  //$NON-NLS-1$
1543
	} else if (token.equals("assertIdentifier")) { //$NON-NLS-1$
1544
		this.options.put(
1545
			CompilerOptions.OPTION_ReportAssertIdentifier,
1546
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1547
	} else if (token.equals("enumIdentifier")) { //$NON-NLS-1$
1548
		this.options.put(
1549
				CompilerOptions.OPTION_ReportEnumIdentifier,
1550
				isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1551
	} else if (token.equals("finally")) { //$NON-NLS-1$
1552
		this.options.put(
1553
			CompilerOptions.OPTION_ReportFinallyBlockNotCompletingNormally,
1554
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1555
	} else if (token.equals("unusedThrown")) { //$NON-NLS-1$
1556
		this.options.put(
1557
			CompilerOptions.OPTION_ReportUnusedDeclaredThrownException,
1558
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1559
	} else if (token.equals("unqualifiedField") //$NON-NLS-1$
1560
			|| token.equals("unqualified-field-access")) { //$NON-NLS-1$
1561
		this.options.put(
1562
			CompilerOptions.OPTION_ReportUnqualifiedFieldAccess,
1563
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1564
	} else if (token.equals("typeHiding")) { //$NON-NLS-1$
1565
		this.options.put(
1566
			CompilerOptions.OPTION_ReportTypeParameterHiding,
1567
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1568
	} else if (token.equals("varargsCast")) { //$NON-NLS-1$
1569
		this.options.put(
1570
			CompilerOptions.OPTION_ReportVarargsArgumentNeedCast,
1571
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1572
	} else if (token.equals("null")) { //$NON-NLS-1$
1573
		this.options.put(
1574
			CompilerOptions.OPTION_ReportNullReference,
1575
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1576
	} else if (token.equals("boxing")) { //$NON-NLS-1$
1577
		this.options.put(
1578
			CompilerOptions.OPTION_ReportAutoboxing,
1579
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1580
	} else if (token.equals("over-ann")) { //$NON-NLS-1$
1581
		this.options.put(
1582
			CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
1583
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1584
	} else if (token.equals("dep-ann")) { //$NON-NLS-1$
1585
		this.options.put(
1586
			CompilerOptions.OPTION_ReportMissingDeprecatedAnnotation,
1587
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1588
	} else if (token.equals("intfAnnotation")) { //$NON-NLS-1$
1589
		this.options.put(
1590
			CompilerOptions.OPTION_ReportAnnotationSuperInterface,
1591
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1592
	} else if (token.equals("enumSwitch") //$NON-NLS-1$
1593
			|| token.equals("incomplete-switch")) { //$NON-NLS-1$
1594
		this.options.put(
1595
			CompilerOptions.OPTION_ReportIncompleteEnumSwitch,
1596
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1597
	} else if (token.equals("hiding")) { //$NON-NLS-1$
1598
		this.options.put(
1599
			CompilerOptions.OPTION_ReportHiddenCatchBlock,
1600
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1601
		this.options.put(
1602
			CompilerOptions.OPTION_ReportLocalVariableHiding,
1603
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1604
		this.options.put(
1605
			CompilerOptions.OPTION_ReportFieldHiding,
1606
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1607
		this.options.put(
1608
			CompilerOptions.OPTION_ReportTypeParameterHiding,
1609
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1610
	} else if (token.equals("static-access")) { //$NON-NLS-1$
1611
		this.options.put(
1612
			CompilerOptions.OPTION_ReportNonStaticAccessToStatic,
1613
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1614
		this.options.put(
1615
			CompilerOptions.OPTION_ReportIndirectStaticAccess,
1616
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1617
	} else if (token.equals("unused")) { //$NON-NLS-1$
1618
		this.options.put(
1619
			CompilerOptions.OPTION_ReportUnusedLocal, 
1620
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1621
		this.options.put(
1622
			CompilerOptions.OPTION_ReportUnusedParameter,
1623
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1624
		this.options.put(
1625
			CompilerOptions.OPTION_ReportUnusedImport,
1626
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1627
		this.options.put(
1628
			CompilerOptions.OPTION_ReportUnusedPrivateMember,
1629
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1630
		this.options.put(
1631
			CompilerOptions.OPTION_ReportUnusedDeclaredThrownException,
1632
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1633
		this.options.put(
1634
				CompilerOptions.OPTION_ReportUnusedLabel,
1635
				isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1636
	} else if (token.equals("paramAssign")) { //$NON-NLS-1$
1637
		this.options.put(
1638
			CompilerOptions.OPTION_ReportParameterAssignment,
1639
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1640
	} else if (token.equals("discouraged")) { //$NON-NLS-1$
1641
		this.options.put(
1642
			CompilerOptions.OPTION_ReportDiscouragedReference,
1643
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1644
	} else if (token.equals("forbidden")) { //$NON-NLS-1$
1645
		this.options.put(
1646
			CompilerOptions.OPTION_ReportForbiddenReference,
1647
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1648
	} else if (token.equals("fallthrough")) { //$NON-NLS-1$
1649
		this.options.put(
1650
			CompilerOptions.OPTION_ReportFallthroughCase,
1651
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1652
	} else {
1653
		throw new InvalidInputException(this.bind("configure.invalidWarning", token)); //$NON-NLS-1$
1654
	}
1655
}
1656
1657
/*
1658
Handle extdirs processing
1659
*/
1660
protected ArrayList handleExtdirs(ArrayList extdirsClasspaths) {
1661
 	final File javaHome = getJavaHome();
1662
1663
	/*
1664
	 * Feed endorsedDirClasspath according to:
1665
	 * - -extdirs first if present;
1666
	 * - else java.ext.dirs if defined;
1667
	 * - else default extensions directory for the platform.
1668
	 */
1669
	if (extdirsClasspaths == null) {
1670
		extdirsClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
1671
		String extdirsStr = System.getProperty("java.ext.dirs"); //$NON-NLS-1$
1672
		if (extdirsStr == null) {
1673
			extdirsClasspaths.add(javaHome.getAbsolutePath() + "/lib/ext"); //$NON-NLS-1$
1674
		} else {
1675
			StringTokenizer tokenizer = new StringTokenizer(extdirsStr, File.pathSeparator);
1676
			while (tokenizer.hasMoreTokens()) 
1677
				extdirsClasspaths.add(tokenizer.nextToken());
1678
		}
1679
	}
1680
	
1681
	/*
1682
	 * Feed extdirsClasspath with the entries found into the directories listed by
1683
	 * extdirsNames.
1684
	 */
1685
	if (extdirsClasspaths.size() != 0) {
1686
		File[] directoriesToCheck = new File[extdirsClasspaths.size()];
1687
		for (int i = 0; i < directoriesToCheck.length; i++) 
1688
			directoriesToCheck[i] = new File((String) extdirsClasspaths.get(i));
1689
		extdirsClasspaths.clear();
1690
		File[][] extdirsJars = getLibrariesFiles(directoriesToCheck);
1691
		if (extdirsJars != null) {
1692
			for (int i = 0, max = extdirsJars.length; i < max; i++) {
1693
				File[] current = extdirsJars[i];
1694
				if (current != null) {
1695
					for (int j = 0, max2 = current.length; j < max2; j++) {
1696
						FileSystem.Classpath classpath = 
1697
							FileSystem.getClasspath(
1698
									current[j].getAbsolutePath(),
1699
									null, null); 
1700
						if (classpath != null) {
1701
							extdirsClasspaths.add(classpath);
1702
						}
1703
					}
1704
				} else if (directoriesToCheck[i].isFile()) {
1705
					this.logger.logIncorrectExtDirsEntry(directoriesToCheck[i].getAbsolutePath());
1706
				}
1707
			}
1708
		}
1709
	}
1710
	
1711
	return extdirsClasspaths;
1712
}
1713
1714
/*
1331
Decode the command line arguments 
1715
Decode the command line arguments 
1332
 */
1716
 */
1333
public void configure(String[] argv) throws InvalidInputException {
1717
public void configure(String[] argv) throws InvalidInputException {
Lines 1811-2136 Link Here
1811
					while (tokenizer.hasMoreTokens()) {
2195
					while (tokenizer.hasMoreTokens()) {
1812
						String token = tokenizer.nextToken();
2196
						String token = tokenizer.nextToken();
1813
						tokenCounter++;
2197
						tokenCounter++;
1814
						if (token.equals("constructorName")) { //$NON-NLS-1$
2198
						handleWarningToken(token, isEnabling, useEnableJavadoc);
1815
							this.options.put(
1816
								CompilerOptions.OPTION_ReportMethodWithConstructorName,
1817
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1818
						} else if (token.equals("pkgDefaultMethod") || token.equals("packageDefaultMethod")/*backward compatible*/ ) { //$NON-NLS-1$ //$NON-NLS-2$
1819
							this.options.put(
1820
								CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod,
1821
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1822
						} else if (token.equals("maskedCatchBlock") || token.equals("maskedCatchBlocks")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1823
							this.options.put(
1824
								CompilerOptions.OPTION_ReportHiddenCatchBlock,
1825
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1826
						} else if (token.equals("deprecation")) { //$NON-NLS-1$
1827
							this.options.put(
1828
								CompilerOptions.OPTION_ReportDeprecation, 
1829
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1830
							this.options.put(
1831
								CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, 
1832
								CompilerOptions.DISABLED);
1833
							this.options.put(
1834
								CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, 
1835
								CompilerOptions.DISABLED);						
1836
						} else if (token.equals("allDeprecation")) { //$NON-NLS-1$
1837
							this.options.put(
1838
								CompilerOptions.OPTION_ReportDeprecation, 
1839
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1840
							this.options.put(
1841
								CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, 
1842
								isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1843
							this.options.put(
1844
								CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, 
1845
								isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1846
						} else if (token.equals("unusedLocal") || token.equals("unusedLocals")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1847
							this.options.put(
1848
								CompilerOptions.OPTION_ReportUnusedLocal, 
1849
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1850
						} else if (token.equals("unusedArgument") || token.equals("unusedArguments")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1851
							this.options.put(
1852
								CompilerOptions.OPTION_ReportUnusedParameter,
1853
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1854
						} else if (token.equals("unusedImport") || token.equals("unusedImports")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1855
							this.options.put(
1856
								CompilerOptions.OPTION_ReportUnusedImport,
1857
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1858
						} else if (token.equals("unusedPrivate")) { //$NON-NLS-1$
1859
							this.options.put(
1860
								CompilerOptions.OPTION_ReportUnusedPrivateMember,
1861
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1862
						} else if (token.equals("unusedLabel")) { //$NON-NLS-1$
1863
							this.options.put(
1864
								CompilerOptions.OPTION_ReportUnusedLabel,
1865
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1866
						} else if (token.equals("localHiding")) { //$NON-NLS-1$
1867
							this.options.put(
1868
								CompilerOptions.OPTION_ReportLocalVariableHiding,
1869
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1870
						} else if (token.equals("fieldHiding")) { //$NON-NLS-1$
1871
							this.options.put(
1872
								CompilerOptions.OPTION_ReportFieldHiding,
1873
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1874
						} else if (token.equals("specialParamHiding")) { //$NON-NLS-1$
1875
							this.options.put(
1876
								CompilerOptions.OPTION_ReportSpecialParameterHidingField,
1877
								isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1878
						} else if (token.equals("conditionAssign")) { //$NON-NLS-1$
1879
							this.options.put(
1880
								CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment,
1881
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1882
	   					} else if (token.equals("syntheticAccess") //$NON-NLS-1$
1883
	   							|| token.equals("synthetic-access")) { //$NON-NLS-1$
1884
							this.options.put(
1885
								CompilerOptions.OPTION_ReportSyntheticAccessEmulation,
1886
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1887
						} else if (token.equals("nls")) { //$NON-NLS-1$
1888
							this.options.put(
1889
								CompilerOptions.OPTION_ReportNonExternalizedStringLiteral,
1890
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1891
						} else if (token.equals("staticReceiver")) { //$NON-NLS-1$
1892
							this.options.put(
1893
								CompilerOptions.OPTION_ReportNonStaticAccessToStatic,
1894
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1895
						} else if (token.equals("indirectStatic")) { //$NON-NLS-1$
1896
							this.options.put(
1897
								CompilerOptions.OPTION_ReportIndirectStaticAccess,
1898
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1899
						} else if (token.equals("noEffectAssign")) { //$NON-NLS-1$
1900
							this.options.put(
1901
								CompilerOptions.OPTION_ReportNoEffectAssignment,
1902
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1903
						} else if (token.equals("intfNonInherited") || token.equals("interfaceNonInherited")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$
1904
							this.options.put(
1905
								CompilerOptions.OPTION_ReportIncompatibleNonInheritedInterfaceMethod,
1906
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1907
						} else if (token.equals("charConcat") || token.equals("noImplicitStringConversion")/*backward compatible*/) {//$NON-NLS-1$ //$NON-NLS-2$
1908
							this.options.put(
1909
								CompilerOptions.OPTION_ReportNoImplicitStringConversion,
1910
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1911
						} else if (token.equals("semicolon")) {//$NON-NLS-1$ 
1912
							this.options.put(
1913
								CompilerOptions.OPTION_ReportEmptyStatement,
1914
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1915
						} else if (token.equals("serial")) {//$NON-NLS-1$ 
1916
							this.options.put(
1917
								CompilerOptions.OPTION_ReportMissingSerialVersion,
1918
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1919
						} else if (token.equals("emptyBlock")) {//$NON-NLS-1$ 
1920
							this.options.put(
1921
								CompilerOptions.OPTION_ReportUndocumentedEmptyBlock,
1922
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1923
						} else if (token.equals("uselessTypeCheck")) {//$NON-NLS-1$ 
1924
							this.options.put(
1925
								CompilerOptions.OPTION_ReportUnnecessaryTypeCheck,
1926
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1927
						} else if (token.equals("unchecked") || token.equals("unsafe")) {//$NON-NLS-1$ //$NON-NLS-2$ 
1928
							this.options.put(
1929
								CompilerOptions.OPTION_ReportUncheckedTypeOperation,
1930
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1931
						} else if (token.equals("raw")) {//$NON-NLS-1$
1932
							this.options.put(
1933
								CompilerOptions.OPTION_ReportRawTypeReference,
1934
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
1935
						} else if (token.equals("finalBound")) {//$NON-NLS-1$ 
1936
							this.options.put(
1937
								CompilerOptions.OPTION_ReportFinalParameterBound,
1938
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1939
						} else if (token.equals("suppress")) {//$NON-NLS-1$ 
1940
							this.options.put(
1941
								CompilerOptions.OPTION_SuppressWarnings,
1942
								isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
1943
						} else if (token.equals("warningToken")) {//$NON-NLS-1$ 
1944
							this.options.put(
1945
								CompilerOptions.OPTION_ReportUnhandledWarningToken,
1946
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1947
						} else if (token.equals("unnecessaryElse")) {//$NON-NLS-1$ 
1948
							this.options.put(
1949
								CompilerOptions.OPTION_ReportUnnecessaryElse,
1950
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1951
						} else if (token.equals("javadoc")) {//$NON-NLS-1$ 
1952
							if (!useEnableJavadoc) {
1953
								this.options.put(
1954
									CompilerOptions.OPTION_DocCommentSupport,
1955
									isEnabling ? CompilerOptions.ENABLED: CompilerOptions.DISABLED);
1956
							}
1957
							// if disabling then it's not necessary to set other javadoc options
1958
							if (isEnabling) {
1959
								this.options.put(
1960
									CompilerOptions.OPTION_ReportInvalidJavadoc,
1961
									CompilerOptions.WARNING);
1962
								this.options.put(
1963
									CompilerOptions.OPTION_ReportInvalidJavadocTags,
1964
									CompilerOptions.ENABLED);
1965
								this.options.put(
1966
									CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef,
1967
									CompilerOptions.DISABLED);
1968
								this.options.put(
1969
									CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef,
1970
									CompilerOptions.DISABLED);
1971
								this.options.put(
1972
									CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility,
1973
									CompilerOptions.PRIVATE);
1974
								this.options.put(
1975
									CompilerOptions.OPTION_ReportMissingJavadocTags,
1976
									CompilerOptions.WARNING);
1977
								this.options.put(
1978
									CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility,
1979
									CompilerOptions.PRIVATE);
1980
							}
1981
						} else if (token.equals("allJavadoc")) { //$NON-NLS-1$
1982
							if (!useEnableJavadoc) {
1983
								this.options.put(
1984
									CompilerOptions.OPTION_DocCommentSupport,
1985
									isEnabling ? CompilerOptions.ENABLED: CompilerOptions.DISABLED);
1986
							}
1987
							// if disabling then it's not necessary to set other javadoc options
1988
							if (isEnabling) {
1989
								this.options.put(
1990
								CompilerOptions.OPTION_ReportInvalidJavadoc,
1991
								CompilerOptions.WARNING);
1992
								this.options.put(
1993
									CompilerOptions.OPTION_ReportInvalidJavadocTags,
1994
									CompilerOptions.ENABLED);
1995
								this.options.put(
1996
									CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility,
1997
									CompilerOptions.PRIVATE);
1998
								this.options.put(
1999
									CompilerOptions.OPTION_ReportMissingJavadocTags,
2000
									CompilerOptions.WARNING);
2001
								this.options.put(
2002
									CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility,
2003
									CompilerOptions.PRIVATE);
2004
								this.options.put(
2005
									CompilerOptions.OPTION_ReportMissingJavadocComments,
2006
									CompilerOptions.WARNING);
2007
							}
2008
						} else if (token.startsWith("tasks")) { //$NON-NLS-1$
2009
							String taskTags = ""; //$NON-NLS-1$
2010
							int start = token.indexOf('(');
2011
							int end = token.indexOf(')');
2012
							if (start >= 0 && end >= 0 && start < end){
2013
								taskTags = token.substring(start+1, end).trim();
2014
								taskTags = taskTags.replace('|',',');
2015
							}
2016
							if (taskTags.length() == 0){
2017
								throw new InvalidInputException(this.bind("configure.invalidTaskTag", token)); //$NON-NLS-1$
2018
							}
2019
							this.options.put(
2020
								CompilerOptions.OPTION_TaskTags,
2021
								isEnabling ? taskTags : "");  //$NON-NLS-1$
2022
						} else if (token.equals("assertIdentifier")) { //$NON-NLS-1$
2023
							this.options.put(
2024
								CompilerOptions.OPTION_ReportAssertIdentifier,
2025
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2026
						} else if (token.equals("enumIdentifier")) { //$NON-NLS-1$
2027
							this.options.put(
2028
									CompilerOptions.OPTION_ReportEnumIdentifier,
2029
									isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2030
						} else if (token.equals("finally")) { //$NON-NLS-1$
2031
							this.options.put(
2032
								CompilerOptions.OPTION_ReportFinallyBlockNotCompletingNormally,
2033
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2034
						} else if (token.equals("unusedThrown")) { //$NON-NLS-1$
2035
							this.options.put(
2036
								CompilerOptions.OPTION_ReportUnusedDeclaredThrownException,
2037
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2038
						} else if (token.equals("unqualifiedField") //$NON-NLS-1$
2039
								|| token.equals("unqualified-field-access")) { //$NON-NLS-1$
2040
							this.options.put(
2041
								CompilerOptions.OPTION_ReportUnqualifiedFieldAccess,
2042
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2043
						} else if (token.equals("typeHiding")) { //$NON-NLS-1$
2044
							this.options.put(
2045
								CompilerOptions.OPTION_ReportTypeParameterHiding,
2046
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2047
						} else if (token.equals("varargsCast")) { //$NON-NLS-1$
2048
							this.options.put(
2049
								CompilerOptions.OPTION_ReportVarargsArgumentNeedCast,
2050
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
2051
						} else if (token.equals("null")) { //$NON-NLS-1$
2052
							this.options.put(
2053
								CompilerOptions.OPTION_ReportNullReference,
2054
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
2055
						} else if (token.equals("boxing")) { //$NON-NLS-1$
2056
							this.options.put(
2057
								CompilerOptions.OPTION_ReportAutoboxing,
2058
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
2059
						} else if (token.equals("over-ann")) { //$NON-NLS-1$
2060
							this.options.put(
2061
								CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
2062
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
2063
						} else if (token.equals("dep-ann")) { //$NON-NLS-1$
2064
							this.options.put(
2065
								CompilerOptions.OPTION_ReportMissingDeprecatedAnnotation,
2066
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
2067
						} else if (token.equals("intfAnnotation")) { //$NON-NLS-1$
2068
							this.options.put(
2069
								CompilerOptions.OPTION_ReportAnnotationSuperInterface,
2070
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
2071
						} else if (token.equals("enumSwitch") //$NON-NLS-1$
2072
								|| token.equals("incomplete-switch")) { //$NON-NLS-1$
2073
							this.options.put(
2074
								CompilerOptions.OPTION_ReportIncompleteEnumSwitch,
2075
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);						
2076
						} else if (token.equals("hiding")) { //$NON-NLS-1$
2077
							this.options.put(
2078
								CompilerOptions.OPTION_ReportHiddenCatchBlock,
2079
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2080
							this.options.put(
2081
								CompilerOptions.OPTION_ReportLocalVariableHiding,
2082
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2083
							this.options.put(
2084
								CompilerOptions.OPTION_ReportFieldHiding,
2085
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2086
							this.options.put(
2087
								CompilerOptions.OPTION_ReportTypeParameterHiding,
2088
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2089
						} else if (token.equals("static-access")) { //$NON-NLS-1$
2090
							this.options.put(
2091
								CompilerOptions.OPTION_ReportNonStaticAccessToStatic,
2092
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2093
							this.options.put(
2094
								CompilerOptions.OPTION_ReportIndirectStaticAccess,
2095
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2096
						} else if (token.equals("unused")) { //$NON-NLS-1$
2097
							this.options.put(
2098
								CompilerOptions.OPTION_ReportUnusedLocal, 
2099
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2100
							this.options.put(
2101
								CompilerOptions.OPTION_ReportUnusedParameter,
2102
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2103
							this.options.put(
2104
								CompilerOptions.OPTION_ReportUnusedImport,
2105
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2106
							this.options.put(
2107
								CompilerOptions.OPTION_ReportUnusedPrivateMember,
2108
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2109
							this.options.put(
2110
								CompilerOptions.OPTION_ReportUnusedDeclaredThrownException,
2111
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2112
							this.options.put(
2113
									CompilerOptions.OPTION_ReportUnusedLabel,
2114
									isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2115
						} else if (token.equals("paramAssign")) { //$NON-NLS-1$
2116
							this.options.put(
2117
								CompilerOptions.OPTION_ReportParameterAssignment,
2118
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2119
						} else if (token.equals("discouraged")) { //$NON-NLS-1$
2120
							this.options.put(
2121
								CompilerOptions.OPTION_ReportDiscouragedReference,
2122
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2123
						} else if (token.equals("forbidden")) { //$NON-NLS-1$
2124
							this.options.put(
2125
								CompilerOptions.OPTION_ReportForbiddenReference,
2126
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2127
						} else if (token.equals("fallthrough")) { //$NON-NLS-1$
2128
							this.options.put(
2129
								CompilerOptions.OPTION_ReportFallthroughCase,
2130
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
2131
						} else {
2132
							throw new InvalidInputException(this.bind("configure.invalidWarning", token)); //$NON-NLS-1$
2133
						}
2134
					}
2199
					}
2135
					if (tokenCounter == 0)
2200
					if (tokenCounter == 0)
2136
						throw new InvalidInputException(
2201
						throw new InvalidInputException(
Lines 2438-2444 Link Here
2438
			customEncoding);
2503
			customEncoding);
2439
}
2504
}
2440
2505
2441
private void disableWarnings() {
2506
protected void disableWarnings() {
2442
	Object[] entries = this.options.entrySet().toArray();
2507
	Object[] entries = this.options.entrySet().toArray();
2443
	for (int i = 0, max = entries.length; i < max; i++) {
2508
	for (int i = 0, max = entries.length; i < max; i++) {
2444
		Map.Entry entry = (Map.Entry) entries[i];
2509
		Map.Entry entry = (Map.Entry) entries[i];
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+5 lines)
Lines 268-270 Link Here
268
template.restrictedAccess.constructor = The constructor {0} is not accessible due to restriction on classpath entry {1}
268
template.restrictedAccess.constructor = The constructor {0} is not accessible due to restriction on classpath entry {1}
269
template.restrictedAccess.field = The field {0} from the type {1} is not accessible due to restriction on classpath entry {2}
269
template.restrictedAccess.field = The field {0} from the type {1} is not accessible due to restriction on classpath entry {2}
270
template.restrictedAccess.method = The method {0} from the type {1} is not accessible due to restriction on classpath entry {2}
270
template.restrictedAccess.method = The method {0} from the type {1} is not accessible due to restriction on classpath entry {2}
271
272
# GCCMain messages.
273
gcc.zipArg=-fzip-target requires argument
274
gcc.zipDepArg=-fzip-dependency requires argument
275
gcc.noClasspath=no classpath specified
(-)batch/org/eclipse/jdt/internal/compiler/batch/GCCMain.java (+442 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.jdt.internal.compiler.batch;
5
6
import java.io.BufferedOutputStream;
7
import java.io.BufferedReader;
8
import java.io.ByteArrayInputStream;
9
import java.io.File;
10
import java.io.FileOutputStream;
11
import java.io.FileReader;
12
import java.io.IOException;
13
import java.io.InputStreamReader;
14
import java.io.OutputStream;
15
import java.io.PrintWriter;
16
import java.io.UnsupportedEncodingException;
17
import java.util.ArrayList;
18
import java.util.HashSet;
19
import java.util.Iterator;
20
import java.util.Map;
21
import java.util.StringTokenizer;
22
import java.util.zip.CRC32;
23
import java.util.zip.ZipEntry;
24
import java.util.zip.ZipOutputStream;
25
26
import org.eclipse.jdt.core.compiler.InvalidInputException;
27
import org.eclipse.jdt.internal.compiler.ClassFile;
28
import org.eclipse.jdt.internal.compiler.CompilationResult;
29
import org.eclipse.jdt.internal.compiler.env.AccessRule;
30
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
31
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
32
import org.eclipse.jdt.internal.compiler.util.Messages;
33
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
34
35
/**
36
 * This is an alternate entry point for the command-line compiler which
37
 * is simpler to integrate into GCC.  In particular the option processing
38
 * is more GNU-like and the recognized options are similar to those supported
39
 * by other GCC front ends.
40
 */
41
public class GCCMain extends Main {
42
43
	// All the compilation units specified on the command line.
44
	private HashSet commandLineCompilationUnits = new HashSet();
45
	// True if we are only checking syntax.
46
	private boolean syntaxOnly;
47
	// If not null, the name of the output zip file.
48
	// If null, we are generating class files in the file system,
49
	// not a zip file.
50
	private String zipDestination;
51
	// The zip stream to which we're writing, or null if it hasn't been opened.
52
	private ZipOutputStream zipStream;
53
	
54
	// If not null, the name of the zip file to which dependency class files
55
	// should be written.
56
	private String zipDependencyDestination;
57
	// The zip stream to which dependency files should be written.
58
	private ZipOutputStream zipDependencyStream;
59
60
	public GCCMain(PrintWriter outWriter, PrintWriter errWriter,
61
			boolean systemExitWhenFinished) {
62
		super(outWriter, errWriter, systemExitWhenFinished);
63
		this.logger.setEmacs();
64
	}
65
66
	public GCCMain(PrintWriter outWriter, PrintWriter errWriter,
67
			boolean systemExitWhenFinished, Map customDefaultOptions) {
68
		super(outWriter, errWriter, systemExitWhenFinished,
69
				customDefaultOptions);
70
		this.logger.setEmacs();
71
	}
72
73
	private void fail(Exception t) {
74
		this.logger.logException(t);
75
		System.exit(1);
76
	}
77
78
	public CompilationUnit[] getCompilationUnits() throws InvalidInputException {
79
		CompilationUnit[] units = super.getCompilationUnits();
80
		for (int i = 0; i < units.length; ++i)
81
			this.commandLineCompilationUnits.add(units[i]);
82
		return units;
83
	}
84
85
	private String combine(char[] one, char[] two) {
86
		StringBuffer b = new StringBuffer();
87
		b.append(one);
88
		b.append(two);
89
		return b.toString();
90
	}
91
92
	private ZipOutputStream getZipOutput() throws IOException {
93
		if (this.zipDestination != null && this.zipStream == null) {
94
			OutputStream os;
95
			if ("-".equals(this.zipDestination)) { //$NON-NLS-1$
96
				os = System.out;
97
			} else {
98
				os = new FileOutputStream(this.zipDestination);
99
			}
100
			zipStream = new ZipOutputStream(new BufferedOutputStream(os));
101
			zipStream.setMethod(ZipOutputStream.STORED);
102
		}
103
		return zipStream;
104
	}
105
106
	private ZipOutputStream getDependencyOutput() throws IOException {
107
		if (this.zipDependencyDestination != null && this.zipDependencyStream == null) {
108
			OutputStream os = new FileOutputStream(zipDependencyDestination);
109
			zipDependencyStream = new ZipOutputStream(new BufferedOutputStream(os));
110
			zipDependencyStream.setMethod(ZipOutputStream.STORED);
111
		}
112
		return zipDependencyStream;
113
	}
114
115
	public void outputClassFiles(CompilationResult unitResult) {
116
		if (this.syntaxOnly) {
117
			return;
118
		}
119
		if (this.zipDestination == null) {
120
			// Nothing special to do here.
121
			super.outputClassFiles(unitResult);
122
			return;
123
		}
124
		if (unitResult == null || unitResult.hasErrors()) {
125
			return;
126
		}
127
128
		// If we are compiling with indirect dispatch, we don't need
129
		// any dependent classes.  If we are using the C++ ABI, then we
130
		// do need the dependencies in order to do proper layout.
131
		boolean gcjCompile = this.commandLineCompilationUnits.contains(unitResult.getCompilationUnit());
132
		if (this.zipDependencyDestination == null && !gcjCompile) {
133
			return;
134
		}
135
136
		try {
137
			ZipOutputStream dest = gcjCompile ? getZipOutput() : getDependencyOutput();
138
			ClassFile[] classFiles = unitResult.getClassFiles();
139
			for (int i = 0; i < classFiles.length; ++i) {
140
				ClassFile classFile = classFiles[i];
141
				String filename = combine(classFile.fileName(), SuffixConstants.SUFFIX_class);
142
				if (this.verbose)
143
					this.out.println(
144
							Messages.bind(
145
									Messages.compilation_write,
146
									new String[] {
147
								String.valueOf(this.exportedClassFilesCounter+1),
148
								filename
149
							}));
150
				ZipEntry entry = new ZipEntry(filename);
151
				byte[] contents = classFile.getBytes();
152
				CRC32 crc = new CRC32();
153
				crc.update(contents);
154
				entry.setSize(contents.length);
155
				entry.setCrc(crc.getValue());
156
				dest.putNextEntry(entry);
157
				dest.write(contents);
158
				dest.closeEntry();
159
			}
160
		} catch (IOException err) {
161
			fail(err);
162
		}
163
	}
164
	
165
	private String getArgument(String option) {
166
		int index = option.indexOf('=');
167
		return option.substring(index + 1);
168
	}
169
170
	private void addPath(ArrayList result, String currentClasspathName) {
171
		String customEncoding = null;
172
		AccessRule[] accessRules = new AccessRule[0];
173
		String templates[] = new String[AccessRuleSet.MESSAGE_TEMPLATES_LENGTH];
174
		templates[0] = this.bind(
175
			"template.restrictedAccess.type", //$NON-NLS-1$
176
			new String[] {"{0}", currentClasspathName}); //$NON-NLS-1$ 
177
		templates[1] = this.bind(
178
			"template.restrictedAccess.constructor", //$NON-NLS-1$
179
			new String[] {"{0}", currentClasspathName}); //$NON-NLS-1$ 
180
		templates[2] = this.bind(
181
			"template.restrictedAccess.method", //$NON-NLS-1$
182
			new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ 
183
		templates[3] = this.bind(
184
			"template.restrictedAccess.field", //$NON-NLS-1$
185
			new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ 
186
		AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules, templates);
187
		FileSystem.Classpath currentClasspath = FileSystem
188
				.getClasspath(currentClasspathName,
189
						customEncoding, accessRuleSet);
190
		if (currentClasspath != null) {
191
			result.add(currentClasspath);
192
		}
193
	}
194
	
195
	private void parsePath(ArrayList result, String path) {
196
		StringTokenizer iter = new StringTokenizer(path, File.pathSeparator);
197
		while (iter.hasMoreTokens()) {
198
			addPath(result, iter.nextToken());
199
		}
200
	}
201
202
	protected void handleWarningToken(String token, boolean isEnabling,
203
			boolean useEnableJavadoc) throws InvalidInputException {
204
		// Recognize this for compatibility with older versions of gcj.
205
		if ("deprecated".equals(token)) //$NON-NLS-1$
206
			token = "deprecation"; //$NON-NLS-1$
207
		else if ("static-access".equals(token)   //$NON-NLS-1$
208
				|| "dep-ann".equals(token) //$NON-NLS-1$
209
				|| "over-ann".equals(token)) { //$NON-NLS-1$
210
			// Some exceptions to the warning naming rule.
211
		} else if ("extraneous-semicolon".equals(token)) { //$NON-NLS-1$
212
			// Compatibility with earlier versions of gcj.
213
			token = "semicolon"; //$NON-NLS-1$
214
		} else {
215
			// Turn "foo-bar-baz" into eclipse-style "fooBarBaz".
216
			StringBuffer newToken = new StringBuffer(token.length());
217
			StringTokenizer t = new StringTokenizer(token, "-"); //$NON-NLS-1$
218
			boolean first = true;
219
			while (t.hasMoreTokens()) {
220
				String next = t.nextToken();
221
				if (first) {
222
					newToken.append(next);
223
					first = false;
224
				} else {
225
					newToken.append(Character.toUpperCase(next.charAt(0)));
226
					newToken.append(next.substring(1));
227
				}
228
			}
229
			token = newToken.toString();
230
		}
231
		super.handleWarningToken(token, isEnabling, useEnableJavadoc);
232
	}
233
234
	/**
235
	 * Set the debug level to the indicated value.  The level should be
236
	 * between 0 and 2, inclusive, but this is not checked.
237
	 * @param level the debug level
238
	 */
239
	private void setDebugLevel(int level) {
240
		this.options.put(
241
				CompilerOptions.OPTION_LocalVariableAttribute,
242
				level > 1 ? CompilerOptions.GENERATE : CompilerOptions.DO_NOT_GENERATE);
243
		this.options.put(
244
				CompilerOptions.OPTION_LineNumberAttribute,
245
				level > 0 ? CompilerOptions.GENERATE : CompilerOptions.DO_NOT_GENERATE);
246
		this.options.put(
247
				CompilerOptions.OPTION_SourceFileAttribute,
248
				CompilerOptions.GENERATE);
249
	}
250
251
	private void readFileList(String file, ArrayList result) {
252
		try {
253
			BufferedReader b = new BufferedReader(new FileReader(file));
254
			String line;
255
			while ((line = b.readLine()) != null) {
256
				if (line.endsWith(SUFFIX_STRING_java))
257
					result.add(line);
258
			}
259
			b.close();
260
		} catch (IOException err) {
261
			fail(err);
262
		}
263
	}
264
	
265
	private void readAllFileListFiles(ArrayList fileList, ArrayList result) {
266
		Iterator it = fileList.iterator();
267
		while (it.hasNext()) {
268
			readFileList((String) it.next(), result);
269
		}
270
	}
271
272
	public void configure(String[] argv) throws InvalidInputException {
273
		if ((argv == null) || (argv.length == 0)) {
274
			// This is a "can't happen".
275
			System.exit(1);
276
		}
277
278
		ArrayList files = new ArrayList();
279
		ArrayList otherFiles = new ArrayList();
280
		String classpath = null;
281
		boolean haveFileList = false;
282
283
		for (int i = 0; i < argv.length; ++i) {
284
			String currentArg = argv[i];
285
			
286
			if (currentArg.startsWith("-fencoding=")) { //$NON-NLS-1$
287
				// Simply accept the last one.
288
				String encoding = getArgument(currentArg);
289
				try { // ensure encoding is supported
290
					new InputStreamReader(new ByteArrayInputStream(new byte[0]), encoding);
291
				} catch (UnsupportedEncodingException e) {
292
					throw new InvalidInputException(
293
						this.bind("configure.unsupportedEncoding", encoding)); //$NON-NLS-1$
294
				}
295
				this.options.put(CompilerOptions.OPTION_Encoding, encoding);
296
			} else if (currentArg.startsWith("-foutput-class-dir=")) { //$NON-NLS-1$
297
				String arg = getArgument(currentArg);
298
				if (this.destinationPath != null) {
299
					StringBuffer errorMessage = new StringBuffer();
300
					errorMessage.append("-d"); //$NON-NLS-1$
301
					errorMessage.append(' ');
302
					errorMessage.append(arg);
303
					throw new InvalidInputException(
304
						this.bind("configure.duplicateOutputPath", errorMessage.toString())); //$NON-NLS-1$
305
				}
306
				this.destinationPath = arg;
307
				// this.generatePackagesStructure = true;
308
			} else if (currentArg.startsWith("-fbootclasspath=")) { //$NON-NLS-1$
309
				classpath = getArgument(currentArg);
310
			} else if (currentArg.equals("-fzip-target")) { //$NON-NLS-1$
311
				++i;
312
				if (i >= argv.length)
313
					throw new InvalidInputException(this.bind("gcc.zipArg")); //$NON-NLS-1$
314
				this.zipDestination = argv[i];
315
			} else if (currentArg.equals("-fzip-dependency")) { //$NON-NLS-1$
316
				++i;
317
				if (i >= argv.length)
318
					throw new InvalidInputException(this.bind("gcc.zipDepArg")); //$NON-NLS-1$
319
				this.zipDependencyDestination = argv[i];
320
			} else if (currentArg.startsWith("-g")) { //$NON-NLS-1$
321
				if (currentArg.equals("-g0")) { //$NON-NLS-1$
322
					setDebugLevel(0);
323
				} else if (currentArg.equals("-g2") || currentArg.equals("-g3") //$NON-NLS-1$ //$NON-NLS-2$
324
						|| currentArg.equals("-g")) { //$NON-NLS-1$
325
					setDebugLevel(2);
326
				} else {
327
					// Handle -g1 but also things like -gstabs.
328
					setDebugLevel(1);
329
				}
330
			} else if (currentArg.startsWith("-Wno-")) { //$NON-NLS-1$
331
				handleWarningToken(currentArg.substring(5), false, false);
332
			} else if (currentArg.startsWith("-W")) { //$NON-NLS-1$
333
				handleWarningToken(currentArg.substring(2), true, false);
334
			} else if (currentArg.equals("-w")) { //$NON-NLS-1$
335
				disableWarnings();
336
			} else if (currentArg.startsWith("-O")) { //$NON-NLS-1$
337
				// Ignore.
338
			} else if (currentArg.equals("-v")) { //$NON-NLS-1$
339
				this.verbose = true;
340
			} else if (currentArg.equals("-fsyntax-only")) { //$NON-NLS-1$
341
				this.syntaxOnly = true;
342
			} else if (currentArg.startsWith("-fsource=")) { //$NON-NLS-1$
343
				currentArg = getArgument(currentArg);
344
				if (currentArg.equals("1.3")) { //$NON-NLS-1$
345
					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
346
				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
347
					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
348
				} else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
349
					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
350
				} else if (currentArg.equals("1.6") || currentArg.equals("6") || currentArg.equals("6.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
351
					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
352
				} else {
353
					throw new InvalidInputException(this.bind("configure.source", currentArg)); //$NON-NLS-1$
354
				}
355
			} else if (currentArg.startsWith("-ftarget=")) { //$NON-NLS-1$
356
				currentArg = getArgument(currentArg);
357
				if (currentArg.equals("1.1")) { //$NON-NLS-1$
358
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
359
				} else if (currentArg.equals("1.2")) { //$NON-NLS-1$
360
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
361
				} else if (currentArg.equals("1.3")) { //$NON-NLS-1$
362
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3);
363
				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
364
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
365
				} else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
366
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
367
				} else if (currentArg.equals("1.6") || currentArg.equals("6") || currentArg.equals("6.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
368
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
369
				} else if (currentArg.equals("jsr14")) { //$NON-NLS-1$
370
					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_JSR14);
371
				} else {
372
					throw new InvalidInputException(this.bind("configure.targetJDK", currentArg)); //$NON-NLS-1$
373
				}
374
			} else if (currentArg.equals("-ffilelist-file")) { //$NON-NLS-1$
375
				haveFileList = true;
376
			} else if (currentArg.endsWith(SuffixConstants.SUFFIX_STRING_java)) {
377
				files.add(currentArg);
378
			} else if (currentArg.charAt(0) == '-'){
379
				// FIXME: error if not a file?
380
			} else {
381
				otherFiles.add(currentArg);
382
			}
383
		}
384
385
		// Read the file list file.  We read them all, but really there
386
		// will only be one.
387
		if (haveFileList)
388
			readAllFileListFiles(otherFiles, files);
389
390
		this.filenames = (String[]) files.toArray(new String[0]);
391
		this.encodings = new String[this.filenames.length];
392
		this.destinationPaths = new String[this.filenames.length];
393
		for (int i = 0; i < this.filenames.length; ++i)
394
			this.destinationPaths[i] = this.destinationPath;
395
		
396
		// Classpath processing.
397
		ArrayList result = new ArrayList();
398
		if (classpath == null)
399
			throw new InvalidInputException(this.bind("gcc.noClasspath")); //$NON-NLS-1$
400
		parsePath(result, classpath);
401
402
		// We must always create both output files, even if one is not used.
403
		// That way we will always pass valid zip file on to jc1.
404
		try {
405
			getZipOutput();
406
			getDependencyOutput();
407
		} catch (IOException err) {
408
			fail(err);
409
		}
410
411
		this.checkedClasspaths = new FileSystem.Classpath[result.size()];
412
		result.toArray(this.checkedClasspaths);
413
414
		this.logger.logCommandLineArguments(argv);
415
		this.logger.logOptions(this.options);
416
		this.logger.logClasspath(this.checkedClasspaths);
417
		
418
		this.repetitions = 1;
419
	}
420
421
	public boolean compile(String[] argv) {
422
		boolean result = super.compile(argv);
423
		try {
424
			if (zipStream != null) {
425
				zipStream.finish();
426
				zipStream.close();
427
			}
428
			if (zipDependencyStream != null) {
429
				zipDependencyStream.finish();
430
				zipDependencyStream.close();
431
			}
432
		} catch (IOException err) {
433
			fail(err);
434
		}
435
		return result;
436
	}
437
438
	public static void main(String[] argv) {
439
		boolean result = new GCCMain(new PrintWriter(System.out), new PrintWriter(System.err), false).compile(argv);
440
		System.exit(result ? 0 : 1);
441
	}
442
}

Return to bug 159641