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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-7 / +33 lines)
Lines 2063-2068 Link Here
2063
								return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()}));
2063
								return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()}));
2064
							}
2064
							}
2065
						}
2065
						}
2066
						IJavaModelStatus status = validateLibraryContents(path, project, entryPathMsg);
2067
						if (status != JavaModelStatus.VERIFIED_OK) 
2068
							return status;
2066
						break;
2069
						break;
2067
					case IResource.FOLDER :	// internal binary folder
2070
					case IResource.FOLDER :	// internal binary folder
2068
						if (sourceAttachment != null
2071
						if (sourceAttachment != null
Lines 2083-2095 Link Here
2083
					} else {
2086
					} else {
2084
						return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), project.getElementName()}));
2087
						return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), project.getElementName()}));
2085
					}
2088
					}
2086
				} else if (sourceAttachment != null
2089
				} else {
2087
						&& !sourceAttachment.isEmpty()
2090
					if (sourceAttachment != null
2088
						&& JavaModel.getTarget(sourceAttachment, true) == null){
2091
							&& !sourceAttachment.isEmpty()
2089
					if (container != null) {
2092
							&& JavaModel.getTarget(sourceAttachment, true) == null){
2090
						return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toOSString(), container}));
2093
						if (container != null) {
2091
					} else {
2094
							return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toOSString(), container}));
2092
						return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), project.getElementName()}));
2095
						} else {
2096
							return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), project.getElementName()}));
2097
						}
2098
					}
2099
					if(file.isFile()) {
2100
						IJavaModelStatus status = validateLibraryContents(path, project, entryPathMsg);
2101
						if (status != JavaModelStatus.VERIFIED_OK) 
2102
							return status;
2093
					}
2103
					}
2094
				}
2104
				}
2095
			} else {
2105
			} else {
Lines 2121-2124 Link Here
2121
		}
2131
		}
2122
		return JavaModelStatus.VERIFIED_OK;
2132
		return JavaModelStatus.VERIFIED_OK;
2123
	}
2133
	}
2134
2135
	private static IJavaModelStatus validateLibraryContents(IPath path, IJavaProject project, String entryPathMsg) {
2136
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
2137
		ZipFile zip = null;
2138
		try {
2139
			zip = manager.getZipFile(path);
2140
		} catch (CoreException e) {
2141
			return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(
2142
					Messages.classpath_illegalLibraryArchive,
2143
					new String[] {entryPathMsg, project.getElementName()}));							
2144
		}
2145
		finally {
2146
			manager.closeZipFile(zip);
2147
		}
2148
		return JavaModelStatus.VERIFIED_OK;
2149
	}
2124
}
2150
}
(-)src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java (-2 / +22 lines)
Lines 13-18 Link Here
13
import junit.framework.*;
13
import junit.framework.*;
14
14
15
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.resources.IMarker;
16
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
Lines 25-30 Link Here
25
import org.eclipse.jdt.internal.core.*;
26
import org.eclipse.jdt.internal.core.*;
26
27
27
import java.io.File;
28
import java.io.File;
29
import java.io.FileInputStream;
28
import java.io.IOException;
30
import java.io.IOException;
29
import java.util.*;
31
import java.util.*;
30
32
Lines 103-112 Link Here
103
	}
105
	}
104
}
106
}
105
107
106
public void testClosedProject() throws JavaModelException {
108
public void testClosedProject() throws JavaModelException, IOException {
107
	IPath project1Path = env.addProject("CP1"); //$NON-NLS-1$
109
	IPath project1Path = env.addProject("CP1"); //$NON-NLS-1$
110
	IProject project1 = ResourcesPlugin.getWorkspace().getRoot().getProject("CP1");
108
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
111
	env.addExternalJars(project1Path, Util.getJavaClassLibs());
109
	IPath jarPath = env.addInternalJar(project1Path, "temp.jar", new byte[] {0}); //$NON-NLS-1$
112
	
113
	String jarFile = project1.getLocation().toOSString() + File.separator + "temp.jar";
114
	
115
	org.eclipse.jdt.core.tests.util.Util.createJar(
116
			null,
117
			new String[] {
118
				"META-INF/MANIFEST.MF",
119
				"Manifest-Version: 1.0\n",
120
			},
121
			jarFile,
122
			null,
123
			JavaCore.VERSION_1_4);
124
125
	FileInputStream fis = new FileInputStream(jarFile);
126
	int length = fis.available();
127
	byte[] jarContent = new byte[length];
128
	fis.read(jarContent); 
129
	IPath jarPath = env.addInternalJar(project1Path, "temp.jar", jarContent); //$NON-NLS-1$
110
130
111
	IPath project2Path = env.addProject("CP2"); //$NON-NLS-1$
131
	IPath project2Path = env.addProject("CP2"); //$NON-NLS-1$
112
	env.addExternalJars(project2Path, Util.getJavaClassLibs());
132
	env.addExternalJars(project2Path, Util.getJavaClassLibs());
(-)src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java (-8 / +21 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.io.IOException;
13
import java.util.HashMap;
14
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.Map;
15
16
Lines 1313-1319 Link Here
1313
 * @bug 138599: [model][classpath] Need a way to mark a classpath variable as deprecated
1314
 * @bug 138599: [model][classpath] Need a way to mark a classpath variable as deprecated
1314
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=138599"
1315
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=138599"
1315
 */
1316
 */
1316
public void testVariableInitializerDeprecated() throws CoreException {
1317
public void testVariableInitializerDeprecated() throws CoreException, IOException {
1317
	try {
1318
	try {
1318
		// Create initializer
1319
		// Create initializer
1319
		String varName = "TEST_DEPRECATED";
1320
		String varName = "TEST_DEPRECATED";
Lines 1326-1332 Link Here
1326
1327
1327
		// Create project
1328
		// Create project
1328
		IJavaProject project = createJavaProject("P1");
1329
		IJavaProject project = createJavaProject("P1");
1329
		createFile("/P1/lib.jar", "");
1330
		addLibrary(project, "lib.jar", null, new String[0],
1331
				new String[]{"META-INF/MANIFEST.MF", 
1332
					"Manifest-Version: 1.0\n"} , 
1333
					JavaCore.VERSION_1_4);
1330
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED"), null, null);
1334
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED"), null, null);
1331
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1335
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1332
		assertStatus("Classpath variable 'TEST_DEPRECATED' in project 'P1' is deprecated: Test deprecated flag", status);
1336
		assertStatus("Classpath variable 'TEST_DEPRECATED' in project 'P1' is deprecated: Test deprecated flag", status);
Lines 1367-1373 Link Here
1367
 * @bug 156226: [model][classpath] Allow classpath variable to be marked as non modifiable
1371
 * @bug 156226: [model][classpath] Allow classpath variable to be marked as non modifiable
1368
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156226"
1372
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156226"
1369
 */
1373
 */
1370
public void testVariableInitializerReadOnly() throws CoreException {
1374
public void testVariableInitializerReadOnly() throws CoreException, IOException {
1371
	try {
1375
	try {
1372
		// Create initializer
1376
		// Create initializer
1373
		String varName = "TEST_READ_ONLY";
1377
		String varName = "TEST_READ_ONLY";
Lines 1380-1386 Link Here
1380
1384
1381
		// Create project
1385
		// Create project
1382
		IJavaProject project = createJavaProject("P1");
1386
		IJavaProject project = createJavaProject("P1");
1383
		createFile("/P1/lib.jar", "");
1387
		addLibrary(project, "lib.jar", null, new String[0],
1388
				new String[]{"META-INF/MANIFEST.MF", 
1389
					"Manifest-Version: 1.0\n"} , 
1390
					JavaCore.VERSION_1_4);
1384
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_READ_ONLY"), null, null);
1391
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_READ_ONLY"), null, null);
1385
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1392
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1386
		assertStatus("OK", status);
1393
		assertStatus("OK", status);
Lines 1391-1397 Link Here
1391
		deleteProject("P1");
1398
		deleteProject("P1");
1392
	}
1399
	}
1393
}
1400
}
1394
public void testVariableInitializerDeprecatedAndReadOnly() throws CoreException {
1401
public void testVariableInitializerDeprecatedAndReadOnly() throws CoreException, IOException {
1395
	try {
1402
	try {
1396
		// Create initializer
1403
		// Create initializer
1397
		String varName = "TEST_DEPRECATED_READ_ONLY";
1404
		String varName = "TEST_DEPRECATED_READ_ONLY";
Lines 1405-1411 Link Here
1405
1412
1406
		// Create project
1413
		// Create project
1407
		IJavaProject project = createJavaProject("P1");
1414
		IJavaProject project = createJavaProject("P1");
1408
		createFile("/P1/lib.jar", "");
1415
		addLibrary(project, "lib.jar", null, new String[0],
1416
				new String[]{"META-INF/MANIFEST.MF", 
1417
					"Manifest-Version: 1.0\n"} , 
1418
					JavaCore.VERSION_1_4);
1409
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED_READ_ONLY"), null, null);
1419
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED_READ_ONLY"), null, null);
1410
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1420
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1411
		assertStatus("Classpath variable 'TEST_DEPRECATED_READ_ONLY' in project 'P1' is deprecated: A deprecated and read-only initializer", status);
1421
		assertStatus("Classpath variable 'TEST_DEPRECATED_READ_ONLY' in project 'P1' is deprecated: A deprecated and read-only initializer", status);
Lines 1422-1428 Link Here
1422
 * @bug 172207: [model] Marker for deprecated classpath variable should always have WARNING severity
1432
 * @bug 172207: [model] Marker for deprecated classpath variable should always have WARNING severity
1423
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=172207"
1433
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=172207"
1424
 */
1434
 */
1425
public void testVariableInitializerBug172207() throws CoreException {
1435
public void testVariableInitializerBug172207() throws CoreException, IOException {
1426
	try {
1436
	try {
1427
		// Create initializer
1437
		// Create initializer
1428
		String varName = "TEST_DEPRECATED_READ_ONLY";
1438
		String varName = "TEST_DEPRECATED_READ_ONLY";
Lines 1436-1442 Link Here
1436
1446
1437
		// Create project
1447
		// Create project
1438
		IJavaProject project = createJavaProject("P1");
1448
		IJavaProject project = createJavaProject("P1");
1439
		createFile("/P1/lib.jar", "");
1449
		addLibrary(project, "lib.jar", null, new String[0],
1450
				new String[]{"META-INF/MANIFEST.MF", 
1451
					"Manifest-Version: 1.0\n"} , 
1452
					JavaCore.VERSION_1_4);
1440
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED_READ_ONLY"), null, null);
1453
		IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED_READ_ONLY"), null, null);
1441
		IClasspathEntry[] entries = project.getRawClasspath();
1454
		IClasspathEntry[] entries = project.getRawClasspath();
1442
		int length = entries.length;
1455
		int length = entries.length;
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-35 / +128 lines)
Lines 549-558 Link Here
549
/*
549
/*
550
 * Ensures that adding a library entry for an existing external ZIP archive doesn't generate a marker
550
 * Ensures that adding a library entry for an existing external ZIP archive doesn't generate a marker
551
 */
551
 */
552
public void testAddZIPArchive1() throws CoreException {
552
public void testAddZIPArchive1() throws CoreException, IOException {
553
	try {
553
	try {
554
		IJavaProject p = createJavaProject("P");
554
		IJavaProject p = createJavaProject("P");
555
		createExternalFile("externalLib.abc", "");
555
		org.eclipse.jdt.core.tests.util.Util.createJar(
556
				null,
557
				new String[] {
558
					"META-INF/MANIFEST.MF",
559
					"Manifest-Version: 1.0\n",
560
				},
561
				getExternalResourcePath("externalLib.abc"),
562
				null,
563
				JavaCore.VERSION_1_4);
556
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib.abc")), null, null)});
564
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib.abc")), null, null)});
557
		assertMarkers("Unexpected markers", "", p);
565
		assertMarkers("Unexpected markers", "", p);
558
	} finally {
566
	} finally {
Lines 564-572 Link Here
564
/*
572
/*
565
 * Ensures that creating a project with a library entry for an existing external ZIP archive doesn't generate a marker
573
 * Ensures that creating a project with a library entry for an existing external ZIP archive doesn't generate a marker
566
 */
574
 */
567
public void testAddZIPArchive2() throws CoreException {
575
public void testAddZIPArchive2() throws CoreException, IOException {
568
	try {
576
	try {
569
		createExternalFile("externalLib.abc", "");
577
		org.eclipse.jdt.core.tests.util.Util.createJar(
578
				null,
579
				new String[] {
580
					"META-INF/MANIFEST.MF",
581
					"Manifest-Version: 1.0\n",
582
				},
583
				getExternalResourcePath("externalLib.abc"),
584
				null,
585
				JavaCore.VERSION_1_4);
570
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
586
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
571
		assertMarkers("Unexpected markers", "", p);
587
		assertMarkers("Unexpected markers", "", p);
572
	} finally {
588
	} finally {
Lines 614-626 Link Here
614
/*
630
/*
615
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing removes the marker
631
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing removes the marker
616
 */
632
 */
617
public void testAddZIPArchive5() throws CoreException {
633
public void testAddZIPArchive5() throws CoreException, IOException {
618
	try {
634
	try {
619
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
635
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
620
		refreshExternalArchives(p);
636
		refreshExternalArchives(p);
621
		waitForAutoBuild();
637
		waitForAutoBuild();
622
638
		org.eclipse.jdt.core.tests.util.Util.createJar(
623
		createExternalFile("externalLib.abc", "");
639
				null,
640
				new String[] {
641
					"META-INF/MANIFEST.MF",
642
					"Manifest-Version: 1.0\n",
643
				},
644
				getExternalResourcePath("externalLib.abc"),
645
				null,
646
				JavaCore.VERSION_1_4);
624
		refreshExternalArchives(p);
647
		refreshExternalArchives(p);
625
		assertMarkers("Unexpected markers", "", p);
648
		assertMarkers("Unexpected markers", "", p);
626
	} finally {
649
	} finally {
Lines 633-645 Link Here
633
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing after a restart
656
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing after a restart
634
 * removes the marker
657
 * removes the marker
635
 */
658
 */
636
public void testAddZIPArchive6() throws CoreException {
659
public void testAddZIPArchive6() throws CoreException, IOException {
637
	try {
660
	try {
638
		simulateExitRestart();
661
		simulateExitRestart();
639
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
662
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
640
		refreshExternalArchives(p);
663
		refreshExternalArchives(p);
641
664
		org.eclipse.jdt.core.tests.util.Util.createJar(
642
		createExternalFile("externalLib.abc", "");
665
				null,
666
				new String[] {
667
					"META-INF/MANIFEST.MF",
668
					"Manifest-Version: 1.0\n",
669
				},
670
				getExternalResourcePath("externalLib.abc"),
671
				null,
672
				JavaCore.VERSION_1_4);
643
		refreshExternalArchives(p);
673
		refreshExternalArchives(p);
644
		assertMarkers("Unexpected markers", "", p);
674
		assertMarkers("Unexpected markers", "", p);
645
	} finally {
675
	} finally {
Lines 651-663 Link Here
651
/*
681
/*
652
 * Ensures that adding a library entry for an existing internal ZIP archive doesn't generate a marker
682
 * Ensures that adding a library entry for an existing internal ZIP archive doesn't generate a marker
653
 */
683
 */
654
public void testAddZIPArchive7() throws CoreException {
684
public void testAddZIPArchive7() throws CoreException, IOException {
655
	try {
685
	try {
656
		IJavaProject p = createJavaProject("P");
686
		IJavaProject p = createJavaProject("P");
657
		refreshExternalArchives(p);
687
		refreshExternalArchives(p);
658
		waitForAutoBuild();
688
		waitForAutoBuild();
659
689
		addLibrary(p, "internalLib.abc", null, new String[0],
660
		createFile("/P/internalLib.abc", "");
690
				new String[]{"META-INF/MANIFEST.MF", 
691
					"Manifest-Version: 1.0\n"} , 
692
					JavaCore.VERSION_1_4);
661
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path("/P/internalLib.abc"), null, null)});
693
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path("/P/internalLib.abc"), null, null)});
662
		assertMarkers("Unexpected markers", "", p);
694
		assertMarkers("Unexpected markers", "", p);
663
	} finally {
695
	} finally {
Lines 2729-2735 Link Here
2729
	String externalJarPath = getWorkspaceRoot().getLocation().append("external.jar").toOSString();
2761
	String externalJarPath = getWorkspaceRoot().getLocation().append("external.jar").toOSString();
2730
	try {
2762
	try {
2731
		IJavaProject p = createJavaProject("P");
2763
		IJavaProject p = createJavaProject("P");
2732
		Util.writeToFile("", externalJarPath);
2764
		org.eclipse.jdt.core.tests.util.Util.createJar(
2765
				null,
2766
				new String[] {
2767
					"META-INF/MANIFEST.MF",
2768
					"Manifest-Version: 1.0\n",
2769
				},
2770
				externalJarPath,
2771
				null,
2772
				JavaCore.VERSION_1_4);
2733
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path("../external.jar"), null, null)});
2773
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path("../external.jar"), null, null)});
2734
		assertMarkers(
2774
		assertMarkers(
2735
			"Unexpected markers", 
2775
			"Unexpected markers", 
Lines 3122-3129 Link Here
3122
		waitUntilIndexesReady();
3162
		waitUntilIndexesReady();
3123
		waitForAutoBuild();
3163
		waitForAutoBuild();
3124
		// at this point, a marker indicates that test185733.jar has been created: "Project 'P' is missing required library: '[...]\test185733.jar'"
3164
		// at this point, a marker indicates that test185733.jar has been created: "Project 'P' is missing required library: '[...]\test185733.jar'"
3125
3165
		org.eclipse.jdt.core.tests.util.Util.createJar(
3126
		createFile(new File(getExternalPath()), "test185733.jar", "");
3166
				null,
3167
				new String[] {
3168
					"META-INF/MANIFEST.MF",
3169
					"Manifest-Version: 1.0\n",
3170
				},
3171
				getExternalResourcePath("test185733.jar"),
3172
				null,
3173
				JavaCore.VERSION_1_4);
3127
		refreshExternalArchives(p);
3174
		refreshExternalArchives(p);
3128
		assertMarkers(
3175
		assertMarkers(
3129
			"Unexpected markers",
3176
			"Unexpected markers",
Lines 3749-3761 Link Here
3749
 * Ensures that a marker is removed if adding an internal jar that is on the classpath in another project
3796
 * Ensures that a marker is removed if adding an internal jar that is on the classpath in another project
3750
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=213723 )
3797
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=213723 )
3751
 */
3798
 */
3752
public void testFixClasspath1() throws CoreException {
3799
public void testFixClasspath1() throws CoreException, IOException {
3753
	try {
3800
	try {
3754
		createProject("P1");
3801
		createProject("P1");
3755
		IJavaProject project = createJavaProject("P2", new String[0], new String[] {"/P1/lib.jar"}, "bin");
3802
		IJavaProject project = createJavaProject("P2", new String[0], new String[0], "bin");
3756
		waitForAutoBuild();
3803
		waitForAutoBuild();
3757
3804
		addLibrary(project, "lib.jar", null, new String[0],
3758
		createFile("/P1/lib.jar", "");
3805
				new String[]{"META-INF/MANIFEST.MF", 
3806
					"Manifest-Version: 1.0\n"} , 
3807
					JavaCore.VERSION_1_4);
3808
		
3759
		assertMarkers(
3809
		assertMarkers(
3760
			"Unexpected markers",
3810
			"Unexpected markers",
3761
			"",
3811
			"",
Lines 3769-3779 Link Here
3769
 * Ensures that a marker is removed if adding an external jar, restarting and refreshing
3819
 * Ensures that a marker is removed if adding an external jar, restarting and refreshing
3770
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=216446 )
3820
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=216446 )
3771
 */
3821
 */
3772
public void testFixClasspath2() throws CoreException {
3822
public void testFixClasspath2() throws CoreException, IOException {
3773
	try {
3823
	try {
3774
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
3824
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
3775
		waitForAutoBuild(); // 1 marker
3825
		waitForAutoBuild(); // 1 marker
3776
		createExternalFile("externalLib.abc", "");
3826
		org.eclipse.jdt.core.tests.util.Util.createJar(
3827
				null,
3828
				new String[] {
3829
					"META-INF/MANIFEST.MF",
3830
					"Manifest-Version: 1.0\n",
3831
				},
3832
				getExternalResourcePath("externalLib.abc"),
3833
				null,
3834
				JavaCore.VERSION_1_4);
3777
		
3835
		
3778
		simulateExitRestart();
3836
		simulateExitRestart();
3779
		refreshExternalArchives(p);
3837
		refreshExternalArchives(p);
Lines 3939-3949 Link Here
3939
 * Ensures that a file not ending with .jar or .zip can be put on the classpath.
3997
 * Ensures that a file not ending with .jar or .zip can be put on the classpath.
3940
 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=182360 )
3998
 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=182360 )
3941
 */
3999
 */
3942
public void testInvalidInternalJar2() throws CoreException {
4000
public void testInvalidInternalJar2() throws CoreException, IOException {
3943
	try {
4001
	try {
3944
		createProject("P1");
4002
		IJavaProject proj =  createJavaProject("P1", new String[] {}, new String[0], "bin");
3945
		createFile("/P1/existing.txt", "");
4003
		
3946
		IJavaProject proj =  createJavaProject("P2", new String[] {}, new String[] {"/P1/existing.txt"}, "bin");
4004
		addLibrary(proj, "existing.txt", null, new String[0],
4005
				new String[]{"META-INF/MANIFEST.MF", 
4006
					"Manifest-Version: 1.0\n"} , 
4007
					JavaCore.VERSION_1_4);
4008
		proj =  createJavaProject("P2", new String[] {}, new String[] {"/P1/existing.txt"}, "bin");
3947
		assertMarkers(
4009
		assertMarkers(
3948
			"Unexpected markers",
4010
			"Unexpected markers",
3949
			"",
4011
			"",
Lines 4933-4944 Link Here
4933
 * Ensures that duplicate entries due to resolution are not reported
4995
 * Ensures that duplicate entries due to resolution are not reported
4934
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
4996
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
4935
 */
4997
 */
4936
public void testDuplicateEntries2() throws CoreException {
4998
public void testDuplicateEntries2() throws CoreException, IOException {
4937
	try {
4999
	try {
4938
		IJavaProject project = createJavaProject("P");
5000
		IJavaProject project = createJavaProject("P");
4939
		VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
5001
		VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
4940
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"}));
5002
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"}));
4941
		createFile("/P/lib.jar", "");
5003
		addLibrary(project, "lib.jar", null, new String[0],
5004
				new String[]{"META-INF/MANIFEST.MF", 
5005
					"Manifest-Version: 1.0\n"} , 
5006
					JavaCore.VERSION_1_4);
4942
		editFile(
5007
		editFile(
4943
			"/P/.classpath",
5008
			"/P/.classpath",
4944
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
5009
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Lines 4948-4953 Link Here
4948
			"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
5013
			"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
4949
			"</classpath>"
5014
			"</classpath>"
4950
		);
5015
		);
5016
		waitForAutoBuild();
4951
		assertMarkers(
5017
		assertMarkers(
4952
			"Unexpected markers",
5018
			"Unexpected markers",
4953
			"",
5019
			"",
Lines 5497-5509 Link Here
5497
/*
5563
/*
5498
 * Ensures that removing an internal ZIP archive referenced by a library entry creates a marker
5564
 * Ensures that removing an internal ZIP archive referenced by a library entry creates a marker
5499
 */
5565
 */
5500
public void testRemoveZIPArchive6() throws CoreException {
5566
public void testRemoveZIPArchive6() throws CoreException, IOException {
5501
	try {
5567
	try {
5502
		IJavaProject p = createJavaProject("P", new String[0], new String[] {"/P/internalLib.abc"}, "");
5568
		IJavaProject p = createJavaProject("P", new String[0], new String[0], "");
5503
		createFile("/P/internalLib.abc", "");
5569
		
5570
		addLibrary(p, "internalLib.abc", null, new String[0],
5571
				new String[]{"META-INF/MANIFEST.MF", 
5572
					"Manifest-Version: 1.0\n"} , 
5573
					JavaCore.VERSION_1_4);
5504
		waitForAutoBuild();
5574
		waitForAutoBuild();
5505
5575
5506
		deleteFile("/P/internalLib.abc");
5576
		deleteFile("/P/internalLib.abc");
5577
		waitForAutoBuild();
5507
		assertMarkers(
5578
		assertMarkers(
5508
			"Unexpected markers",
5579
			"Unexpected markers",
5509
			"Project \'P\' is missing required library: \'internalLib.abc\'",
5580
			"Project \'P\' is missing required library: \'internalLib.abc\'",
Lines 5517-5528 Link Here
5517
 * Ensures that renaming a .jar file and updating the classpath in a PRE_BUILD event doesn't leave markers
5588
 * Ensures that renaming a .jar file and updating the classpath in a PRE_BUILD event doesn't leave markers
5518
 * (regression test for bug 177922 FlexibleProjectContainer refresh logic sporadically leaves project with "missing library" error on rename/delete)
5589
 * (regression test for bug 177922 FlexibleProjectContainer refresh logic sporadically leaves project with "missing library" error on rename/delete)
5519
 */
5590
 */
5520
public void testRenameJar() throws CoreException {
5591
public void testRenameJar() throws CoreException, IOException {
5521
	IResourceChangeListener listener = null;
5592
	IResourceChangeListener listener = null;
5522
	try {
5593
	try {
5523
		final IJavaProject p = createJavaProject("P", new String[0], new String[] {"/P/lib/test1.jar"}, "");
5594
		final IJavaProject p = createJavaProject("P", new String[0], new String[0], "");
5524
		createFolder("/P/lib");
5595
		createFolder("/P/lib");
5525
		createFile("/P/lib/test1.jar", "");
5596
		addLibrary(p, "lib/test1.jar", null, new String[0],
5597
				new String[]{"META-INF/MANIFEST.MF", 
5598
					"Manifest-Version: 1.0\n"} , 
5599
					JavaCore.VERSION_1_4);
5526
		// at this point no markers exist
5600
		// at this point no markers exist
5527
5601
5528
		// register a listener that updates the classpath in a PRE_BUILD event
5602
		// register a listener that updates the classpath in a PRE_BUILD event
Lines 6813-6818 Link Here
6813
		deleteProject("ReferencedProject");
6887
		deleteProject("ReferencedProject");
6814
	}
6888
	}
6815
}
6889
}
6816
6890
/**
6891
 * @bug 229042: [buildpath] could create build path error in case of invalid external JAR format
6892
 * 
6893
 * Test that an invalid archive (JAR) creates a buildpath error
6894
 * 
6895
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=229042"
6896
 * @throws Exception
6897
 */
6898
public void testBug229042() throws Exception {
6899
	try {
6900
		IJavaProject p = createJavaProject("P");
6901
		createFile("/P/library.jar", "");
6902
		setClasspath(p, new IClasspathEntry[] { JavaCore.newLibraryEntry(new Path("/P/library.jar"), null,null)});
6903
		assertMarkers("Unexpected markers", 
6904
				"Illegal type of archive for required library: \'library.jar\' in project \'P\'", p);
6905
	} finally {
6906
		deleteExternalResource("library.jar");
6907
		deleteProject("P");
6908
	}
6909
}
6817
6910
6818
}
6911
}

Return to bug 229042