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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/util/Util.java (-47 / +74 lines)
Lines 639-685 Link Here
639
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJavaClassLib()]
639
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJavaClassLib()]
640
*/
640
*/
641
public static String[] getJavaClassLibs() {
641
public static String[] getJavaClassLibs() {
642
    String jreDir = getJREDirectory();
642
	// check bootclasspath properties for Sun, JRockit and Harmony VMs
643
    final String osName = System.getProperty("os.name");
643
	String bootclasspathProperty = System.getProperty("sun.boot.class.path"); //$NON-NLS-1$
644
    if (jreDir == null) {
644
	if ((bootclasspathProperty == null) || (bootclasspathProperty.length() == 0)) {
645
        return new String[] {};
645
		// IBM J9 VMs
646
    }
646
		bootclasspathProperty = System.getProperty("vm.boot.class.path"); //$NON-NLS-1$
647
    if (osName.startsWith("Mac")) {
647
		if ((bootclasspathProperty == null) || (bootclasspathProperty.length() == 0)) {
648
        return new String[] {
648
			// Harmony using IBM VME
649
            toNativePath(jreDir + "/../Classes/classes.jar")
649
			bootclasspathProperty = System.getProperty("org.apache.harmony.boot.class.path"); //$NON-NLS-1$
650
        };
650
		}
651
    }
651
	}
652
    final String vmName = System.getProperty("java.vm.name");
652
	String[] jars = null;
653
    if ("J9".equals(vmName)) {
653
	if ((bootclasspathProperty != null) && (bootclasspathProperty.length() != 0)) {
654
        return new String[] {
654
		StringTokenizer tokenizer = new StringTokenizer(bootclasspathProperty, File.pathSeparator);
655
            toNativePath(jreDir + "/lib/jclMax/classes.zip")
655
		final int size = tokenizer.countTokens();
656
        };
656
		jars = new String[size];
657
    }
657
		int i = 0;
658
	if ("DRLVM".equals(vmName)) {
658
		while (tokenizer.hasMoreTokens()) {
659
		FilenameFilter jarFilter = new FilenameFilter() {
659
			final String fileName = toNativePath(tokenizer.nextToken());
660
			public boolean accept(File dir, String name) {
660
			if (new File(fileName).exists()) {
661
				return name.endsWith(".jar") & !name.endsWith("-src.jar");
661
				jars[i] = fileName;
662
				i++;
662
			}
663
			}
663
		};
664
		String[] jars = new File(jreDir + "/lib/boot/").list(jarFilter);
665
		for (int i = 0; i < jars.length; i++) {
666
			jars[i] = toNativePath(jreDir + "/lib/boot/" + jars[i]);
667
		}
664
		}
668
		return jars;
665
		if (size != i) {
666
			// resize
667
			System.arraycopy(jars, 0, (jars = new String[i]), 0, i);
668
		}
669
	} else {
670
		String jreDir = getJREDirectory();
671
		final String osName = System.getProperty("os.name");
672
		if (jreDir == null) {
673
			return new String[] {};
674
		}
675
		if (osName.startsWith("Mac")) {
676
			return new String[] {
677
					toNativePath(jreDir + "/../Classes/classes.jar")
678
			};
679
		}
680
		final String vmName = System.getProperty("java.vm.name");
681
		if ("J9".equals(vmName)) {
682
			return new String[] {
683
					toNativePath(jreDir + "/lib/jclMax/classes.zip")
684
			};
685
		}
686
		String[] jarsNames = null;
687
		ArrayList paths = new ArrayList();
688
		if ("DRLVM".equals(vmName)) {
689
			FilenameFilter jarFilter = new FilenameFilter() {
690
				public boolean accept(File dir, String name) {
691
					return name.endsWith(".jar") & !name.endsWith("-src.jar");
692
				}
693
			};
694
			jarsNames = new File(jreDir + "/lib/boot/").list(jarFilter);
695
			addJarEntries(jreDir + "/lib/boot/", jarsNames, paths);
696
		} else {
697
			jarsNames = new String[] {
698
					"/lib/vm.jar",
699
					"/lib/rt.jar",
700
					"/lib/core.jar",
701
					"/lib/security.jar",
702
					"/lib/xml.jar",
703
					"/lib/graphics.jar"
704
			};
705
			addJarEntries(jreDir, jarsNames, paths);
706
		}
707
		jars = new String[paths.size()];
708
		paths.toArray(jars);
669
	}
709
	}
670
    ArrayList paths = new ArrayList();
710
	return jars;
671
    String[] jarsNames = new String[] {
672
    		"/lib/vm.jar",
673
    		"/lib/rt.jar",
674
    		"/lib/core.jar",
675
    		"/lib/security.jar",
676
    		"/lib/xml.jar",
677
    		"/lib/graphics.jar"
678
    };
679
    addJarEntries(jreDir, jarsNames, paths);
680
    String[] result = new String[paths.size()];
681
    paths.toArray(result);
682
    return result;
683
}
711
}
684
private static void addJarEntries(String jreDir, String[] jarNames, ArrayList paths) {
712
private static void addJarEntries(String jreDir, String[] jarNames, ArrayList paths) {
685
	for (int i = 0, max = jarNames.length; i < max; i++) {
713
	for (int i = 0, max = jarNames.length; i < max; i++) {
Lines 691-705 Link Here
691
	}
719
	}
692
}
720
}
693
public static String getJavaClassLibsAsString() {
721
public static String getJavaClassLibsAsString() {
694
    String[] classLibs = getJavaClassLibs();
722
	String[] classLibs = getJavaClassLibs();
695
    StringBuffer buffer = new StringBuffer();
723
	StringBuffer buffer = new StringBuffer();
696
    for (int i = 0, max = classLibs.length; i < max; i++) {
724
	for (int i = 0, max = classLibs.length; i < max; i++) {
697
        buffer
725
		buffer
698
            .append(classLibs[i])
726
		.append(classLibs[i])
699
            .append(File.pathSeparatorChar);
727
		.append(File.pathSeparatorChar);
700
728
	}
701
    }
729
	return buffer.toString();
702
    return buffer.toString();
703
}
730
}
704
/**
731
/**
705
 * Returns the JRE directory this tests are running on.
732
 * Returns the JRE directory this tests are running on.
(-)src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java (-28 / +54 lines)
Lines 77-83 Link Here
77
77
78
	//----------------------------
78
	//----------------------------
79
	//           Step 2
79
	//           Step 2
80
	//----------------------------	
80
	//----------------------------
81
	StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
81
	StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
82
	buffer.append("<classpath>\n"); //$NON-NLS-1$
82
	buffer.append("<classpath>\n"); //$NON-NLS-1$
83
	buffer.append("    <classpathentry kind=\"src\" path=\"src\"/>\n"); //$NON-NLS-1$
83
	buffer.append("    <classpathentry kind=\"src\" path=\"src\"/>\n"); //$NON-NLS-1$
Lines 100-106 Link Here
100
	} finally {
100
	} finally {
101
		env.setAutoBuilding(wasAutoBuilding);
101
		env.setAutoBuilding(wasAutoBuilding);
102
	}
102
	}
103
}	
103
}
104
104
105
public void testClosedProject() throws JavaModelException {
105
public void testClosedProject() throws JavaModelException {
106
	IPath project1Path = env.addProject("CP1"); //$NON-NLS-1$
106
	IPath project1Path = env.addProject("CP1"); //$NON-NLS-1$
Lines 287-300 Link Here
287
	);
287
	);
288
	long lastModified = new java.io.File(externalJar).lastModified();
288
	long lastModified = new java.io.File(externalJar).lastModified();
289
	env.addExternalJar(projectPath, externalJar);
289
	env.addExternalJar(projectPath, externalJar);
290
	
290
291
	// build -> expecting problems
291
	// build -> expecting problems
292
	fullBuild();
292
	fullBuild();
293
	expectingProblemsFor(
293
	expectingProblemsFor(
294
		classTest,
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>]"
295
		"Problem : The method bar() is undefined for the type Y [ resource : </Project/p/X.java> range : <57,60> category : <50> severity : <2>]"
296
	);
296
	);
297
	
297
298
	try {
298
	try {
299
		Thread.sleep(1000);
299
		Thread.sleep(1000);
300
	} catch(InterruptedException e) {
300
	} catch(InterruptedException e) {
Lines 312-325 Link Here
312
		new HashMap(),
312
		new HashMap(),
313
		externalJar
313
		externalJar
314
	);
314
	);
315
	
315
316
	new java.io.File(externalJar).setLastModified(lastModified + 1000); // to be sure its different
316
	new java.io.File(externalJar).setLastModified(lastModified + 1000); // to be sure its different
317
	// refresh project and rebuild -> expecting no problems
317
	// refresh project and rebuild -> expecting no problems
318
	IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject("Project")); //$NON-NLS-1$
318
	IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject("Project")); //$NON-NLS-1$
319
	project.getJavaModel().refreshExternalArchives(new IJavaElement[] {project}, null);
319
	project.getJavaModel().refreshExternalArchives(new IJavaElement[] {project}, null);
320
	incrementalBuild();
320
	incrementalBuild();
321
	expectingNoProblems();
321
	expectingNoProblems();
322
	
322
323
}
323
}
324
324
325
public void testMissingBuilder() throws JavaModelException {
325
public void testMissingBuilder() throws JavaModelException {
Lines 426-432 Link Here
426
426
427
	//----------------------------
427
	//----------------------------
428
	//           Step 2
428
	//           Step 2
429
	//----------------------------	
429
	//----------------------------
430
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
430
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
431
431
432
	incrementalBuild();
432
	incrementalBuild();
Lines 459-465 Link Here
459
	expectingSpecificProblemFor(
459
	expectingSpecificProblemFor(
460
		projectPath,
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$
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
	
462
463
	Problem[] prob1 = env.getProblemsFor(classTest1);
463
	Problem[] prob1 = env.getProblemsFor(classTest1);
464
	Problem[] prob2 = env.getProblemsFor(classTest2);
464
	Problem[] prob2 = env.getProblemsFor(classTest2);
465
	Problem[] prob3 = env.getProblemsFor(classTest3);
465
	Problem[] prob3 = env.getProblemsFor(classTest3);
Lines 474-480 Link Here
474
474
475
	//----------------------------
475
	//----------------------------
476
	//           Step 2
476
	//           Step 2
477
	//----------------------------	
477
	//----------------------------
478
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
478
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
479
479
480
	incrementalBuild();
480
	incrementalBuild();
Lines 516-522 Link Here
516
		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);
517
	env.removeProject(projectPath);
518
}
518
}
519
	
519
520
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
520
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
521
public void testMissingLibrary4() throws JavaModelException {
521
public void testMissingLibrary4() throws JavaModelException {
522
	this.abortOnFailure = false; // this test is failing on some releng boxes => do not abort on failures
522
	this.abortOnFailure = false; // this test is failing on some releng boxes => do not abort on failures
Lines 543-580 Link Here
543
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
543
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345
544
public void testIncompatibleJdkLEvelOnProject() throws JavaModelException {
544
public void testIncompatibleJdkLEvelOnProject() throws JavaModelException {
545
	this.abortOnFailure = false; // NOT sure this test will pass on releng boxes => do not abort on failures
545
	this.abortOnFailure = false; // NOT sure this test will pass on releng boxes => do not abort on failures
546
	
546
547
	// Create project
547
	// Create project
548
	IPath projectPath = env.addProject("Project");
548
	IPath projectPath = env.addProject("Project");
549
	IJavaProject project = env.getJavaProject(projectPath);
549
	IJavaProject project = env.getJavaProject(projectPath);
550
	String[] classlibs = Util.getJavaClassLibs();
550
	String[] classlibs = Util.getJavaClassLibs();
551
	env.addExternalJars(projectPath, classlibs);
551
	env.addExternalJars(projectPath, classlibs);
552
	
552
	Arrays.sort(classlibs);
553
553
	// Build it expecting no problem
554
	// Build it expecting no problem
554
	fullBuild();
555
	fullBuild();
555
	expectingNoProblems();
556
	expectingNoProblems();
556
557
557
	// Build incompatible jdk level problem string
558
	// 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);
559
	String projectRuntime = project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true);
560
560
561
	// Change project incompatible jdk level preferences to warning, perform incremental build and expect 1 problem
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);
562
	project.setOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, CompilerOptions.WARNING);
563
	incrementalBuild();
563
	incrementalBuild();
564
	StringBuffer buffer = new StringBuffer();
565
	for (int i = 0, max = classlibs.length; i < max; i++) {
566
		if (i>0) buffer.append('\n');
567
		buffer.append(getJdkLevelProblem(projectRuntime, project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(), IMarker.SEVERITY_WARNING));
568
	}
569
564
	expectingProblemsFor(
570
	expectingProblemsFor(
565
		projectPath,
571
		projectPath,
566
		getJdkLevelProblem(projectRuntime, jclPath, IMarker.SEVERITY_WARNING)
572
		String.valueOf(buffer)
567
	);
573
	);
568
574
569
	// Change project incompatible jdk level preferences to error, perform incremental build and expect 2 problems
575
	// 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);
576
	project.setOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, CompilerOptions.ERROR);
571
	incrementalBuild();
577
	incrementalBuild();
578
579
	buffer = new StringBuffer();
580
	for (int i = 0, max = classlibs.length; i < max; i++) {
581
		if (i>0) buffer.append('\n');
582
		buffer.append(getJdkLevelProblem(projectRuntime, project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(), IMarker.SEVERITY_ERROR));
583
	}
572
	expectingProblemsFor(
584
	expectingProblemsFor(
573
		projectPath,
585
		projectPath,
574
		"Problem : The project cannot be built until build path errors are resolved [ resource : </Project> range : <-1,-1> category : <10> severity : <2>]\n" + 
586
		"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)
587
		String.valueOf(buffer)
576
	);
588
	);
577
	
589
578
	// Remove project to avoid side effect on other tests
590
	// Remove project to avoid side effect on other tests
579
	env.removeProject(projectPath);
591
	env.removeProject(projectPath);
580
}
592
}
Lines 588-625 Link Here
588
	String incompatibleJdkLevel = preferences.get(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, null);
600
	String incompatibleJdkLevel = preferences.get(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, null);
589
	try {
601
	try {
590
		this.abortOnFailure = false; // NOT sure this test will pass on all releng boxes => do not abort on failures
602
		this.abortOnFailure = false; // NOT sure this test will pass on all releng boxes => do not abort on failures
591
		
603
592
		// Create project
604
		// Create project
593
		IPath projectPath = env.addProject("Project");
605
		IPath projectPath = env.addProject("Project");
594
		IJavaProject project = env.getJavaProject(projectPath);
606
		IJavaProject project = env.getJavaProject(projectPath);
595
		String[] classlibs = Util.getJavaClassLibs();
607
		String[] classlibs = Util.getJavaClassLibs();
596
		env.addExternalJars(projectPath, classlibs);
608
		env.addExternalJars(projectPath, classlibs);
597
		
609
598
		// Build it expecting no problem
610
		// Build it expecting no problem
599
		fullBuild();
611
		fullBuild();
600
		expectingNoProblems();
612
		expectingNoProblems();
601
613
602
		// Build incompatible jdk level problem string
614
		// Build incompatible jdk level problem string
603
		String jclPath = project.getPackageFragmentRoot(classlibs[0]).getPath().makeRelative().toString();
604
		String wkspRuntime = JavaCore.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
615
		String wkspRuntime = JavaCore.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
605
		
616
		// sort classlibs
617
		Arrays.sort(classlibs);
606
		// Change workspace  incompatible jdk level preferences to warning, perform incremental build and expect 1 problem
618
		// 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);
619
		preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.WARNING);
608
		incrementalBuild();
620
		incrementalBuild();
621
622
		StringBuffer buffer = new StringBuffer();
623
		for (int i = 0, max = classlibs.length; i < max; i++) {
624
			if (i>0) buffer.append('\n');
625
			buffer.append(getJdkLevelProblem(wkspRuntime, project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(), IMarker.SEVERITY_WARNING));
626
		}
627
609
		expectingProblemsFor(
628
		expectingProblemsFor(
610
			projectPath,
629
			projectPath,
611
			getJdkLevelProblem(wkspRuntime, jclPath, IMarker.SEVERITY_WARNING)
630
			String.valueOf(buffer)
612
		);
631
		);
613
		
632
614
		// Change workspace incompatible jdk level preferences to error, perform incremental build and expect 2 problems
633
		// 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);
634
		preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.ERROR);
616
		incrementalBuild();
635
		incrementalBuild();
636
637
		buffer = new StringBuffer();
638
		for (int i = 0, max = classlibs.length; i < max; i++) {
639
			if (i>0) buffer.append('\n');
640
			buffer.append(getJdkLevelProblem(wkspRuntime, project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(), IMarker.SEVERITY_ERROR));
641
		}
642
617
		expectingProblemsFor(
643
		expectingProblemsFor(
618
			projectPath,
644
			projectPath,
619
			"Problem : The project cannot be built until build path errors are resolved [ resource : </Project> range : <-1,-1> category : <10> severity : <2>]\n" + 
645
			"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)
646
			String.valueOf(buffer)
621
		);
647
		);
622
		
648
623
		// Remove project to avoid side effect on other tests
649
		// Remove project to avoid side effect on other tests
624
		env.removeProject(projectPath);
650
		env.removeProject(projectPath);
625
	} finally {
651
	} finally {
Lines 753-764 Link Here
753
	);
779
	);
754
	fullBuild();
780
	fullBuild();
755
	expectingNoProblems();
781
	expectingNoProblems();
756
	env.addClass(defaultPackagePath, "Y", 		
782
	env.addClass(defaultPackagePath, "Y",
757
		"public class Y implements X.Entry.Internal {\n" +
783
		"public class Y implements X.Entry.Internal {\n" +
758
		"  public Internal createEntry() {\n" +
784
		"  public Internal createEntry() {\n" +
759
		"    return null;\n" +
785
		"    return null;\n" +
760
		"  }\n" +
786
		"  }\n" +
761
		"}");	
787
		"}");
762
	incrementalBuild();
788
	incrementalBuild();
763
	expectingNoProblems();
789
	expectingNoProblems();
764
}
790
}

Return to bug 195509