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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/builder/BuilderTests.java (-21 / +52 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.builder;
11
package org.eclipse.jdt.core.tests.builder;
12
12
13
import java.util.Arrays;
13
import java.util.Enumeration;
14
import java.util.Enumeration;
14
import java.util.Hashtable;
15
import java.util.Hashtable;
15
import java.util.Vector;
16
import java.util.Vector;
Lines 192-205 Link Here
192
	/** Verifies that the given elements have no problems.
193
	/** Verifies that the given elements have no problems.
193
	 */
194
	 */
194
	protected void expectingNoProblemsFor(IPath[] roots) {
195
	protected void expectingNoProblemsFor(IPath[] roots) {
195
		if (DEBUG)
196
		StringBuffer buffer = new StringBuffer();
196
			printProblemsFor(roots);
197
		Problem[] allProblems = allSortedProblems(roots);
197
198
		if (allProblems != null) {
198
		for (int i = 0; i < roots.length; i++) {
199
			for (int i=0, length=allProblems.length; i<length; i++) {
199
			Problem[] problems = env.getProblemsFor(roots[i]);
200
				buffer.append(allProblems[i]+"\n");
200
			if (problems.length != 0)
201
			}
201
				assertTrue("unexpected problem(s) : " + problems[0], false); //$NON-NLS-1$
202
		}
202
		}
203
		String actual = buffer.toString();
204
		assumeEquals("Unexpected problem(s)!!!", "", actual); //$NON-NLS-1$
203
	}
205
	}
204
206
205
	/** Verifies that the given element has problems and
207
	/** Verifies that the given element has problems and
Lines 284-304 Link Here
284
286
285
	/** Verifies that the given element has problems.
287
	/** Verifies that the given element has problems.
286
	 */
288
	 */
287
	protected void expectingProblemsFor(IPath expected) {
289
	protected void expectingProblemsFor(IPath root, String expected) {
288
		expectingProblemsFor(new IPath[] { expected });
290
		expectingProblemsFor(new IPath[] { root }, expected);
289
	}
291
	}
290
292
291
	/** Verifies that the given elements have problems.
293
	/** Verifies that the given elements have problems.
292
	 */
294
	 */
293
	protected void expectingProblemsFor(IPath[] expected) {
295
	protected void expectingProblemsFor(IPath[] roots, String expected) {
294
		if (DEBUG)
296
		StringBuffer buffer = new StringBuffer();
295
			printProblemsFor(expected);
297
		Problem[] allProblems = allSortedProblems(roots);
296
298
		if (allProblems != null) {
297
		for (int i = 0; i < expected.length; i++) {
299
			for (int i=0, length=allProblems.length; i<length; i++) {
298
			/* get the leaf problems for this type */
300
				if (i>0) buffer.append('\n');
299
			Problem[] problems = env.getProblemsFor(expected[i]);
301
				buffer.append(allProblems[i]);
300
			assertTrue("missing expected problem with " + expected[i].toString(), problems.length > 0); //$NON-NLS-1$
302
			}
301
		}
303
		}
304
		String actual = buffer.toString();
305
		assumeEquals("Invalid problem(s)!!!", expected, actual); //$NON-NLS-1$
302
	}
306
	}
303
307
304
	/** Verifies that the given element has a specific problem.
308
	/** Verifies that the given element has a specific problem.
Lines 325-334 Link Here
325
					}
329
					}
326
				}
330
				}
327
			}
331
			}
328
			System.out.println("--------------------------------------------------------------------------------");
329
			System.out.println("Missing problem while running test "+getName()+":");
330
			System.out.println("	- expected : " + problem);
331
			System.out.println("	- current: " + problemsToString(rootProblems));
332
			/*
332
			/*
333
			for (int j = 0; j < rootProblems.length; j++) {
333
			for (int j = 0; j < rootProblems.length; j++) {
334
				Problem pb = rootProblems[j];
334
				Problem pb = rootProblems[j];
Lines 339-344 Link Here
339
				}
339
				}
340
			}
340
			}
341
			*/
341
			*/
342
			System.out.println("--------------------------------------------------------------------------------");
343
			System.out.println("Missing problem while running test "+getName()+":");
344
			System.out.println("	- expected : " + problem);
345
			System.out.println("	- current: " + problemsToString(rootProblems));
342
			assumeTrue("missing expected problem: " + problem, false);
346
			assumeTrue("missing expected problem: " + problem, false);
343
		}
347
		}
344
	}
348
	}
Lines 429-434 Link Here
429
		super.tearDown();
433
		super.tearDown();
430
	}
434
	}
431
435
436
	/**
437
	 * Concatenate and sort all problems for given root paths.
438
	 * 
439
	 * @param roots The path to get the problems
440
	 * @return All sorted problems of all given path
441
	 */
442
	Problem[] allSortedProblems(IPath[] roots) {
443
		Problem[] allProblems = null;
444
		for (int i = 0, max=roots.length; i<max; i++) {
445
			Problem[] problems = env.getProblemsFor(roots[i]);
446
			int length = problems.length;
447
			if (problems.length != 0) {
448
				if (allProblems == null) {
449
					allProblems = problems;
450
				} else {
451
					int all = allProblems.length;
452
					System.arraycopy(allProblems, 0, allProblems = new Problem[all+length], 0, all);
453
					System.arraycopy(problems, 0, allProblems , all, length);
454
				}
455
			}
456
		}
457
		if (allProblems != null) {
458
			Arrays.sort(allProblems);
459
		}
460
		return allProblems;
461
	}
462
432
	public static Test suite() {
463
	public static Test suite() {
433
		TestSuite suite = new TestSuite();
464
		TestSuite suite = new TestSuite();
434
465
(-)src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java (-5 / +19 lines)
Lines 57-63 Link Here
57
			"class CC {}"); 
57
			"class CC {}"); 
58
58
59
		incrementalBuild(projectPath);
59
		incrementalBuild(projectPath);
60
		expectingProblemsFor(new IPath[]{ pathToD });
60
		expectingProblemsFor(
61
			pathToD,
62
			"Problem : The type CC is already defined [ resource : </Project/src/p/D.java> range : <37,39> category : <-1> severity : <2>]"
63
		);
61
		expectingSpecificProblemsFor(pathToD, new Problem[] {new Problem("", "The type CC is already defined", pathToD, 37, 39, -1, IMarker.SEVERITY_ERROR)});
64
		expectingSpecificProblemsFor(pathToD, new Problem[] {new Problem("", "The type CC is already defined", pathToD, 37, 39, -1, IMarker.SEVERITY_ERROR)});
62
	}
65
	}
63
66
Lines 183-189 Link Here
183
			"public class C extends B { }"); //$NON-NLS-1$
186
			"public class C extends B { }"); //$NON-NLS-1$
184
187
185
		incrementalBuild(projectPath);
188
		incrementalBuild(projectPath);
186
		expectingProblemsFor(new IPath[]{ pathToA, pathToB, pathToC });
189
		expectingProblemsFor(
190
			new IPath[]{ pathToA, pathToB, pathToC },
191
			"Problem : The public type _A must be defined in its own file [ resource : </Project/src/p/A.java> range : <25,27> category : <40> severity : <2>]\n" + 
192
			"Problem : A cannot be resolved to a type [ resource : </Project/src/p/B.java> range : <35,36> category : <40> severity : <2>]\n" + 
193
			"Problem : The hierarchy of the type C is inconsistent [ resource : </Project/src/p/C.java> range : <25,26> category : <40> severity : <2>]"
194
		);
187
		expectingSpecificProblemFor(pathToA, new Problem("_A", "The public type _A must be defined in its own file", pathToA, 25, 27, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
195
		expectingSpecificProblemFor(pathToA, new Problem("_A", "The public type _A must be defined in its own file", pathToA, 25, 27, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
188
		expectingSpecificProblemFor(pathToB, new Problem("B", "A cannot be resolved to a type", pathToB, 35, 36, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
196
		expectingSpecificProblemFor(pathToB, new Problem("B", "A cannot be resolved to a type", pathToB, 35, 36, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
189
		expectingSpecificProblemFor(pathToC, new Problem("C", "The hierarchy of the type C is inconsistent", pathToC, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
197
		expectingSpecificProblemFor(pathToC, new Problem("C", "The hierarchy of the type C is inconsistent", pathToC, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
Lines 252-258 Link Here
252
			"}"); //$NON-NLS-1$
260
			"}"); //$NON-NLS-1$
253
261
254
		incrementalBuild(projectPath);
262
		incrementalBuild(projectPath);
255
		expectingProblemsFor(new IPath[]{ pathToAB });
263
		expectingProblemsFor(
264
			pathToAB,
265
			"Problem : AZ cannot be resolved to a type [ resource : </Project/src/p/AB.java> range : <36,38> category : <40> severity : <2>]"
266
		);
256
		expectingSpecificProblemFor(pathToAB, new Problem("AB", "AZ cannot be resolved to a type", pathToAB, 36, 38, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
267
		expectingSpecificProblemFor(pathToAB, new Problem("AB", "AZ cannot be resolved to a type", pathToAB, 36, 38, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
257
268
258
		env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$
269
		env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$
Lines 319-325 Link Here
319
			"}"); //$NON-NLS-1$
330
			"}"); //$NON-NLS-1$
320
331
321
		incrementalBuild(projectPath);
332
		incrementalBuild(projectPath);
322
		expectingProblemsFor(new IPath[]{ pathToBB });
333
		expectingProblemsFor(
334
			pathToBB,
335
			"Problem : ZA cannot be resolved to a type [ resource : </Project/src/p/BB.java> range : <104,106> category : <40> severity : <2>]"
336
		);
323
		expectingSpecificProblemFor(pathToBB, new Problem("BB.foo()", "ZA cannot be resolved to a type", pathToBB, 104, 106, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
337
		expectingSpecificProblemFor(pathToBB, new Problem("BB.foo()", "ZA cannot be resolved to a type", pathToBB, 104, 106, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
324
338
325
		env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$
339
		env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$
Lines 619-625 Link Here
619
			);
633
			);
620
			
634
			
621
		incrementalBuild();
635
		incrementalBuild();
622
		expectingProblemsFor(x);
636
		expectingProblemsFor(x, "???");
623
		expectingNoPresenceOf(bin.append("X.class")); //$NON-NLS-1$
637
		expectingNoPresenceOf(bin.append("X.class")); //$NON-NLS-1$
624
	}
638
	}
625
639
(-)src/org/eclipse/jdt/core/tests/builder/BasicBuildTests.java (+93 lines)
Lines 19-28 Link Here
19
import org.eclipse.core.resources.IMarker;
19
import org.eclipse.core.resources.IMarker;
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
22
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.JavaCore;
24
import org.eclipse.jdt.core.JavaCore;
24
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.JavaModelException;
26
import org.eclipse.jdt.core.compiler.CategorizedProblem;
25
import org.eclipse.jdt.core.tests.util.Util;
27
import org.eclipse.jdt.core.tests.util.Util;
28
import org.eclipse.jdt.internal.core.JavaModelManager;
26
29
27
/**
30
/**
28
 * Basic tests of the image builder.
31
 * Basic tests of the image builder.
Lines 417-420 Link Here
417
		fullBuild(projectPath);
420
		fullBuild(projectPath);
418
		expectingNoProblems();
421
		expectingNoProblems();
419
	}
422
	}
423
424
	/**
425
	 * @bug 75471: [prefs] no re-compile when loading settings
426
	 * @test Ensure that changing project preferences is well taking into account while rebuilding project
427
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=75471"
428
	 */
429
	public void _testUpdateProjectPreferences() throws JavaModelException {
430
		
431
		IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
432
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
433
434
		// remove old package fragment root so that names don't collide
435
		env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
436
437
		IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
438
		env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
439
440
		env.addClass(root, "util", "MyException", //$NON-NLS-1$ //$NON-NLS-2$
441
			"package util;\n" + 
442
			"public class MyException extends Exception {\n" + 
443
			"	private static final long serialVersionUID = 1L;\n" +
444
			"}"
445
		); //$NON-NLS-1$
446
447
		IPath cuPath = env.addClass(root, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
448
			"package p;\n" + 
449
			"import util.MyException;\n" + 
450
			"public class Test {\n" + 
451
			"}"
452
		);
453
454
		fullBuild(projectPath);
455
		expectingSpecificProblemFor(
456
			projectPath,
457
			new Problem("", "The import util.MyException is never used", cuPath, 18, 34, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$
458
459
		IJavaProject project = env.getJavaProject(projectPath);
460
		project.setOption(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.IGNORE);
461
		incrementalBuild(projectPath);
462
		expectingNoProblems();
463
	}
464
	public void _testUpdateWkspPreferences() throws JavaModelException {
465
		
466
		IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
467
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
468
469
		// remove old package fragment root so that names don't collide
470
		env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
471
472
		IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
473
		env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
474
475
		env.addClass(root, "util", "MyException", //$NON-NLS-1$ //$NON-NLS-2$
476
			"package util;\n" + 
477
			"public class MyException extends Exception {\n" + 
478
			"	private static final long serialVersionUID = 1L;\n" +
479
			"}"
480
		); //$NON-NLS-1$
481
482
		IPath cuPath = env.addClass(root, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
483
			"package p;\n" + 
484
			"import util.MyException;\n" + 
485
			"public class Test {\n" + 
486
			"}"
487
		);
488
489
		fullBuild();
490
		expectingSpecificProblemFor(
491
			projectPath,
492
			new Problem("", "The import util.MyException is never used", cuPath, 18, 34, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$
493
494
		// Save preference
495
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
496
		IEclipsePreferences preferences = manager.getInstancePreferences();
497
		String unusedImport = preferences.get(JavaCore.COMPILER_PB_UNUSED_IMPORT, null);
498
		try {
499
			// Modify preference
500
			preferences.put(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.IGNORE);
501
			incrementalBuild();
502
			expectingNoProblems();
503
		}
504
		finally {
505
			if (unusedImport == null) {
506
				preferences.remove(JavaCore.COMPILER_PB_UNUSED_IMPORT);
507
			} else {
508
				preferences.put(JavaCore.COMPILER_PB_UNUSED_IMPORT, unusedImport);
509
			}
510
		}
511
	}
512
	
420
}
513
}
(-)src/org/eclipse/jdt/core/tests/builder/DependencyTests.java (-1 / +4 lines)
Lines 268-274 Link Here
268
268
269
		// build -> expecting problems
269
		// build -> expecting problems
270
		fullBuild();
270
		fullBuild();
271
		expectingProblemsFor(classTest);
271
		expectingProblemsFor(
272
			classTest,
273
			"Problem : The method bar() is undefined for the type Y [ resource : </Project/p/X.java> range : <57,60> category : <50> severity : <2>]"
274
		);
272
275
273
		try {
276
		try {
274
			Thread.sleep(1000);
277
			Thread.sleep(1000);
(-)src/org/eclipse/jdt/core/tests/builder/Java50Tests.java (-3 / +12 lines)
Lines 54-60 Link Here
54
		);
54
		);
55
55
56
		incrementalBuild(projectPath);
56
		incrementalBuild(projectPath);
57
		expectingProblemsFor(usePath);
57
		expectingProblemsFor(
58
			usePath,
59
			"Problem : The annotation @Ann is disallowed for this location [ resource : </Project/p/Use.java> range : <11,17> category : <40> severity : <2>]"
60
		);
58
	}
61
	}
59
	
62
	
60
	public void testParameterizedType1() throws JavaModelException {
63
	public void testParameterizedType1() throws JavaModelException {
Lines 92-98 Link Here
92
		);
95
		);
93
96
94
		incrementalBuild(projectPath);
97
		incrementalBuild(projectPath);
95
		expectingProblemsFor(usePath);
98
		expectingProblemsFor(
99
			usePath,
100
			"Problem : The method foo(List<Object>) in the type Other is not applicable for the arguments (ArrayList<String>) [ resource : </Project/p/Use.java> range : <104,107> category : <50> severity : <2>]"
101
		);
96
	}
102
	}
97
	
103
	
98
	public void testParameterizedType2() throws JavaModelException {
104
	public void testParameterizedType2() throws JavaModelException {
Lines 130-136 Link Here
130
		);
136
		);
131
137
132
		incrementalBuild(projectPath);
138
		incrementalBuild(projectPath);
133
		expectingProblemsFor(usePath);
139
		expectingProblemsFor(
140
			usePath,
141
			"Problem : Unhandled exception type Exception [ resource : </Project/p/Use.java> range : <92,132> category : <40> severity : <2>]"
142
		);
134
	}
143
	}
135
	
144
	
136
}
145
}
(-)src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java (-452 / +568 lines)
Lines 15-20 Link Here
15
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.resources.IMarker;
16
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18
import org.eclipse.jdt.core.*;
19
import org.eclipse.jdt.core.*;
19
import org.eclipse.jdt.core.compiler.CategorizedProblem;
20
import org.eclipse.jdt.core.compiler.CategorizedProblem;
20
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
21
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
Lines 28-469 Link Here
28
29
29
public class BuildpathTests extends BuilderTests {
30
public class BuildpathTests extends BuilderTests {
30
31
31
	public BuildpathTests(String name) {
32
public BuildpathTests(String name) {
32
		super(name);
33
	super(name);
33
	}
34
}
34
35
	public static Test suite() {
36
		return buildTestSuite(BuildpathTests.class);
37
	}
38
	public void testClasspathFileChange() throws JavaModelException {
39
		// create project with src folder, and alternate unused src2 folder
40
		IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
41
		env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
42
		IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
43
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
44
		env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
45
		IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$
46
			"package p1;\n"+ //$NON-NLS-1$
47
			"public class Test1 extends Zork1 {}" //$NON-NLS-1$
48
		);
49
		// not yet on the classpath
50
		IPath src2Path = env.addFolder(projectPath, "src2"); //$NON-NLS-1$
51
		IPath src2p1Path = env.addFolder(src2Path, "p1"); //$NON-NLS-1$
52
		env.addFile(src2p1Path, "Zork1.java", //$NON-NLS-1$ //$NON-NLS-2$
53
			"package p1;\n"+ //$NON-NLS-1$
54
			"public class Zork1 {}" //$NON-NLS-1$
55
		);
56
57
		fullBuild();
58
		expectingSpecificProblemFor(classTest1, new Problem("src", "Zork1 cannot be resolved to a type", classTest1,39, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
59
35
60
		//----------------------------
36
public static Test suite() {
61
		//           Step 2
37
	return buildTestSuite(BuildpathTests.class);
62
		//----------------------------	
38
}
63
		StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
64
		buffer.append("<classpath>\n"); //$NON-NLS-1$
65
		buffer.append("    <classpathentry kind=\"src\" path=\"src\"/>\n"); //$NON-NLS-1$
66
		buffer.append("    <classpathentry kind=\"src\" path=\"src2\"/>\n"); // add src2 on classpath through resource change //$NON-NLS-1$
67
		String[] classlibs = Util.getJavaClassLibs();
68
		for (int i = 0; i < classlibs.length; i++) {
69
			buffer.append("    <classpathentry kind=\"lib\" path=\"").append(classlibs[i]).append("\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
70
		}
71
		buffer.append("    <classpathentry kind=\"output\" path=\"bin\"/>\n"); //$NON-NLS-1$
72
		buffer.append("</classpath>"); //$NON-NLS-1$
73
		boolean wasAutoBuilding = env.isAutoBuilding();
74
		try {
75
			// turn autobuild on
76
			env.setAutoBuilding(true);
77
			// write new .classpath, will trigger autobuild
78
			env.addFile(projectPath, ".classpath", buffer.toString()); //$NON-NLS-1$
79
			// ensures the builder did see the classpath change
80
			env.waitForAutoBuild();
81
			expectingNoProblems();
82
		} finally {
83
			env.setAutoBuilding(wasAutoBuilding);
84
		}
85
	}	
86
39
87
	public void testClosedProject() throws JavaModelException {
40
private String getJdkLevelProblem(String expectedRuntime, String path, int severity) {
88
		IPath project1Path = env.addProject("CP1"); //$NON-NLS-1$
41
	Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
89
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
42
	long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
90
		IPath jarPath = env.addInternalJar(project1Path, "temp.jar", new byte[] {0}); //$NON-NLS-1$
43
	String jclRuntime = CompilerOptions.versionFromJdkLevel(libraryJDK);
91
44
	StringBuffer jdkLevelProblem = new StringBuffer("Problem : Incompatible .class files version in required binaries. Project 'Project' is targeting a ");
92
		IPath project2Path = env.addProject("CP2"); //$NON-NLS-1$
45
	jdkLevelProblem.append(expectedRuntime);
93
		env.addExternalJars(project2Path, Util.getJavaClassLibs());
46
	jdkLevelProblem.append(" runtime, but is compiled against '");
94
		env.addRequiredProject(project2Path, project1Path);
47
	jdkLevelProblem.append(path);
95
48
	jdkLevelProblem.append("' which requires a ");
96
		IPath project3Path = env.addProject("CP3"); //$NON-NLS-1$
49
	jdkLevelProblem.append(jclRuntime);
97
		env.addExternalJars(project3Path, Util.getJavaClassLibs());
50
	jdkLevelProblem.append(" runtime [ resource : </Project> range : <-1,-1> category : <10> severity : <");
98
		env.addExternalJar(project3Path, jarPath.toString());
51
	jdkLevelProblem.append(severity);
52
	jdkLevelProblem.append(">]");
53
	return jdkLevelProblem.toString();
54
}
99
55
100
		fullBuild();
56
public void testClasspathFileChange() throws JavaModelException {
101
		expectingNoProblems();
57
	// create project with src folder, and alternate unused src2 folder
58
	IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
59
	env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
60
	IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
61
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
62
	env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
63
	IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$
64
		"package p1;\n"+ //$NON-NLS-1$
65
		"public class Test1 extends Zork1 {}" //$NON-NLS-1$
66
	);
67
	// not yet on the classpath
68
	IPath src2Path = env.addFolder(projectPath, "src2"); //$NON-NLS-1$
69
	IPath src2p1Path = env.addFolder(src2Path, "p1"); //$NON-NLS-1$
70
	env.addFile(src2p1Path, "Zork1.java", //$NON-NLS-1$ //$NON-NLS-2$
71
		"package p1;\n"+ //$NON-NLS-1$
72
		"public class Zork1 {}" //$NON-NLS-1$
73
	);
102
74
103
		//----------------------------
75
	fullBuild();
104
		//           Step 2
76
	expectingSpecificProblemFor(classTest1, new Problem("src", "Zork1 cannot be resolved to a type", classTest1,39, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
105
		//----------------------------
106
		env.closeProject(project1Path);
107
77
108
		incrementalBuild();
78
	//----------------------------
109
		expectingOnlyProblemsFor(new IPath[] {project2Path, project3Path});
79
	//           Step 2
110
		expectingOnlySpecificProblemsFor(project2Path,
80
	//----------------------------	
111
			new Problem[] {
81
	StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
112
				new Problem("", "The project cannot be built until build path errors are resolved", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
82
	buffer.append("<classpath>\n"); //$NON-NLS-1$
113
				new Problem("Build path", "Project 'CP2' is missing required Java project: 'CP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
83
	buffer.append("    <classpathentry kind=\"src\" path=\"src\"/>\n"); //$NON-NLS-1$
114
			}
84
	buffer.append("    <classpathentry kind=\"src\" path=\"src2\"/>\n"); // add src2 on classpath through resource change //$NON-NLS-1$
115
		);
85
	String[] classlibs = Util.getJavaClassLibs();
116
		expectingOnlySpecificProblemsFor(project3Path,
86
	for (int i = 0; i < classlibs.length; i++) {
117
			new Problem[] {
87
		buffer.append("    <classpathentry kind=\"lib\" path=\"").append(classlibs[i]).append("\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
118
				new Problem("", "The project cannot be built until build path errors are resolved", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
88
	}
119
				new Problem("Build path", "Project 'CP3' is missing required library: '/CP1/temp.jar'", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
89
	buffer.append("    <classpathentry kind=\"output\" path=\"bin\"/>\n"); //$NON-NLS-1$
120
			}
90
	buffer.append("</classpath>"); //$NON-NLS-1$
121
		);
91
	boolean wasAutoBuilding = env.isAutoBuilding();
92
	try {
93
		// turn autobuild on
94
		env.setAutoBuilding(true);
95
		// write new .classpath, will trigger autobuild
96
		env.addFile(projectPath, ".classpath", buffer.toString()); //$NON-NLS-1$
97
		// ensures the builder did see the classpath change
98
		env.waitForAutoBuild();
99
		expectingNoProblems();
100
	} finally {
101
		env.setAutoBuilding(wasAutoBuilding);
102
	}
103
}	
104
105
public void testClosedProject() throws JavaModelException {
106
	IPath project1Path = env.addProject("CP1"); //$NON-NLS-1$
107
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
108
	IPath jarPath = env.addInternalJar(project1Path, "temp.jar", new byte[] {0}); //$NON-NLS-1$
109
110
	IPath project2Path = env.addProject("CP2"); //$NON-NLS-1$
111
	env.addExternalJars(project2Path, Util.getJavaClassLibs());
112
	env.addRequiredProject(project2Path, project1Path);
113
114
	IPath project3Path = env.addProject("CP3"); //$NON-NLS-1$
115
	env.addExternalJars(project3Path, Util.getJavaClassLibs());
116
	env.addExternalJar(project3Path, jarPath.toString());
122
117
123
		env.openProject(project1Path);
118
	fullBuild();
124
		incrementalBuild();
119
	expectingNoProblems();
125
		expectingNoProblems();
126
120
127
		//----------------------------
121
	//----------------------------
128
		//           Step 3
122
	//           Step 2
129
		//----------------------------
123
	//----------------------------
130
		Hashtable options = JavaCore.getOptions();
124
	env.closeProject(project1Path);
131
		options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE);
132
		JavaCore.setOptions(options);
133
		env.closeProject(project1Path);
134
125
135
		incrementalBuild();
126
	incrementalBuild();
136
		expectingOnlyProblemsFor(new IPath[] {project2Path, project3Path});
127
	expectingOnlyProblemsFor(new IPath[] {project2Path, project3Path});
137
		expectingOnlySpecificProblemFor(project2Path,
128
	expectingOnlySpecificProblemsFor(project2Path,
129
		new Problem[] {
130
			new Problem("", "The project cannot be built until build path errors are resolved", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
138
			new Problem("Build path", "Project 'CP2' is missing required Java project: 'CP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
131
			new Problem("Build path", "Project 'CP2' is missing required Java project: 'CP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
139
		);
132
		}
140
		expectingOnlySpecificProblemFor(project3Path,
133
	);
134
	expectingOnlySpecificProblemsFor(project3Path,
135
		new Problem[] {
136
			new Problem("", "The project cannot be built until build path errors are resolved", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
141
			new Problem("Build path", "Project 'CP3' is missing required library: '/CP1/temp.jar'", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
137
			new Problem("Build path", "Project 'CP3' is missing required library: '/CP1/temp.jar'", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
142
		);
138
		}
139
	);
143
140
144
		env.openProject(project1Path);
141
	env.openProject(project1Path);
145
		incrementalBuild();
142
	incrementalBuild();
146
		expectingNoProblems();
143
	expectingNoProblems();
147
144
148
		options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ABORT);
145
	//----------------------------
149
		JavaCore.setOptions(options);
146
	//           Step 3
150
	}
147
	//----------------------------
148
	Hashtable options = JavaCore.getOptions();
149
	options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE);
150
	JavaCore.setOptions(options);
151
	env.closeProject(project1Path);
151
152
152
	public void testCorruptBuilder() throws JavaModelException {
153
	incrementalBuild();
153
		IPath project1Path = env.addProject("P1"); //$NON-NLS-1$
154
	expectingOnlyProblemsFor(new IPath[] {project2Path, project3Path});
154
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
155
	expectingOnlySpecificProblemFor(project2Path,
155
156
		new Problem("Build path", "Project 'CP2' is missing required Java project: 'CP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
156
		env.addClass(project1Path, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
157
	);
157
			"package p;" + //$NON-NLS-1$
158
	expectingOnlySpecificProblemFor(project3Path,
158
			"public class Test {}" //$NON-NLS-1$
159
		new Problem("Build path", "Project 'CP3' is missing required library: '/CP1/temp.jar'", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
159
		);
160
	);
160
161
161
		fullBuild();
162
	env.openProject(project1Path);
162
		expectingNoProblems();
163
	incrementalBuild();
164
	expectingNoProblems();
163
165
164
		IPath outputFolderPackage = env.getOutputLocation(project1Path).append("p"); //$NON-NLS-1$
166
	options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ABORT);
165
		env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
167
	JavaCore.setOptions(options);
168
}
166
169
167
		IPath subTest = env.addClass(project1Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
170
public void testCorruptBuilder() throws JavaModelException {
168
			"public class SubTest extends p.Test {}" //$NON-NLS-1$
171
	IPath project1Path = env.addProject("P1"); //$NON-NLS-1$
169
		);
172
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
173
174
	env.addClass(project1Path, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
175
		"package p;" + //$NON-NLS-1$
176
		"public class Test {}" //$NON-NLS-1$
177
	);
170
178
171
		incrementalBuild();
179
	fullBuild();
172
		expectingOnlySpecificProblemFor(subTest, new Problem("", "p.Test cannot be resolved to a type", subTest, 29, 35, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$)
180
	expectingNoProblems();
173
181
174
		env.addClass(project1Path, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
182
	IPath outputFolderPackage = env.getOutputLocation(project1Path).append("p"); //$NON-NLS-1$
175
			"package p;" + //$NON-NLS-1$
183
	env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
176
			"public class Test {}" //$NON-NLS-1$
177
		);
178
184
179
		fullBuild();
185
	IPath subTest = env.addClass(project1Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
180
		expectingNoProblems();
186
		"public class SubTest extends p.Test {}" //$NON-NLS-1$
187
	);
181
188
182
		Hashtable options = JavaCore.getOptions();
189
	incrementalBuild();
183
		options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.ENABLED);
190
	expectingOnlySpecificProblemFor(subTest, new Problem("", "p.Test cannot be resolved to a type", subTest, 29, 35, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$)
184
		JavaCore.setOptions(options);
185
191
186
		env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
192
	env.addClass(project1Path, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
193
		"package p;" + //$NON-NLS-1$
194
		"public class Test {}" //$NON-NLS-1$
195
	);
187
196
188
		incrementalBuild();
197
	fullBuild();
189
		expectingNoProblems();
198
	expectingNoProblems();
190
199
191
		options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.IGNORE);
200
	Hashtable options = JavaCore.getOptions();
192
		JavaCore.setOptions(options);
201
	options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.ENABLED);
193
	}
202
	JavaCore.setOptions(options);
194
203
195
	public void testCorruptBuilder2() throws JavaModelException {
204
	env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
196
		IPath project1Path = env.addProject("P1"); //$NON-NLS-1$
197
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
198
		env.removePackageFragmentRoot(project1Path, ""); //$NON-NLS-1$
199
		IPath src = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$
200
		IPath bin = env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$
201
202
		env.addClass(src, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
203
			"package p;" + //$NON-NLS-1$
204
			"public class Test {}" //$NON-NLS-1$
205
		);
206
205
207
		fullBuild();
206
	incrementalBuild();
208
		expectingNoProblems();
207
	expectingNoProblems();
209
208
210
		IPath outputFolderPackage = bin.append("p"); //$NON-NLS-1$
209
	options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.IGNORE);
211
		env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
210
	JavaCore.setOptions(options);
211
}
212
212
213
		IPath subTest = env.addClass(src, "p2", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
213
public void testCorruptBuilder2() throws JavaModelException {
214
			"package p2;" + //$NON-NLS-1$
214
	IPath project1Path = env.addProject("P1"); //$NON-NLS-1$
215
			"public class SubTest extends p.Test {}" //$NON-NLS-1$
215
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
216
		);
216
	env.removePackageFragmentRoot(project1Path, ""); //$NON-NLS-1$
217
	IPath src = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$
218
	IPath bin = env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$
219
220
	env.addClass(src, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
221
		"package p;" + //$NON-NLS-1$
222
		"public class Test {}" //$NON-NLS-1$
223
	);
217
224
218
		incrementalBuild();
225
	fullBuild();
219
		expectingOnlySpecificProblemFor(subTest, new Problem("", "p.Test cannot be resolved to a type", subTest, 40, 46, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$)
226
	expectingNoProblems();
220
227
221
		env.addClass(src, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
228
	IPath outputFolderPackage = bin.append("p"); //$NON-NLS-1$
222
			"package p;" + //$NON-NLS-1$
229
	env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
223
			"public class Test {}" //$NON-NLS-1$
224
		);
225
230
226
		fullBuild();
231
	IPath subTest = env.addClass(src, "p2", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
227
		expectingNoProblems();
232
		"package p2;" + //$NON-NLS-1$
233
		"public class SubTest extends p.Test {}" //$NON-NLS-1$
234
	);
228
235
229
		Hashtable options = JavaCore.getOptions();
236
	incrementalBuild();
230
		options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.ENABLED);
237
	expectingOnlySpecificProblemFor(subTest, new Problem("", "p.Test cannot be resolved to a type", subTest, 40, 46, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$)
231
		JavaCore.setOptions(options);
232
238
233
		env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
239
	env.addClass(src, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$
240
		"package p;" + //$NON-NLS-1$
241
		"public class Test {}" //$NON-NLS-1$
242
	);
234
243
235
		incrementalBuild();
244
	fullBuild();
236
		expectingNoProblems();
245
	expectingNoProblems();
237
246
238
		options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.IGNORE);
247
	Hashtable options = JavaCore.getOptions();
239
		JavaCore.setOptions(options);
248
	options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.ENABLED);
240
	}
249
	JavaCore.setOptions(options);
241
250
242
	/*
251
	env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$
243
	 * Ensures that changing an external jar and refreshing the projects triggers a rebuild
244
	 * (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states)
245
	 */
246
	public void testExternalJarChange() throws JavaModelException, IOException {
247
		// setup
248
		IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
249
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
250
		IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
251
		IPath classTest = env.addClass(root, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$
252
			"package p;\n"+ //$NON-NLS-1$
253
			"public class X {\n" + //$NON-NLS-1$
254
			"  void foo() {\n" + //$NON-NLS-1$
255
			"    new q.Y().bar();\n" + //$NON-NLS-1$
256
			"  }\n" + //$NON-NLS-1$
257
			"}" //$NON-NLS-1$
258
		);
259
		String externalJar = Util.getOutputDirectory() + File.separator + "test.jar"; //$NON-NLS-1$
260
		Util.createJar(
261
			new String[] {
262
				"q/Y.java", //$NON-NLS-1$
263
				"package q;\n" + //$NON-NLS-1$
264
				"public class Y {\n" + //$NON-NLS-1$
265
				"}" //$NON-NLS-1$
266
			},
267
			new HashMap(),
268
			externalJar
269
		);
270
		long lastModified = new java.io.File(externalJar).lastModified();
271
		env.addExternalJar(projectPath, externalJar);
272
		
273
		// build -> expecting problems
274
		fullBuild();
275
		expectingProblemsFor(classTest);
276
		
277
		try {
278
			Thread.sleep(1000);
279
		} catch(InterruptedException e) {
280
		}
281
		// fix jar
282
		Util.createJar(
283
			new String[] {
284
				"q/Y.java", //$NON-NLS-1$
285
				"package q;\n" + //$NON-NLS-1$
286
				"public class Y {\n" + //$NON-NLS-1$
287
				"  public void bar() {\n" + //$NON-NLS-1$
288
				"  }\n" + //$NON-NLS-1$
289
				"}" //$NON-NLS-1$
290
			},
291
			new HashMap(),
292
			externalJar
293
		);
294
		
295
		new java.io.File(externalJar).setLastModified(lastModified + 1000); // to be sure its different
296
		// refresh project and rebuild -> expecting no problems
297
		IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject("Project")); //$NON-NLS-1$
298
		project.getJavaModel().refreshExternalArchives(new IJavaElement[] {project}, null);
299
		incrementalBuild();
300
		expectingNoProblems();
301
		
302
	}
303
252
304
	public void testMissingBuilder() throws JavaModelException {
253
	incrementalBuild();
305
		IPath project1Path = env.addProject("P1"); //$NON-NLS-1$
254
	expectingNoProblems();
306
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
307
308
		IPath project2Path = env.addProject("P2"); //$NON-NLS-1$
309
		env.addExternalJars(project2Path, Util.getJavaClassLibs());
310
		env.addRequiredProject(project2Path, project1Path);
311
255
312
		env.addClass(project1Path, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$
256
	options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.IGNORE);
313
			"public class Test {}" //$NON-NLS-1$
257
	JavaCore.setOptions(options);
314
		);
258
}
315
259
316
		IPath sub = env.addClass(project2Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
260
/*
317
			"public class SubTest extends Test {}" //$NON-NLS-1$
261
 * Ensures that changing an external jar and refreshing the projects triggers a rebuild
318
		);
262
 * (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states)
263
 */
264
public void testExternalJarChange() throws JavaModelException, IOException {
265
	// setup
266
	IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
267
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
268
	IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
269
	IPath classTest = env.addClass(root, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$
270
		"package p;\n"+ //$NON-NLS-1$
271
		"public class X {\n" + //$NON-NLS-1$
272
		"  void foo() {\n" + //$NON-NLS-1$
273
		"    new q.Y().bar();\n" + //$NON-NLS-1$
274
		"  }\n" + //$NON-NLS-1$
275
		"}" //$NON-NLS-1$
276
	);
277
	String externalJar = Util.getOutputDirectory() + File.separator + "test.jar"; //$NON-NLS-1$
278
	Util.createJar(
279
		new String[] {
280
			"q/Y.java", //$NON-NLS-1$
281
			"package q;\n" + //$NON-NLS-1$
282
			"public class Y {\n" + //$NON-NLS-1$
283
			"}" //$NON-NLS-1$
284
		},
285
		new HashMap(),
286
		externalJar
287
	);
288
	long lastModified = new java.io.File(externalJar).lastModified();
289
	env.addExternalJar(projectPath, externalJar);
290
	
291
	// build -> expecting problems
292
	fullBuild();
293
	expectingProblemsFor(
294
		classTest,
295
		"Problem : The method bar() is undefined for the type Y [ resource : </Project/p/X.java> range : <57,60> category : <50> severity : <2>]"
296
	);
297
	
298
	try {
299
		Thread.sleep(1000);
300
	} catch(InterruptedException e) {
301
	}
302
	// fix jar
303
	Util.createJar(
304
		new String[] {
305
			"q/Y.java", //$NON-NLS-1$
306
			"package q;\n" + //$NON-NLS-1$
307
			"public class Y {\n" + //$NON-NLS-1$
308
			"  public void bar() {\n" + //$NON-NLS-1$
309
			"  }\n" + //$NON-NLS-1$
310
			"}" //$NON-NLS-1$
311
		},
312
		new HashMap(),
313
		externalJar
314
	);
315
	
316
	new java.io.File(externalJar).setLastModified(lastModified + 1000); // to be sure its different
317
	// refresh project and rebuild -> expecting no problems
318
	IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject("Project")); //$NON-NLS-1$
319
	project.getJavaModel().refreshExternalArchives(new IJavaElement[] {project}, null);
320
	incrementalBuild();
321
	expectingNoProblems();
322
	
323
}
319
324
320
		fullBuild();
325
public void testMissingBuilder() throws JavaModelException {
321
		expectingNoProblems();
326
	IPath project1Path = env.addProject("P1"); //$NON-NLS-1$
327
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
328
329
	IPath project2Path = env.addProject("P2"); //$NON-NLS-1$
330
	env.addExternalJars(project2Path, Util.getJavaClassLibs());
331
	env.addRequiredProject(project2Path, project1Path);
322
332
323
		env.removeRequiredProject(project2Path, project1Path);
333
	env.addClass(project1Path, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$
334
		"public class Test {}" //$NON-NLS-1$
335
	);
324
336
325
		incrementalBuild();
337
	IPath sub = env.addClass(project2Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
326
		expectingOnlySpecificProblemFor(sub, new Problem("", "Test cannot be resolved to a type", sub, 29, 33, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$)
338
		"public class SubTest extends Test {}" //$NON-NLS-1$
339
	);
327
340
328
		env.addRequiredProject(project2Path, project1Path);
341
	fullBuild();
342
	expectingNoProblems();
329
343
330
		try {
344
	env.removeRequiredProject(project2Path, project1Path);
331
			JavaProject p = (JavaProject) env.getJavaProject(project1Path);
332
			p.deconfigure();
333
			JavaModelManager.getJavaModelManager().setLastBuiltState(p.getProject(), null);
334
		} catch (CoreException e) {
335
			e.printStackTrace();
336
		}
337
345
338
		env.addClass(project2Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
346
	incrementalBuild();
339
			"public class SubTest extends Test {}" //$NON-NLS-1$
347
	expectingOnlySpecificProblemFor(sub, new Problem("", "Test cannot be resolved to a type", sub, 29, 33, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$)
340
		);
341
348
342
		incrementalBuild();
349
	env.addRequiredProject(project2Path, project1Path);
343
		expectingNoProblems();
344
	}
345
350
346
	public void testMissingFieldType() throws JavaModelException {
351
	try {
347
		IPath projectPath = env.addProject("Project1"); //$NON-NLS-1$
352
		JavaProject p = (JavaProject) env.getJavaProject(project1Path);
348
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
353
		p.deconfigure();
349
		IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
354
		JavaModelManager.getJavaModelManager().setLastBuiltState(p.getProject(), null);
350
		env.addClass(root, "p1", "Test", //$NON-NLS-1$ //$NON-NLS-2$
355
	} catch (CoreException e) {
351
			"package p1;\n"+ //$NON-NLS-1$
356
		e.printStackTrace();
352
			"public class Test {}" //$NON-NLS-1$
357
	}
353
		);
354
358
355
		fullBuild();
359
	env.addClass(project2Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$
356
		expectingNoProblems();
360
		"public class SubTest extends Test {}" //$NON-NLS-1$
361
	);
357
362
358
		IPath projectPath2 = env.addProject("Project2"); //$NON-NLS-1$
363
	incrementalBuild();
359
		env.addExternalJars(projectPath2, Util.getJavaClassLibs());
364
	expectingNoProblems();
360
		env.addRequiredProject(projectPath2, projectPath);
365
}
361
		IPath root2 = env.getPackageFragmentRootPath(projectPath2, ""); //$NON-NLS-1$
362
		env.addClass(root2, "p2", "Test2", //$NON-NLS-1$ //$NON-NLS-2$
363
			"package p2;\n"+ //$NON-NLS-1$
364
			"public class Test2 {\n" + //$NON-NLS-1$
365
			"	public static p1.Test field;\n" + //$NON-NLS-1$
366
			"}" //$NON-NLS-1$
367
		);
368
366
369
		incrementalBuild();
367
public void testMissingFieldType() throws JavaModelException {
370
		expectingNoProblems();
368
	IPath projectPath = env.addProject("Project1"); //$NON-NLS-1$
369
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
370
	IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
371
	env.addClass(root, "p1", "Test", //$NON-NLS-1$ //$NON-NLS-2$
372
		"package p1;\n"+ //$NON-NLS-1$
373
		"public class Test {}" //$NON-NLS-1$
374
	);
371
375
372
		IPath projectPath3 = env.addProject("Project3"); //$NON-NLS-1$
376
	fullBuild();
373
		env.addExternalJars(projectPath3, Util.getJavaClassLibs());
377
	expectingNoProblems();
374
		env.addRequiredProject(projectPath3, projectPath2);
375
		IPath root3 = env.getPackageFragmentRootPath(projectPath3, ""); //$NON-NLS-1$
376
		env.addClass(root3, "p3", "Test3", //$NON-NLS-1$ //$NON-NLS-2$
377
			"package p3;\n"+ //$NON-NLS-1$
378
			"public class Test3 extends p2.Test2 {\n" + //$NON-NLS-1$
379
			"	static Object field;\n" + //$NON-NLS-1$
380
			"}" //$NON-NLS-1$
381
		);
382
378
383
		incrementalBuild();
379
	IPath projectPath2 = env.addProject("Project2"); //$NON-NLS-1$
384
		expectingNoProblems();
380
	env.addExternalJars(projectPath2, Util.getJavaClassLibs());
385
	}
381
	env.addRequiredProject(projectPath2, projectPath);
382
	IPath root2 = env.getPackageFragmentRootPath(projectPath2, ""); //$NON-NLS-1$
383
	env.addClass(root2, "p2", "Test2", //$NON-NLS-1$ //$NON-NLS-2$
384
		"package p2;\n"+ //$NON-NLS-1$
385
		"public class Test2 {\n" + //$NON-NLS-1$
386
		"	public static p1.Test field;\n" + //$NON-NLS-1$
387
		"}" //$NON-NLS-1$
388
	);
386
389
387
	public void testMissingLibrary1() throws JavaModelException {
390
	incrementalBuild();
388
		IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
391
	expectingNoProblems();
389
		env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
390
		IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
391
		IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
392
		IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$
393
			"package p1;\n"+ //$NON-NLS-1$
394
			"public class Test1 {}" //$NON-NLS-1$
395
		);
396
392
397
		fullBuild();
393
	IPath projectPath3 = env.addProject("Project3"); //$NON-NLS-1$
398
		expectingOnlyProblemsFor(new IPath[] {projectPath, classTest1});
394
	env.addExternalJars(projectPath3, Util.getJavaClassLibs());
399
		expectingOnlySpecificProblemsFor(projectPath,
395
	env.addRequiredProject(projectPath3, projectPath2);
400
			new Problem[] {
396
	IPath root3 = env.getPackageFragmentRootPath(projectPath3, ""); //$NON-NLS-1$
401
				new Problem("", "The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
397
	env.addClass(root3, "p3", "Test3", //$NON-NLS-1$ //$NON-NLS-2$
402
				new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
398
		"package p3;\n"+ //$NON-NLS-1$
403
			}
399
		"public class Test3 extends p2.Test2 {\n" + //$NON-NLS-1$
404
		);
400
		"	static Object field;\n" + //$NON-NLS-1$
401
		"}" //$NON-NLS-1$
402
	);
405
403
406
		//----------------------------
404
	incrementalBuild();
407
		//           Step 2
405
	expectingNoProblems();
408
		//----------------------------	
406
}
409
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
410
407
411
		incrementalBuild();
408
public void testMissingLibrary1() throws JavaModelException {
412
		expectingNoProblems();
409
	IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
413
		expectingPresenceOf(new IPath[]{
410
	env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
414
			bin.append("p1").append("Test1.class"), //$NON-NLS-1$ //$NON-NLS-2$
411
	IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
415
		});
412
	IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
416
	}
413
	IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$
417
	
414
		"package p1;\n"+ //$NON-NLS-1$
418
	public void testMissingLibrary2() throws JavaModelException {
415
		"public class Test1 {}" //$NON-NLS-1$
419
		IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
416
	);
420
		env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
421
		IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
422
		IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
423
		IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$
424
			"package p1;\n"+ //$NON-NLS-1$
425
			"public class Test1 {}" //$NON-NLS-1$
426
		);
427
		IPath classTest2 = env.addClass(root, "p2", "Test2", //$NON-NLS-1$ //$NON-NLS-2$
428
			"package p2;\n"+ //$NON-NLS-1$
429
			"public class Test2 {}" //$NON-NLS-1$
430
		);
431
		IPath classTest3 = env.addClass(root, "p2", "Test3", //$NON-NLS-1$ //$NON-NLS-2$
432
			"package p2;\n"+ //$NON-NLS-1$
433
			"public class Test3 {}" //$NON-NLS-1$
434
		);
435
417
436
		fullBuild();
418
	fullBuild();
437
		expectingSpecificProblemFor(
419
	expectingOnlyProblemsFor(new IPath[] {projectPath, classTest1});
438
			projectPath,
420
	expectingOnlySpecificProblemsFor(projectPath,
439
			new Problem("", "The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
421
		new Problem[] {
440
		
422
			new Problem("", "The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
441
		Problem[] prob1 = env.getProblemsFor(classTest1);
423
			new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
442
		Problem[] prob2 = env.getProblemsFor(classTest2);
443
		Problem[] prob3 = env.getProblemsFor(classTest3);
444
		assertEquals("too many problems", prob1.length + prob2.length + prob3.length, 1); //$NON-NLS-1$
445
		if(prob1.length == 1) {
446
			expectingSpecificProblemFor(classTest1, new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, -1, -1, -1, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
447
		} else if (prob2.length == 1) {
448
			expectingSpecificProblemFor(classTest2, new Problem("p2", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest2, -1, -1, -1, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
449
		} else {
450
			expectingSpecificProblemFor(classTest3, new Problem("p2", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest3, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
451
		}
424
		}
425
	);
452
426
453
		//----------------------------
427
	//----------------------------
454
		//           Step 2
428
	//           Step 2
455
		//----------------------------	
429
	//----------------------------	
456
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
430
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
457
431
458
		incrementalBuild();
432
	incrementalBuild();
459
		expectingNoProblems();
433
	expectingNoProblems();
460
		expectingPresenceOf(new IPath[]{
434
	expectingPresenceOf(new IPath[]{
461
			bin.append("p1").append("Test1.class"), //$NON-NLS-1$ //$NON-NLS-2$
435
		bin.append("p1").append("Test1.class"), //$NON-NLS-1$ //$NON-NLS-2$
462
			bin.append("p2").append("Test2.class"), //$NON-NLS-1$ //$NON-NLS-2$
436
	});
463
			bin.append("p2").append("Test3.class") //$NON-NLS-1$ //$NON-NLS-2$
437
	env.removeProject(projectPath);
464
		});
438
}
439
440
public void testMissingLibrary2() throws JavaModelException {
441
	IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
442
	env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
443
	IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
444
	IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
445
	IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$
446
		"package p1;\n"+ //$NON-NLS-1$
447
		"public class Test1 {}" //$NON-NLS-1$
448
	);
449
	IPath classTest2 = env.addClass(root, "p2", "Test2", //$NON-NLS-1$ //$NON-NLS-2$
450
		"package p2;\n"+ //$NON-NLS-1$
451
		"public class Test2 {}" //$NON-NLS-1$
452
	);
453
	IPath classTest3 = env.addClass(root, "p2", "Test3", //$NON-NLS-1$ //$NON-NLS-2$
454
		"package p2;\n"+ //$NON-NLS-1$
455
		"public class Test3 {}" //$NON-NLS-1$
456
	);
457
458
	fullBuild();
459
	expectingSpecificProblemFor(
460
		projectPath,
461
		new Problem("", "The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
462
	
463
	Problem[] prob1 = env.getProblemsFor(classTest1);
464
	Problem[] prob2 = env.getProblemsFor(classTest2);
465
	Problem[] prob3 = env.getProblemsFor(classTest3);
466
	assertEquals("too many problems", prob1.length + prob2.length + prob3.length, 1); //$NON-NLS-1$
467
	if(prob1.length == 1) {
468
		expectingSpecificProblemFor(classTest1, new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, -1, -1, -1, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
469
	} else if (prob2.length == 1) {
470
		expectingSpecificProblemFor(classTest2, new Problem("p2", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest2, -1, -1, -1, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
471
	} else {
472
		expectingSpecificProblemFor(classTest3, new Problem("p2", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest3, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
465
	}
473
	}
466
474
475
	//----------------------------
476
	//           Step 2
477
	//----------------------------	
478
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
479
480
	incrementalBuild();
481
	expectingNoProblems();
482
	expectingPresenceOf(new IPath[]{
483
		bin.append("p1").append("Test1.class"), //$NON-NLS-1$ //$NON-NLS-2$
484
		bin.append("p2").append("Test2.class"), //$NON-NLS-1$ //$NON-NLS-2$
485
		bin.append("p2").append("Test3.class") //$NON-NLS-1$ //$NON-NLS-2$
486
	});
487
	env.removeProject(projectPath);
488
}
489
467
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
490
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
468
public void testMissingLibrary3() throws JavaModelException {
491
public void testMissingLibrary3() throws JavaModelException {
469
	this.abortOnFailure = false; // this test is failing on some releng boxes => do not abort on failures
492
	this.abortOnFailure = false; // this test is failing on some releng boxes => do not abort on failures
Lines 491-496 Link Here
491
	expectingSpecificProblemFor(
514
	expectingSpecificProblemFor(
492
		projectPath,
515
		projectPath,
493
		new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR));
516
		new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR));
517
	env.removeProject(projectPath);
494
}
518
}
495
	
519
	
496
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
520
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
Lines 509-621 Link Here
509
		projectPath,
533
		projectPath,
510
		new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR));
534
		new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR));
511
	project.setOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, CompilerOptions.WARNING);
535
	project.setOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, CompilerOptions.WARNING);
512
	cleanBuild();
536
	incrementalBuild();
513
	expectingSpecificProblemFor(
537
	expectingSpecificProblemFor(
514
		projectPath,
538
		projectPath,
515
		new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH,
539
		new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH,
516
				IMarker.SEVERITY_WARNING));
540
				IMarker.SEVERITY_WARNING));
541
	env.removeProject(projectPath);
517
}
542
}
543
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
544
public void testIncompatibleJdkLEvelOnProject() throws JavaModelException {
545
	this.abortOnFailure = false; // NOT sure this test will pass on releng boxes => do not abort on failures
518
	
546
	
519
	public void testMissingProject() throws JavaModelException {
547
	// Create project
520
		IPath project1Path = env.addProject("MP1"); //$NON-NLS-1$
548
	IPath projectPath = env.addProject("Project");
521
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
549
	IJavaProject project = env.getJavaProject(projectPath);
522
550
	String[] classlibs = Util.getJavaClassLibs();
523
		IPath project2Path = env.addProject("MP2"); //$NON-NLS-1$
551
	env.addExternalJars(projectPath, classlibs);
524
		env.addExternalJars(project2Path, Util.getJavaClassLibs());
552
	
525
		env.addRequiredProject(project2Path, project1Path);
553
	// Build it expecting no problem
554
	fullBuild();
555
	expectingNoProblems();
556
557
	// Build incompatible jdk level problem string
558
	String jclPath = project.getPackageFragmentRoot(classlibs[0]).getPath().makeRelative().toString();
559
	String projectRuntime = project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true);
560
561
	// Change project incompatible jdk level preferences to warning, perform incremental build and expect 1 problem
562
	project.setOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, CompilerOptions.WARNING);
563
	incrementalBuild();
564
	expectingProblemsFor(
565
		projectPath,
566
		getJdkLevelProblem(projectRuntime, jclPath, IMarker.SEVERITY_WARNING)
567
	);
526
568
569
	// Change project incompatible jdk level preferences to error, perform incremental build and expect 2 problems
570
	project.setOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, CompilerOptions.ERROR);
571
	incrementalBuild();
572
	expectingProblemsFor(
573
		projectPath,
574
		"Problem : The project cannot be built until build path errors are resolved [ resource : </Project> range : <-1,-1> category : <10> severity : <2>]\n" + 
575
		getJdkLevelProblem(projectRuntime, jclPath, IMarker.SEVERITY_ERROR)
576
	);
577
	
578
	// Remove project to avoid side effect on other tests
579
	env.removeProject(projectPath);
580
}
581
582
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
583
public void testIncompatibleJdkLEvelOnWksp() throws JavaModelException {
584
585
	// Save preference
586
	JavaModelManager manager = JavaModelManager.getJavaModelManager();
587
	IEclipsePreferences preferences = manager.getInstancePreferences();
588
	String incompatibleJdkLevel = preferences.get(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, null);
589
	try {
590
		this.abortOnFailure = false; // NOT sure this test will pass on all releng boxes => do not abort on failures
591
		
592
		// Create project
593
		IPath projectPath = env.addProject("Project");
594
		IJavaProject project = env.getJavaProject(projectPath);
595
		String[] classlibs = Util.getJavaClassLibs();
596
		env.addExternalJars(projectPath, classlibs);
597
		
598
		// Build it expecting no problem
527
		fullBuild();
599
		fullBuild();
528
		expectingNoProblems();
600
		expectingNoProblems();
529
601
530
		//----------------------------
602
		// Build incompatible jdk level problem string
531
		//           Step 2
603
		String jclPath = project.getPackageFragmentRoot(classlibs[0]).getPath().makeRelative().toString();
532
		//----------------------------
604
		String wkspRuntime = JavaCore.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
533
		env.removeProject(project1Path);
605
		
534
606
		// Change workspace  incompatible jdk level preferences to warning, perform incremental build and expect 1 problem
607
		preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.WARNING);
535
		incrementalBuild();
608
		incrementalBuild();
536
		expectingOnlyProblemsFor(project2Path);
609
		expectingProblemsFor(
537
		expectingOnlySpecificProblemsFor(project2Path,
610
			projectPath,
538
			new Problem[] {
611
			getJdkLevelProblem(wkspRuntime, jclPath, IMarker.SEVERITY_WARNING)
539
				new Problem("", "The project cannot be built until build path errors are resolved", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
612
		);
540
				new Problem("Build path", "Project 'MP2' is missing required Java project: 'MP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
613
		
541
			}
614
		// Change workspace incompatible jdk level preferences to error, perform incremental build and expect 2 problems
615
		preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.ERROR);
616
		incrementalBuild();
617
		expectingProblemsFor(
618
			projectPath,
619
			"Problem : The project cannot be built until build path errors are resolved [ resource : </Project> range : <-1,-1> category : <10> severity : <2>]\n" + 
620
			getJdkLevelProblem(wkspRuntime, jclPath, IMarker.SEVERITY_ERROR)
542
		);
621
		);
622
		
623
		// Remove project to avoid side effect on other tests
624
		env.removeProject(projectPath);
625
	} finally {
626
		// Put back workspace preferences same as before running the test
627
		if (incompatibleJdkLevel == null) {
628
			preferences.remove(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL);
629
		} else {
630
			preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, incompatibleJdkLevel);
631
		}
632
	}
633
}
543
634
544
		project1Path = env.addProject("MP1"); //$NON-NLS-1$
635
public void testMissingProject() throws JavaModelException {
545
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
636
	IPath project1Path = env.addProject("MP1"); //$NON-NLS-1$
637
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
638
639
	IPath project2Path = env.addProject("MP2"); //$NON-NLS-1$
640
	env.addExternalJars(project2Path, Util.getJavaClassLibs());
641
	env.addRequiredProject(project2Path, project1Path);
546
642
547
		incrementalBuild();
643
	fullBuild();
548
		expectingNoProblems();
644
	expectingNoProblems();
549
645
550
		//----------------------------
646
	//----------------------------
551
		//           Step 3
647
	//           Step 2
552
		//----------------------------
648
	//----------------------------
553
		Hashtable options = JavaCore.getOptions();
649
	env.removeProject(project1Path);
554
		options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE);
555
		JavaCore.setOptions(options);
556
		env.removeProject(project1Path);
557
650
558
		incrementalBuild();
651
	incrementalBuild();
559
		expectingOnlyProblemsFor(project2Path);
652
	expectingOnlyProblemsFor(project2Path);
560
		expectingOnlySpecificProblemFor(project2Path,
653
	expectingOnlySpecificProblemsFor(project2Path,
654
		new Problem[] {
655
			new Problem("", "The project cannot be built until build path errors are resolved", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$
561
			new Problem("Build path", "Project 'MP2' is missing required Java project: 'MP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
656
			new Problem("Build path", "Project 'MP2' is missing required Java project: 'MP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
562
		);
657
		}
658
	);
563
659
564
		project1Path = env.addProject("MP1"); //$NON-NLS-1$
660
	project1Path = env.addProject("MP1"); //$NON-NLS-1$
565
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
661
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
566
662
567
		incrementalBuild();
663
	incrementalBuild();
568
		expectingNoProblems();
664
	expectingNoProblems();
569
665
570
		options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ABORT);
666
	//----------------------------
571
		JavaCore.setOptions(options);
667
	//           Step 3
572
	}
668
	//----------------------------
573
	
669
	Hashtable options = JavaCore.getOptions();
574
	public void testMissingOptionalProject() throws JavaModelException {
670
	options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE);
575
		IPath project1Path = env.addProject("MP1"); //$NON-NLS-1$
671
	JavaCore.setOptions(options);
576
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
672
	env.removeProject(project1Path);
577
578
		IPath project2Path = env.addProject("MP2"); //$NON-NLS-1$
579
		env.addExternalJars(project2Path, Util.getJavaClassLibs());
580
		env.addRequiredProject(project2Path, project1Path, true/*optional*/);
581
673
582
		fullBuild();
674
	incrementalBuild();
583
		expectingNoProblems();
675
	expectingOnlyProblemsFor(project2Path);
676
	expectingOnlySpecificProblemFor(project2Path,
677
		new Problem("Build path", "Project 'MP2' is missing required Java project: 'MP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
678
	);
584
679
585
		//----------------------------
680
	project1Path = env.addProject("MP1"); //$NON-NLS-1$
586
		//           Step 2
681
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
587
		//----------------------------
588
		env.removeProject(project1Path);
589
682
590
		incrementalBuild();
683
	incrementalBuild();
591
		expectingNoProblems();
684
	expectingNoProblems();
592
685
593
		project1Path = env.addProject("MP1"); //$NON-NLS-1$
686
	options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ABORT);
594
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
687
	JavaCore.setOptions(options);
688
}
595
689
596
		incrementalBuild();
690
public void testMissingOptionalProject() throws JavaModelException {
597
		expectingNoProblems();
691
	IPath project1Path = env.addProject("MP1"); //$NON-NLS-1$
692
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
693
694
	IPath project2Path = env.addProject("MP2"); //$NON-NLS-1$
695
	env.addExternalJars(project2Path, Util.getJavaClassLibs());
696
	env.addRequiredProject(project2Path, project1Path, true/*optional*/);
598
697
599
		//----------------------------
698
	fullBuild();
600
		//           Step 3
699
	expectingNoProblems();
601
		//----------------------------
602
		Hashtable options = JavaCore.getOptions();
603
		options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE);
604
		JavaCore.setOptions(options);
605
		env.removeProject(project1Path);
606
700
607
		incrementalBuild();
701
	//----------------------------
608
		expectingNoProblems();
702
	//           Step 2
703
	//----------------------------
704
	env.removeProject(project1Path);
609
705
610
		project1Path = env.addProject("MP1"); //$NON-NLS-1$
706
	incrementalBuild();
611
		env.addExternalJars(project1Path, Util.getJavaClassLibs());
707
	expectingNoProblems();
612
708
613
		incrementalBuild();
709
	project1Path = env.addProject("MP1"); //$NON-NLS-1$
614
		expectingNoProblems();
710
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
615
711
616
		options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ABORT);
712
	incrementalBuild();
617
		JavaCore.setOptions(options);
713
	expectingNoProblems();
618
	}
714
715
	//----------------------------
716
	//           Step 3
717
	//----------------------------
718
	Hashtable options = JavaCore.getOptions();
719
	options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE);
720
	JavaCore.setOptions(options);
721
	env.removeProject(project1Path);
722
723
	incrementalBuild();
724
	expectingNoProblems();
725
726
	project1Path = env.addProject("MP1"); //$NON-NLS-1$
727
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
728
729
	incrementalBuild();
730
	expectingNoProblems();
731
732
	options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ABORT);
733
	JavaCore.setOptions(options);
734
}
619
735
620
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132
736
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132
621
public void test0100() throws JavaModelException {
737
public void test0100() throws JavaModelException {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java (-1 lines)
Lines 28-34 Link Here
28
	static final String LINE_SEPARATOR = System.getProperty("line.separator");
28
	static final String LINE_SEPARATOR = System.getProperty("line.separator");
29
	public static ArrayList ALL_CLASSES = null;
29
	public static ArrayList ALL_CLASSES = null;
30
	static final String DOC_COMMENT_SUPPORT = System.getProperty("doc.support");
30
	static final String DOC_COMMENT_SUPPORT = System.getProperty("doc.support");
31
	static boolean debug = false;
32
31
33
	// Javadoc execution
32
	// Javadoc execution
34
	protected static final String JAVADOC_NAME = 
33
	protected static final String JAVADOC_NAME = 
(-)src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java (-5 / +28 lines)
Lines 17-23 Link Here
17
import java.util.*;
17
import java.util.*;
18
18
19
import org.eclipse.jdt.core.Flags;
19
import org.eclipse.jdt.core.Flags;
20
import org.eclipse.jdt.core.tests.util.Util;
20
import org.eclipse.jdt.internal.compiler.batch.Main;
21
import org.eclipse.jdt.internal.compiler.batch.Main;
22
import org.eclipse.test.performance.Performance;
21
import org.eclipse.test.performance.PerformanceTestCase;
23
import org.eclipse.test.performance.PerformanceTestCase;
22
24
23
import junit.framework.AssertionFailedError;
25
import junit.framework.AssertionFailedError;
Lines 239-249 Link Here
239
 * Otherwise, the thrown exception {@link AssertionFailedError} is catched
241
 * Otherwise, the thrown exception {@link AssertionFailedError} is catched
240
 * and its message is only displayed in the console hence producing no JUnit failure.
242
 * and its message is only displayed in the console hence producing no JUnit failure.
241
 */
243
 */
242
protected void assumeEquals(String msg, Object expected, Object actual) {
244
protected void assumeEquals(String msg, String expected, String actual) {
243
	try {
245
	try {
244
		assertEquals(msg, expected, actual);
246
		assertStringEquals(msg, expected, actual, false);
247
	} catch (ComparisonFailure cf) {
248
		System.out.println("Failure while running test "+Performance.getDefault().getDefaultScenarioId(this)+"!!!");
249
		System.out.println("Actual output is:");
250
		System.out.println(Util.displayString(cf.getActual(), 2));
251
		System.out.println();
252
		if (abortOnFailure) {
253
			throw cf;
254
		}
245
	} catch (AssertionFailedError afe) {
255
	} catch (AssertionFailedError afe) {
246
		if (abortOnFailure) throw afe;
256
		if (abortOnFailure) {
257
			throw afe;
258
		}
247
		printAssertionFailure(afe);
259
		printAssertionFailure(afe);
248
	}
260
	}
249
}
261
}
Lines 257-271 Link Here
257
protected void assumeTrue(String msg, boolean cond) {
269
protected void assumeTrue(String msg, boolean cond) {
258
	try {
270
	try {
259
		assertTrue(msg, cond);
271
		assertTrue(msg, cond);
272
	} catch (ComparisonFailure cf) {
273
		if (abortOnFailure) {
274
			System.out.println("Failure while running test "+Performance.getDefault().getDefaultScenarioId(this)+"!!!");
275
			System.out.println("Actual output is:");
276
			System.out.println(Util.displayString(cf.getActual(), 2));
277
			System.out.println();
278
			throw cf;
279
		}
280
		printAssertionFailure(cf);
260
	} catch (AssertionFailedError afe) {
281
	} catch (AssertionFailedError afe) {
261
		if (abortOnFailure) throw afe;
282
		if (abortOnFailure) {
283
			throw afe;
284
		}
262
		printAssertionFailure(afe);
285
		printAssertionFailure(afe);
263
	}
286
	}
264
}
287
}
265
288
266
private void printAssertionFailure(AssertionFailedError afe) {
289
private void printAssertionFailure(AssertionFailedError afe) {
267
	System.out.println("\n!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!");
290
	System.out.println("\n!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!");
268
	System.out.println("Catched assertion while running test "+getName()+":");
291
	System.out.println("Catched assertion failure while running test "+getName()+":");
269
	System.out.println("	"+afe.getMessage());
292
	System.out.println("	"+afe.getMessage());
270
	System.out.println("--------------------------------------------------------------------------------\n");
293
	System.out.println("--------------------------------------------------------------------------------\n");
271
}
294
}
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-43 / +55 lines)
Lines 18-23 Link Here
18
import java.util.Hashtable;
18
import java.util.Hashtable;
19
import java.util.Iterator;
19
import java.util.Iterator;
20
import java.util.Map;
20
import java.util.Map;
21
import java.util.StringTokenizer;
22
21
import javax.xml.parsers.DocumentBuilder;
23
import javax.xml.parsers.DocumentBuilder;
22
import javax.xml.parsers.DocumentBuilderFactory;
24
import javax.xml.parsers.DocumentBuilderFactory;
23
import javax.xml.parsers.ParserConfigurationException;
25
import javax.xml.parsers.ParserConfigurationException;
Lines 1386-1429 Link Here
1386
		return null;
1388
		return null;
1387
	}
1389
	}
1388
1390
1389
	/**
1391
		/**
1390
	 * Returns the project custom preference pool.
1392
    	 * Returns the project custom preference pool.
1391
	 * Project preferences may include custom encoding.
1393
    	 * Project preferences may include custom encoding.
1392
	 * @return IEclipsePreferences
1394
    	 * @return IEclipsePreferences
1393
	 */
1395
    	 */
1394
	public IEclipsePreferences getEclipsePreferences(){
1396
    	public IEclipsePreferences getEclipsePreferences(){
1395
		if (!JavaProject.hasJavaNature(this.project)) return null;
1397
    		if (!JavaProject.hasJavaNature(this.project)) return null;
1396
		// Get cached preferences if exist
1398
    		// Get cached preferences if exist
1397
		JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
1399
    		JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
1398
		if (perProjectInfo.preferences != null) return perProjectInfo.preferences;
1400
    		if (perProjectInfo.preferences != null) return perProjectInfo.preferences;
1399
		// Init project preferences
1401
    		// Init project preferences
1400
		IScopeContext context = new ProjectScope(getProject());
1402
    		IScopeContext context = new ProjectScope(getProject());
1401
		final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
1403
    		final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
1402
		updatePreferences(eclipsePreferences);
1404
    		updatePreferences(eclipsePreferences);
1403
		perProjectInfo.preferences = eclipsePreferences;
1405
    		perProjectInfo.preferences = eclipsePreferences;
1404
1406
    
1405
		// Listen to node removal from parent in order to reset cache (see bug 68993)
1407
    		// Listen to node removal from parent in order to reset cache (see bug 68993)
1406
		IEclipsePreferences.INodeChangeListener nodeListener = new IEclipsePreferences.INodeChangeListener() {
1408
    		IEclipsePreferences.INodeChangeListener nodeListener = new IEclipsePreferences.INodeChangeListener() {
1407
			public void added(IEclipsePreferences.NodeChangeEvent event) {
1409
    			public void added(IEclipsePreferences.NodeChangeEvent event) {
1408
				// do nothing
1410
    				// do nothing
1409
			}
1411
    			}
1410
			public void removed(IEclipsePreferences.NodeChangeEvent event) {
1412
    			public void removed(IEclipsePreferences.NodeChangeEvent event) {
1411
				if (event.getChild() == eclipsePreferences) {
1413
    				if (event.getChild() == eclipsePreferences) {
1412
					JavaModelManager.getJavaModelManager().resetProjectPreferences(JavaProject.this);
1414
    					JavaModelManager.getJavaModelManager().resetProjectPreferences(JavaProject.this);
1413
				}
1415
    				}
1414
			}
1416
    			}
1415
		};
1417
    		};
1416
		((IEclipsePreferences) eclipsePreferences.parent()).addNodeChangeListener(nodeListener);
1418
    		((IEclipsePreferences) eclipsePreferences.parent()).addNodeChangeListener(nodeListener);
1417
1419
    
1418
		// Listen to preference changes
1420
    		// Listen to preference changes
1419
		IEclipsePreferences.IPreferenceChangeListener preferenceListener = new IEclipsePreferences.IPreferenceChangeListener() {
1421
    		IEclipsePreferences.IPreferenceChangeListener preferenceListener = new IEclipsePreferences.IPreferenceChangeListener() {
1420
			public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
1422
    			public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
1421
				JavaModelManager.getJavaModelManager().resetProjectOptions(JavaProject.this);
1423
    				JavaModelManager manager = JavaModelManager.getJavaModelManager();
1422
			}
1424
    				int length = JavaCore.PLUGIN_ID.length() + 1;
1423
		};
1425
    				String key = event.getKey();
1424
		eclipsePreferences.addPreferenceChangeListener(preferenceListener);
1426
    				StringTokenizer tokenizer = new StringTokenizer(key.substring(length));
1425
		return eclipsePreferences;
1427
    				String token = tokenizer.nextToken();
1426
	}
1428
    				if (key.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) ||
1429
    					token.equals("builder") || //$NON-NLS-1$
1430
    					key.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) ||
1431
    					key.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) ||
1432
    					key.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL) ||
1433
    					token.equals("classpath")) //$NON-NLS-1$
1434
    				{
1435
    					manager.deltaState.addClasspathValidation(JavaProject.this);
1436
    				}
1437
    				manager.resetProjectOptions(JavaProject.this);
1438
    			}
1439
    		};
1440
    		eclipsePreferences.addPreferenceChangeListener(preferenceListener);
1441
    		return eclipsePreferences;
1442
    	}
1427
		
1443
		
1428
	public String getElementName() {
1444
	public String getElementName() {
1429
		return this.project.getName();
1445
		return this.project.getName();
Lines 2159-2170 Link Here
2159
2175
2160
	/**
2176
	/**
2161
	 * load preferences from a shareable format (VCM-wise)
2177
	 * load preferences from a shareable format (VCM-wise)
2162
	 * @deprecated WARNING, visibility of this method will be decreased soon
2163
	 * 	to private and won't be usable in the future.
2164
	 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=59258">bug 59258</a>
2165
	 * TODO (frederic) set visibility from public to private
2166
	 */
2178
	 */
2167
	 public Preferences loadPreferences() {
2179
	 private Preferences loadPreferences() {
2168
	 	
2180
	 	
2169
	 	Preferences preferences = new Preferences();
2181
	 	Preferences preferences = new Preferences();
2170
	 	IPath projectMetaLocation = getPluginWorkingLocation();
2182
	 	IPath projectMetaLocation = getPluginWorkingLocation();
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-37 / +68 lines)
Lines 1126-1169 Link Here
1126
	/**
1126
	/**
1127
	 * Update the classpath variable cache
1127
	 * Update the classpath variable cache
1128
	 */
1128
	 */
1129
	public static class EclipsePreferencesListener implements IEclipsePreferences.IPreferenceChangeListener {
1129
	public class EclipsePreferencesListener implements IEclipsePreferences.IPreferenceChangeListener {
1130
		/**
1130
		/**
1131
		 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
1131
         * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
1132
		 */
1132
         */
1133
		public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
1133
        public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
1134
			String propertyName = event.getKey();
1134
        	String propertyName = event.getKey();
1135
			if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
1135
        	if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
1136
				String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
1136
        		String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
1137
				JavaModelManager manager = getJavaModelManager();
1137
        		JavaModelManager manager = getJavaModelManager();
1138
				if (manager.variablesWithInitializer.contains(varName)) {
1138
        		if (manager.variablesWithInitializer.contains(varName)) {
1139
					// revert preference value as we will not apply it to JavaCore classpath variable
1139
        			// revert preference value as we will not apply it to JavaCore classpath variable
1140
					String oldValue = (String) event.getOldValue();
1140
        			String oldValue = (String) event.getOldValue();
1141
					if (oldValue == null) {
1141
        			if (oldValue == null) {
1142
						// unexpected old value => remove variable from set
1142
        				// unexpected old value => remove variable from set
1143
						manager.variablesWithInitializer.remove(varName);
1143
        				manager.variablesWithInitializer.remove(varName);
1144
					} else {
1144
        			} else {
1145
						manager.getInstancePreferences().put(varName, oldValue);
1145
        				manager.getInstancePreferences().put(varName, oldValue);
1146
					}
1146
        			}
1147
				} else {
1147
        		} else {
1148
					String newValue = (String)event.getNewValue();
1148
        			String newValue = (String)event.getNewValue();
1149
					IPath newPath;
1149
        			IPath newPath;
1150
					if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1150
        			if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1151
						newPath = new Path(newValue);
1151
        				newPath = new Path(newValue);
1152
					} else {
1152
        			} else {
1153
						newPath = null;
1153
        				newPath = null;
1154
					}
1154
        			}
1155
					try {
1155
        			try {
1156
						SetVariablesOperation operation = new SetVariablesOperation(new String[] {varName}, new IPath[] {newPath}, false/*don't update preferences*/);
1156
        				SetVariablesOperation operation = new SetVariablesOperation(new String[] {varName}, new IPath[] {newPath}, false/*don't update preferences*/);
1157
						operation.runOperation(null/*no progress available*/);
1157
        				operation.runOperation(null/*no progress available*/);
1158
					} catch (JavaModelException e) {
1158
        			} catch (JavaModelException e) {
1159
						Util.log(e, "Could not set classpath variable " + varName + " to " + newPath); //$NON-NLS-1$ //$NON-NLS-2$
1159
        				Util.log(e, "Could not set classpath variable " + varName + " to " + newPath); //$NON-NLS-1$ //$NON-NLS-2$
1160
					}
1160
        			}
1161
				}
1161
        		}
1162
			}
1162
        	}
1163
			if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) {
1163
        	else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) {
1164
				recreatePersistedContainer(propertyName, (String)event.getNewValue(), false);
1164
        		recreatePersistedContainer(propertyName, (String)event.getNewValue(), false);
1165
			}
1165
        	} else {
1166
		}
1166
        		int length = JavaCore.PLUGIN_ID.length() + 1;
1167
        		String key = event.getKey();
1168
        		StringTokenizer tokenizer = new StringTokenizer(key.substring(length));
1169
        		String token = tokenizer.nextToken();
1170
        		if (key.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) ||
1171
        			token.equals("builder") || //$NON-NLS-1$
1172
        			key.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) ||
1173
        			key.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) ||
1174
        			key.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL) ||
1175
        			token.equals("classpath")) //$NON-NLS-1$
1176
        		{
1177
        			JavaModelManager manager = JavaModelManager.getJavaModelManager();
1178
        			IJavaModel model = manager.getJavaModel();
1179
        			IJavaProject[] projects;
1180
        			try {
1181
        				projects = model.getJavaProjects();
1182
        				for (int i = 0, pl = projects.length; i < pl; i++) {
1183
        					JavaProject javaProject = (JavaProject) projects[i];
1184
	    					manager.deltaState.addClasspathValidation(javaProject);
1185
	    					try {
1186
	    						// need to touch the project to force validation by DeltaProcessor
1187
	                            javaProject.getProject().touch(null);
1188
                            } catch (CoreException e) {
1189
	                            // skip
1190
                            }
1191
        				}
1192
        			} catch (JavaModelException e) {
1193
        				// skip
1194
        			}
1195
        		}
1196
        	}
1197
        }
1167
	}
1198
	}
1168
1199
1169
	/**
1200
	/**
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-7 / +1 lines)
Lines 2189-2205 Link Here
2189
						break;
2189
						break;
2190
				}
2190
				}
2191
				break;
2191
				break;
2192
			case IResource.FOLDER :
2193
				/* check settings change */
2194
				IFolder folder = (IFolder) resource;
2195
				processChildren = folder.getName().equals(JavaProject.DEFAULT_PREFERENCES_DIRNAME);
2196
				break;
2197
			case IResource.FILE :
2192
			case IResource.FILE :
2198
				/* check classpath or prefs files change */
2193
				/* check classpath or prefs files change */
2199
				IFile file = (IFile) resource;
2194
				IFile file = (IFile) resource;
2200
				String fileName = file.getName();
2195
				String fileName = file.getName();
2201
				if (fileName.equals(JavaProject.CLASSPATH_FILENAME) ||
2196
				if (fileName.equals(JavaProject.CLASSPATH_FILENAME)) {
2202
					fileName.equals(JavaProject.JAVA_CORE_PREFS_FILE)) {
2203
					JavaProject javaProject = (JavaProject)JavaCore.create(file.getProject());
2197
					JavaProject javaProject = (JavaProject)JavaCore.create(file.getProject());
2204
					this.state.addClasspathValidation(javaProject);
2198
					this.state.addClasspathValidation(javaProject);
2205
					affectedProjects.add(file.getProject().getFullPath());
2199
					affectedProjects.add(file.getProject().getFullPath());

Return to bug 172345