### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/OptionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/OptionTests.java,v retrieving revision 1.22 diff -u -r1.22 OptionTests.java --- src/org/eclipse/jdt/core/tests/model/OptionTests.java 6 Apr 2006 15:25:05 -0000 1.22 +++ src/org/eclipse/jdt/core/tests/model/OptionTests.java 20 Aug 2007 10:10:18 -0000 @@ -30,619 +30,669 @@ int eventCount = 0; - class TestPropertyListener implements IEclipsePreferences.IPreferenceChangeListener { - public void preferenceChange(PreferenceChangeEvent event) { - eventCount++; - } - } - - public OptionTests(String name) { - super(name); +class TestPropertyListener implements IEclipsePreferences.IPreferenceChangeListener { + public void preferenceChange(PreferenceChangeEvent event) { + eventCount++; } - static { +} + +public OptionTests(String name) { + super(name); +} +static { // TESTS_NUMBERS = new int[] { 125360 }; // TESTS_RANGE = new int[] { 4, -1 }; - } - public static Test suite() { - return buildModelTestSuite(OptionTests.class); - } - - protected void tearDown() throws Exception { - // Put back default options - JavaCore.setOptions(JavaCore.getDefaultOptions()); - - super.tearDown(); - } - - /** - * Test persistence of project custom options - */ - public void test01() throws CoreException { - try { - IJavaProject projectA = - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - IJavaProject projectB = - this.createJavaProject( - "B", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - - Hashtable options = new Hashtable(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); - options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); - JavaCore.setOptions(options); - - options.clear(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true)); - assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true)); - assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true)); - - // check project B custom options (should be none, indicating it sees global ones only) - assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true)); - assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOption(JavaCore.COMPILER_COMPLIANCE, true)); - assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true)); - - // flush custom options - project A should revert to global ones - projectA.setOptions(null); - assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true)); - assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true)); - assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true)); - - } finally { - this.deleteProject("A"); - this.deleteProject("B"); - } - } - - /** - * Test custom encoding - */ - public void test02() throws CoreException { - try { - IJavaProject projectA = - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - IJavaProject projectB = - this.createJavaProject( - "B", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - - String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING); - - Hashtable options = new Hashtable(); - options.put(JavaCore.CORE_ENCODING, "custom"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom encoding", "custom", projectA.getOption(JavaCore.CORE_ENCODING, true)); - - // check project B custom options (should be none, indicating it sees global ones only) - assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOption(JavaCore.CORE_ENCODING, true)); - - // flush custom options - project A should revert to global ones - projectA.setOptions(null); - assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOption(JavaCore.CORE_ENCODING, true)); - - } finally { - this.deleteProject("A"); - this.deleteProject("B"); - } - } - - /** - * Test custom project option (if not considering JavaCore options) - */ - public void test03() throws CoreException { - try { - IJavaProject projectA = - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - IJavaProject projectB = - this.createJavaProject( - "B", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - - Hashtable options = new Hashtable(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); - options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); - JavaCore.setOptions(options); - - options.clear(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false)); - assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false)); - assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false)); - - // check project B custom options (should be none, indicating it sees global ones only) - assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false)); - assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOption(JavaCore.COMPILER_COMPLIANCE, false)); - assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false)); - - // flush custom options - project A should revert to global ones - projectA.setOptions(null); - assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false)); - assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false)); - assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false)); - - } finally { - this.deleteProject("A"); - this.deleteProject("B"); - } - } - /** - * Test persistence of project custom options - using getOptions() - */ - public void test04() throws CoreException { - try { - IJavaProject projectA = - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - IJavaProject projectB = - this.createJavaProject( - "B", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - - Hashtable options = new Hashtable(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); - options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); - JavaCore.setOptions(options); - - options.clear(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - - // check project B custom options (should be none, indicating it sees global ones only) - assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - - // flush custom options - project A should revert to global ones - projectA.setOptions(null); - assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - - } finally { - this.deleteProject("A"); - this.deleteProject("B"); - } - } - - /** - * Test custom encoding - using getOptions() - */ - public void test05() throws CoreException { - try { - IJavaProject projectA = - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - IJavaProject projectB = - this.createJavaProject( - "B", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - - String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING); - - Hashtable options = new Hashtable(); - options.put(JavaCore.CORE_ENCODING, "custom"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom encoding", "custom", projectA.getOptions(true).get(JavaCore.CORE_ENCODING)); - - // check project B custom options (should be none, indicating it sees global ones only) - assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOptions(true).get(JavaCore.CORE_ENCODING)); - - // flush custom options - project A should revert to global ones - projectA.setOptions(null); - assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOptions(true).get(JavaCore.CORE_ENCODING)); - - } finally { - this.deleteProject("A"); - this.deleteProject("B"); - } - } - - /** - * Test custom project option (if not considering JavaCore options) - using getOptions() - */ - public void test06() throws CoreException { - try { - IJavaProject projectA = - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - IJavaProject projectB = - this.createJavaProject( - "B", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - - Hashtable options = new Hashtable(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); - options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); - JavaCore.setOptions(options); - - options.clear(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - - // check project B custom options (should be none, indicating it sees global ones only) - assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - - // flush custom options - project A should revert to global ones - projectA.setOptions(null); - assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - - } finally { - this.deleteProject("A"); - this.deleteProject("B"); - } - } - /** - * Custom options must replace existing ones completely without loosing property listeners - * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26255 - * http://bugs.eclipse.org/bugs/show_bug.cgi?id=49691 - */ - public void test07() throws CoreException { - try { - this.eventCount = 0; - JavaProject projectA = (JavaProject) - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - // Preferences preferences = projectA.getPreferences(); - // preferences.addPropertyChangeListener(new TestPropertyListener()); - IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences(); - TestPropertyListener listener = new TestPropertyListener(); - eclipsePreferences.addPreferenceChangeListener(listener); - - Hashtable options = new Hashtable(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - // assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences()); - assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences()); - assertTrue("projA:preferences property listener has been lost", eventCount == 2); +} +public static Test suite() { + return buildModelTestSuite(OptionTests.class); +} + +protected void tearDown() throws Exception { + // Put back default options + JavaCore.setOptions(JavaCore.getDefaultOptions()); + + super.tearDown(); +} + +/** + * Test persistence of project custom options + */ +public void test01() throws CoreException { + try { + IJavaProject projectA = + this.createJavaProject( + "A", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + IJavaProject projectB = + this.createJavaProject( + "B", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + Hashtable options = new Hashtable(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); + options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); + JavaCore.setOptions(options); + + options.clear(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); + projectA.setOptions(options); + + // check project A custom options + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true)); + assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true)); + assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true)); - // change custom options to have one less - options.clear(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); - projectA.setOptions(options); - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected custom value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); - assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); - // assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences()); - assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences()); - assertTrue("projA:preferences property listener has been lost", eventCount == 3); - } finally { - this.deleteProject("A"); - } + // check project B custom options (should be none, indicating it sees global ones only) + assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true)); + assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOption(JavaCore.COMPILER_COMPLIANCE, true)); + assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true)); + + // flush custom options - project A should revert to global ones + projectA.setOptions(null); + assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true)); + assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true)); + assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true)); + + } finally { + this.deleteProject("A"); + this.deleteProject("B"); } - /** - * Empty custom option must not be ignored - * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26251 - */ - public void test08() throws CoreException { - try { - IJavaProject projectA = - this.createJavaProject( - "A", - new String[] {}, // source folders - new String[] {}, // lib folders - new String[] {}, // projects - ""); - - Hashtable options = new Hashtable(); - options.put(JavaCore.COMPILER_TASK_TAGS, "TODO:"); - JavaCore.setOptions(options); - - - // check project A custom options - assertEquals("1#projA:unexpected custom value for task tags option", null, projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false)); - assertEquals("1#projA:unexpected custom value for inherited task tags option", "TODO:", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true)); - assertEquals("1#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS)); - - // change custom options to have one less - options.clear(); - options.put(JavaCore.COMPILER_TASK_TAGS, ""); - projectA.setOptions(options); - assertEquals("2#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false)); - assertEquals("2#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true)); - assertEquals("2#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS)); - - // change custom options to have one less - options.clear(); - options.put(JavaCore.COMPILER_TASK_TAGS, "@TODO"); - JavaCore.setOptions(options); - assertEquals("3#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false)); - assertEquals("3#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true)); - assertEquals("3#workspace:unexpected custom value for task tags option", "@TODO", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS)); - - } finally { - this.deleteProject("A"); - } - } - /** - * Custom options must replace existing ones completely without loosing property listeners - * http://bugs.eclipse.org/bugs/show_bug.cgi?id=59258 - * http://bugs.eclipse.org/bugs/show_bug.cgi?id=60896 - */ - public void test09() throws CoreException { - try { - this.eventCount = 0; - JavaProject projectA = (JavaProject) this.createJavaProject("A", new String[] {}, ""); - // Preferences preferences = projectA.getPreferences(); - // preferences.addPropertyChangeListener(new TestPropertyListener()); - IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences(); - eclipsePreferences.addPreferenceChangeListener(new TestPropertyListener()); +} + +/** + * Test custom encoding + */ +public void test02() throws CoreException { + try { + IJavaProject projectA = + this.createJavaProject( + "A", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + IJavaProject projectB = + this.createJavaProject( + "B", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING); + + Hashtable options = new Hashtable(); + options.put(JavaCore.CORE_ENCODING, "custom"); + projectA.setOptions(options); + + // check project A custom options + assertEquals("projA:unexpected custom encoding", "custom", projectA.getOption(JavaCore.CORE_ENCODING, true)); - Hashtable options = new Hashtable(); - options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); - options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); - projectA.setOptions(options); - - // check project A custom options - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); - assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences()); - assertEquals("projA:preferences property listener has been lost", 2, eventCount); + // check project B custom options (should be none, indicating it sees global ones only) + assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOption(JavaCore.CORE_ENCODING, true)); + + // flush custom options - project A should revert to global ones + projectA.setOptions(null); + assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOption(JavaCore.CORE_ENCODING, true)); + + } finally { + this.deleteProject("A"); + this.deleteProject("B"); + } +} + +/** + * Test custom project option (if not considering JavaCore options) + */ +public void test03() throws CoreException { + try { + IJavaProject projectA = + this.createJavaProject( + "A", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + IJavaProject projectB = + this.createJavaProject( + "B", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + Hashtable options = new Hashtable(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); + options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); + JavaCore.setOptions(options); + + options.clear(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); + projectA.setOptions(options); + + // check project A custom options + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false)); + assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false)); + assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false)); - // delete/create project A and verify that options are well reset - this.deleteProject("A"); - projectA = (JavaProject) this.createJavaProject("A", new String[] {}, ""); - assertEquals("projA:unexpected custom value for deprecation option", JavaCore.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE), projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); - assertEquals("projA:unexpected custom value for compliance option", JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE), projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); - assertTrue("projA:preferences should not be reset", eclipsePreferences != projectA.getEclipsePreferences()); - } finally { - this.deleteProject("A"); - } + // check project B custom options (should be none, indicating it sees global ones only) + assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false)); + assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOption(JavaCore.COMPILER_COMPLIANCE, false)); + assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false)); + + // flush custom options - project A should revert to global ones + projectA.setOptions(null); + assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false)); + assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false)); + assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false)); + + } finally { + this.deleteProject("A"); + this.deleteProject("B"); } - - /* - * Ensures that a classpath variable is still in the preferences after shutdown/restart - * (regression test for bug 98720 [preferences] classpath variables are not exported if the session is closed and restored) - */ - public void test10() throws CoreException { - JavaCore.setClasspathVariable("TEST", new Path("testing"), null); - simulateExitRestart(); - JavaModelManager manager = JavaModelManager.getJavaModelManager(); - IEclipsePreferences preferences = manager.getInstancePreferences(); - assertEquals( - "Should find variable TEST in preferences", - "testing", - preferences.get(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", "null")); - } - - /* - * Ensures that a classpath variable is removed from the preferences if set to null - * (regression test for bug 98720 [preferences] classpath variables are not exported if the session is closed and restored) - */ - public void test11() throws CoreException { - JavaCore.setClasspathVariable("TEST", new Path("testing"), null); - JavaCore.removeClasspathVariable("TEST", null); - JavaModelManager manager = JavaModelManager.getJavaModelManager(); - IEclipsePreferences preferences = manager.getInstancePreferences(); - assertEquals( - "Should not find variable TEST in preferences", - "null", - preferences.get(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", "null")); - } - - /* - * Ensures that classpath problems are removed when a missing classpath variable is added through the preferences - * (regression test for bug 109691 Importing preferences does not update classpath variables) - */ - public void test12() throws CoreException { - IEclipsePreferences preferences = JavaModelManager.getJavaModelManager().getInstancePreferences(); - try { - IJavaProject project = createJavaProject("P", new String[0], new String[] {"TEST"}, ""); - waitForAutoBuild(); - preferences.put(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", getExternalJCLPathString()); - assertMarkers("Unexpected markers", "", project); - } finally { - deleteProject("P"); - preferences.remove(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST"); - } +} +/** + * Test persistence of project custom options - using getOptions() + */ +public void test04() throws CoreException { + try { + IJavaProject projectA = + this.createJavaProject( + "A", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + IJavaProject projectB = + this.createJavaProject( + "B", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + Hashtable options = new Hashtable(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); + options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); + JavaCore.setOptions(options); + + options.clear(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); + projectA.setOptions(options); + + // check project A custom options + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); + + // check project B custom options (should be none, indicating it sees global ones only) + assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); + + // flush custom options - project A should revert to global ones + projectA.setOptions(null); + assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); + + } finally { + this.deleteProject("A"); + this.deleteProject("B"); } +} - /** - * Bug 68993: [Preferences] IAE when opening project preferences - * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=68993" - */ - public void testBug68993() throws CoreException, BackingStoreException { - try { - JavaProject projectA = (JavaProject) this.createJavaProject( +/** + * Test custom encoding - using getOptions() + */ +public void test05() throws CoreException { + try { + IJavaProject projectA = + this.createJavaProject( "A", new String[] {}, // source folders new String[] {}, // lib folders new String[] {}, // projects ""); + IJavaProject projectB = + this.createJavaProject( + "B", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING); - // Store project eclipse prefs - IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences(); + Hashtable options = new Hashtable(); + options.put(JavaCore.CORE_ENCODING, "custom"); + projectA.setOptions(options); - // set all project options as custom ones: this is what happens when user select - // "Use project settings" in project 'Java Compiler' preferences page... - Hashtable options = new Hashtable(projectA.getOptions(true)); - projectA.setOptions(options); - - // reset all project custom options: this is what happens when user select - // "Use workspace settings" in project 'Java Compiler' preferences page... - options = new Hashtable(); - options.put("internal.default.compliance", JavaCore.DEFAULT); - projectA.setOptions(options); - - // verify that project preferences have been reset - assertFalse("projA: Preferences should have been reset", eclipsePreferences == projectA.getEclipsePreferences()); - assertEquals("projA: We should not have any custom options!", 0, projectA.getEclipsePreferences().keys().length); - } finally { - this.deleteProject("A"); - } + // check project A custom options + assertEquals("projA:unexpected custom encoding", "custom", projectA.getOptions(true).get(JavaCore.CORE_ENCODING)); + + // check project B custom options (should be none, indicating it sees global ones only) + assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOptions(true).get(JavaCore.CORE_ENCODING)); + + // flush custom options - project A should revert to global ones + projectA.setOptions(null); + assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOptions(true).get(JavaCore.CORE_ENCODING)); + + } finally { + this.deleteProject("A"); + this.deleteProject("B"); } +} - /** - * Bug 72214: [Preferences] IAE when opening project preferences - * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=72214" - */ - public void testBug72214() throws CoreException, BackingStoreException { - // Remove JavaCore instance prefs - JavaModelManager manager = JavaModelManager.getJavaModelManager(); - IEclipsePreferences preferences = manager.getInstancePreferences(); - int size = JavaCore.getOptions().size(); - preferences.removeNode(); - - // verify that JavaCore preferences have been reset - assertFalse("JavaCore preferences should have been reset", preferences == manager.getInstancePreferences()); - assertEquals("JavaCore preferences should have been resotred!", size, JavaCore.getOptions().size()); - } - - /** - * Bug 100393: Defaults for compiler errors/warnings settings - * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=100393" - */ - public void testBug100393() throws CoreException, BackingStoreException { - // Get default compiler options - Map options = new CompilerOptions().getMap(); - - // verify that CompilerOptions default preferences for modified options - assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING, options.get(CompilerOptions.OPTION_ReportUnusedLocal)); - assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING, options.get(CompilerOptions.OPTION_ReportUnusedPrivateMember)); - assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE, options.get(CompilerOptions.OPTION_ReportFieldHiding)); - assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.IGNORE, options.get(CompilerOptions.OPTION_ReportLocalVariableHiding)); - } - public void testBug100393b() throws CoreException, BackingStoreException { - // Get JavaCore default preferences - JavaModelManager manager = JavaModelManager.getJavaModelManager(); - IEclipsePreferences preferences = manager.getDefaultPreferences(); - - // verify that JavaCore default preferences for modified options - assertEquals("Invalid default for "+JavaCore.COMPILER_PB_UNUSED_LOCAL, "warning", preferences.get(JavaCore.COMPILER_PB_UNUSED_LOCAL, "null")); - assertEquals("Invalid default for "+JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, "warning", preferences.get(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, "null")); - assertEquals("Invalid default for "+JavaCore.COMPILER_PB_FIELD_HIDING, "ignore", preferences.get(JavaCore.COMPILER_PB_FIELD_HIDING, "null")); - assertEquals("Invalid default for "+JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, "ignore", preferences.get(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, "null")); - } - - /** - * @bug 125360: IJavaProject#setOption() doesn't work if same option as default - * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=125360" - */ - public void testBug125360() throws CoreException, BackingStoreException { - try { - JavaProject project = (JavaProject) createJavaProject( - "P", +/** + * Test custom project option (if not considering JavaCore options) - using getOptions() + */ +public void test06() throws CoreException { + try { + IJavaProject projectA = + this.createJavaProject( + "A", new String[] {}, // source folders new String[] {}, // lib folders new String[] {}, // projects ""); - project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4); - project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); - String option = project.getOption(JavaCore.COMPILER_SOURCE, true); - assertEquals(JavaCore.VERSION_1_3, option); - } finally { - deleteProject("P"); - } + IJavaProject projectB = + this.createJavaProject( + "B", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + Hashtable options = new Hashtable(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "8.0"); + options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR); + JavaCore.setOptions(options); + + options.clear(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); + projectA.setOptions(options); + + // check project A custom options + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); + + // check project B custom options (should be none, indicating it sees global ones only) + assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); + + // flush custom options - project A should revert to global ones + projectA.setOptions(null); + assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); + + } finally { + this.deleteProject("A"); + this.deleteProject("B"); } - - /** - * @bug 131707: Cannot add classpath variables when starting with -pluginCustomization option - * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=131707" - */ - public void testBug131707() throws CoreException { - IEclipsePreferences defaultPreferences = new DefaultScope().getNode(JavaCore.PLUGIN_ID); - try { - defaultPreferences.put("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB", "c:\\temp\\lib.jar"); - simulateExitRestart(); - String[] variableNames = JavaCore.getClasspathVariableNames(); - for (int i = 0, length = variableNames.length; i < length; i++) { - if ("MY_DEFAULT_LIB".equals(variableNames[i])) { - assertEquals( - "Unexpected value for MY_DEFAULT_LIB", - new Path("c:\\temp\\lib.jar"), - JavaCore.getClasspathVariable("MY_DEFAULT_LIB")); - return; - } +} +/** + * Custom options must replace existing ones completely without loosing property listeners + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26255 + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=49691 + */ +public void test07() throws CoreException { + try { + this.eventCount = 0; + JavaProject projectA = (JavaProject) + this.createJavaProject( + "A", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); +// Preferences preferences = projectA.getPreferences(); +// preferences.addPropertyChangeListener(new TestPropertyListener()); + IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences(); + TestPropertyListener listener = new TestPropertyListener(); + eclipsePreferences.addPreferenceChangeListener(listener); + + Hashtable options = new Hashtable(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); + projectA.setOptions(options); + + // check project A custom options + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); +// assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences()); + assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences()); + assertTrue("projA:preferences property listener has been lost", eventCount == 2); + + // change custom options to have one less + options.clear(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); + projectA.setOptions(options); + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected custom value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE)); + assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); +// assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences()); + assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences()); + assertTrue("projA:preferences property listener has been lost", eventCount == 3); + } finally { + this.deleteProject("A"); + } +} +/** + * Empty custom option must not be ignored + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26251 + */ +public void test08() throws CoreException { + try { + IJavaProject projectA = + this.createJavaProject( + "A", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + Hashtable options = new Hashtable(); + options.put(JavaCore.COMPILER_TASK_TAGS, "TODO:"); + JavaCore.setOptions(options); + + + // check project A custom options + assertEquals("1#projA:unexpected custom value for task tags option", null, projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false)); + assertEquals("1#projA:unexpected custom value for inherited task tags option", "TODO:", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true)); + assertEquals("1#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS)); + + // change custom options to have one less + options.clear(); + options.put(JavaCore.COMPILER_TASK_TAGS, ""); + projectA.setOptions(options); + assertEquals("2#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false)); + assertEquals("2#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true)); + assertEquals("2#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS)); + + // change custom options to have one less + options.clear(); + options.put(JavaCore.COMPILER_TASK_TAGS, "@TODO"); + JavaCore.setOptions(options); + assertEquals("3#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false)); + assertEquals("3#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true)); + assertEquals("3#workspace:unexpected custom value for task tags option", "@TODO", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS)); + + } finally { + this.deleteProject("A"); + } +} +/** + * Custom options must replace existing ones completely without loosing property listeners + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=59258 + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=60896 + */ +public void test09() throws CoreException { + try { + this.eventCount = 0; + JavaProject projectA = (JavaProject) this.createJavaProject("A", new String[] {}, ""); +// Preferences preferences = projectA.getPreferences(); +// preferences.addPropertyChangeListener(new TestPropertyListener()); + IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences(); + eclipsePreferences.addPreferenceChangeListener(new TestPropertyListener()); + + Hashtable options = new Hashtable(); + options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_COMPLIANCE, "10.0"); + projectA.setOptions(options); + + // check project A custom options + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); + assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences()); + assertEquals("projA:preferences property listener has been lost", 2, eventCount); + + // delete/create project A and verify that options are well reset + this.deleteProject("A"); + projectA = (JavaProject) this.createJavaProject("A", new String[] {}, ""); + assertEquals("projA:unexpected custom value for deprecation option", JavaCore.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE), projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE)); + assertEquals("projA:unexpected custom value for compliance option", JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE), projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE)); + assertTrue("projA:preferences should not be reset", eclipsePreferences != projectA.getEclipsePreferences()); + } finally { + this.deleteProject("A"); + } +} + +/* + * Ensures that a classpath variable is still in the preferences after shutdown/restart + * (regression test for bug 98720 [preferences] classpath variables are not exported if the session is closed and restored) + */ +public void test10() throws CoreException { + JavaCore.setClasspathVariable("TEST", new Path("testing"), null); + simulateExitRestart(); + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences preferences = manager.getInstancePreferences(); + assertEquals( + "Should find variable TEST in preferences", + "testing", + preferences.get(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", "null")); +} + +/* + * Ensures that a classpath variable is removed from the preferences if set to null + * (regression test for bug 98720 [preferences] classpath variables are not exported if the session is closed and restored) + */ +public void test11() throws CoreException { + JavaCore.setClasspathVariable("TEST", new Path("testing"), null); + JavaCore.removeClasspathVariable("TEST", null); + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences preferences = manager.getInstancePreferences(); + assertEquals( + "Should not find variable TEST in preferences", + "null", + preferences.get(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", "null")); +} + +/* + * Ensures that classpath problems are removed when a missing classpath variable is added through the preferences + * (regression test for bug 109691 Importing preferences does not update classpath variables) + */ +public void test12() throws CoreException { + IEclipsePreferences preferences = JavaModelManager.getJavaModelManager().getInstancePreferences(); + try { + IJavaProject project = createJavaProject("P", new String[0], new String[] {"TEST"}, ""); + waitForAutoBuild(); + preferences.put(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", getExternalJCLPathString()); + assertMarkers("Unexpected markers", "", project); + } finally { + deleteProject("P"); + preferences.remove(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST"); + } +} + +/** + * Bug 68993: [Preferences] IAE when opening project preferences + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=68993" + */ +public void testBug68993() throws CoreException, BackingStoreException { + try { + JavaProject projectA = (JavaProject) this.createJavaProject( + "A", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + + // Store project eclipse prefs + IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences(); + + // set all project options as custom ones: this is what happens when user select + // "Use project settings" in project 'Java Compiler' preferences page... + Hashtable options = new Hashtable(projectA.getOptions(true)); + projectA.setOptions(options); + + // reset all project custom options: this is what happens when user select + // "Use workspace settings" in project 'Java Compiler' preferences page... + options = new Hashtable(); + options.put("internal.default.compliance", JavaCore.DEFAULT); + projectA.setOptions(options); + + // verify that project preferences have been reset + assertFalse("projA: Preferences should have been reset", eclipsePreferences == projectA.getEclipsePreferences()); + assertEquals("projA: We should not have any custom options!", 0, projectA.getEclipsePreferences().keys().length); + } finally { + this.deleteProject("A"); + } +} + +/** + * Bug 72214: [Preferences] IAE when opening project preferences + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=72214" + */ +public void testBug72214() throws CoreException, BackingStoreException { + // Remove JavaCore instance prefs + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences preferences = manager.getInstancePreferences(); + int size = JavaCore.getOptions().size(); + preferences.removeNode(); + + // verify that JavaCore preferences have been reset + assertFalse("JavaCore preferences should have been reset", preferences == manager.getInstancePreferences()); + assertEquals("JavaCore preferences should have been resotred!", size, JavaCore.getOptions().size()); +} + +/** + * Bug 100393: Defaults for compiler errors/warnings settings + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=100393" + */ +public void testBug100393() throws CoreException, BackingStoreException { + // Get default compiler options + Map options = new CompilerOptions().getMap(); + + // verify that CompilerOptions default preferences for modified options + assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING, options.get(CompilerOptions.OPTION_ReportUnusedLocal)); + assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING, options.get(CompilerOptions.OPTION_ReportUnusedPrivateMember)); + assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE, options.get(CompilerOptions.OPTION_ReportFieldHiding)); + assertEquals("Invalid default for "+CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.IGNORE, options.get(CompilerOptions.OPTION_ReportLocalVariableHiding)); +} +public void testBug100393b() throws CoreException, BackingStoreException { + // Get JavaCore default preferences + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences preferences = manager.getDefaultPreferences(); + + // verify that JavaCore default preferences for modified options + assertEquals("Invalid default for "+JavaCore.COMPILER_PB_UNUSED_LOCAL, "warning", preferences.get(JavaCore.COMPILER_PB_UNUSED_LOCAL, "null")); + assertEquals("Invalid default for "+JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, "warning", preferences.get(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, "null")); + assertEquals("Invalid default for "+JavaCore.COMPILER_PB_FIELD_HIDING, "ignore", preferences.get(JavaCore.COMPILER_PB_FIELD_HIDING, "null")); + assertEquals("Invalid default for "+JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, "ignore", preferences.get(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, "null")); +} + +/** + * @bug 125360: IJavaProject#setOption() doesn't work if same option as default + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=125360" + */ +public void testBug125360() throws CoreException, BackingStoreException { + try { + JavaProject project = (JavaProject) createJavaProject( + "P", + new String[] {}, // source folders + new String[] {}, // lib folders + new String[] {}, // projects + ""); + project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4); + project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + String option = project.getOption(JavaCore.COMPILER_SOURCE, true); + assertEquals(JavaCore.VERSION_1_3, option); + } finally { + deleteProject("P"); + } +} + +/** + * @bug 131707: Cannot add classpath variables when starting with -pluginCustomization option + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=131707" + */ +public void testBug131707() throws CoreException { + IEclipsePreferences defaultPreferences = new DefaultScope().getNode(JavaCore.PLUGIN_ID); + try { + defaultPreferences.put("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB", "c:\\temp\\lib.jar"); + simulateExitRestart(); + String[] variableNames = JavaCore.getClasspathVariableNames(); + for (int i = 0, length = variableNames.length; i < length; i++) { + if ("MY_DEFAULT_LIB".equals(variableNames[i])) { + assertEquals( + "Unexpected value for MY_DEFAULT_LIB", + new Path("c:\\temp\\lib.jar"), + JavaCore.getClasspathVariable("MY_DEFAULT_LIB")); + return; } - assertFalse("Variable MY_DEFAULT_LIB not found", true); - } finally { - defaultPreferences.remove("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB"); } + assertFalse("Variable MY_DEFAULT_LIB not found", true); + } finally { + defaultPreferences.remove("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB"); } } + +/** + * @bug 152562: [prefs] IJavaProject.setOption(..., null) does not work + * @test Verify that setting an option to null removes it from project preferences + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=152562" + */ +public void testBug152562() throws CoreException { + String wkspCompilerSource = JavaCore.getOption(JavaCore.COMPILER_SOURCE); + String compilerSource = wkspCompilerSource.equals(JavaCore.VERSION_1_5) ? JavaCore.VERSION_1_6 : JavaCore.VERSION_1_5; + try { + JavaProject project = (JavaProject) createJavaProject("P"); + project.setOption(JavaCore.COMPILER_SOURCE, compilerSource); + String option = project.getOption(JavaCore.COMPILER_SOURCE, true); + if (!option.equals(compilerSource)) { + System.err.println("Unexpected option value: "+option+" instead of: "+compilerSource); + } + project.setOption(JavaCore.COMPILER_SOURCE, null); + option = project.getOption(JavaCore.COMPILER_SOURCE, true); + assertEquals(wkspCompilerSource, option); + } finally { + deleteProject("P"); + } +} + +/** + * @bug 152578: [prefs] IJavaProject.setOption(Object,Object) wrongly removes key when value is equals to JavaCore one + * @test Verify that setting an option to workspace value does not remove it from project preferences + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=152578" + */ +public void testBug152578() throws CoreException { + Hashtable wkspOptions = JavaCore.getOptions(); + String wkspCompilerSource = (String) wkspOptions.get(JavaCore.COMPILER_SOURCE); + String compilerSource = wkspCompilerSource.equals(JavaCore.VERSION_1_5) ? JavaCore.VERSION_1_6 : JavaCore.VERSION_1_5; + try { + JavaProject project = (JavaProject) createJavaProject("P"); + project.setOption(JavaCore.COMPILER_SOURCE, wkspCompilerSource); + String option = project.getOption(JavaCore.COMPILER_SOURCE, true); + if (!option.equals(wkspCompilerSource)) { + System.err.println("Unexpected option value: "+option+" instead of: "+wkspCompilerSource); + } + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_SOURCE, compilerSource); + JavaCore.setOptions(newOptions); + option = project.getOption(JavaCore.COMPILER_SOURCE, false); + assertNotNull("Project should still have the option set!", option); + } finally { + deleteProject("P"); + JavaCore.setOptions(wkspOptions); + } +} +} Index: src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java,v retrieving revision 1.85 diff -u -r1.85 JavaProjectTests.java --- src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 8 Aug 2007 15:28:12 -0000 1.85 +++ src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 20 Aug 2007 10:10:18 -0000 @@ -1587,4 +1587,19 @@ deleteProject("P"); } } + +/** + * @bug 183923: [prefs] NPE in JavaProject#setOptions + * @test Verify that no NPE occurs when options is set on an invalid project + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=183923" + */ +public void testBug183923() throws CoreException, IOException { + try { + setUpJavaProject("JavaProjectTestsInvalidProject"); + } catch (JavaModelException jme) { + assertEquals("Unexpected JavaModelException", "JavaProjectTestsInvalidProject does not exist", jme.getMessage()); + } finally { + deleteProject("JavaProjectTestsInvalidProject"); + } +} } #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.389 diff -u -r1.389 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 24 Apr 2007 11:17:09 -0000 1.389 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 20 Aug 2007 10:10:23 -0000 @@ -1376,7 +1376,8 @@ /** * Returns the project custom preference pool. * Project preferences may include custom encoding. - * @return IEclipsePreferences + * @return IEclipsePreferences or null if the project + * does not have a java nature. */ public IEclipsePreferences getEclipsePreferences(){ if (!JavaProject.hasJavaNature(this.project)) return null; @@ -2673,11 +2674,9 @@ */ public void setOption(String optionName, String optionValue) { if (!JavaModelManager.getJavaModelManager().optionNames.contains(optionName)) return; // unrecognized option - if (optionValue == null) return; // invalid value IEclipsePreferences projectPreferences = getEclipsePreferences(); - String defaultValue = JavaCore.getOption(optionName); - if (optionValue.equals(defaultValue)) { - // set default value => remove preference + if (optionValue == null) { + // remove preference projectPreferences.remove(optionName); } else { projectPreferences.put(optionName, optionValue); @@ -2697,6 +2696,7 @@ public void setOptions(Map newOptions) { IEclipsePreferences projectPreferences = getEclipsePreferences(); + if (projectPreferences == null) return; try { if (newOptions == null){ projectPreferences.clear(); Index: model/org/eclipse/jdt/core/IJavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java,v retrieving revision 1.91 diff -u -r1.91 IJavaProject.java --- model/org/eclipse/jdt/core/IJavaProject.java 6 Mar 2007 02:38:49 -0000 1.91 +++ model/org/eclipse/jdt/core/IJavaProject.java 20 Aug 2007 10:10:22 -0000 @@ -808,13 +808,23 @@ IClasspathEntry[] readRawClasspath(); /** - * Helper method for setting one option value only. Equivalent to Map options = this.getOptions(false); map.put(optionName, optionValue); this.setOptions(map) + * Helper method for setting one option value only. + *

+ * Equivalent to: + *

+	 * 	Map options = this.getOptions(false);
+	 * 	map.put(optionName, optionValue);
+	 * 	this.setOptions(map)
+	 *  
*

* For a complete description of the configurable options, see JavaCore#getDefaultOptions. *

* * @param optionName the name of an option - * @param optionValue the value of the option to set + * @param optionValue the value of the option to set. If null, then the option + * is removed from project preferences. + * @throws NullPointerException if optionName is null + * (see {@link org.osgi.service.prefs.Preferences#put(String, String)}). * @see JavaCore#getDefaultOptions() * @since 3.0 */