View | Details | Raw Unified | Return to bug 59258 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/OptionTests.java (-395 / +437 lines)
Lines 11-427 Link Here
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.util.Hashtable;
13
import java.util.Hashtable;
14
15
import junit.framework.Test;
14
import junit.framework.Test;
16
import junit.framework.TestSuite;
15
import junit.framework.TestSuite;
17
18
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.Preferences;
17
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
21
import org.eclipse.jdt.core.IJavaProject;
19
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.JavaCore;
20
import org.eclipse.jdt.core.JavaCore;
23
import org.eclipse.jdt.internal.core.JavaProject;
21
import org.eclipse.jdt.internal.core.JavaProject;
24
22
25
public class OptionTests extends ModifyingResourceTests {
23
public class OptionTests extends ModifyingResourceTests {
26
24
	
27
int eventCount = 0;
25
	int eventCount = 0;
28
26
	
29
class TestPropertyListener implements Preferences.IPropertyChangeListener {
27
	class TestPropertyListener implements IEclipsePreferences.IPreferenceChangeListener {
30
	public void propertyChange(PropertyChangeEvent event) {
28
		public void preferenceChange(PreferenceChangeEvent event) {
31
		eventCount++;
29
			eventCount++;
30
		}
32
	}
31
	}
33
}
32
	
34
33
	public OptionTests(String name) {
35
public OptionTests(String name) {
34
		super(name);
36
	super(name);
37
}
38
public static Test suite() {
39
40
	if (false){
41
		TestSuite suite = new Suite(OptionTests.class.getName());
42
		suite.addTest(new ClasspathTests("testDenseCycleDetection"));
43
		return suite;
44
	}
45
	return new Suite(OptionTests.class);	
46
}
47
/**
48
 * Test persistence of project custom options
49
 */
50
public void test01() throws CoreException {
51
	try {
52
		IJavaProject projectA = 
53
			this.createJavaProject(
54
				"A", 
55
				new String[] {}, // source folders
56
				new String[] {}, // lib folders
57
				new String[] {}, // projects
58
				"");
59
		IJavaProject projectB = 
60
			this.createJavaProject(
61
				"B", 
62
				new String[] {}, // source folders
63
				new String[] {}, // lib folders
64
				new String[] {}, // projects
65
				"");
66
				
67
		Hashtable options = new Hashtable();
68
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
69
		options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
70
		options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
71
		JavaCore.setOptions(options);
72
73
		options.clear();
74
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
75
		options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
76
		projectA.setOptions(options);
77
78
		// check project A custom options		
79
		assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true));
80
		assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true));
81
		assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true));
82
		
83
		// check project B custom options	(should be none, indicating it sees global ones only)
84
		assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true));
85
		assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOption(JavaCore.COMPILER_COMPLIANCE, true));
86
		assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true));
87
88
		// flush custom options - project A should revert to global ones
89
		projectA.setOptions(null); 
90
		assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true));
91
		assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true));
92
		assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true));
93
94
	} finally {
95
		this.deleteProject("A");
96
		this.deleteProject("B");
97
	}
35
	}
98
}
36
	public static Test suite() {
99
37
	
100
/**
38
		if (false){
101
 * Test custom encoding
39
			TestSuite suite = new Suite(OptionTests.class.getName());
102
 */
40
			suite.addTest(new OptionTests("test02"));
103
public void test02() throws CoreException {
41
			suite.addTest(new OptionTests("test03"));
104
	try {
42
			suite.addTest(new OptionTests("test07"));
105
		IJavaProject projectA = 
43
			suite.addTest(new OptionTests("test08"));
106
			this.createJavaProject(
44
			return suite;
107
				"A", 
45
		}
108
				new String[] {}, // source folders
46
		return new Suite(OptionTests.class);	
109
				new String[] {}, // lib folders
110
				new String[] {}, // projects
111
				"");
112
		IJavaProject projectB = 
113
			this.createJavaProject(
114
				"B", 
115
				new String[] {}, // source folders
116
				new String[] {}, // lib folders
117
				new String[] {}, // projects
118
				"");
119
				
120
		String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING);
121
122
		Hashtable options = new Hashtable();
123
		options.put(JavaCore.CORE_ENCODING, "custom");
124
		projectA.setOptions(options);
125
126
		// check project A custom options		
127
		assertEquals("projA:unexpected custom encoding", "custom", projectA.getOption(JavaCore.CORE_ENCODING, true));
128
		
129
		// check project B custom options	(should be none, indicating it sees global ones only)
130
		assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOption(JavaCore.CORE_ENCODING, true));
131
132
		// flush custom options - project A should revert to global ones
133
		projectA.setOptions(null); 
134
		assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOption(JavaCore.CORE_ENCODING, true));
135
136
	} finally {
137
		this.deleteProject("A");
138
		this.deleteProject("B");
139
	}
47
	}
140
}
48
	/**
141
49
	 * Test persistence of project custom options
142
/**
50
	 */
143
 * Test custom project option (if not considering JavaCore options)
51
	public void test01() throws CoreException {
144
 */
52
		try {
145
public void test03() throws CoreException {
53
			IJavaProject projectA = 
146
	try {
54
				this.createJavaProject(
147
		IJavaProject projectA = 
55
					"A", 
148
			this.createJavaProject(
56
					new String[] {}, // source folders
149
				"A", 
57
					new String[] {}, // lib folders
150
				new String[] {}, // source folders
58
					new String[] {}, // projects
151
				new String[] {}, // lib folders
59
					"");
152
				new String[] {}, // projects
60
			IJavaProject projectB = 
153
				"");
61
				this.createJavaProject(
154
		IJavaProject projectB = 
62
					"B", 
155
			this.createJavaProject(
63
					new String[] {}, // source folders
156
				"B", 
64
					new String[] {}, // lib folders
157
				new String[] {}, // source folders
65
					new String[] {}, // projects
158
				new String[] {}, // lib folders
66
					"");
159
				new String[] {}, // projects
67
					
160
				"");
68
			Hashtable options = new Hashtable();
161
				
69
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
162
		Hashtable options = new Hashtable();
70
			options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
163
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
71
			options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
164
		options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
72
			JavaCore.setOptions(options);
165
		options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
73
	
166
		JavaCore.setOptions(options);
74
			options.clear();
167
75
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
168
		options.clear();
76
			options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
169
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
77
			projectA.setOptions(options);
170
		options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
78
	
171
		projectA.setOptions(options);
79
			// check project A custom options		
172
80
			assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true));
173
		// check project A custom options		
81
			assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true));
174
		assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false));
82
			assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true));
175
		assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false));
83
			
176
		assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false));
84
			// check project B custom options	(should be none, indicating it sees global ones only)
85
			assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true));
86
			assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOption(JavaCore.COMPILER_COMPLIANCE, true));
87
			assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true));
88
	
89
			// flush custom options - project A should revert to global ones
90
			projectA.setOptions(null); 
91
			assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, true));
92
			assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, true));
93
			assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, true));
94
	
95
		} finally {
96
			this.deleteProject("A");
97
			this.deleteProject("B");
98
		}
99
	}
100
	
101
	/**
102
	 * Test custom encoding
103
	 */
104
	public void test02() throws CoreException {
105
		try {
106
			IJavaProject projectA = 
107
				this.createJavaProject(
108
					"A", 
109
					new String[] {}, // source folders
110
					new String[] {}, // lib folders
111
					new String[] {}, // projects
112
					"");
113
			IJavaProject projectB = 
114
				this.createJavaProject(
115
					"B", 
116
					new String[] {}, // source folders
117
					new String[] {}, // lib folders
118
					new String[] {}, // projects
119
					"");
120
					
121
			String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING);
122
	
123
			Hashtable options = new Hashtable();
124
			options.put(JavaCore.CORE_ENCODING, "custom");
125
			projectA.setOptions(options);
126
	
127
			// check project A custom options		
128
			assertEquals("projA:unexpected custom encoding", "custom", projectA.getOption(JavaCore.CORE_ENCODING, true));
129
			
130
			// check project B custom options	(should be none, indicating it sees global ones only)
131
			assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOption(JavaCore.CORE_ENCODING, true));
132
	
133
			// flush custom options - project A should revert to global ones
134
			projectA.setOptions(null); 
135
			assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOption(JavaCore.CORE_ENCODING, true));
136
	
137
		} finally {
138
			this.deleteProject("A");
139
			this.deleteProject("B");
140
		}
141
	}
142
	
143
	/**
144
	 * Test custom project option (if not considering JavaCore options)
145
	 */
146
	public void test03() throws CoreException {
147
		try {
148
			IJavaProject projectA = 
149
				this.createJavaProject(
150
					"A", 
151
					new String[] {}, // source folders
152
					new String[] {}, // lib folders
153
					new String[] {}, // projects
154
					"");
155
			IJavaProject projectB = 
156
				this.createJavaProject(
157
					"B", 
158
					new String[] {}, // source folders
159
					new String[] {}, // lib folders
160
					new String[] {}, // projects
161
					"");
162
					
163
			Hashtable options = new Hashtable();
164
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
165
			options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
166
			options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
167
			JavaCore.setOptions(options);
168
	
169
			options.clear();
170
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
171
			options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
172
			projectA.setOptions(options);
173
	
174
			// check project A custom options		
175
			assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false));
176
			assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false));
177
			assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false));
178
			
179
			// check project B custom options	(should be none, indicating it sees global ones only)
180
			assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false));
181
			assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOption(JavaCore.COMPILER_COMPLIANCE, false));
182
			assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false));
183
	
184
			// flush custom options - project A should revert to global ones
185
			projectA.setOptions(null); 
186
			assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false));
187
			assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false));
188
			assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false));
189
	
190
		} finally {
191
			this.deleteProject("A");
192
			this.deleteProject("B");
193
		}
194
	}
195
	/**
196
	 * Test persistence of project custom options - using getOptions()
197
	 */
198
	public void test04() throws CoreException {
199
		try {
200
			IJavaProject projectA = 
201
				this.createJavaProject(
202
					"A", 
203
					new String[] {}, // source folders
204
					new String[] {}, // lib folders
205
					new String[] {}, // projects
206
					"");
207
			IJavaProject projectB = 
208
				this.createJavaProject(
209
					"B", 
210
					new String[] {}, // source folders
211
					new String[] {}, // lib folders
212
					new String[] {}, // projects
213
					"");
214
					
215
			Hashtable options = new Hashtable();
216
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
217
			options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
218
			options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
219
			JavaCore.setOptions(options);
220
	
221
			options.clear();
222
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
223
			options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
224
			projectA.setOptions(options);
225
	
226
			// check project A custom options		
227
			assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
228
			assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
229
			assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
230
			
231
			// check project B custom options	(should be none, indicating it sees global ones only)
232
			assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
233
			assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
234
			assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
235
	
236
			// flush custom options - project A should revert to global ones
237
			projectA.setOptions(null); 
238
			assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
239
			assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
240
			assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
241
	
242
		} finally {
243
			this.deleteProject("A");
244
			this.deleteProject("B");
245
		}
246
	}
247
	
248
	/**
249
	 * Test custom encoding - using getOptions()
250
	 */
251
	public void test05() throws CoreException {
252
		try {
253
			IJavaProject projectA = 
254
				this.createJavaProject(
255
					"A", 
256
					new String[] {}, // source folders
257
					new String[] {}, // lib folders
258
					new String[] {}, // projects
259
					"");
260
			IJavaProject projectB = 
261
				this.createJavaProject(
262
					"B", 
263
					new String[] {}, // source folders
264
					new String[] {}, // lib folders
265
					new String[] {}, // projects
266
					"");
267
					
268
			String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING);
269
	
270
			Hashtable options = new Hashtable();
271
			options.put(JavaCore.CORE_ENCODING, "custom");
272
			projectA.setOptions(options);
273
	
274
			// check project A custom options		
275
			assertEquals("projA:unexpected custom encoding", "custom", projectA.getOptions(true).get(JavaCore.CORE_ENCODING));
276
			
277
			// check project B custom options	(should be none, indicating it sees global ones only)
278
			assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOptions(true).get(JavaCore.CORE_ENCODING));
279
	
280
			// flush custom options - project A should revert to global ones
281
			projectA.setOptions(null); 
282
			assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOptions(true).get(JavaCore.CORE_ENCODING));
283
	
284
		} finally {
285
			this.deleteProject("A");
286
			this.deleteProject("B");
287
		}
288
	}
289
	
290
	/**
291
	 * Test custom project option (if not considering JavaCore options) - using getOptions()
292
	 */
293
	public void test06() throws CoreException {
294
		try {
295
			IJavaProject projectA = 
296
				this.createJavaProject(
297
					"A", 
298
					new String[] {}, // source folders
299
					new String[] {}, // lib folders
300
					new String[] {}, // projects
301
					"");
302
			IJavaProject projectB = 
303
				this.createJavaProject(
304
					"B", 
305
					new String[] {}, // source folders
306
					new String[] {}, // lib folders
307
					new String[] {}, // projects
308
					"");
309
					
310
			Hashtable options = new Hashtable();
311
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
312
			options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
313
			options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
314
			JavaCore.setOptions(options);
315
	
316
			options.clear();
317
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
318
			options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
319
			projectA.setOptions(options);
320
	
321
			// check project A custom options		
322
			assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
323
			assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
324
			assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
325
			
326
			// check project B custom options	(should be none, indicating it sees global ones only)
327
			assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
328
			assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
329
			assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
330
	
331
			// flush custom options - project A should revert to global ones
332
			projectA.setOptions(null); 
333
			assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
334
			assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
335
			assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
336
	
337
		} finally {
338
			this.deleteProject("A");
339
			this.deleteProject("B");
340
		}
341
	}
342
	/**
343
	 * Custom options must replace existing ones completely without loosing property listeners
344
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
345
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
346
	 */
347
	public void test07() throws CoreException {
348
		try {
349
			this.eventCount = 0;
350
			JavaProject projectA = (JavaProject)
351
				this.createJavaProject(
352
					"A", 
353
					new String[] {}, // source folders
354
					new String[] {}, // lib folders
355
					new String[] {}, // projects
356
					"");
357
	//		Preferences preferences = projectA.getPreferences();
358
	//		preferences.addPropertyChangeListener(new TestPropertyListener());
359
			IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences();
360
			TestPropertyListener listener = new TestPropertyListener();
361
			eclipsePreferences.addPreferenceChangeListener(listener);
177
		
362
		
178
		// check project B custom options	(should be none, indicating it sees global ones only)
363
			Hashtable options = new Hashtable();
179
		assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false));
364
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
180
		assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOption(JavaCore.COMPILER_COMPLIANCE, false));
365
			options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
181
		assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false));
366
			projectA.setOptions(options);
182
367
	
183
		// flush custom options - project A should revert to global ones
368
			// check project A custom options		
184
		projectA.setOptions(null); 
369
			assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
185
		assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOption(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, false));
370
			assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
186
		assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOption(JavaCore.COMPILER_COMPLIANCE, false));
371
			assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
187
		assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOption(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, false));
372
	//		assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences());
188
373
			assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences());
189
	} finally {
374
			assertTrue("projA:preferences property listener has been lost", eventCount == 2);
190
		this.deleteProject("A");
191
		this.deleteProject("B");
192
	}
193
}
194
/**
195
 * Test persistence of project custom options - using getOptions()
196
 */
197
public void test04() throws CoreException {
198
	try {
199
		IJavaProject projectA = 
200
			this.createJavaProject(
201
				"A", 
202
				new String[] {}, // source folders
203
				new String[] {}, // lib folders
204
				new String[] {}, // projects
205
				"");
206
		IJavaProject projectB = 
207
			this.createJavaProject(
208
				"B", 
209
				new String[] {}, // source folders
210
				new String[] {}, // lib folders
211
				new String[] {}, // projects
212
				"");
213
				
214
		Hashtable options = new Hashtable();
215
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
216
		options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
217
		options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
218
		JavaCore.setOptions(options);
219
220
		options.clear();
221
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
222
		options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
223
		projectA.setOptions(options);
224
225
		// check project A custom options		
226
		assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
227
		assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
228
		assertEquals("projA:unexpected inherited value1 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
229
		
375
		
230
		// check project B custom options	(should be none, indicating it sees global ones only)
376
			// change custom options to have one less
231
		assertEquals("projB:unexpected custom value for deprecation option", JavaCore.DISABLED, projectB.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
377
			options.clear();
232
		assertEquals("projB:unexpected custom value for compliance option", "8.0", projectB.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
378
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
233
		assertEquals("projB:unexpected inherited value for hidden-catch option", JavaCore.ERROR, projectB.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
379
			projectA.setOptions(options);
234
380
			assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
235
		// flush custom options - project A should revert to global ones
381
			assertEquals("projA:unexpected custom value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
236
		projectA.setOptions(null); 
382
			assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
237
		assertEquals("projA:unexpected reverted value for deprecation option", JavaCore.DISABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
383
	//		assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences());
238
		assertEquals("projA:unexpected reverted value for compliance option", "8.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
384
			assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences());
239
		assertEquals("projA:unexpected inherited value2 for hidden-catch option", JavaCore.ERROR, projectA.getOptions(true).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
385
			assertTrue("projA:preferences property listener has been lost", eventCount == 3);
240
386
		} finally {
241
	} finally {
387
			this.deleteProject("A");
242
		this.deleteProject("A");
388
		}
243
		this.deleteProject("B");
244
	}
389
	}
245
}
390
	/**
246
391
	 * Empty custom option must not be ignored
247
/**
392
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26251
248
 * Test custom encoding - using getOptions()
393
	 */
249
 */
394
	public void test08() throws CoreException {
250
public void test05() throws CoreException {
395
		try {
251
	try {
396
			IJavaProject projectA = 
252
		IJavaProject projectA = 
397
				this.createJavaProject(
253
			this.createJavaProject(
398
					"A", 
254
				"A", 
399
					new String[] {}, // source folders
255
				new String[] {}, // source folders
400
					new String[] {}, // lib folders
256
				new String[] {}, // lib folders
401
					new String[] {}, // projects
257
				new String[] {}, // projects
402
					"");
258
				"");
403
	
259
		IJavaProject projectB = 
404
			Hashtable options = new Hashtable();
260
			this.createJavaProject(
405
			options.put(JavaCore.COMPILER_TASK_TAGS, "TODO:");
261
				"B", 
406
			JavaCore.setOptions(options);
262
				new String[] {}, // source folders
407
			
263
				new String[] {}, // lib folders
408
	
264
				new String[] {}, // projects
409
			// check project A custom options		
265
				"");
410
			assertEquals("1#projA:unexpected custom value for task tags option", null, projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false));
266
				
411
			assertEquals("1#projA:unexpected custom value for inherited task tags option", "TODO:", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true));
267
		String globalEncoding = JavaCore.getOption(JavaCore.CORE_ENCODING);
412
			assertEquals("1#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
268
413
			
269
		Hashtable options = new Hashtable();
414
			// change custom options to have one less
270
		options.put(JavaCore.CORE_ENCODING, "custom");
415
			options.clear();
271
		projectA.setOptions(options);
416
			options.put(JavaCore.COMPILER_TASK_TAGS, "");
272
417
			projectA.setOptions(options);
273
		// check project A custom options		
418
			assertEquals("2#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false));
274
		assertEquals("projA:unexpected custom encoding", "custom", projectA.getOptions(true).get(JavaCore.CORE_ENCODING));
419
			assertEquals("2#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true));
275
		
420
			assertEquals("2#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
276
		// check project B custom options	(should be none, indicating it sees global ones only)
421
	
277
		assertEquals("projB:unexpected custom encoding", globalEncoding, projectB.getOptions(true).get(JavaCore.CORE_ENCODING));
422
			// change custom options to have one less
278
423
			options.clear();
279
		// flush custom options - project A should revert to global ones
424
			options.put(JavaCore.COMPILER_TASK_TAGS, "@TODO");
280
		projectA.setOptions(null); 
425
			JavaCore.setOptions(options);
281
		assertEquals("projA:unexpected reverted encoding", globalEncoding, projectA.getOptions(true).get(JavaCore.CORE_ENCODING));
426
			assertEquals("3#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false));
282
427
			assertEquals("3#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true));
283
	} finally {
428
			assertEquals("3#workspace:unexpected custom value for task tags option", "@TODO", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
284
		this.deleteProject("A");
429
	
285
		this.deleteProject("B");
430
		} finally {
431
			this.deleteProject("A");
432
		}
286
	}
433
	}
287
}
434
	/**
288
435
	 * Custom options must replace existing ones completely without loosing property listeners
289
/**
436
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=59258
290
 * Test custom project option (if not considering JavaCore options) - using getOptions()
437
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=60896
291
 */
438
	 */
292
public void test06() throws CoreException {
439
	public void test09() throws CoreException {
293
	try {
440
		try {
294
		IJavaProject projectA = 
441
			this.eventCount = 0;
295
			this.createJavaProject(
442
			JavaProject projectA = (JavaProject) this.createJavaProject("A", new String[] {}, "");
296
				"A", 
443
	//		Preferences preferences = projectA.getPreferences();
297
				new String[] {}, // source folders
444
	//		preferences.addPropertyChangeListener(new TestPropertyListener());
298
				new String[] {}, // lib folders
445
			IEclipsePreferences eclipsePreferences = projectA.getEclipsePreferences();
299
				new String[] {}, // projects
446
			eclipsePreferences.addPreferenceChangeListener(new TestPropertyListener());
300
				"");
301
		IJavaProject projectB = 
302
			this.createJavaProject(
303
				"B", 
304
				new String[] {}, // source folders
305
				new String[] {}, // lib folders
306
				new String[] {}, // projects
307
				"");
308
				
309
		Hashtable options = new Hashtable();
310
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.DISABLED);
311
		options.put(JavaCore.COMPILER_COMPLIANCE, "8.0");
312
		options.put(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK, JavaCore.ERROR);
313
		JavaCore.setOptions(options);
314
315
		options.clear();
316
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
317
		options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
318
		projectA.setOptions(options);
319
320
		// check project A custom options		
321
		assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
322
		assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
323
		assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
324
		
325
		// check project B custom options	(should be none, indicating it sees global ones only)
326
		assertEquals("projB:unexpected custom value for deprecation option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
327
		assertEquals("projB:unexpected custom value for compliance option", null, projectB.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
328
		assertEquals("projB:unexpected inherited value for hidden-catch option", null, projectB.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
329
330
		// flush custom options - project A should revert to global ones
331
		projectA.setOptions(null); 
332
		assertEquals("projA:unexpected reverted value for deprecation option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
333
		assertEquals("projA:unexpected reverted value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
334
		assertEquals("projA:unexpected inherited value2 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
335
336
	} finally {
337
		this.deleteProject("A");
338
		this.deleteProject("B");
339
	}
340
}
341
/**
342
 * Custom options must replace existing ones completely without loosing property listeners
343
 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
344
 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
345
 */
346
public void test07() throws CoreException {
347
	try {
348
		JavaProject projectA = (JavaProject)
349
			this.createJavaProject(
350
				"A", 
351
				new String[] {}, // source folders
352
				new String[] {}, // lib folders
353
				new String[] {}, // projects
354
				"");
355
		Preferences preferences = projectA.getPreferences();
356
		preferences.addPropertyChangeListener(new TestPropertyListener());
357
	
358
		Hashtable options = new Hashtable();
359
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
360
		options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
361
		projectA.setOptions(options);
362
363
		// check project A custom options		
364
		assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
365
		assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
366
		assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
367
		assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences());
368
		assertTrue("projA:preferences property listener has been lost", eventCount == 2);
369
	
370
		// change custom options to have one less
371
		options.clear();
372
		options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
373
		projectA.setOptions(options);
374
		assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(false).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
375
		assertEquals("projA:unexpected custom value for compliance option", null, projectA.getOptions(false).get(JavaCore.COMPILER_COMPLIANCE));
376
		assertEquals("projA:unexpected inherited value1 for hidden-catch option", null, projectA.getOptions(false).get(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK));
377
		assertTrue("projA:preferences should not be reset", preferences == projectA.getPreferences());
378
		assertTrue("projA:preferences property listener has been lost", eventCount == 3);
379
	} finally {
380
		this.deleteProject("A");
381
	}
382
}
383
/**
384
 * Empty custom option must not be ignored
385
 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26251
386
 */
387
public void test08() throws CoreException {
388
	try {
389
		IJavaProject projectA = 
390
			this.createJavaProject(
391
				"A", 
392
				new String[] {}, // source folders
393
				new String[] {}, // lib folders
394
				new String[] {}, // projects
395
				"");
396
397
		Hashtable options = new Hashtable();
398
		options.put(JavaCore.COMPILER_TASK_TAGS, "TODO:");
399
		JavaCore.setOptions(options);
400
		
447
		
401
448
			Hashtable options = new Hashtable();
402
		// check project A custom options		
449
			options.put(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, JavaCore.ENABLED);
403
		assertEquals("1#projA:unexpected custom value for task tags option", null, projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false));
450
			options.put(JavaCore.COMPILER_COMPLIANCE, "10.0");
404
		assertEquals("1#projA:unexpected custom value for inherited task tags option", "TODO:", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true));
451
			projectA.setOptions(options);
405
		assertEquals("1#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
452
	
453
			// check project A custom options		
454
			assertEquals("projA:unexpected custom value for deprecation option", JavaCore.ENABLED, projectA.getOptions(true).get(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE));
455
			assertEquals("projA:unexpected custom value for compliance option", "10.0", projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
456
			assertTrue("projA:preferences should not be reset", eclipsePreferences == projectA.getEclipsePreferences());
457
			assertEquals("projA:preferences property listener has been lost", 2, eventCount);
406
		
458
		
407
		// change custom options to have one less
459
			// delete/create project A and verify that options are well reset
408
		options.clear();
460
			this.deleteProject("A");
409
		options.put(JavaCore.COMPILER_TASK_TAGS, "");
461
			projectA = (JavaProject) this.createJavaProject("A", new String[] {}, "");
410
		projectA.setOptions(options);
462
			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));
411
		assertEquals("2#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false));
463
			assertEquals("projA:unexpected custom value for compliance option", JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE), projectA.getOptions(true).get(JavaCore.COMPILER_COMPLIANCE));
412
		assertEquals("2#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true));
464
			assertTrue("projA:preferences should not be reset", eclipsePreferences != projectA.getEclipsePreferences());
413
		assertEquals("2#workspace:unexpected custom value for task tags option", "TODO:", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
465
		} finally {
414
466
			this.deleteProject("A");
415
		// change custom options to have one less
467
		}
416
		options.clear();
417
		options.put(JavaCore.COMPILER_TASK_TAGS, "@TODO");
418
		JavaCore.setOptions(options);
419
		assertEquals("3#projA:unexpected custom value for task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, false));
420
		assertEquals("3#projA:unexpected custom value for inherited task tags option", "", projectA.getOption(JavaCore.COMPILER_TASK_TAGS, true));
421
		assertEquals("3#workspace:unexpected custom value for task tags option", "@TODO", JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
422
423
	} finally {
424
		this.deleteProject("A");
425
	}
468
	}
426
}
427
}
469
}

Return to bug 59258