View | Details | Raw Unified | Return to bug 182360
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-7 / +63 lines)
Lines 1484-1501 Link Here
1484
        " with ''+''.\n" +
1484
        " with ''+''.\n" +
1485
        " \n" +
1485
        " \n" +
1486
        " Classpath options:\n" +
1486
        " Classpath options:\n" +
1487
        "    -cp -classpath <directories and zip/jar files separated by " + File.pathSeparator + ">\n" +
1487
        "    -cp -classpath <directories and ZIP archives separated by " + File.pathSeparator + ">\n" +
1488
        "                       specify location for application classes and sources.\n" +
1488
        "                       specify location for application classes and sources.\n" +
1489
        "                       Each directory or file can specify access rules for\n" +
1489
        "                       Each directory or file can specify access rules for\n" +
1490
        "                       types between ''['' and '']'' (e.g. [-X] to forbid\n" +
1490
        "                       types between ''['' and '']'' (e.g. [-X] to forbid\n" +
1491
        "                       access to type X, [~X] to discourage access to type X,\n" +
1491
        "                       access to type X, [~X] to discourage access to type X,\n" +
1492
        "                       [+p/X" + File.pathSeparator + "-p/*] to forbid access to all types in package p\n" +
1492
        "                       [+p/X" + File.pathSeparator + "-p/*] to forbid access to all types in package p\n" +
1493
        "                       but allow access to p/X)\n" +
1493
        "                       but allow access to p/X)\n" +
1494
        "    -bootclasspath <directories and zip/jar files separated by " + File.pathSeparator + ">\n" +
1494
        "    -bootclasspath <directories and ZIP archives separated by " + File.pathSeparator + ">\n" +
1495
        "                       specify location for system classes. Each directory or\n" +
1495
        "                       specify location for system classes. Each directory or\n" +
1496
        "                       file can specify access rules for types between ''[''\n" +
1496
        "                       file can specify access rules for types between ''[''\n" +
1497
        "                       and '']''\n" +
1497
        "                       and '']''\n" +
1498
        "    -sourcepath <directories and zip/jar files separated by " + File.pathSeparator + ">\n" +
1498
        "    -sourcepath <directories and ZIP archives separated by " + File.pathSeparator + ">\n" +
1499
        "                       specify location for application sources. Each directory\n" +
1499
        "                       specify location for application sources. Each directory\n" +
1500
        "                       or file can specify access rules for types between ''[''\n" +
1500
        "                       or file can specify access rules for types between ''[''\n" +
1501
        "                       and '']''. Each directory can further specify a specific\n" +
1501
        "                       and '']''. Each directory can further specify a specific\n" +
Lines 1503-1514 Link Here
1503
        "                       and '']''; this overrides the general ''-d'' option.\n" +
1503
        "                       and '']''; this overrides the general ''-d'' option.\n" +
1504
        "                       .class files created from source files contained in a\n" +
1504
        "                       .class files created from source files contained in a\n" +
1505
        "                       jar file are put in the user.dir folder in case no\n" +
1505
        "                       jar file are put in the user.dir folder in case no\n" +
1506
        "                       general ''-d'' option is specified. zip/jar files cannot\n" +
1506
        "                       general ''-d'' option is specified. ZIP archives cannot\n" +
1507
        "                       override the general ''-d'' option\n" +
1507
        "                       override the general ''-d'' option\n" +
1508
        "    -extdirs <directories separated by " + File.pathSeparator + ">\n" +
1508
        "    -extdirs <directories separated by " + File.pathSeparator + ">\n" +
1509
        "                       specify location for extension zip/jar files\n" +
1509
        "                       specify location for extension ZIP archives\n" +
1510
        "    -endorseddirs <directories separated by " + File.pathSeparator + ">\n" +
1510
        "    -endorseddirs <directories separated by " + File.pathSeparator + ">\n" +
1511
        "                       specify location for endorsed zip/jar files\n" +
1511
        "                       specify location for endorsed ZIP archives\n" +
1512
        "    -d <dir>           destination directory (if omitted, no directory is\n" +
1512
        "    -d <dir>           destination directory (if omitted, no directory is\n" +
1513
        "                       created); this option can be overridden per source\n" +
1513
        "                       created); this option can be overridden per source\n" +
1514
		"                       directory\n" +
1514
		"                       directory\n" +
Lines 1544-1550 Link Here
1544
        " Annotation processing options:\n" + 
1544
        " Annotation processing options:\n" + 
1545
        "   These options are meaningful only in a 1.6 environment.\n" + 
1545
        "   These options are meaningful only in a 1.6 environment.\n" + 
1546
        "    -Akey[=value]        options that are passed to annotation processors\n" + 
1546
        "    -Akey[=value]        options that are passed to annotation processors\n" + 
1547
        "    -processorpath <directories and zip/jar files separated by " + File.pathSeparator + ">\n" + 
1547
        "    -processorpath <directories and ZIP archives separated by " + File.pathSeparator + ">\n" + 
1548
        "                         specify locations where to find annotation processors.\n" + 
1548
        "                         specify locations where to find annotation processors.\n" + 
1549
        "                         If this option is not used, the classpath will be\n" + 
1549
        "                         If this option is not used, the classpath will be\n" + 
1550
        "                         searched for processors\n" + 
1550
        "                         searched for processors\n" + 
Lines 10798-10801 Link Here
10798
	this.verifier.execute("Y", new String[] {OUTPUT_DIR });
10798
	this.verifier.execute("Y", new String[] {OUTPUT_DIR });
10799
	assertTrue(this.verifier.getExecutionOutput().startsWith("1")); // skip trailing newline
10799
	assertTrue(this.verifier.getExecutionOutput().startsWith("1")); // skip trailing newline
10800
}
10800
}
10801
10802
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=182360
10803
public void test281_classpath() {
10804
	runConformTest(
10805
		new String[] {
10806
			"src1/X.java",
10807
			"public class X {\n" +
10808
			"}",
10809
		},
10810
        "\"" + OUTPUT_DIR +  File.separator + "src1/X.java\" -cp Y.java",
10811
        "" /* expectedOutOutputString */,
10812
        "incorrect classpath: Y.java\n",
10813
        false/*shouldFlushOutput*/);
10814
}
10815
10816
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=182360
10817
public void test282_classpath() {
10818
	runConformTest(
10819
		new String[] {
10820
			"src1/X.java",
10821
			"public class X {\n" +
10822
			"}",
10823
		},
10824
        "\"" + OUTPUT_DIR +  File.separator + "src1/X.java\" -cp p/Y.java",
10825
        "" /* expectedOutOutputString */,
10826
        "incorrect classpath: p/Y.java\n",
10827
        false/*shouldFlushOutput*/);
10828
}
10829
10830
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=182360
10831
public void test283_classpath() {
10832
	runConformTest(
10833
		new String[] {
10834
			"src1/X.java",
10835
			"public class X {\n" +
10836
			"}",
10837
		},
10838
        "\"" + OUTPUT_DIR +  File.separator + "src1/X.java\" -cp Y.class",
10839
        "" /* expectedOutOutputString */,
10840
        "incorrect classpath: Y.class\n",
10841
        false/*shouldFlushOutput*/);
10842
}
10843
10844
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=182360
10845
public void test284_classpath() {
10846
	runConformTest(
10847
		new String[] {
10848
			"src1/X.java",
10849
			"public class X {\n" +
10850
			"}",
10851
		},
10852
        "\"" + OUTPUT_DIR +  File.separator + "src1/X.java\" -cp p/Y.class",
10853
        "" /* expectedOutOutputString */,
10854
        "incorrect classpath: p/Y.class\n",
10855
        false/*shouldFlushOutput*/);
10856
}
10801
}
10857
}
(-)model/org/eclipse/jdt/core/WorkingCopyOwner.java (-3 / +2 lines)
Lines 11-17 Link Here
11
package org.eclipse.jdt.core;
11
package org.eclipse.jdt.core;
12
12
13
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.Path;
15
import org.eclipse.jdt.internal.core.BufferManager;
14
import org.eclipse.jdt.internal.core.BufferManager;
16
import org.eclipse.jdt.internal.core.CompilationUnit;
15
import org.eclipse.jdt.internal.core.CompilationUnit;
17
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
16
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
Lines 135-141 Link Here
135
	 */
134
	 */
136
	public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
135
	public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
137
		ExternalJavaProject project = new ExternalJavaProject(classpath);
136
		ExternalJavaProject project = new ExternalJavaProject(classpath);
138
		IPackageFragment parent = project.getPackageFragmentRoot(Path.EMPTY).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
137
		IPackageFragment parent = project.getPackageFragmentRoot(project.getProject()).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
139
		CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
138
		CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
140
		result.becomeWorkingCopy(problemRequestor, monitor);
139
		result.becomeWorkingCopy(problemRequestor, monitor);
141
		return result;
140
		return result;
Lines 182-188 Link Here
182
	 */
181
	 */
183
	public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProgressMonitor monitor) throws JavaModelException {
182
	public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProgressMonitor monitor) throws JavaModelException {
184
		ExternalJavaProject project = new ExternalJavaProject(classpath);
183
		ExternalJavaProject project = new ExternalJavaProject(classpath);
185
		IPackageFragment parent = project.getPackageFragmentRoot(Path.EMPTY).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
184
		IPackageFragment parent = project.getPackageFragmentRoot(project.getProject()).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
186
		CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
185
		CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
187
		result.becomeWorkingCopy(getProblemRequestor(result), monitor);
186
		result.becomeWorkingCopy(getProblemRequestor(result), monitor);
188
		return result;
187
		return result;
(-)model/org/eclipse/jdt/core/IJavaProject.java (-4 / +5 lines)
Lines 473-480 Link Here
473
	IPath getOutputLocation() throws JavaModelException;
473
	IPath getOutputLocation() throws JavaModelException;
474
474
475
	/**
475
	/**
476
	 * Returns a package fragment root for an external library (a JAR or - since 3.4 - a class folder)
476
	 * Returns a package fragment root for an external library 
477
	 * at the specified file system path.
477
	 * (a ZIP archive - e.g. a <code>.jar</code>, a <code>.zip</code> file, etc. -
478
	 * or - since 3.4 - a class folder) at the specified file system path.
478
	 * This is a handle-only method.  The underlying <code>java.io.File</code>
479
	 * This is a handle-only method.  The underlying <code>java.io.File</code>
479
	 * may or may not exist. No resource is associated with this local library
480
	 * may or may not exist. No resource is associated with this local library
480
	 * package fragment root.
481
	 * package fragment root.
Lines 487-499 Link Here
487
	/**
488
	/**
488
	 * Returns a package fragment root for the given resource, which
489
	 * Returns a package fragment root for the given resource, which
489
	 * must either be a folder representing the top of a package hierarchy,
490
	 * must either be a folder representing the top of a package hierarchy,
490
	 * or a <code>.jar</code> or <code>.zip</code> file.
491
	 * or a ZIP archive (e.g. a <code>.jar</code>, a <code>.zip</code> file, etc.)
491
	 * This is a handle-only method.  The underlying resource may or may not exist. 
492
	 * This is a handle-only method.  The underlying resource may or may not exist. 
492
	 * 
493
	 * 
493
	 * @param resource the given resource
494
	 * @param resource the given resource
494
	 * @return a package fragment root for the given resource, which
495
	 * @return a package fragment root for the given resource, which
495
	 * must either be a folder representing the top of a package hierarchy,
496
	 * must either be a folder representing the top of a package hierarchy,
496
	 * or a <code>.jar</code> or <code>.zip</code> file
497
	 * or a ZIP archive (e.g. a <code>.jar</code>, a <code>.zip</code> file, etc.)
497
	 */
498
	 */
498
	IPackageFragmentRoot getPackageFragmentRoot(IResource resource);
499
	IPackageFragmentRoot getPackageFragmentRoot(IResource resource);
499
500
(-)model/org/eclipse/jdt/core/JavaCore.java (-28 / +19 lines)
Lines 127-133 Link Here
127
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
127
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
128
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
128
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
129
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
129
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
130
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
131
import org.eclipse.jdt.internal.core.*;
130
import org.eclipse.jdt.internal.core.*;
132
import org.eclipse.jdt.internal.core.builder.JavaBuilder;
131
import org.eclipse.jdt.internal.core.builder.JavaBuilder;
133
import org.eclipse.jdt.internal.core.builder.State;
132
import org.eclipse.jdt.internal.core.builder.State;
Lines 2363-2369 Link Here
2363
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions()
2362
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions()
2364
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
2363
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
2365
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
2364
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
2366
	 *	<li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
2365
	 *	<li>a ZIP archive (e.g. a <code>.jar</code>, a <code>.zip</code> file, etc.) - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
2367
	 *	</ul>
2366
	 *	</ul>
2368
	 * <p>
2367
	 * <p>
2369
	 * Creating a Java element has the side effect of creating and opening all of the
2368
	 * Creating a Java element has the side effect of creating and opening all of the
Lines 2421-2427 Link Here
2421
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions()
2420
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions()
2422
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
2421
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
2423
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
2422
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
2424
	 *	<li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
2423
	 *	<li>a ZIP archive (e.g. a <code>.jar</code>, a <code>.zip</code> file, etc.) - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
2425
	 *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
2424
	 *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
2426
	 *    	or <code>IPackageFragment</code></li>
2425
	 *    	or <code>IPackageFragment</code></li>
2427
	 *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
2426
	 *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
Lines 2448-2454 Link Here
2448
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions()
2447
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions()
2449
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
2448
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
2450
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
2449
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
2451
	 *	<li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
2450
	 *	<li>a ZIP archive (e.g. a <code>.jar</code>, a <code>.zip</code> file, etc.) - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
2452
	 *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
2451
	 *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
2453
	 *    	or <code>IPackageFragment</code></li>
2452
	 *    	or <code>IPackageFragment</code></li>
2454
	 *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
2453
	 *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
Lines 3231-3250 Link Here
3231
							entry.getExtraAttributes(),
3230
							entry.getExtraAttributes(),
3232
							entry.isExported());
3231
							entry.isExported());
3233
				case IResource.FILE :
3232
				case IResource.FILE :
3234
					if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resolvedResource.getName())) {
3233
					// internal binary archive
3235
						// internal binary archive
3236
						return JavaCore.newLibraryEntry(
3237
								resolvedPath,
3238
								getResolvedVariablePath(entry.getSourceAttachmentPath()),
3239
								getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
3240
								entry.getAccessRules(),
3241
								entry.getExtraAttributes(),
3242
								entry.isExported());
3243
					}
3244
					break;
3245
3246
				case IResource.FOLDER :
3247
					// internal binary folder
3248
					return JavaCore.newLibraryEntry(
3234
					return JavaCore.newLibraryEntry(
3249
							resolvedPath,
3235
							resolvedPath,
3250
							getResolvedVariablePath(entry.getSourceAttachmentPath()),
3236
							getResolvedVariablePath(entry.getSourceAttachmentPath()),
Lines 3252-3266 Link Here
3252
							entry.getAccessRules(),
3238
							entry.getAccessRules(),
3253
							entry.getExtraAttributes(),
3239
							entry.getExtraAttributes(),
3254
							entry.isExported());
3240
							entry.isExported());
3255
			}
3241
				case IResource.FOLDER :
3256
		}
3242
					// internal binary folder
3257
		if (target instanceof File) {
3258
			File externalFile = JavaModel.getFile(target);
3259
			if (externalFile != null) {
3260
				// outside the workspace
3261
				String fileName = externalFile.getName().toLowerCase();
3262
				if (fileName.endsWith(SuffixConstants.SUFFIX_STRING_jar) || fileName.endsWith(SuffixConstants.SUFFIX_STRING_zip)) {
3263
					// external binary archive
3264
					return JavaCore.newLibraryEntry(
3243
					return JavaCore.newLibraryEntry(
3265
							resolvedPath,
3244
							resolvedPath,
3266
							getResolvedVariablePath(entry.getSourceAttachmentPath()),
3245
							getResolvedVariablePath(entry.getSourceAttachmentPath()),
Lines 3268-3274 Link Here
3268
							entry.getAccessRules(),
3247
							entry.getAccessRules(),
3269
							entry.getExtraAttributes(),
3248
							entry.getExtraAttributes(),
3270
							entry.isExported());
3249
							entry.isExported());
3271
				}
3250
			}
3251
		}
3252
		if (target instanceof File) {
3253
			File externalFile = JavaModel.getFile(target);
3254
			if (externalFile != null) {
3255
				// external binary archive
3256
				return JavaCore.newLibraryEntry(
3257
						resolvedPath,
3258
						getResolvedVariablePath(entry.getSourceAttachmentPath()),
3259
						getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
3260
						entry.getAccessRules(),
3261
						entry.getExtraAttributes(),
3262
						entry.isExported());
3272
			} else { 
3263
			} else { 
3273
				// non-existing file
3264
				// non-existing file
3274
				if (resolvedPath.isAbsolute()){
3265
				if (resolvedPath.isAbsolute()){
(-)model/org/eclipse/jdt/core/JavaConventions.java (-9 lines)
Lines 25-31 Link Here
25
import org.eclipse.jdt.internal.compiler.parser.Scanner;
25
import org.eclipse.jdt.internal.compiler.parser.Scanner;
26
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
26
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
27
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
27
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
28
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
29
import org.eclipse.jdt.internal.core.*;
28
import org.eclipse.jdt.internal.core.*;
30
import org.eclipse.jdt.internal.core.util.Messages;
29
import org.eclipse.jdt.internal.core.util.Messages;
31
30
Lines 62-75 Link Here
62
		if (rootPath1 == null || rootPath2 == null) {
61
		if (rootPath1 == null || rootPath2 == null) {
63
			return false;
62
			return false;
64
		}
63
		}
65
		String extension1 = rootPath1.getFileExtension();
66
		String extension2 = rootPath2.getFileExtension();
67
		if (extension1 != null && (extension1.equalsIgnoreCase(SuffixConstants.EXTENSION_JAR) || extension1.equalsIgnoreCase(SuffixConstants.EXTENSION_ZIP))) {
68
			return false;
69
		} 
70
		if (extension2 != null && (extension2.equalsIgnoreCase(SuffixConstants.EXTENSION_JAR) || extension2.equalsIgnoreCase(SuffixConstants.EXTENSION_ZIP))) {
71
			return false;
72
		}
73
		return rootPath1.isPrefixOf(rootPath2) || rootPath2.isPrefixOf(rootPath1);
64
		return rootPath1.isPrefixOf(rootPath2) || rootPath2.isPrefixOf(rootPath1);
74
	}
65
	}
75
66
(-)model/org/eclipse/jdt/internal/core/util/HandleFactory.java (-1 / +1 lines)
Lines 270-276 Link Here
270
			int index = 0;
270
			int index = 0;
271
			for (int i = 0; i < length; i++) {
271
			for (int i = 0; i < length; i++) {
272
				IPath path = enclosingProjectsAndJars[i];
272
				IPath path = enclosingProjectsAndJars[i];
273
				if (!org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(path.lastSegment())) {
273
				if (path.segmentCount() == 1) {
274
					projects[index++] = this.javaModel.getJavaProject(path.segment(0));
274
					projects[index++] = this.javaModel.getJavaProject(path.segment(0));
275
				}
275
				}
276
			}
276
			}
(-)model/org/eclipse/jdt/internal/core/ExternalPackageFragmentRoot.java (-1 / +1 lines)
Lines 107-113 Link Here
107
	
107
	
108
	public IResource resource(PackageFragmentRoot root) {
108
	public IResource resource(PackageFragmentRoot root) {
109
		if (this.resource == null)
109
		if (this.resource == null)
110
			return (IResource) (this.resource = JavaModelManager.getExternalManager().getFolder(this.externalPath));
110
			return this.resource = JavaModelManager.getExternalManager().getFolder(this.externalPath);
111
		return super.resource(root);
111
		return super.resource(root);
112
	}
112
	}
113
	
113
	
(-)model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java (-1 / +1 lines)
Lines 77-83 Link Here
77
		File externalFolder = externalPath.toFile();
77
		File externalFolder = externalPath.toFile();
78
		if (externalFolder.isFile())
78
		if (externalFolder.isFile())
79
			return false;
79
			return false;
80
		if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(externalPath.lastSegment()) && !externalFolder.exists())
80
		if (externalPath.getFileExtension() != null/*likely a .jar, .zip, .rar or other file*/ && !externalFolder.exists())
81
			return false;
81
			return false;
82
		return true;
82
		return true;
83
	}
83
	}
(-)model/org/eclipse/jdt/internal/core/JavaModel.java (-1 / +1 lines)
Lines 318-324 Link Here
318
		return target;
318
		return target;
319
	return getExternalTarget(path, checkResourceExistence);
319
	return getExternalTarget(path, checkResourceExistence);
320
}
320
}
321
public static Object getWorkspaceTarget(IPath path) {
321
public static IResource getWorkspaceTarget(IPath path) {
322
	if (path == null || path.getDevice() != null)
322
	if (path == null || path.getDevice() != null)
323
		return null;
323
		return null;
324
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
324
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
(-)model/org/eclipse/jdt/internal/core/SourceMapper.java (-19 / +15 lines)
Lines 412-418 Link Here
412
			}
412
			}
413
		}
413
		}
414
414
415
		if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
415
		Object target = JavaModel.getTarget(this.sourcePath, true);
416
		if (target instanceof IContainer) {
417
			computeRootPath((IContainer)target, firstLevelPackageNames, containsADefaultPackage, tempRoots);
418
		} else {
416
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
419
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
417
			ZipFile zip = null;
420
			ZipFile zip = null;
418
			try {
421
			try {
Lines 443-453 Link Here
443
			} finally {
446
			} finally {
444
				manager.closeZipFile(zip); // handle null case
447
				manager.closeZipFile(zip); // handle null case
445
			}
448
			}
446
		} else {
447
			Object target = JavaModel.getTarget(this.sourcePath, true);
448
			if (target instanceof IContainer) {
449
				computeRootPath((IContainer)target, firstLevelPackageNames, containsADefaultPackage, tempRoots);
450
			}
451
		}
449
		}
452
		int size = tempRoots.size();
450
		int size = tempRoots.size();
453
		if (this.rootPaths != null) {
451
		if (this.rootPaths != null) {
Lines 884-890 Link Here
884
	
882
	
885
	public char[] findSource(String fullName) {
883
	public char[] findSource(String fullName) {
886
		char[] source = null;
884
		char[] source = null;
887
		if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
885
		Object target = JavaModel.getTarget(this.sourcePath, true);
886
		if (target instanceof IContainer) {
887
			IResource res = ((IContainer)target).findMember(fullName);
888
			if (res instanceof IFile) {
889
				try {
890
					source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
891
				} catch (JavaModelException e) {
892
					// ignore
893
				}
894
			}
895
		} else {
888
			// try to get the entry
896
			// try to get the entry
889
			ZipEntry entry = null;
897
			ZipEntry entry = null;
890
			ZipFile zip = null;
898
			ZipFile zip = null;
Lines 901-918 Link Here
901
			} finally {
909
			} finally {
902
				manager.closeZipFile(zip); // handle null case
910
				manager.closeZipFile(zip); // handle null case
903
			}
911
			}
904
		} else {
905
			Object target = JavaModel.getTarget(this.sourcePath, true);
906
			if (target instanceof IContainer) {
907
				IResource res = ((IContainer)target).findMember(fullName);
908
				if (res instanceof IFile) {
909
					try {
910
						source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
911
					} catch (JavaModelException e) {
912
						// ignore
913
					}
914
				}
915
			}
916
		}
912
		}
917
		return source;
913
		return source;
918
	}
914
	}
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (-46 / +14 lines)
Lines 38-47 Link Here
38
	public final static String NO_SOURCE_ATTACHMENT = ""; //$NON-NLS-1$
38
	public final static String NO_SOURCE_ATTACHMENT = ""; //$NON-NLS-1$
39
39
40
	/**
40
	/**
41
	 * The resource associated with this root.
41
	 * The resource associated with this root (null for external jar)
42
	 * (an IResource or a java.io.File (for external jar only))
43
	 */
42
	 */
44
	protected Object resource;
43
	protected IResource resource;
45
	
44
	
46
/**
45
/**
47
 * Constructs a package fragment root which is the root of the java package
46
 * Constructs a package fragment root which is the root of the java package
Lines 335-361 Link Here
335
		JavaProject parentProject = (JavaProject) getJavaProject();
334
		JavaProject parentProject = (JavaProject) getJavaProject();
336
		try {
335
		try {
337
			entry = parentProject.getClasspathEntryFor(rootPath);
336
			entry = parentProject.getClasspathEntryFor(rootPath);
338
			if (entry != null){
337
			if (entry != null) {
339
				Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
338
				Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
340
				if (target instanceof IResource) {
339
				if (target != null) {
341
					if (target instanceof IFile) {
340
					return entry;
342
						IFile file = (IFile) target;
343
						if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
344
							return entry;
345
						}
346
					} else if (target instanceof IContainer) {
347
						return entry;
348
					}
349
				} else if (target instanceof java.io.File){
350
					java.io.File file = JavaModel.getFile(target);
351
					if (file != null) {
352
						if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
353
							return entry;
354
						}
355
					} else {
356
						// external directory
357
						return entry;
358
					}
359
				}
341
				}
360
			}
342
			}
361
		} catch(JavaModelException e){
343
		} catch(JavaModelException e){
Lines 372-391 Link Here
372
				entry = jProject.getClasspathEntryFor(rootPath);
354
				entry = jProject.getClasspathEntryFor(rootPath);
373
				if (entry != null){
355
				if (entry != null){
374
					Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
356
					Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
375
					if (target instanceof IResource) {
357
					if (target != null) {
376
						if (target instanceof IFile){
358
						return entry;
377
							IFile file = (IFile) target;
378
							if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
379
								return entry;
380
							}
381
						} else if (target instanceof IContainer) {
382
							return entry;
383
						}
384
					} else if (target instanceof java.io.File){
385
						java.io.File file = (java.io.File) target;
386
						if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
387
							return entry;
388
						}
389
					}
359
					}
390
				}
360
				}
391
			} catch(JavaModelException e){
361
			} catch(JavaModelException e){
Lines 587-601 Link Here
587
557
588
558
589
public IResource resource() {
559
public IResource resource() {
590
	if (this.resource instanceof IResource) // perf improvement to avoid message send in resource()
560
	if (this.resource != null) // perf improvement to avoid message send in resource()
591
		return (IResource) this.resource;
561
		return this.resource;
592
	return super.resource();
562
	return super.resource();
593
}
563
}
594
/*
564
/*
595
 * @see IJavaElement
565
 * @see IJavaElement
596
 */
566
 */
597
public IResource resource(PackageFragmentRoot root) {
567
public IResource resource(PackageFragmentRoot root) {
598
	return (IResource)this.resource;
568
	return this.resource;
599
}
569
}
600
570
601
/**
571
/**
Lines 776-793 Link Here
776
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) {
746
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) {
777
	buffer.append(this.tabString(tab));
747
	buffer.append(this.tabString(tab));
778
	IPath path = getPath();
748
	IPath path = getPath();
779
	if (getJavaProject().getElementName().equals(path.segment(0))) {
749
	if (isExternal()) {
750
		buffer.append(path.toOSString());
751
	} else if (getJavaProject().getElementName().equals(path.segment(0))) {
780
	    if (path.segmentCount() == 1) {
752
	    if (path.segmentCount() == 1) {
781
			buffer.append("<project root>"); //$NON-NLS-1$
753
			buffer.append("<project root>"); //$NON-NLS-1$
782
	    } else {
754
	    } else {
783
			buffer.append(path.removeFirstSegments(1).makeRelative());
755
			buffer.append(path.removeFirstSegments(1).makeRelative());
784
	    }
756
	    }
785
	} else {
757
	} else {
786
	    if (isExternal()) {
758
		buffer.append(path);
787
			buffer.append(path.toOSString());
788
	    } else {
789
			buffer.append(path);
790
	    }
791
	}
759
	}
792
	if (info == null) {
760
	if (info == null) {
793
		buffer.append(" (not open)"); //$NON-NLS-1$
761
		buffer.append(" (not open)"); //$NON-NLS-1$
(-)model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java (-1 / +1 lines)
Lines 134-140 Link Here
134
							String resName = res.getName();
134
							String resName = res.getName();
135
						
135
						
136
							// ignore a jar file on the classpath
136
							// ignore a jar file on the classpath
137
							if (isClasspathResolved && org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
137
							if (isClasspathResolved && isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
138
								break;
138
								break;
139
							}
139
							}
140
							// ignore .java file if src == project
140
							// ignore .java file if src == project
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-68 / +53 lines)
Lines 479-485 Link Here
479
	 * @param accumulatedRoots ObjectVector
479
	 * @param accumulatedRoots ObjectVector
480
	 * @param rootIDs HashSet
480
	 * @param rootIDs HashSet
481
	 * @param referringEntry the CP entry (project) referring to this entry, or null if initial project
481
	 * @param referringEntry the CP entry (project) referring to this entry, or null if initial project
482
	 * @param checkExistency boolean
483
	 * @param retrieveExportedRoots boolean
482
	 * @param retrieveExportedRoots boolean
484
	 * @throws JavaModelException
483
	 * @throws JavaModelException
485
	 */
484
	 */
Lines 488-494 Link Here
488
		ObjectVector accumulatedRoots, 
487
		ObjectVector accumulatedRoots, 
489
		HashSet rootIDs, 
488
		HashSet rootIDs, 
490
		IClasspathEntry referringEntry,
489
		IClasspathEntry referringEntry,
491
		boolean checkExistency,
492
		boolean retrieveExportedRoots,
490
		boolean retrieveExportedRoots,
493
		Map rootToResolvedEntries) throws JavaModelException {
491
		Map rootToResolvedEntries) throws JavaModelException {
494
			
492
			
Lines 506-546 Link Here
506
			case IClasspathEntry.CPE_SOURCE :
504
			case IClasspathEntry.CPE_SOURCE :
507
505
508
				if (projectPath.isPrefixOf(entryPath)){
506
				if (projectPath.isPrefixOf(entryPath)){
509
					if (checkExistency) {
507
					Object target = JavaModel.getTarget(entryPath, true/*check existency*/);
510
						Object target = JavaModel.getTarget(entryPath, checkExistency);
508
					if (target == null) return;
511
						if (target == null) return;
509
512
	
510
					if (target instanceof IFolder || target instanceof IProject){
513
						if (target instanceof IFolder || target instanceof IProject){
511
						root = getPackageFragmentRoot((IResource)target);
514
							root = getPackageFragmentRoot((IResource)target);
515
						}
516
					} else {
517
						root = getFolderPackageFragmentRoot(entryPath);
518
					}
512
					}
519
				}
513
				}
520
				break;
514
				break;
521
515
522
			// internal/external JAR or folder
516
			// internal/external JAR or folder
523
			case IClasspathEntry.CPE_LIBRARY :
517
			case IClasspathEntry.CPE_LIBRARY :
524
			
518
				if (referringEntry != null  && !resolvedEntry.isExported()) 
525
				if (referringEntry != null  && !resolvedEntry.isExported()) return;
519
					return;
526
				
520
				Object target = JavaModel.getTarget(entryPath, true/*check existency*/);
527
				if (checkExistency) {
521
				if (target == null) 
528
					Object target = JavaModel.getTarget(entryPath, checkExistency);
522
					return;
529
					if (target == null) return;
523
530
	
524
				if (target instanceof IResource){
531
					if (target instanceof IResource){
525
					// internal target
532
						// internal target
526
					root = getPackageFragmentRoot((IResource) target, entryPath);
533
						root = getPackageFragmentRoot((IResource) target, entryPath);
527
				} else if (target instanceof File) {
534
					} else if (target instanceof File) {
528
					// external target
535
						// external target
529
					if (JavaModel.isFile(target)) {
536
						if (JavaModel.isFile(target) && (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(entryPath.lastSegment()))) {
530
						root = new JarPackageFragmentRoot(entryPath, this);
537
							root = new JarPackageFragmentRoot(entryPath, this);
531
					} else if (((File) target).isDirectory()) {
538
						} else if (((File) target).isDirectory()) {
532
						root = new ExternalPackageFragmentRoot(entryPath, this);
539
							root = new ExternalPackageFragmentRoot(entryPath, this);
540
						}
541
					}
533
					}
542
				} else {
543
					root = getPackageFragmentRoot(entryPath);
544
				}
534
				}
545
				break;
535
				break;
546
536
Lines 561-567 Link Here
561
							accumulatedRoots, 
551
							accumulatedRoots, 
562
							rootIDs, 
552
							rootIDs, 
563
							rootToResolvedEntries == null ? resolvedEntry : ((ClasspathEntry)resolvedEntry).combineWith((ClasspathEntry) referringEntry), // only combine if need to build the reverse map 
553
							rootToResolvedEntries == null ? resolvedEntry : ((ClasspathEntry)resolvedEntry).combineWith((ClasspathEntry) referringEntry), // only combine if need to build the reverse map 
564
							checkExistency, 
565
							retrieveExportedRoots,
554
							retrieveExportedRoots,
566
							rootToResolvedEntries);
555
							rootToResolvedEntries);
567
					}
556
					}
Lines 596-602 Link Here
596
			accumulatedRoots, 
585
			accumulatedRoots, 
597
			new HashSet(5), // rootIDs
586
			new HashSet(5), // rootIDs
598
			null, // inside original project
587
			null, // inside original project
599
			true, // check existency
600
			retrieveExportedRoots,
588
			retrieveExportedRoots,
601
			rootToResolvedEntries);
589
			rootToResolvedEntries);
602
		IPackageFragmentRoot[] rootArray = new IPackageFragmentRoot[accumulatedRoots.size()];
590
		IPackageFragmentRoot[] rootArray = new IPackageFragmentRoot[accumulatedRoots.size()];
Lines 613-619 Link Here
613
	 * @param accumulatedRoots ObjectVector
601
	 * @param accumulatedRoots ObjectVector
614
	 * @param rootIDs HashSet
602
	 * @param rootIDs HashSet
615
	 * @param referringEntry project entry referring to this CP or null if initial project
603
	 * @param referringEntry project entry referring to this CP or null if initial project
616
	 * @param checkExistency boolean
617
	 * @param retrieveExportedRoots boolean
604
	 * @param retrieveExportedRoots boolean
618
	 * @throws JavaModelException
605
	 * @throws JavaModelException
619
	 */
606
	 */
Lines 622-628 Link Here
622
		ObjectVector accumulatedRoots, 
609
		ObjectVector accumulatedRoots, 
623
		HashSet rootIDs, 
610
		HashSet rootIDs, 
624
		IClasspathEntry referringEntry,
611
		IClasspathEntry referringEntry,
625
		boolean checkExistency,
626
		boolean retrieveExportedRoots,
612
		boolean retrieveExportedRoots,
627
		Map rootToResolvedEntries) throws JavaModelException {
613
		Map rootToResolvedEntries) throws JavaModelException {
628
614
Lines 635-641 Link Here
635
				accumulatedRoots,
621
				accumulatedRoots,
636
				rootIDs,
622
				rootIDs,
637
				referringEntry,
623
				referringEntry,
638
				checkExistency,
639
				retrieveExportedRoots,
624
				retrieveExportedRoots,
640
				rootToResolvedEntries);
625
				rootToResolvedEntries);
641
		}
626
		}
Lines 1622-1652 Link Here
1622
			path = getPath().append(path);
1607
			path = getPath().append(path);
1623
		}
1608
		}
1624
		int segmentCount = path.segmentCount();
1609
		int segmentCount = path.segmentCount();
1625
		switch (segmentCount) {
1610
		if (segmentCount == 0) {
1626
			case 0:
1611
			return null;
1627
				return null;
1612
		}
1628
			case 1:
1613
		if (path.getDevice() != null || JavaModel.getExternalTarget(path, true/*check existence*/) != null) {
1629
				if (path.equals(getPath())) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75814
1614
			// external path
1630
					// default root
1615
			return getPackageFragmentRoot0(path);
1631
					return getPackageFragmentRoot(this.project);
1616
		}
1632
				}
1617
		IWorkspaceRoot workspaceRoot = this.project.getWorkspace().getRoot();
1633
			default:
1618
		if (segmentCount == 1) {
1634
				// a path ending with .jar/.zip is still ambiguous and could still resolve to a source/lib folder 
1619
			String projectName = path.segment(0);
1635
				// thus will try to guess based on existing resource
1620
			if (getElementName().equals(projectName)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75814
1636
				if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(path.lastSegment())) {
1621
				// default root
1637
					IResource resource = this.project.getWorkspace().getRoot().findMember(path); 
1622
				return getPackageFragmentRoot(this.project);
1638
					if (resource != null && resource.getType() == IResource.FOLDER){
1623
			} else {
1639
						return getPackageFragmentRoot(resource);
1624
				// lib being another project
1640
					}
1625
				return getPackageFragmentRoot(workspaceRoot.getProject(projectName));
1641
					return getPackageFragmentRoot0(path);
1626
			}
1642
				} else if (segmentCount == 1) {
1627
		}
1643
					// lib being another project
1628
		IResource resource = workspaceRoot.findMember(path); 
1644
					return getPackageFragmentRoot(this.project.getWorkspace().getRoot().getProject(path.lastSegment()));
1629
		if (resource == null) {
1645
				} else {
1630
			// resource doesn't exist in workspace
1646
					// lib being a folder
1631
			if (path.getFileExtension() != null) {
1647
					return getPackageFragmentRoot(this.project.getWorkspace().getRoot().getFolder(path));
1632
				// assume it is a file
1648
				}
1633
				resource = workspaceRoot.getFile(path);
1634
			} else {
1635
				// assume it is a folder
1636
				resource = workspaceRoot.getFolder(path);
1637
			}
1649
		}
1638
		}
1639
		return getPackageFragmentRoot(resource);
1650
	}
1640
	}
1651
1641
1652
	/**
1642
	/**
Lines 1659-1669 Link Here
1659
	private IPackageFragmentRoot getPackageFragmentRoot(IResource resource, IPath entryPath) {
1649
	private IPackageFragmentRoot getPackageFragmentRoot(IResource resource, IPath entryPath) {
1660
		switch (resource.getType()) {
1650
		switch (resource.getType()) {
1661
			case IResource.FILE:
1651
			case IResource.FILE:
1662
				if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resource.getName())) {
1652
				return new JarPackageFragmentRoot(resource, this);
1663
					return new JarPackageFragmentRoot(resource, this);
1664
				} else {
1665
					return null;
1666
				}
1667
			case IResource.FOLDER:
1653
			case IResource.FOLDER:
1668
				if (ExternalFoldersManager.isInternalPathForExternalFolder(resource.getFullPath()))
1654
				if (ExternalFoldersManager.isInternalPathForExternalFolder(resource.getFullPath()))
1669
					return new ExternalPackageFragmentRoot(resource, entryPath, this);
1655
					return new ExternalPackageFragmentRoot(resource, entryPath, this);
Lines 1679-1685 Link Here
1679
	 * @see IJavaProject
1665
	 * @see IJavaProject
1680
	 */
1666
	 */
1681
	public IPackageFragmentRoot getPackageFragmentRoot(String libraryPath) {
1667
	public IPackageFragmentRoot getPackageFragmentRoot(String libraryPath) {
1682
1683
		return getPackageFragmentRoot0(JavaProject.canonicalizedPath(new Path(libraryPath)));
1668
		return getPackageFragmentRoot0(JavaProject.canonicalizedPath(new Path(libraryPath)));
1684
	}
1669
	}
1685
1670
Lines 1687-1696 Link Here
1687
	 * no path canonicalization
1672
	 * no path canonicalization
1688
	 */
1673
	 */
1689
	public IPackageFragmentRoot getPackageFragmentRoot0(IPath libraryPath) {
1674
	public IPackageFragmentRoot getPackageFragmentRoot0(IPath libraryPath) {
1690
		if (!org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(libraryPath.lastSegment()))
1675
		IFolder linkedFolder = JavaModelManager.getExternalManager().getFolder(libraryPath);
1691
			return new ExternalPackageFragmentRoot(libraryPath, this);
1676
		if (linkedFolder != null)
1677
			return new ExternalPackageFragmentRoot(linkedFolder, libraryPath, this);
1692
		return new JarPackageFragmentRoot(libraryPath, this);
1678
		return new JarPackageFragmentRoot(libraryPath, this);
1693
		
1694
	}
1679
	}
1695
1680
1696
	/**
1681
	/**
(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-14 / +10 lines)
Lines 19-24 Link Here
19
import java.util.HashSet;
19
import java.util.HashSet;
20
import java.util.Map;
20
import java.util.Map;
21
21
22
import org.eclipse.core.resources.IContainer;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IWorkspaceRoot;
25
import org.eclipse.core.resources.IWorkspaceRoot;
Lines 1375-1381 Link Here
1375
					break;
1376
					break;
1376
1377
1377
				case IClasspathEntry.CPE_LIBRARY:
1378
				case IClasspathEntry.CPE_LIBRARY:
1378
					hasLibFolder |= !org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(path.lastSegment());
1379
					Object target = JavaModel.getTarget(path, false/*don't check resource existence*/);
1380
					hasLibFolder |= target instanceof IContainer;
1379
					if ((index = Util.indexOfMatchingPath(path, outputLocations, outputCount)) != -1){
1381
					if ((index = Util.indexOfMatchingPath(path, outputLocations, outputCount)) != -1){
1380
						allowNestingInOutputLocations[index] = true;
1382
						allowNestingInOutputLocations[index] = true;
1381
					}
1383
					}
Lines 1415-1421 Link Here
1415
1417
1416
			// allow nesting source entries in each other as long as the outer entry excludes the inner one
1418
			// allow nesting source entries in each other as long as the outer entry excludes the inner one
1417
			if (kind == IClasspathEntry.CPE_SOURCE
1419
			if (kind == IClasspathEntry.CPE_SOURCE
1418
					|| (kind == IClasspathEntry.CPE_LIBRARY && !org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(entryPath.lastSegment()))){
1420
					|| (kind == IClasspathEntry.CPE_LIBRARY && (JavaModel.getTarget(entryPath, false/*don't check existence*/) instanceof IContainer))) {
1419
				for (int j = 0; j < classpath.length; j++){
1421
				for (int j = 0; j < classpath.length; j++){
1420
					IClasspathEntry otherEntry = classpath[j];
1422
					IClasspathEntry otherEntry = classpath[j];
1421
					if (otherEntry == null) continue;
1423
					if (otherEntry == null) continue;
Lines 1424-1430 Link Here
1424
					if (entry != otherEntry
1426
					if (entry != otherEntry
1425
						&& (otherKind == IClasspathEntry.CPE_SOURCE
1427
						&& (otherKind == IClasspathEntry.CPE_SOURCE
1426
								|| (otherKind == IClasspathEntry.CPE_LIBRARY
1428
								|| (otherKind == IClasspathEntry.CPE_LIBRARY
1427
										&& !org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(otherPath.lastSegment())))){
1429
										&& (JavaModel.getTarget(otherPath, false/*don't check existence*/) instanceof IContainer)))) {
1428
						char[][] inclusionPatterns, exclusionPatterns;
1430
						char[][] inclusionPatterns, exclusionPatterns;
1429
						if (otherPath.isPrefixOf(entryPath)
1431
						if (otherPath.isPrefixOf(entryPath)
1430
								&& !otherPath.equals(entryPath)
1432
								&& !otherPath.equals(entryPath)
Lines 1636-1650 Link Here
1636
						IResource resolvedResource = (IResource) target;
1638
						IResource resolvedResource = (IResource) target;
1637
						switch(resolvedResource.getType()){
1639
						switch(resolvedResource.getType()){
1638
							case IResource.FILE :
1640
							case IResource.FILE :
1639
								if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resolvedResource.getName())) {
1641
								if (checkSourceAttachment
1640
									if (checkSourceAttachment
1642
									&& sourceAttachment != null
1641
										&& sourceAttachment != null
1643
									&& !sourceAttachment.isEmpty()
1642
										&& !sourceAttachment.isEmpty()
1644
									&& JavaModel.getTarget(sourceAttachment, true) == null){
1643
										&& JavaModel.getTarget(sourceAttachment, true) == null){
1645
									return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
1644
										return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
1645
									}
1646
								} else {
1647
									return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryArchive, new String[] {entryPathMsg, projectName}));
1648
								}
1646
								}
1649
								break;
1647
								break;
1650
							case IResource.FOLDER :	// internal binary folder
1648
							case IResource.FOLDER :	// internal binary folder
Lines 1659-1666 Link Here
1659
						File file = JavaModel.getFile(target);
1657
						File file = JavaModel.getFile(target);
1660
					    if (file == null) {
1658
					    if (file == null) {
1661
							return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), projectName}));
1659
							return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), projectName}));
1662
					    } else if (!org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())) {
1663
							return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryArchive, (new String[] {path.toOSString(), projectName})));
1664
					    } else if (checkSourceAttachment
1660
					    } else if (checkSourceAttachment
1665
								&& sourceAttachment != null
1661
								&& sourceAttachment != null
1666
								&& !sourceAttachment.isEmpty()
1662
								&& !sourceAttachment.isEmpty()
(-)model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java (-30 / +36 lines)
Lines 12-17 Link Here
12
12
13
import java.util.*;
13
import java.util.*;
14
import java.util.zip.ZipEntry;
14
import java.util.zip.ZipEntry;
15
import java.util.zip.ZipException;
15
import java.util.zip.ZipFile;
16
import java.util.zip.ZipFile;
16
17
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IResource;
Lines 71-89 Link Here
71
		IJavaElement[] children;
72
		IJavaElement[] children;
72
		ZipFile jar = null;
73
		ZipFile jar = null;
73
		try {
74
		try {
74
			// always create the default package
75
			rawPackageInfo.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
76
	
77
			IJavaProject project = getJavaProject();
75
			IJavaProject project = getJavaProject();
78
			String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
76
			String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
79
			String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
77
			String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
80
			jar = getJar();
78
			jar = getJar();
79
80
			// always create the default package
81
			rawPackageInfo.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
82
			
81
			for (Enumeration e= jar.entries(); e.hasMoreElements();) {
83
			for (Enumeration e= jar.entries(); e.hasMoreElements();) {
82
				ZipEntry member= (ZipEntry) e.nextElement();
84
				ZipEntry member= (ZipEntry) e.nextElement();
83
				initRawPackageInfo(rawPackageInfo, member.getName(), member.isDirectory(), sourceLevel, compliance);
85
				initRawPackageInfo(rawPackageInfo, member.getName(), member.isDirectory(), sourceLevel, compliance);
84
			}
86
			}
85
			
87
			
86
			//l oop through all of referenced packages, creating package fragments if necessary
88
			// loop through all of referenced packages, creating package fragments if necessary
87
			// and cache the entry names in the rawPackageInfo table
89
			// and cache the entry names in the rawPackageInfo table
88
			children = new IJavaElement[rawPackageInfo.size()];
90
			children = new IJavaElement[rawPackageInfo.size()];
89
			int index = 0;
91
			int index = 0;
Lines 93-100 Link Here
93
				children[index++] = getPackageFragment(pkgName);
95
				children[index++] = getPackageFragment(pkgName);
94
			}
96
			}
95
		} catch (CoreException e) {
97
		} catch (CoreException e) {
96
			if (e instanceof JavaModelException) throw (JavaModelException)e;
98
			if (e.getCause() instanceof ZipException) {
97
			throw new JavaModelException(e);
99
				// not a ZIP archive, leave the children empty
100
				Util.log(e, "Invalid ZIP archive: " + toStringWithAncestors()); //$NON-NLS-1$
101
				children = NO_ELEMENTS;
102
			} else if (e instanceof JavaModelException) {
103
				throw (JavaModelException)e;
104
			} else {
105
				throw new JavaModelException(e);
106
			}
98
		} finally {
107
		} finally {
99
			JavaModelManager.getJavaModelManager().closeZipFile(jar);
108
			JavaModelManager.getJavaModelManager().closeZipFile(jar);
100
		}
109
		}
Lines 178-192 Link Here
178
		}
187
		}
179
	}	
188
	}	
180
	public IResource resource(PackageFragmentRoot root) {
189
	public IResource resource(PackageFragmentRoot root) {
181
		if (this.resource == null && org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(this.jarPath.lastSegment())) {
190
		if (this.resource == null) {
182
			this.resource = JavaModel.getTarget(this.jarPath, false);
183
		}
184
		if (this.resource instanceof IResource) {
185
			return super.resource(root);
186
		} else {
187
			// external jar
191
			// external jar
188
			return null;
192
			return null;
189
		}
193
		}
194
		return super.resource(root);
190
	}
195
	}
191
196
192
197
Lines 266-288 Link Here
266
	}
271
	}
267
272
268
	/**
273
	/**
269
 * Returns whether the corresponding resource or associated file exists
274
	 * Returns whether the corresponding resource or associated file exists
270
 */
275
	 */
271
protected boolean resourceExists(IResource underlyingResource) {
276
	protected boolean resourceExists(IResource underlyingResource) {
272
	if (underlyingResource == null) {
277
		if (underlyingResource == null) {
273
		return 
278
			return 
274
			JavaModel.getTarget(
279
				JavaModel.getExternalTarget(
275
				getPath(), // don't make the path relative as this is an external archive
280
					getPath()/*don't make the path relative as this is an external archive*/, 
276
				true) != null;
281
					true/*check existence*/) != null;	
277
	} else {
282
		} else {
278
		return super.resourceExists(underlyingResource);
283
			return super.resourceExists(underlyingResource);
284
		}
285
	}
286
	
287
	protected void toStringAncestors(StringBuffer buffer) {
288
		if (isExternal())
289
			// don't show project as it is irrelevant for external jar files.
290
			// also see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146615
291
			return;
292
		super.toStringAncestors(buffer);
279
	}
293
	}
280
}
281
protected void toStringAncestors(StringBuffer buffer) {
282
	if (isExternal())
283
		// don't show project as it is irrelevant for external jar files.
284
		// also see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146615
285
		return;
286
	super.toStringAncestors(buffer);
287
}
288
}
294
}
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-4 / +3 lines)
Lines 720-726 Link Here
720
	 *	<li>a project - the element returned is the corresponding <code>IJavaProject</code></li>
720
	 *	<li>a project - the element returned is the corresponding <code>IJavaProject</code></li>
721
	 *	<li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
721
	 *	<li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
722
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
722
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
723
	 *	<li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
723
	 *	<li>a ZIP archive (e.g. a <code>.jar</code>, a <code>.zip</code> file, etc.) - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
724
	 *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
724
	 *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
725
	 *			or <code>IPackageFragment</code></li>
725
	 *			or <code>IPackageFragment</code></li>
726
	 *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
726
	 *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
Lines 757-763 Link Here
757
	 * <p>The file must be one of:<ul>
757
	 * <p>The file must be one of:<ul>
758
	 *	<li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
758
	 *	<li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
759
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
759
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
760
	 *	<li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
760
	 *	<li>a ZIP archive (e.g. a <code>.jar</code>, a <code>.zip</code> file, etc.) - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
761
	 *	</ul>
761
	 *	</ul>
762
	 * <p>
762
	 * <p>
763
	 * Creating a Java element has the side effect of creating and opening all of the
763
	 * Creating a Java element has the side effect of creating and opening all of the
Lines 777-784 Link Here
777
				return createCompilationUnitFrom(file, project);
777
				return createCompilationUnitFrom(file, project);
778
			if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name))
778
			if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name))
779
				return createClassFileFrom(file, project);
779
				return createClassFileFrom(file, project);
780
			if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(name))
780
			return createJarPackageFragmentRootFrom(file, project);
781
				return createJarPackageFragmentRootFrom(file, project);
782
		}
781
		}
783
		return null;
782
		return null;
784
	}
783
	}
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java (-1 / +1 lines)
Lines 77-83 Link Here
77
						if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) 
77
						if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) 
78
							continue nextResource;
78
							continue nextResource;
79
						// ignore .zip or .jar file on classpath
79
						// ignore .zip or .jar file on classpath
80
						if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath)) 
80
						if (isClasspathEntry(member.getFullPath(), classpath)) 
81
							continue nextResource;
81
							continue nextResource;
82
						break;
82
						break;
83
83
(-)model/org/eclipse/jdt/internal/core/ClasspathChange.java (-1 lines)
Lines 324-330 Link Here
324
							accumulatedRoots, 
324
							accumulatedRoots, 
325
							rootIDs,
325
							rootIDs,
326
							null, // inside original project
326
							null, // inside original project
327
							true, // check existency
328
							false, // don't retrieve exported roots
327
							false, // don't retrieve exported roots
329
							null); /*no reverse map*/
328
							null); /*no reverse map*/
330
						pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()];
329
						pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()];
(-)batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java (-3 / +1 lines)
Lines 164-172 Link Here
164
						convertPathSeparators(destinationPath));
164
						convertPathSeparators(destinationPath));
165
		}
165
		}
166
	} else {
166
	} else {
167
		String lowercaseClasspathName = classpathName.toLowerCase();
167
		if (Util.isPotentialZipArchive(classpathName)) {
168
		if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar)
169
				|| lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) {
170
			if (isSourceOnly) {
168
			if (isSourceOnly) {
171
				// source only mode
169
				// source only mode
172
				result = new ClasspathSourceJar(file, true, accessRuleSet,
170
				result = new ClasspathSourceJar(file, true, accessRuleSet,
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-8 / +3 lines)
Lines 472-478 Link Here
472
						File f = new File(classpath);
472
						File f = new File(classpath);
473
						String id = null;
473
						String id = null;
474
						if (f.isFile()) {
474
						if (f.isFile()) {
475
							if (Util.isArchiveFileName(classpath)) {
475
							if (Util.isPotentialZipArchive(classpath)) {
476
								id = Logger.CLASSPATH_JAR;
476
								id = Logger.CLASSPATH_JAR;
477
							} else {
477
							} else {
478
								id = Logger.CLASSPATH_FILE;
478
								id = Logger.CLASSPATH_FILE;
Lines 1333-1343 Link Here
1333
public static File[][] getLibrariesFiles(File[] files) {
1333
public static File[][] getLibrariesFiles(File[] files) {
1334
	FilenameFilter filter = new FilenameFilter() {
1334
	FilenameFilter filter = new FilenameFilter() {
1335
		public boolean accept(File dir, String name) {
1335
		public boolean accept(File dir, String name) {
1336
			String lowerCaseName = name.toLowerCase();
1336
			return Util.isPotentialZipArchive(name);
1337
			if (lowerCaseName.endsWith(SuffixConstants.SUFFIX_STRING_jar) || lowerCaseName.endsWith(SuffixConstants.SUFFIX_STRING_zip)) {
1338
				return true;
1339
			}
1340
			return false;
1341
		}
1337
		}
1342
	};
1338
	};
1343
	final int filesLength = files.length;
1339
	final int filesLength = files.length;
Lines 1494-1501 Link Here
1494
		destPath = NONE; // keep == comparison valid
1490
		destPath = NONE; // keep == comparison valid
1495
	}
1491
	}
1496
	if (rejectDestinationPathOnJars && destPath != null &&
1492
	if (rejectDestinationPathOnJars && destPath != null &&
1497
			(currentClasspathName.endsWith(".jar") || //$NON-NLS-1$
1493
			Util.isPotentialZipArchive(currentClasspathName)) {
1498
				currentClasspathName.endsWith(".zip"))) { //$NON-NLS-1$
1499
		throw new InvalidInputException(
1494
		throw new InvalidInputException(
1500
			this.bind("configure.unexpectedDestinationPathEntryFile", //$NON-NLS-1$
1495
			this.bind("configure.unexpectedDestinationPathEntryFile", //$NON-NLS-1$
1501
						currentClasspathName));
1496
						currentClasspathName));
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-7 / +7 lines)
Lines 115-132 Link Here
115
\ with ''+''.\n\
115
\ with ''+''.\n\
116
\ \n\
116
\ \n\
117
\ Classpath options:\n\
117
\ Classpath options:\n\
118
\    -cp -classpath <directories and zip/jar files separated by {0}>\n\
118
\    -cp -classpath <directories and ZIP archives separated by {0}>\n\
119
\                       specify location for application classes and sources.\n\
119
\                       specify location for application classes and sources.\n\
120
\                       Each directory or file can specify access rules for\n\
120
\                       Each directory or file can specify access rules for\n\
121
\                       types between ''['' and '']'' (e.g. [-X] to forbid\n\
121
\                       types between ''['' and '']'' (e.g. [-X] to forbid\n\
122
\                       access to type X, [~X] to discourage access to type X,\n\
122
\                       access to type X, [~X] to discourage access to type X,\n\
123
\                       [+p/X{0}-p/*] to forbid access to all types in package p\n\
123
\                       [+p/X{0}-p/*] to forbid access to all types in package p\n\
124
\                       but allow access to p/X)\n\
124
\                       but allow access to p/X)\n\
125
\    -bootclasspath <directories and zip/jar files separated by {0}>\n\
125
\    -bootclasspath <directories and ZIP archives separated by {0}>\n\
126
\                       specify location for system classes. Each directory or\n\
126
\                       specify location for system classes. Each directory or\n\
127
\                       file can specify access rules for types between ''[''\n\
127
\                       file can specify access rules for types between ''[''\n\
128
\                       and '']''\n\
128
\                       and '']''\n\
129
\    -sourcepath <directories and zip/jar files separated by {0}>\n\
129
\    -sourcepath <directories and ZIP archives separated by {0}>\n\
130
\                       specify location for application sources. Each directory\n\
130
\                       specify location for application sources. Each directory\n\
131
\                       or file can specify access rules for types between ''[''\n\
131
\                       or file can specify access rules for types between ''[''\n\
132
\                       and '']''. Each directory can further specify a specific\n\
132
\                       and '']''. Each directory can further specify a specific\n\
Lines 134-145 Link Here
134
\                       and '']''; this overrides the general ''-d'' option.\n\
134
\                       and '']''; this overrides the general ''-d'' option.\n\
135
\                       .class files created from source files contained in a\n\
135
\                       .class files created from source files contained in a\n\
136
\                       jar file are put in the user.dir folder in case no\n\
136
\                       jar file are put in the user.dir folder in case no\n\
137
\                       general ''-d'' option is specified. zip/jar files cannot\n\
137
\                       general ''-d'' option is specified. ZIP archives cannot\n\
138
\                       override the general ''-d'' option\n\
138
\                       override the general ''-d'' option\n\
139
\    -extdirs <directories separated by {0}>\n\
139
\    -extdirs <directories separated by {0}>\n\
140
\                       specify location for extension zip/jar files\n\
140
\                       specify location for extension ZIP archives\n\
141
\    -endorseddirs <directories separated by {0}>\n\
141
\    -endorseddirs <directories separated by {0}>\n\
142
\                       specify location for endorsed zip/jar files\n\
142
\                       specify location for endorsed ZIP archives\n\
143
\    -d <dir>           destination directory (if omitted, no directory is\n\
143
\    -d <dir>           destination directory (if omitted, no directory is\n\
144
\                       created); this option can be overridden per source\n\
144
\                       created); this option can be overridden per source\n\
145
\                       directory\n\
145
\                       directory\n\
Lines 175-181 Link Here
175
\ Annotation processing options:\n\
175
\ Annotation processing options:\n\
176
\   These options are meaningful only in a 1.6 environment.\n\
176
\   These options are meaningful only in a 1.6 environment.\n\
177
\    -Akey[=value]        options that are passed to annotation processors\n\
177
\    -Akey[=value]        options that are passed to annotation processors\n\
178
\    -processorpath <directories and zip/jar files separated by {0}>\n\
178
\    -processorpath <directories and ZIP archives separated by {0}>\n\
179
\                         specify locations where to find annotation processors.\n\
179
\                         specify locations where to find annotation processors.\n\
180
\                         If this option is not used, the classpath will be\n\
180
\                         If this option is not used, the classpath will be\n\
181
\                         searched for processors\n\
181
\                         searched for processors\n\
(-)compiler/org/eclipse/jdt/internal/compiler/util/SuffixConstants.java (-15 lines)
Lines 25-43 Link Here
25
	public final static char[] SUFFIX_CLASS = SUFFIX_STRING_CLASS.toCharArray();
25
	public final static char[] SUFFIX_CLASS = SUFFIX_STRING_CLASS.toCharArray();
26
	public final static char[] SUFFIX_java = SUFFIX_STRING_java.toCharArray();
26
	public final static char[] SUFFIX_java = SUFFIX_STRING_java.toCharArray();
27
	public final static char[] SUFFIX_JAVA = SUFFIX_STRING_JAVA.toCharArray();
27
	public final static char[] SUFFIX_JAVA = SUFFIX_STRING_JAVA.toCharArray();
28
	
29
	public final static String EXTENSION_jar = "jar"; //$NON-NLS-1$
30
	public final static String EXTENSION_JAR = "JAR"; //$NON-NLS-1$
31
	public final static String EXTENSION_zip = "zip"; //$NON-NLS-1$
32
	public final static String EXTENSION_ZIP = "ZIP"; //$NON-NLS-1$
33
34
	public final static String SUFFIX_STRING_jar = "." + EXTENSION_jar; //$NON-NLS-1$
35
	public final static String SUFFIX_STRING_JAR = "." + EXTENSION_JAR; //$NON-NLS-1$
36
	public final static String SUFFIX_STRING_zip = "." + EXTENSION_zip; //$NON-NLS-1$
37
	public final static String SUFFIX_STRING_ZIP = "." + EXTENSION_ZIP; //$NON-NLS-1$
38
39
	public final static char[] SUFFIX_jar = SUFFIX_STRING_jar.toCharArray();
40
	public final static char[] SUFFIX_JAR = SUFFIX_STRING_JAR.toCharArray();
41
	public final static char[] SUFFIX_zip = SUFFIX_STRING_zip.toCharArray(); 
42
	public final static char[] SUFFIX_ZIP = SUFFIX_STRING_ZIP.toCharArray();
43
}
28
}
(-)compiler/org/eclipse/jdt/internal/compiler/util/Util.java (-23 / +29 lines)
Lines 470-503 Link Here
470
			}
470
			}
471
		}
471
		}
472
	}	
472
	}	
473
473
	/**
474
	/**
474
	 * Returns true iff str.toLowerCase().endsWith(".jar") || str.toLowerCase().endsWith(".zip")
475
	 * Returns whether the given name is potentially a zip archive file name
475
	 * implementation is not creating extra strings.
476
	 * (it has a file extension and it is not ".java" nor ".class")
476
	 */
477
	 */
477
	public final static boolean isArchiveFileName(String name) {
478
	public final static boolean isPotentialZipArchive(String name) {
478
		int nameLength = name == null ? 0 : name.length();
479
		int lastDot = name.lastIndexOf('.');
479
		int suffixLength = SUFFIX_JAR.length;
480
		if (lastDot == -1)
480
		if (nameLength < suffixLength) return false;
481
			return false; // no file extension, it cannot be a zip archive name
481
482
		if (name.lastIndexOf(File.separatorChar) > lastDot)
482
		// try to match as JAR file
483
			return false; // dot was before the last file separator, it cannot be a zip archive name
483
		for (int i = 0; i < suffixLength; i++) {
484
		int length = name.length();
484
			char c = name.charAt(nameLength - i - 1);
485
		int extensionLength = length - lastDot - 1;
485
			int suffixIndex = suffixLength - i - 1;
486
		if (extensionLength == EXTENSION_java.length()) {
486
			if (c != SUFFIX_jar[suffixIndex] && c != SUFFIX_JAR[suffixIndex]) {
487
			for (int i = extensionLength-1; i >=0; i--) {
487
488
				if (Character.toLowerCase(name.charAt(length - extensionLength + i)) != EXTENSION_java.charAt(i)) {
488
				// try to match as ZIP file
489
					break; // not a ".java" file, check ".class" file case below
489
				suffixLength = SUFFIX_ZIP.length;
490
				}
490
				if (nameLength < suffixLength) return false;
491
				if (i == 0) {
491
				for (int j = 0; j < suffixLength; j++) {
492
					return false; // it is a ".java" file, it cannot be a zip archive name
492
					c = name.charAt(nameLength - j - 1);
493
					suffixIndex = suffixLength - j - 1;
494
					if (c != SUFFIX_zip[suffixIndex] && c != SUFFIX_ZIP[suffixIndex]) return false;
495
				}
493
				}
496
				return true;
497
			}
494
			}
498
		}
495
		}
499
		return true;		
496
		if (extensionLength == EXTENSION_class.length()) {
500
	}	
497
			for (int i = extensionLength-1; i >=0; i--) {
498
				if (Character.toLowerCase(name.charAt(length - extensionLength + i)) != EXTENSION_class.charAt(i)) {
499
					return true; // not a ".class" file, so this is a potential archive name
500
				}
501
			}
502
			return false; // it is a ".class" file, it cannot be a zip archive name
503
		}
504
		return true; // it is neither a ".java" file nor a ".class" file, so this is a potential archive name
505
	}
506
501
	/**
507
	/**
502
	 * Returns true iff str.toLowerCase().endsWith(".class")
508
	 * Returns true iff str.toLowerCase().endsWith(".class")
503
	 * implementation is not creating extra strings.
509
	 * implementation is not creating extra strings.
(-)antadapter/org/eclipse/jdt/core/CheckDebugAttributes.java (-7 / +11 lines)
Lines 13-18 Link Here
13
import java.io.IOException;
13
import java.io.IOException;
14
import java.util.Enumeration;
14
import java.util.Enumeration;
15
import java.util.zip.ZipEntry;
15
import java.util.zip.ZipEntry;
16
import java.util.zip.ZipException;
16
import java.util.zip.ZipFile;
17
import java.util.zip.ZipFile;
17
18
18
import org.apache.tools.ant.BuildException;
19
import org.apache.tools.ant.BuildException;
Lines 50-57 Link Here
50
		}
51
		}
51
		try {
52
		try {
52
			boolean hasDebugAttributes = false;
53
			boolean hasDebugAttributes = false;
53
			if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(this.file)) {
54
			if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(this.file)) {
54
				ZipFile jarFile = new ZipFile(this.file);
55
				IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(this.file, IClassFileReader.ALL);
56
				hasDebugAttributes = checkClassFile(classFileReader);
57
			} else {
58
				ZipFile jarFile = null;
59
				try {
60
					jarFile = new ZipFile(this.file);
61
				} catch (ZipException e) {
62
					throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile")); //$NON-NLS-1$
63
				}
55
				for (Enumeration entries = jarFile.entries(); !hasDebugAttributes && entries.hasMoreElements(); ) {
64
				for (Enumeration entries = jarFile.entries(); !hasDebugAttributes && entries.hasMoreElements(); ) {
56
					ZipEntry entry = (ZipEntry) entries.nextElement();
65
					ZipEntry entry = (ZipEntry) entries.nextElement();
57
					if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entry.getName())) {
66
					if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entry.getName())) {
Lines 59-69 Link Here
59
						hasDebugAttributes = checkClassFile(classFileReader);
68
						hasDebugAttributes = checkClassFile(classFileReader);
60
					}
69
					}
61
				}
70
				}
62
			} else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(this.file)) {
63
				IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(this.file, IClassFileReader.ALL);
64
				hasDebugAttributes = checkClassFile(classFileReader);
65
			} else {
66
				throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile")); //$NON-NLS-1$
67
			}
71
			}
68
			if (hasDebugAttributes) {
72
			if (hasDebugAttributes) {
69
				getProject().setUserProperty(this.property, "has debug"); //$NON-NLS-1$
73
				getProject().setUserProperty(this.property, "has debug"); //$NON-NLS-1$
(-)model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java (-4 lines)
Lines 161-168 Link Here
161
					IResource resource = (IResource) target;
161
					IResource resource = (IResource) target;
162
					ClasspathLocation bLocation = null;
162
					ClasspathLocation bLocation = null;
163
					if (resource instanceof IFile) {
163
					if (resource instanceof IFile) {
164
						if (!(org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(path.lastSegment())))
165
							continue nextEntry;
166
						AccessRuleSet accessRuleSet = 
164
						AccessRuleSet accessRuleSet = 
167
							(JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
165
							(JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
168
							&& JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
166
							&& JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
Lines 191-198 Link Here
191
						binaryLocationsPerProject.put(p, existingLocations);
189
						binaryLocationsPerProject.put(p, existingLocations);
192
					}
190
					}
193
				} else if (target instanceof File) {
191
				} else if (target instanceof File) {
194
					if (!(org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(path.lastSegment())))
195
						continue nextEntry;
196
					AccessRuleSet accessRuleSet = 
192
					AccessRuleSet accessRuleSet = 
197
						(JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
193
						(JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
198
							&& JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
194
							&& JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
(-)Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JarTests.java (-1 / +1 lines)
Lines 362-368 Link Here
362
	
362
	
363
	
363
	
364
	IPackageFragmentRoot wrongRoot = jProject1.getPackageFragmentRoot(jarPath);
364
	IPackageFragmentRoot wrongRoot = jProject1.getPackageFragmentRoot(jarPath);
365
	IPackageFragmentRoot rightRoot = jProject2.getPackageFragmentRoot(jarPath);
365
	IPackageFragmentRoot rightRoot = jProject2.getPackageFragmentRoot(workspaceRoot.getFile(new Path(jarPath)));
366
	
366
	
367
	assertTrue("Wrong PackageFragmentRoot exists", !wrongRoot.exists());
367
	assertTrue("Wrong PackageFragmentRoot exists", !wrongRoot.exists());
368
	assertTrue("Right PackageFragmentRoot does not exists", rightRoot.exists());
368
	assertTrue("Right PackageFragmentRoot does not exists", rightRoot.exists());
(-)src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java (-5 / +45 lines)
Lines 490-496 Link Here
490
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P3", "/P1"}) {
490
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P3", "/P1"}) {
491
	        public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
491
	        public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
492
	            super.initialize(containerPath, project);
492
	            super.initialize(containerPath, project);
493
	            getJavaModel().refreshExternalArchives(new IJavaElement[] {p1}, null);
493
	            refreshExternalArchives(p1);
494
	        }
494
	        }
495
		});
495
		});
496
		getWorkspace().run(new IWorkspaceRunnable() {
496
		getWorkspace().run(new IWorkspaceRunnable() {
Lines 894-910 Link Here
894
	try {
894
	try {
895
		createProject("P1");
895
		createProject("P1");
896
		createExternalFolder("externalLib");
896
		createExternalFolder("externalLib");
897
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", getExternalFolderPath("externalLib")}));
897
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", getExternalResourcePath("externalLib")}));
898
		IJavaProject p2 = createJavaProject(
898
		IJavaProject p2 = createJavaProject(
899
				"P2", 
899
				"P2", 
900
				new String[] {}, 
900
				new String[] {}, 
901
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
901
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
902
				"");
902
				"");
903
		IPackageFragmentRoot root = p2.getPackageFragmentRoot(getExternalFolderPath("externalLib"));
903
		IPackageFragmentRoot root = p2.getPackageFragmentRoot(getExternalResourcePath("externalLib"));
904
		assertTrue(getExternalFolderPath("externalLib") + " should exist", root.exists());
904
		assertTrue(getExternalResourcePath("externalLib") + " should exist", root.exists());
905
	} finally {
905
	} finally {
906
		stopDeltas();
906
		stopDeltas();
907
		deleteExternalFolder("externalLib");
907
		deleteExternalResource("externalLib");
908
		deleteProject("P1");
909
		deleteProject("P2");
910
	}
911
}
912
913
public void testContainerInitializer22() throws CoreException {
914
	try {
915
		createProject("P1");
916
		createExternalFile("externalLib.abc", "");
917
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", getExternalResourcePath("externalLib.abc")}));
918
		IJavaProject p2 = createJavaProject(
919
				"P2", 
920
				new String[] {}, 
921
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
922
				"");
923
		IPackageFragmentRoot root = p2.getPackageFragmentRoot(getExternalResourcePath("externalLib.abc"));
924
		assertTrue(getExternalResourcePath("externalLib.abc") + " should exist", root.exists());
925
	} finally {
926
		stopDeltas();
927
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P2");
928
		deleteProject("P1");
929
		deleteProject("P2");
930
	}
931
}
932
933
public void testContainerInitializer23() throws CoreException {
934
	try {
935
		createProject("P1");
936
		IFile lib = createFile("/P1/internalLib.abc", "");
937
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1/internalLib.abc"}));
938
		IJavaProject p2 = createJavaProject(
939
				"P2", 
940
				new String[] {}, 
941
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
942
				"");
943
		IPackageFragmentRoot root = p2.getPackageFragmentRoot(lib);
944
		assertTrue("/P1/internalLib.abc should exist", root.exists());
945
	} finally {
946
		stopDeltas();
947
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P2");
908
		deleteProject("P1");
948
		deleteProject("P1");
909
		deleteProject("P2");
949
		deleteProject("P2");
910
	}
950
	}
(-)src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java (-17 / +17 lines)
Lines 84-90 Link Here
84
		);
84
		);
85
	} finally {
85
	} finally {
86
		if(f != null) {
86
		if(f != null) {
87
			deleteFile(f);
87
			deleteResource(f);
88
		}
88
		}
89
		this.deleteProject("P");
89
		this.deleteProject("P");
90
		this.stopDeltas();
90
		this.stopDeltas();
Lines 118-124 Link Here
118
		);
118
		);
119
	} finally {
119
	} finally {
120
		if(f != null) {
120
		if(f != null) {
121
			deleteFile(f);
121
			deleteResource(f);
122
		}
122
		}
123
		this.deleteProject("P");
123
		this.deleteProject("P");
124
		this.stopDeltas();
124
		this.stopDeltas();
Lines 151-157 Link Here
151
		);
151
		);
152
	} finally {
152
	} finally {
153
		if(f != null) {
153
		if(f != null) {
154
			deleteFile(f);
154
			deleteResource(f);
155
		}
155
		}
156
		this.deleteProject("P");
156
		this.deleteProject("P");
157
		this.stopDeltas();
157
		this.stopDeltas();
Lines 185-191 Link Here
185
		);
185
		);
186
	} finally {
186
	} finally {
187
		if(f != null) {
187
		if(f != null) {
188
			deleteFile(f);
188
			deleteResource(f);
189
		}
189
		}
190
		this.deleteProject("P");
190
		this.deleteProject("P");
191
		this.stopDeltas();
191
		this.stopDeltas();
Lines 223-229 Link Here
223
		);
223
		);
224
	} finally {
224
	} finally {
225
		if(f != null) {
225
		if(f != null) {
226
			deleteFile(f);
226
			deleteResource(f);
227
		}
227
		}
228
		this.deleteProject("P");
228
		this.deleteProject("P");
229
		this.stopDeltas();
229
		this.stopDeltas();
Lines 261-267 Link Here
261
		);
261
		);
262
	} finally {
262
	} finally {
263
		if(f != null) {
263
		if(f != null) {
264
			deleteFile(f);
264
			deleteResource(f);
265
		}
265
		}
266
		this.deleteProject("P");
266
		this.deleteProject("P");
267
		this.stopDeltas();
267
		this.stopDeltas();
Lines 297-303 Link Here
297
		);
297
		);
298
	} finally {
298
	} finally {
299
		if(f != null) {
299
		if(f != null) {
300
			deleteFile(f);
300
			deleteResource(f);
301
		}
301
		}
302
		this.deleteProject("P");
302
		this.deleteProject("P");
303
		this.stopDeltas();
303
		this.stopDeltas();
Lines 329-335 Link Here
329
		);
329
		);
330
	} finally {
330
	} finally {
331
		if(f != null) {
331
		if(f != null) {
332
			deleteFile(f);
332
			deleteResource(f);
333
		}
333
		}
334
		this.deleteProject("P");
334
		this.deleteProject("P");
335
		this.stopDeltas();
335
		this.stopDeltas();
Lines 361-367 Link Here
361
		);
361
		);
362
	} finally {
362
	} finally {
363
		if(f != null) {
363
		if(f != null) {
364
			deleteFile(f);
364
			deleteResource(f);
365
		}
365
		}
366
		this.deleteProject("P");
366
		this.deleteProject("P");
367
		this.stopDeltas();
367
		this.stopDeltas();
Lines 394-400 Link Here
394
		);
394
		);
395
	} finally {
395
	} finally {
396
		if(f != null) {
396
		if(f != null) {
397
			deleteFile(f);
397
			deleteResource(f);
398
		}
398
		}
399
		this.deleteProject("P");
399
		this.deleteProject("P");
400
		this.stopDeltas();
400
		this.stopDeltas();
Lines 417-423 Link Here
417
		waitUntilIndexesReady();
417
		waitUntilIndexesReady();
418
		startDeltas();
418
		startDeltas();
419
		
419
		
420
		deleteFile(f);
420
		deleteResource(f);
421
		getJavaModel().refreshExternalArchives(null,null);
421
		getJavaModel().refreshExternalArchives(null,null);
422
		
422
		
423
		assertDeltas(
423
		assertDeltas(
Lines 427-433 Link Here
427
		);
427
		);
428
	} finally {
428
	} finally {
429
		if(f != null) {
429
		if(f != null) {
430
			deleteFile(f);
430
			deleteResource(f);
431
		}
431
		}
432
		this.deleteProject("P");
432
		this.deleteProject("P");
433
		this.stopDeltas();
433
		this.stopDeltas();
Lines 450-456 Link Here
450
		waitUntilIndexesReady();
450
		waitUntilIndexesReady();
451
		startDeltas();
451
		startDeltas();
452
		
452
		
453
		deleteFile(f);
453
		deleteResource(f);
454
		getJavaModel().refreshExternalArchives(new IJavaElement[]{project},null);
454
		getJavaModel().refreshExternalArchives(new IJavaElement[]{project},null);
455
		
455
		
456
		assertDeltas(
456
		assertDeltas(
Lines 460-466 Link Here
460
		);
460
		);
461
	} finally {
461
	} finally {
462
		if(f != null) {
462
		if(f != null) {
463
			deleteFile(f);
463
			deleteResource(f);
464
		}
464
		}
465
		this.deleteProject("P");
465
		this.deleteProject("P");
466
		this.stopDeltas();
466
		this.stopDeltas();
Lines 483-489 Link Here
483
		waitUntilIndexesReady();
483
		waitUntilIndexesReady();
484
		startDeltas();
484
		startDeltas();
485
		
485
		
486
		deleteFile(f);
486
		deleteResource(f);
487
		IPackageFragmentRoot root = project.getPackageFragmentRoot(pPath);
487
		IPackageFragmentRoot root = project.getPackageFragmentRoot(pPath);
488
		getJavaModel().refreshExternalArchives(new IJavaElement[]{root},null);
488
		getJavaModel().refreshExternalArchives(new IJavaElement[]{root},null);
489
		
489
		
Lines 494-500 Link Here
494
		);
494
		);
495
	} finally {
495
	} finally {
496
		if(f != null) {
496
		if(f != null) {
497
			deleteFile(f);
497
			deleteResource(f);
498
		}
498
		}
499
		this.deleteProject("P");
499
		this.deleteProject("P");
500
		this.stopDeltas();
500
		this.stopDeltas();
Lines 541-547 Link Here
541
		);
541
		);
542
	} finally {
542
	} finally {
543
		if(f != null) {
543
		if(f != null) {
544
			deleteFile(f);
544
			deleteResource(f);
545
		}
545
		}
546
		this.deleteProject("P");
546
		this.deleteProject("P");
547
		this.stopDeltas();
547
		this.stopDeltas();
(-)src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (-26 / +364 lines)
Lines 62-68 Link Here
62
	try {
62
	try {
63
		IJavaProject p = createJavaProject("P");
63
		IJavaProject p = createJavaProject("P");
64
		createExternalFolder("externalLib");
64
		createExternalFolder("externalLib");
65
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
65
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib")), null, null)});
66
		assertElementDescendants(
66
		assertElementDescendants(
67
			"Unexpected project content", 
67
			"Unexpected project content", 
68
			"P\n" + 
68
			"P\n" + 
Lines 71-77 Link Here
71
			p
71
			p
72
		);
72
		);
73
	} finally {
73
	} finally {
74
		deleteExternalFolder("externalLib");
74
		deleteExternalResource("externalLib");
75
		deleteProject("P");
75
		deleteProject("P");
76
	}
76
	}
77
}
77
}
Lines 82-88 Link Here
82
public void testAddExternalLibFolder2() throws CoreException {
82
public void testAddExternalLibFolder2() throws CoreException {
83
	try {
83
	try {
84
		IJavaProject p = createJavaProject("P");
84
		IJavaProject p = createJavaProject("P");
85
		IPath path = new Path(getExternalFolderPath("externalLib"));
85
		IPath path = new Path(getExternalResourcePath("externalLib"));
86
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
86
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
87
		assertElementDescendants(
87
		assertElementDescendants(
88
			"Unexpected project content", 
88
			"Unexpected project content", 
Lines 102-108 Link Here
102
		IJavaProject p = createJavaProject("P");
102
		IJavaProject p = createJavaProject("P");
103
		createExternalFolder("externalLib/p");
103
		createExternalFolder("externalLib/p");
104
		createExternalFile("externalLib/p/X.class", "");
104
		createExternalFile("externalLib/p/X.class", "");
105
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
105
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib")), null, null)});
106
		assertElementDescendants(
106
		assertElementDescendants(
107
			"Unexpected project content", 
107
			"Unexpected project content", 
108
			"P\n" + 
108
			"P\n" + 
Lines 113-119 Link Here
113
			p
113
			p
114
		);
114
		);
115
	} finally {
115
	} finally {
116
		deleteExternalFolder("externalLib");
116
		deleteExternalResource("externalLib");
117
		deleteProject("P");
117
		deleteProject("P");
118
	}
118
	}
119
}
119
}
Lines 123-129 Link Here
123
 */
123
 */
124
public void testAddExternalLibFolder4() throws CoreException {
124
public void testAddExternalLibFolder4() throws CoreException {
125
	try {
125
	try {
126
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
126
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
127
		expandAll(p);
127
		expandAll(p);
128
		createExternalFolder("externalLib");
128
		createExternalFolder("externalLib");
129
		refresh(p);
129
		refresh(p);
Lines 135-141 Link Here
135
			p
135
			p
136
		);
136
		);
137
	} finally {
137
	} finally {
138
		deleteExternalFolder("externalLib");
138
		deleteExternalResource("externalLib");
139
		deleteProject("P");
139
		deleteProject("P");
140
	}
140
	}
141
}
141
}
Lines 149-155 Link Here
149
		simulateExitRestart();
149
		simulateExitRestart();
150
		createExternalFolder("externalLib/p");
150
		createExternalFolder("externalLib/p");
151
		createExternalFile("externalLib/p/X.class", "");
151
		createExternalFile("externalLib/p/X.class", "");
152
		IJavaProject p = importJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
152
		IJavaProject p = importJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
153
		waitForAutoBuild(); // since the project is imported, the linked folder can only be created by auto-build
153
		waitForAutoBuild(); // since the project is imported, the linked folder can only be created by auto-build
154
		assertElementDescendants(
154
		assertElementDescendants(
155
			"Unexpected project content", 
155
			"Unexpected project content", 
Lines 161-167 Link Here
161
			p
161
			p
162
		);
162
		);
163
	} finally {
163
	} finally {
164
		deleteExternalFolder("externalLib");
164
		deleteExternalResource("externalLib");
165
		deleteProject("P");
166
	}
167
}
168
169
/*
170
 * Ensures that adding a library entry for an existing empty external ZIP archive updates the model
171
 */
172
public void testAddZIPArchive1() throws Exception {
173
	try {
174
		IJavaProject p = createJavaProject("P");
175
		createExternalFile("externalLib.abc", "");
176
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib.abc")), null, null)});
177
		assertElementDescendants(
178
			"Unexpected project content", 
179
			"P\n" + 
180
			"  "+ getExternalPath() + "externalLib.abc",
181
			p
182
		);
183
	} finally {
184
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
185
		deleteProject("P");
186
	}
187
}
188
189
/*
190
 * Ensures that adding a library entry for an non-existing external ZIP archive updates the model
191
 */
192
public void testAddZIPArchive2() throws CoreException {
193
	try {
194
		IJavaProject p = createJavaProject("P");
195
		IPath path = new Path(getExternalResourcePath("externalLib.abc"));
196
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
197
		assertElementDescendants(
198
			"Unexpected project content", 
199
			"P",
200
			p
201
		);
202
	} finally {
203
		deleteProject("P");
204
	}
205
}
206
207
/*
208
 * Ensures that adding a library entry for an existing non-empty external ZIP archive updates the model
209
 */
210
public void testAddZIPArchive3() throws CoreException, IOException {
211
	try {
212
		IJavaProject p = createJavaProject("P");
213
		org.eclipse.jdt.core.tests.util.Util.createJar(
214
			new String[] {
215
				"p/X.java",
216
				"package p;\n" +
217
				"public class X {\n" +
218
				"}"
219
			},
220
			getExternalResourcePath("externalLib.abc"), 
221
			"1.4");
222
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib.abc")), null, null)});
223
		assertElementDescendants(
224
			"Unexpected project content", 
225
			"P\n" + 
226
			"  "+ getExternalPath() + "externalLib.abc\n" + 
227
			"    <default> (...)\n" + 
228
			"    p (...)\n" + 
229
			"      X.class\n" + 
230
			"        class X\n" + 
231
			"          X()",
232
			p
233
		);
234
	} finally {
235
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
236
		deleteProject("P");
237
	}
238
}
239
240
/*
241
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing updates the model
242
 */
243
public void testAddZIPArchive4() throws Exception {
244
	try {
245
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
246
		expandAll(p);
247
		createExternalFile("externalLib.abc", "");
248
		refreshExternalArchives(p);
249
		assertElementDescendants(
250
			"Unexpected project content", 
251
			"P\n" + 
252
			"  "+ getExternalPath() + "externalLib.abc",
253
			p
254
		);
255
	} finally {
256
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
257
		deleteProject("P");
258
	}
259
}
260
261
/*
262
 * Ensures that importing a Java project with a library entry for an existing empty external ZIP archive after restart
263
 * updates the model
264
 */
265
public void testAddZIPArchive5() throws Exception {
266
	try {
267
		simulateExitRestart();
268
		org.eclipse.jdt.core.tests.util.Util.createJar(
269
			new String[] {
270
				"p/X.java",
271
				"package p;\n" +
272
				"public class X {\n" +
273
				"}"
274
			},
275
			getExternalResourcePath("externalLib.abc"), 
276
			"1.4");
277
		IJavaProject p = importJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
278
		assertElementDescendants(
279
			"Unexpected project content", 
280
			"P\n" + 
281
			"  "+ getExternalPath() + "externalLib.abc\n" + 
282
			"    <default> (...)\n" + 
283
			"    p (...)\n" + 
284
			"      X.class\n" + 
285
			"        class X\n" + 
286
			"          X()",
287
			p
288
		);
289
	} finally {
290
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
291
		deleteProject("P");
292
	}
293
}
294
295
/*
296
 * Ensures that adding a library entry for an existing empty internal ZIP archive updates the model
297
 */
298
public void testAddZIPArchive6() throws Exception {
299
	try {
300
		IJavaProject p = createJavaProject("P");
301
		createFile("/P/internalLib.abc", "");
302
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path("/P/internalLib.abc"), null, null)});
303
		assertElementDescendants(
304
			"Unexpected project content", 
305
			"P\n" + 
306
			"  internalLib.abc",
307
			p
308
		);
309
	} finally {
165
		deleteProject("P");
310
		deleteProject("P");
166
	}
311
	}
167
}
312
}
Lines 257-263 Link Here
257
public void testChangeExternalLibFolder1() throws CoreException, IOException {
402
public void testChangeExternalLibFolder1() throws CoreException, IOException {
258
	try {
403
	try {
259
		createExternalFolder("externalLib");
404
		createExternalFolder("externalLib");
260
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "bin");
405
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "bin");
261
		expandAll(p);
406
		expandAll(p);
262
		
407
		
263
		createExternalFolder("externalLib/p");
408
		createExternalFolder("externalLib/p");
Lines 273-279 Link Here
273
			p
418
			p
274
		);
419
		);
275
	} finally {
420
	} finally {
276
		deleteExternalFolder("externalLib");
421
		deleteExternalResource("externalLib");
277
		deleteProject("P");
422
		deleteProject("P");
278
	}
423
	}
279
}
424
}
Lines 285-294 Link Here
285
	try {
430
	try {
286
		createExternalFolder("externalLib/p");
431
		createExternalFolder("externalLib/p");
287
		createExternalFile("externalLib/p/X.class", "");
432
		createExternalFile("externalLib/p/X.class", "");
288
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "bin");
433
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "bin");
289
		expandAll(p);
434
		expandAll(p);
290
		
435
		
291
		deleteExternalFolder("externalLib/p");
436
		deleteExternalResource("externalLib/p");
292
		refresh(p);
437
		refresh(p);
293
		assertElementDescendants(
438
		assertElementDescendants(
294
			"Unexpected project content", 
439
			"Unexpected project content", 
Lines 298-304 Link Here
298
			p
443
			p
299
		);
444
		);
300
	} finally {
445
	} finally {
301
		deleteExternalFolder("externalLib");
446
		deleteExternalResource("externalLib");
447
		deleteProject("P");
448
	}
449
}
450
451
/*
452
 * Ensures that changing the content of an external ZIP archive and refreshing updates the model
453
 */
454
public void testChangeZIPArchive1() throws CoreException, IOException {
455
	try {
456
		createExternalFile("externalLib.abc", "");
457
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "bin");
458
		expandAll(p);
459
		
460
		org.eclipse.jdt.core.tests.util.Util.createJar(
461
			new String[] {
462
				"p/X.java",
463
				"package p;\n" +
464
				"public class X {\n" +
465
				"}"
466
			},
467
			getExternalResourcePath("externalLib.abc"), 
468
			"1.4");
469
		refreshExternalArchives(p);
470
		assertElementDescendants(
471
			"Unexpected project content", 
472
			"P\n" + 
473
			"  "+ getExternalPath() + "externalLib.abc\n" + 
474
			"    <default> (...)\n" + 
475
			"    p (...)\n" + 
476
			"      X.class\n" + 
477
			"        class X\n" + 
478
			"          X()",
479
			p
480
		);
481
	} finally {
482
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
483
		deleteProject("P");
484
	}
485
}
486
487
/*
488
 * Ensures that changing the content of an external ZIP archive and refreshing updates the model
489
 */
490
public void testChangeZIPArchive2() throws CoreException, IOException {
491
	try {
492
		org.eclipse.jdt.core.tests.util.Util.createJar(
493
			new String[] {
494
				"p/X.java",
495
				"package p;\n" +
496
				"public class X {\n" +
497
				"}"
498
			},
499
			getExternalResourcePath("externalLib.abc"), 
500
			"1.4");
501
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "bin");
502
		expandAll(p);
503
		
504
		org.eclipse.jdt.core.tests.util.Util.createJar(
505
			new String[] {
506
				"p2/X.java",
507
				"package p2;\n" +
508
				"public class X {\n" +
509
				"}"
510
			},
511
			getExternalResourcePath("externalLib.abc"), 
512
			"1.4");
513
		refreshExternalArchives(p);
514
		assertElementDescendants(
515
			"Unexpected project content", 
516
			"P\n" + 
517
			"  "+ getExternalPath() + "externalLib.abc\n" + 
518
			"    <default> (...)\n" + 
519
			"    p2 (...)\n" + 
520
			"      X.class\n" + 
521
			"        class X\n" + 
522
			"          X()",
523
			p
524
		);
525
	} finally {
526
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
527
		deleteProject("P");
528
	}
529
}
530
531
/*
532
 * Ensures that changing the content of an internal ZIP archive and refreshing updates the model
533
 */
534
public void testChangeZIPArchive3() throws CoreException, IOException {
535
	try {
536
		IJavaProject p = createJavaProject("P", new String[0], new String[] {"/P/internalLib.abc"}, "bin");
537
		IFile lib = createFile("/P/internalLib.abc", "");
538
		expandAll(p);
539
		
540
		org.eclipse.jdt.core.tests.util.Util.createJar(
541
			new String[] {
542
				"p/X.java",
543
				"package p;\n" +
544
				"public class X {\n" +
545
				"}"
546
			},
547
			lib.getLocation().toOSString(), 
548
			"1.4");
549
		p.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
550
		assertElementDescendants(
551
			"Unexpected project content", 
552
			"P\n" + 
553
			"  internalLib.abc\n" + 
554
			"    <default> (...)\n" + 
555
			"    p (...)\n" + 
556
			"      X.class\n" + 
557
			"        class X\n" + 
558
			"          X()",
559
			p
560
		);
561
	} finally {
302
		deleteProject("P");
562
		deleteProject("P");
303
	}
563
	}
304
}
564
}
Lines 1025-1032 Link Here
1025
	try {
1285
	try {
1026
		createExternalFolder("externalLib/p/META-INF");
1286
		createExternalFolder("externalLib/p/META-INF");
1027
		createExternalFile("externalLib/p/test.txt", "test");
1287
		createExternalFile("externalLib/p/test.txt", "test");
1028
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1288
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
1029
		IPackageFragment pkg = getPackageFragmentRoot("P", getExternalFolderPath("externalLib")).getPackageFragment("p");
1289
		IPackageFragment pkg = getPackageFragmentRoot("P", getExternalResourcePath("externalLib")).getPackageFragment("p");
1030
		Object[] resources = pkg.getNonJavaResources();
1290
		Object[] resources = pkg.getNonJavaResources();
1031
		assertResourceTreeEquals(
1291
		assertResourceTreeEquals(
1032
			"unexpected non java resources", 
1292
			"unexpected non java resources", 
Lines 1035-1041 Link Here
1035
			resources);
1295
			resources);
1036
	} finally {
1296
	} finally {
1037
		deleteProject("P");
1297
		deleteProject("P");
1038
		deleteExternalFolder("externalLib");
1298
		deleteExternalResource("externalLib");
1039
	}
1299
	}
1040
}
1300
}
1041
1301
Lines 1188-1195 Link Here
1188
	try {
1448
	try {
1189
		createExternalFolder("externalLib/META-INF");
1449
		createExternalFolder("externalLib/META-INF");
1190
		createExternalFile("externalLib/test.txt", "test");
1450
		createExternalFile("externalLib/test.txt", "test");
1191
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1451
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
1192
		IPackageFragmentRoot root = getPackageFragmentRoot("P", getExternalFolderPath("externalLib"));
1452
		IPackageFragmentRoot root = getPackageFragmentRoot("P", getExternalResourcePath("externalLib"));
1193
		Object[] resources = root.getNonJavaResources();
1453
		Object[] resources = root.getNonJavaResources();
1194
		assertResourceTreeEquals(
1454
		assertResourceTreeEquals(
1195
			"unexpected non java resources", 
1455
			"unexpected non java resources", 
Lines 1198-1204 Link Here
1198
			resources);
1458
			resources);
1199
	} finally {
1459
	} finally {
1200
		deleteProject("P");
1460
		deleteProject("P");
1201
		deleteExternalFolder("externalLib");
1461
		deleteExternalResource("externalLib");
1202
	}
1462
	}
1203
}
1463
}
1204
/**
1464
/**
Lines 1605-1611 Link Here
1605
public void testRemoveExternalLibFolder1() throws CoreException {
1865
public void testRemoveExternalLibFolder1() throws CoreException {
1606
	try {
1866
	try {
1607
		createExternalFolder("externalLib");
1867
		createExternalFolder("externalLib");
1608
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1868
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
1609
		expandAll(p);
1869
		expandAll(p);
1610
		setClasspath(p, new IClasspathEntry[] {});
1870
		setClasspath(p, new IClasspathEntry[] {});
1611
		assertElementDescendants(
1871
		assertElementDescendants(
Lines 1614-1620 Link Here
1614
			p
1874
			p
1615
		);
1875
		);
1616
	} finally {
1876
	} finally {
1617
		deleteExternalFolder("externalLib");
1877
		deleteExternalResource("externalLib");
1618
		deleteProject("P");
1878
		deleteProject("P");
1619
	}
1879
	}
1620
}
1880
}
Lines 1624-1630 Link Here
1624
 */
1884
 */
1625
public void testRemoveExternalLibFolder2() throws CoreException {
1885
public void testRemoveExternalLibFolder2() throws CoreException {
1626
	try {
1886
	try {
1627
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1887
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
1628
		expandAll(p);
1888
		expandAll(p);
1629
		setClasspath(p, new IClasspathEntry[] {});
1889
		setClasspath(p, new IClasspathEntry[] {});
1630
		assertElementDescendants(
1890
		assertElementDescendants(
Lines 1644-1652 Link Here
1644
public void testRemoveExternalLibFolder3() throws CoreException {
1904
public void testRemoveExternalLibFolder3() throws CoreException {
1645
	try {
1905
	try {
1646
		createExternalFolder("externalLib");
1906
		createExternalFolder("externalLib");
1647
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
1907
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
1648
		expandAll(p);
1908
		expandAll(p);
1649
		deleteExternalFolder("externalLib");
1909
		deleteExternalResource("externalLib");
1650
		refresh(p);
1910
		refresh(p);
1651
		assertElementDescendants(
1911
		assertElementDescendants(
1652
			"Unexpected project content", 
1912
			"Unexpected project content", 
Lines 1654-1660 Link Here
1654
			p
1914
			p
1655
		);
1915
		);
1656
	} finally {
1916
	} finally {
1657
		deleteExternalFolder("externalLib");
1917
		deleteExternalResource("externalLib");
1918
		deleteProject("P");
1919
	}
1920
}
1921
1922
/*
1923
 * Ensures that removing a library entry for an existing external ZIP archive updates the model
1924
 */
1925
public void testRemoveZIPArchive1() throws CoreException {
1926
	try {
1927
		createExternalFile("externalLib.abc", "");
1928
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
1929
		expandAll(p);
1930
		setClasspath(p, new IClasspathEntry[] {});
1931
		assertElementDescendants(
1932
			"Unexpected project content", 
1933
			"P",
1934
			p
1935
		);
1936
	} finally {
1937
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
1938
		deleteProject("P");
1939
	}
1940
}
1941
1942
/*
1943
 * Ensures that removing a library entry for a non-existing external ZIP archive updates the model
1944
 */
1945
public void testRemoveZIPArchive2() throws CoreException {
1946
	try {
1947
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
1948
		expandAll(p);
1949
		setClasspath(p, new IClasspathEntry[] {});
1950
		assertElementDescendants(
1951
			"Unexpected project content", 
1952
			"P",
1953
			p
1954
		);
1955
	} finally {
1956
		deleteProject("P");
1957
	}
1958
}
1959
1960
1961
/*
1962
 * Ensures that removing an external ZIP archive referenced by a library entry and refreshing updates the model
1963
 */
1964
public void testRemoveZIPArchive3() throws CoreException {
1965
	try {
1966
		createExternalFile("externalLib.abc", "");
1967
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
1968
		expandAll(p);
1969
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
1970
		assertElementDescendants(
1971
			"Unexpected project content", 
1972
			"P",
1973
			p
1974
		);
1975
	} finally {
1976
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
1977
		deleteProject("P");
1978
	}
1979
}
1980
1981
/*
1982
 * Ensures that removing a library entry for an existing internal ZIP archive updates the model
1983
 */
1984
public void testRemoveZIPArchive4() throws CoreException {
1985
	try {
1986
		IJavaProject p = createJavaProject("P", new String[0], new String[] {"/P/internalLib.abc"}, "");
1987
		createFile("/P/internalLib.abc", "");
1988
		expandAll(p);
1989
		setClasspath(p, new IClasspathEntry[] {});
1990
		assertElementDescendants(
1991
			"Unexpected project content", 
1992
			"P",
1993
			p
1994
		);
1995
	} finally {
1658
		deleteProject("P");
1996
		deleteProject("P");
1659
	}
1997
	}
1660
}
1998
}
(-)src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java (-1 / +92 lines)
Lines 56-62 Link Here
56
	super(name);
56
	super(name);
57
}
57
}
58
protected String getExternalFolder() {
58
protected String getExternalFolder() {
59
	return getExternalFolderPath("externalFolder");
59
	return getExternalResourcePath("externalFolder");
60
}
60
}
61
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) {
61
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) {
62
	ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2);
62
	ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2);
Lines 93-98 Link Here
93
		};
93
		};
94
	org.eclipse.jdt.core.tests.util.Util.createClassFolder(pathsAndContents, externalFolder + "/lib", "1.4");
94
	org.eclipse.jdt.core.tests.util.Util.createClassFolder(pathsAndContents, externalFolder + "/lib", "1.4");
95
	org.eclipse.jdt.core.tests.util.Util.createSourceDir(pathsAndContents, externalFolder + "/src");
95
	org.eclipse.jdt.core.tests.util.Util.createSourceDir(pathsAndContents, externalFolder + "/src");
96
	
97
	org.eclipse.jdt.core.tests.util.Util.createJar(pathsAndContents, externalFolder + "/lib.abc", "1.4");
98
	org.eclipse.jdt.core.tests.util.Util.createSourceZip(pathsAndContents, externalFolder + "/src.abc");
96
}
99
}
97
private void setUpGenericJar() throws IOException, CoreException {
100
private void setUpGenericJar() throws IOException, CoreException {
98
	String[] pathAndContents = new String[] {
101
	String[] pathAndContents = new String[] {
Lines 407-412 Link Here
407
	}
410
	}
408
}
411
}
409
/*
412
/*
413
 * Ensures that one can attach an external ZIP archive containing sources to a library folder.
414
 */
415
public void testZIPArchive1() throws CoreException {
416
	try {
417
		IProject p = createProject("P1");
418
		IFolder lib = p.getFolder("lib");
419
		lib.createLink(new Path(getExternalFolder() + "/lib"), IResource.NONE, null);
420
		IJavaProject javaProject = createJavaProject("P2", new String[0], new String[] {"/P1/lib"}, "");
421
		IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(lib);
422
		attachSource(root, getExternalFolder() + "/src.abc", "");
423
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
424
		assertSourceEquals(
425
			"Unexpected source",
426
			"public class X {\n" + 
427
			"}",
428
			type.getSource());
429
	} finally {
430
		deleteProject("P1");
431
		deleteProject("P2");
432
	}
433
}
434
/*
435
 * Ensures that one can attach a source folder to an external ZIP archive.
436
 */
437
public void testZIPArchive2() throws CoreException {
438
	try {
439
		IProject p = createProject("P1");
440
		IFolder src = p.getFolder("src");
441
		src.createLink(new Path(getExternalFolder() + "/src"), IResource.NONE, null);
442
		String externalLib = getExternalFolder() + "/lib.abc";
443
		IJavaProject javaProject = createJavaProject("P2", new String[0], new String[] {externalLib}, "");
444
		IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(externalLib);
445
		attachSource(root, "/P1/src", "");
446
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
447
		assertSourceEquals(
448
			"Unexpected source",
449
			"public class X {\n" + 
450
			"}",
451
			type.getSource());
452
	} finally {
453
		deleteProject("P1");
454
		deleteProject("P2");
455
	}
456
}
457
/*
458
 * Ensures that one can attach an external ZIP archive containing sources to an external ZIP archive.
459
 */
460
public void testZIPArchive3() throws CoreException {
461
	try {
462
		String externalLib = getExternalFolder() + "/lib.abc";
463
		IJavaProject javaProject = createJavaProject("P", new String[0], new String[] {externalLib}, "");
464
		IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(externalLib);
465
		attachSource(root, getExternalFolder() + "/src.abc", "");
466
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
467
		assertSourceEquals(
468
			"Unexpected source",
469
			"public class X {\n" + 
470
			"}",
471
			type.getSource());
472
	} finally {
473
		deleteProject("P");
474
	}
475
}
476
/*
477
 * Ensures that one can attach an internal ZIP archive containing sources to an internal ZIP archive.
478
 */
479
public void testZIPArchive4() throws CoreException {
480
	try {
481
		IProject p = createProject("P1");
482
		IFile lib = p.getFile("lib.abc");
483
		lib.createLink(new Path(getExternalFolder() + "/lib.abc"), IResource.NONE, null);
484
		IFile src = p.getFile("src.abc");
485
		src.createLink(new Path(getExternalFolder() + "/src.abc"), IResource.NONE, null);
486
		IJavaProject javaProject = createJavaProject("P2", new String[0], new String[] {"/P1/lib.abc"}, "");
487
		IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(lib);
488
		attachSource(root, "/P1/src.abc", "");
489
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
490
		assertSourceEquals(
491
			"Unexpected source",
492
			"public class X {\n" + 
493
			"}",
494
			type.getSource());
495
	} finally {
496
		deleteProject("P1");
497
		deleteProject("P2");
498
	}
499
}
500
/*
410
 * Ensures that the source of a generic method can be retrieved.
501
 * Ensures that the source of a generic method can be retrieved.
411
 */
502
 */
412
public void testGeneric1() throws JavaModelException {
503
public void testGeneric1() throws JavaModelException {
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (-4 / +36 lines)
Lines 715-723 Link Here
715
				"}",
715
				"}",
716
			},
716
			},
717
			new HashMap(),
717
			new HashMap(),
718
			getExternalFolderPath("externalLib"));
718
			getExternalResourcePath("externalLib"));
719
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
719
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
720
		IClassFile classFile = getClassFile("P", getExternalFolderPath("externalLib"), "p", "X.class");
720
		IClassFile classFile = getClassFile("P", getExternalResourcePath("externalLib"), "p", "X.class");
721
		ITypeHierarchy hierarchy = classFile.getType().newTypeHierarchy(null);
721
		ITypeHierarchy hierarchy = classFile.getType().newTypeHierarchy(null);
722
		assertHierarchyEquals(
722
		assertHierarchyEquals(
723
			"Focus: X [in X.class [in p [in "+ getExternalPath() + "externalLib]]]\n" + 
723
			"Focus: X [in X.class [in p [in "+ getExternalPath() + "externalLib]]]\n" + 
Lines 727-733 Link Here
727
			hierarchy);
727
			hierarchy);
728
	} finally {
728
	} finally {
729
		deleteProject("P");
729
		deleteProject("P");
730
		deleteExternalFolder("externalLib");
730
		deleteExternalResource("externalLib");
731
	}
732
}
733
/*
734
 * Ensures that subtypes are found in an external ZIP archive
735
 */
736
public void testZIPArchive() throws CoreException, IOException {
737
	try {
738
		org.eclipse.jdt.core.tests.util.Util.createJar(
739
			new String[] {
740
				"p/X.java",
741
				"package p;\n" +
742
				"public class X {\n" +
743
				"}",
744
				"p/Y.java",
745
				"package p;\n" +
746
				"public class Y extends X {\n" +
747
				"}",
748
			},
749
			getExternalResourcePath("externalLib.abc"), 
750
			"1.4");
751
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
752
		IClassFile classFile = getClassFile("P", getExternalResourcePath("externalLib.abc"), "p", "X.class");
753
		ITypeHierarchy hierarchy = classFile.getType().newTypeHierarchy(null);
754
		assertHierarchyEquals(
755
			"Focus: X [in X.class [in p [in "+ getExternalPath() + "externalLib.abc]]]\n" + 
756
			"Super types:\n" + 
757
			"Sub types:\n" + 
758
			"  Y [in Y.class [in p [in "+ getExternalPath() + "externalLib.abc]]]\n",
759
			hierarchy);
760
	} finally {
761
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
762
		deleteProject("P");
731
	}
763
	}
732
}
764
}
733
/*
765
/*
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests2.java (-1 / +1 lines)
Lines 2332-2338 Link Here
2332
			requestor.getResults());
2332
			requestor.getResults());
2333
	} finally {
2333
	} finally {
2334
		removeClasspathEntry(this.currentProject, new Path(jarName));
2334
		removeClasspathEntry(this.currentProject, new Path(jarName));
2335
		deleteFile(new File(jarName));
2335
		deleteResource(new File(jarName));
2336
	}
2336
	}
2337
}
2337
}
2338
}
2338
}
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-28 / +246 lines)
Lines 44-50 Link Here
44
import org.eclipse.jdt.core.IClasspathContainer;
44
import org.eclipse.jdt.core.IClasspathContainer;
45
import org.eclipse.jdt.core.IClasspathEntry;
45
import org.eclipse.jdt.core.IClasspathEntry;
46
import org.eclipse.jdt.core.ICompilationUnit;
46
import org.eclipse.jdt.core.ICompilationUnit;
47
import org.eclipse.jdt.core.IJavaElement;
48
import org.eclipse.jdt.core.IJavaElementDelta;
47
import org.eclipse.jdt.core.IJavaElementDelta;
49
import org.eclipse.jdt.core.IJavaModelMarker;
48
import org.eclipse.jdt.core.IJavaModelMarker;
50
import org.eclipse.jdt.core.IJavaModelStatus;
49
import org.eclipse.jdt.core.IJavaModelStatus;
Lines 162-171 Link Here
162
	try {
161
	try {
163
		IJavaProject p = createJavaProject("P");
162
		IJavaProject p = createJavaProject("P");
164
		createExternalFolder("externalLib");
163
		createExternalFolder("externalLib");
165
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
164
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib")), null, null)});
166
		assertMarkers("Unexpected markers", "", p);
165
		assertMarkers("Unexpected markers", "", p);
167
	} finally {
166
	} finally {
168
		deleteExternalFolder("externalLib");
167
		deleteExternalResource("externalLib");
169
		deleteProject("P");
168
		deleteProject("P");
170
	}
169
	}
171
}
170
}
Lines 176-185 Link Here
176
public void testAddExternalLibFolder2() throws CoreException {
175
public void testAddExternalLibFolder2() throws CoreException {
177
	try {
176
	try {
178
		createExternalFolder("externalLib");
177
		createExternalFolder("externalLib");
179
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
178
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
180
		assertMarkers("Unexpected markers", "", p);
179
		assertMarkers("Unexpected markers", "", p);
181
	} finally {
180
	} finally {
182
		deleteExternalFolder("externalLib");
181
		deleteExternalResource("externalLib");
183
		deleteProject("P");
182
		deleteProject("P");
184
	}
183
	}
185
}
184
}
Lines 191-197 Link Here
191
	try {
190
	try {
192
		waitForAutoBuild();
191
		waitForAutoBuild();
193
		IJavaProject p = createJavaProject("P");
192
		IJavaProject p = createJavaProject("P");
194
		IPath path = new Path(getExternalFolderPath("externalLib"));
193
		IPath path = new Path(getExternalResourcePath("externalLib"));
195
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
194
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
196
		assertMarkers(
195
		assertMarkers(
197
			"Unexpected markers", 
196
			"Unexpected markers", 
Lines 208-214 Link Here
208
public void testAddExternalLibFolder4() throws CoreException {
207
public void testAddExternalLibFolder4() throws CoreException {
209
	try {
208
	try {
210
		waitForAutoBuild();
209
		waitForAutoBuild();
211
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
210
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
212
		assertMarkers(
211
		assertMarkers(
213
			"Unexpected markers", 
212
			"Unexpected markers", 
214
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
213
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
Lines 223-235 Link Here
223
 */
222
 */
224
public void testAddExternalLibFolder5() throws CoreException {
223
public void testAddExternalLibFolder5() throws CoreException {
225
	try {
224
	try {
226
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
225
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
227
		waitForAutoBuild();
226
		waitForAutoBuild();
228
		createExternalFolder("externalLib");
227
		createExternalFolder("externalLib");
229
		refresh(p);
228
		refresh(p);
230
		assertMarkers("Unexpected markers", "", p);
229
		assertMarkers("Unexpected markers", "", p);
231
	} finally {
230
	} finally {
232
		deleteExternalFolder("externalLib");
231
		deleteExternalResource("externalLib");
233
		deleteProject("P");
232
		deleteProject("P");
234
	}
233
	}
235
}
234
}
Lines 241-253 Link Here
241
public void testAddExternalLibFolder6() throws CoreException {
240
public void testAddExternalLibFolder6() throws CoreException {
242
	try {
241
	try {
243
		simulateExitRestart();
242
		simulateExitRestart();
244
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
243
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
245
		waitForAutoBuild();
244
		waitForAutoBuild();
246
		createExternalFolder("externalLib");
245
		createExternalFolder("externalLib");
247
		refresh(p);
246
		refresh(p);
248
		assertMarkers("Unexpected markers", "", p);
247
		assertMarkers("Unexpected markers", "", p);
249
	} finally {
248
	} finally {
250
		deleteExternalFolder("externalLib");
249
		deleteExternalResource("externalLib");
250
		deleteProject("P");
251
	}
252
}
253
254
/*
255
 * Ensures that adding a library entry for an existing external ZIP archive doesn't generate a marker
256
 */
257
public void testAddZIPArchive1() throws CoreException {
258
	try {
259
		IJavaProject p = createJavaProject("P");
260
		createExternalFile("externalLib.abc", "");
261
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib.abc")), null, null)});
262
		assertMarkers("Unexpected markers", "", p);
263
	} finally {
264
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
265
		deleteProject("P");
266
	}
267
}
268
269
/*
270
 * Ensures that creating a project with a library entry for an existing external ZIP archive doesn't generate a marker
271
 */
272
public void testAddZIPArchive2() throws CoreException {
273
	try {
274
		createExternalFile("externalLib.abc", "");
275
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
276
		assertMarkers("Unexpected markers", "", p);
277
	} finally {
278
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
279
		deleteProject("P");
280
	}
281
}
282
283
/*
284
 * Ensures that adding a library entry for a non-existing external ZIP archive generates a marker
285
 */
286
public void testAddZIPArchive3() throws CoreException {
287
	try {
288
		waitForAutoBuild();
289
		IJavaProject p = createJavaProject("P");
290
		IPath path = new Path(getExternalResourcePath("externalLib.abc"));
291
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
292
		assertMarkers(
293
			"Unexpected markers", 
294
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib.abc\'",
295
			p);
296
	} finally {
297
		deleteProject("P");
298
	}
299
}
300
301
/*
302
 * Ensures that creating a project with a library entry for a non-existing external ZIP archive generates a marker
303
 */
304
public void testAddZIPArchive4() throws CoreException {
305
	try {
306
		waitForAutoBuild();
307
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
308
		assertMarkers(
309
			"Unexpected markers", 
310
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib.abc\'",
311
			p);
312
	} finally {
313
		deleteProject("P");
314
	}
315
}
316
317
/*
318
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing removes the marker
319
 */
320
public void testAddZIPArchive5() throws CoreException {
321
	try {
322
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
323
		waitForAutoBuild();
324
		createExternalFile("externalLib.abc", "");
325
		refreshExternalArchives(p);
326
		assertMarkers("Unexpected markers", "", p);
327
	} finally {
328
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
329
		deleteProject("P");
330
	}
331
}
332
333
/*
334
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing after a restart
335
 * removes the marker
336
 */
337
public void testAddZIPArchive6() throws CoreException {
338
	try {
339
		simulateExitRestart();
340
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
341
		waitForAutoBuild();
342
		createExternalFile("externalLib.abc", "");
343
		refreshExternalArchives(p);
344
		assertMarkers("Unexpected markers", "", p);
345
	} finally {
346
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
347
		deleteProject("P");
348
	}
349
}
350
351
/*
352
 * Ensures that adding a library entry for an existing internal ZIP archive doesn't generate a marker
353
 */
354
public void testAddZIPArchive7() throws CoreException {
355
	try {
356
		IJavaProject p = createJavaProject("P");
357
		createFile("/P/internalLib.abc", "");
358
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path("/P/internalLib.abc"), null, null)});
359
		assertMarkers("Unexpected markers", "", p);
360
	} finally {
251
		deleteProject("P");
361
		deleteProject("P");
252
	}
362
	}
253
}
363
}
Lines 730-736 Link Here
730
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=220542 )
840
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=220542 )
731
 */
841
 */
732
public void testExternalize2() throws CoreException {
842
public void testExternalize2() throws CoreException {
733
	String externalLibPath = getExternalFolderPath("externalLib") + File.separator;
843
	String externalLibPath = getExternalResourcePath("externalLib") + File.separator;
734
	IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(externalLibPath), null, null);
844
	IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(externalLibPath), null, null);
735
	assertEquals("Unexpected external path", externalLibPath, entry.getPath().toOSString());
845
	assertEquals("Unexpected external path", externalLibPath, entry.getPath().toOSString());
736
}
846
}
Lines 902-907 Link Here
902
		IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length+1];
1012
		IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length+1];
903
		System.arraycopy(originalCP, 0, newCP, 0, originalCP.length);
1013
		System.arraycopy(originalCP, 0, newCP, 0, originalCP.length);
904
		newCP[originalCP.length] = JavaCore.newLibraryEntry(new Path("/P/src/lib"), null, null);
1014
		newCP[originalCP.length] = JavaCore.newLibraryEntry(new Path("/P/src/lib"), null, null);
1015
		createFolder("/P/src/lib");
905
		
1016
		
906
		IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
1017
		IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
907
		
1018
		
Lines 2370-2382 Link Here
2370
		// at this point, a marker indicates that test185733.jar has been created: "Project 'P' is missing required library: '[...]\test185733.jar'"
2481
		// at this point, a marker indicates that test185733.jar has been created: "Project 'P' is missing required library: '[...]\test185733.jar'"
2371
		
2482
		
2372
		createFile(new File(getExternalPath()), "test185733.jar", "");
2483
		createFile(new File(getExternalPath()), "test185733.jar", "");
2373
		getJavaModel().refreshExternalArchives(new IJavaElement[] {p}, null);
2484
		refreshExternalArchives(p);
2374
		assertMarkers(
2485
		assertMarkers(
2375
			"Unexpected markers", 
2486
			"Unexpected markers", 
2376
			"",
2487
			"",
2377
			p);
2488
			p);
2378
	} finally {
2489
	} finally {
2379
		deleteFile(new File(externalJarPath));
2490
		deleteResource(new File(externalJarPath));
2380
		deleteProject("P");
2491
		deleteProject("P");
2381
	}
2492
	}
2382
}
2493
}
Lines 2393-2400 Link Here
2393
		waitForAutoBuild();
2504
		waitForAutoBuild();
2394
		// at this point, the project has no markers
2505
		// at this point, the project has no markers
2395
		
2506
		
2396
		deleteFile(externalJar);
2507
		deleteResource(externalJar);
2397
		getJavaModel().refreshExternalArchives(new IJavaElement[] {p}, null);
2508
		refreshExternalArchives(p);
2398
		assertMarkers(
2509
		assertMarkers(
2399
			"Unexpected markers", 
2510
			"Unexpected markers", 
2400
			"Project \'P\' is missing required library: \'" + externalJar.getPath() + "\'",
2511
			"Project \'P\' is missing required library: \'" + externalJar.getPath() + "\'",
Lines 2677-2683 Link Here
2677
	}
2788
	}
2678
}
2789
}
2679
/*
2790
/*
2680
 * Ensures that a file not ending with .jar or .zip cannot be put on the classpath.
2791
 * Ensures that a file not ending with .jar or .zip can be put on the classpath.
2792
 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=182360 )
2681
 */
2793
 */
2682
public void testInvalidInternalJar2() throws CoreException {
2794
public void testInvalidInternalJar2() throws CoreException {
2683
	try {
2795
	try {
Lines 2686-2692 Link Here
2686
		IJavaProject proj =  createJavaProject("P2", new String[] {}, new String[] {"/P1/existing.txt"}, "bin");
2798
		IJavaProject proj =  createJavaProject("P2", new String[] {}, new String[] {"/P1/existing.txt"}, "bin");
2687
		assertMarkers(
2799
		assertMarkers(
2688
			"Unexpected markers",
2800
			"Unexpected markers",
2689
			"Illegal type of archive for required library: \'/P1/existing.txt\' in project 'P2'",
2801
			"",
2690
			proj);
2802
			proj);
2691
	} finally {
2803
	} finally {
2692
		deleteProject("P1");
2804
		deleteProject("P1");
Lines 2721-2727 Link Here
2721
		IJavaProject javaProject = createJavaProject("P");
2833
		IJavaProject javaProject = createJavaProject("P");
2722
		IProject project = javaProject.getProject();
2834
		IProject project = javaProject.getProject();
2723
		project.close(null);
2835
		project.close(null);
2724
		deleteFile(new File(project.getLocation().toOSString(), ".classpath"));
2836
		deleteResource(new File(project.getLocation().toOSString(), ".classpath"));
2725
		waitForAutoBuild();
2837
		waitForAutoBuild();
2726
		project.open(null);
2838
		project.open(null);
2727
		waitForAutoBuild();
2839
		waitForAutoBuild();
Lines 3949-3960 Link Here
3949
public void testRemoveExternalLibFolder1() throws CoreException {
4061
public void testRemoveExternalLibFolder1() throws CoreException {
3950
	try {
4062
	try {
3951
		createExternalFolder("externalLib");
4063
		createExternalFolder("externalLib");
3952
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
4064
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
3953
		waitForAutoBuild();
4065
		waitForAutoBuild();
3954
		setClasspath(p, new IClasspathEntry[] {});
4066
		setClasspath(p, new IClasspathEntry[] {});
3955
		assertMarkers("Unexpected markers", "", p);
4067
		assertMarkers("Unexpected markers", "", p);
3956
	} finally {
4068
	} finally {
3957
		deleteExternalFolder("externalLib");
4069
		deleteExternalResource("externalLib");
3958
		deleteProject("P");
4070
		deleteProject("P");
3959
	}
4071
	}
3960
}
4072
}
Lines 3964-3970 Link Here
3964
 */
4076
 */
3965
public void testRemoveExternalLibFolder2() throws CoreException {
4077
public void testRemoveExternalLibFolder2() throws CoreException {
3966
	try {
4078
	try {
3967
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
4079
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
3968
		waitForAutoBuild();
4080
		waitForAutoBuild();
3969
		setClasspath(p, new IClasspathEntry[] {});
4081
		setClasspath(p, new IClasspathEntry[] {});
3970
		assertMarkers(
4082
		assertMarkers(
Lines 3982-3997 Link Here
3982
public void testRemoveExternalLibFolder3() throws CoreException {
4094
public void testRemoveExternalLibFolder3() throws CoreException {
3983
	try {
4095
	try {
3984
		createExternalFolder("externalLib");
4096
		createExternalFolder("externalLib");
3985
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
4097
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
3986
		waitForAutoBuild();
4098
		waitForAutoBuild();
3987
		deleteExternalFolder("externalLib");
4099
		deleteExternalResource("externalLib");
3988
		refresh(p);
4100
		refresh(p);
3989
		assertMarkers(
4101
		assertMarkers(
3990
			"Unexpected markers", 
4102
			"Unexpected markers", 
3991
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
4103
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
3992
			p);
4104
			p);
3993
	} finally {
4105
	} finally {
3994
		deleteExternalFolder("externalLib");
4106
		deleteExternalResource("externalLib");
3995
		deleteProject("P");
4107
		deleteProject("P");
3996
	}
4108
	}
3997
}
4109
}
Lines 4004-4019 Link Here
4004
	try {
4116
	try {
4005
		simulateExitRestart();
4117
		simulateExitRestart();
4006
		createExternalFolder("externalLib");
4118
		createExternalFolder("externalLib");
4007
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
4119
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
4008
		waitForAutoBuild();
4120
		waitForAutoBuild();
4009
		deleteExternalFolder("externalLib");
4121
		deleteExternalResource("externalLib");
4010
		refresh(p);
4122
		refresh(p);
4011
		assertMarkers(
4123
		assertMarkers(
4012
			"Unexpected markers", 
4124
			"Unexpected markers", 
4013
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
4125
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib\'",
4014
			p);
4126
			p);
4015
	} finally {
4127
	} finally {
4016
		deleteExternalFolder("externalLib");
4128
		deleteExternalResource("externalLib");
4129
		deleteProject("P");
4130
	}
4131
}
4132
4133
/*
4134
 * Ensures that removing a library entry for an existing external ZIP archive doesn't generate a marker
4135
 */
4136
public void testRemoveZIPArchive1() throws CoreException {
4137
	try {
4138
		createExternalFile("externalLib.abc", "");
4139
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
4140
		waitForAutoBuild();
4141
		setClasspath(p, new IClasspathEntry[] {});
4142
		assertMarkers("Unexpected markers", "", p);
4143
	} finally {
4144
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
4145
		deleteProject("P");
4146
	}
4147
}
4148
4149
/*
4150
 * Ensures that removing a library entry for a non-existing external ZIP archive removes the marker
4151
 */
4152
public void testRemoveZIPArchive2() throws CoreException {
4153
	try {
4154
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
4155
		waitForAutoBuild();
4156
		setClasspath(p, new IClasspathEntry[] {});
4157
		assertMarkers(
4158
			"Unexpected markers", 
4159
			"",
4160
			p);
4161
	} finally {
4162
		deleteProject("P");
4163
	}
4164
}
4165
4166
/*
4167
 * Ensures that removing an external ZIP archive referenced by a library entry creates a marker
4168
 */
4169
public void testRemoveZIPArchive3() throws CoreException {
4170
	try {
4171
		createExternalFile("externalLib.abc", "");
4172
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
4173
		waitForAutoBuild();
4174
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
4175
		assertMarkers(
4176
			"Unexpected markers", 
4177
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib.abc\'",
4178
			p);
4179
	} finally {
4180
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
4181
		deleteProject("P");
4182
	}
4183
}
4184
4185
/*
4186
 * Ensures that removing an external ZIP archive referenced by a library entry and refreshing after a restart
4187
 * creates a marker
4188
 */
4189
public void testRemoveZIPArchive4() throws CoreException {
4190
	try {
4191
		simulateExitRestart();
4192
		createExternalFile("externalLib.abc", "");
4193
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
4194
		waitForAutoBuild();
4195
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
4196
		assertMarkers(
4197
			"Unexpected markers", 
4198
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "externalLib.abc\'",
4199
			p);
4200
	} finally {
4201
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
4202
		deleteProject("P");
4203
	}
4204
}
4205
4206
/*
4207
 * Ensures that removing a library entry for an existing internal ZIP archive doesn't generate a marker
4208
 */
4209
public void testRemoveZIPArchive5() throws CoreException {
4210
	try {
4211
		IJavaProject p = createJavaProject("P", new String[0], new String[] {"/P/internalLib.abc"}, "");
4212
		createFile("/P/internalLib.abc", "");
4213
		waitForAutoBuild();
4214
		setClasspath(p, new IClasspathEntry[] {});
4215
		assertMarkers("Unexpected markers", "", p);
4216
	} finally {
4217
		deleteProject("P");
4218
	}
4219
}
4220
4221
/*
4222
 * Ensures that removing an internal ZIP archive referenced by a library entry creates a marker
4223
 */
4224
public void testRemoveZIPArchive6() throws CoreException {
4225
	try {
4226
		IJavaProject p = createJavaProject("P", new String[0], new String[] {"/P/internalLib.abc"}, "");
4227
		createFile("/P/internalLib.abc", "");
4228
		waitForAutoBuild();
4229
		deleteFile("/P/internalLib.abc");
4230
		assertMarkers(
4231
			"Unexpected markers", 
4232
			"Project \'P\' is missing required library: \'internalLib.abc\'",
4233
			p);
4234
	} finally {
4017
		deleteProject("P");
4235
		deleteProject("P");
4018
	}
4236
	}
4019
}
4237
}
(-)src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java (-2 / +6 lines)
Lines 123-130 Link Here
123
protected IFolder createFolder(String path) throws CoreException {
123
protected IFolder createFolder(String path) throws CoreException {
124
	return createFolder(new Path(path));
124
	return createFolder(new Path(path));
125
}
125
}
126
protected void deleteExternalFolder(String relativePath) {
126
protected void deleteExternalResource(String relativePath) {
127
	deleteFile(new File(getExternalPath() + relativePath));
127
	deleteResource(new File(getExternalPath() + relativePath));
128
}
129
protected void deleteAndRefreshExternalZIPArchive(String relativePath, String referringProject) throws JavaModelException {
130
	deleteExternalResource(relativePath);
131
	refreshExternalArchives(getJavaProject(referringProject));
128
}
132
}
129
protected void deleteFile(String filePath) throws CoreException {
133
protected void deleteFile(String filePath) throws CoreException {
130
	deleteResource(this.getFile(filePath));
134
	deleteResource(this.getFile(filePath));
(-)src/org/eclipse/jdt/core/tests/model/EncodingTests.java (-1 / +1 lines)
Lines 847-853 Link Here
847
		assertEquals("We should not get any character!", "", new String(ifileContents));
847
		assertEquals("We should not get any character!", "", new String(ifileContents));
848
		
848
		
849
		// Delete empty file
849
		// Delete empty file
850
		deleteFile(file);
850
		deleteResource(file);
851
	}	
851
	}	
852
852
853
	/**
853
	/**
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (-2 / +2 lines)
Lines 1191-1197 Link Here
1191
		);
1191
		);
1192
	} finally {
1192
	} finally {
1193
		removeClasspathEntry(project, new Path(jarPath));
1193
		removeClasspathEntry(project, new Path(jarPath));
1194
		deleteFile(new File(jarPath));
1194
		deleteResource(new File(jarPath));
1195
	}
1195
	}
1196
}
1196
}
1197
/**
1197
/**
Lines 1284-1290 Link Here
1284
		);
1284
		);
1285
	} finally {
1285
	} finally {
1286
		removeClasspathEntry(project, new Path(jarName));
1286
		removeClasspathEntry(project, new Path(jarName));
1287
		deleteFile(new File(jarName));
1287
		deleteResource(new File(jarName));
1288
	}
1288
	}
1289
}
1289
}
1290
/**
1290
/**
(-)src/org/eclipse/jdt/core/tests/model/SearchParticipantTests.java (-1 / +1 lines)
Lines 138-144 Link Here
138
138
139
	public void setUpSuite() throws Exception {
139
	public void setUpSuite() throws Exception {
140
		super.setUpSuite();
140
		super.setUpSuite();
141
		deleteFile(getIndexLocation().toFile());
141
		deleteResource(getIndexLocation().toFile());
142
	}
142
	}
143
143
144
	public void tearDownSuite() throws Exception {
144
	public void tearDownSuite() throws Exception {
(-)src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java (-1 / +1 lines)
Lines 2607-2613 Link Here
2607
				"Member");
2607
				"Member");
2608
		assertEquals("test0114.Test.Member<java.lang.String>", ((IType)elements[0]).getFullyQualifiedParameterizedName());
2608
		assertEquals("test0114.Test.Member<java.lang.String>", ((IType)elements[0]).getFullyQualifiedParameterizedName());
2609
	} finally {
2609
	} finally {
2610
		deleteFile(rootLocation.append("test0114").toFile());
2610
		deleteResource(rootLocation.append("test0114").toFile());
2611
	}
2611
	}
2612
}
2612
}
2613
}
2613
}
(-)src/org/eclipse/jdt/core/tests/model/ExistenceTests.java (-2 / +2 lines)
Lines 316-323 Link Here
316
 */
316
 */
317
public void testNonExistingExternalPackageFragmentRoot2() throws CoreException {
317
public void testNonExistingExternalPackageFragmentRoot2() throws CoreException {
318
	try {
318
	try {
319
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("nonExisting")}, "");
319
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("nonExisting")}, "");
320
		IPackageFragmentRoot root = p.getPackageFragmentRoot(getExternalFolderPath("nonExisting"));
320
		IPackageFragmentRoot root = p.getPackageFragmentRoot(getExternalResourcePath("nonExisting"));
321
		assertFalse("root should not exist", root.exists());
321
		assertFalse("root should not exist", root.exists());
322
	} finally {
322
	} finally {
323
		deleteProject("P");
323
		deleteProject("P");
(-)src/org/eclipse/jdt/core/tests/model/JavaElementDeltaTests.java (-29 / +290 lines)
Lines 271-277 Link Here
271
		createExternalFolder("externalLib");
271
		createExternalFolder("externalLib");
272
		refresh(p);
272
		refresh(p);
273
		startDeltas();
273
		startDeltas();
274
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
274
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib")), null, null)});
275
		assertDeltas(
275
		assertDeltas(
276
			"Unexpected delta", 
276
			"Unexpected delta", 
277
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
277
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
Lines 282-288 Link Here
282
		);
282
		);
283
	} finally {
283
	} finally {
284
		stopDeltas();
284
		stopDeltas();
285
		deleteExternalFolder("externalLib");
285
		deleteExternalResource("externalLib");
286
		deleteProject("P");
286
		deleteProject("P");
287
	}
287
	}
288
}
288
}
Lines 294-300 Link Here
294
	try {
294
	try {
295
		IJavaProject p = createJavaProject("P");
295
		IJavaProject p = createJavaProject("P");
296
		refresh(p);
296
		refresh(p);
297
		IPath path = new Path(getExternalFolderPath("externalLib"));
297
		IPath path = new Path(getExternalResourcePath("externalLib"));
298
		startDeltas();
298
		startDeltas();
299
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
299
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
300
		assertDeltas(
300
		assertDeltas(
Lines 315-321 Link Here
315
 */
315
 */
316
public void testAddExternalLibFolder3() throws CoreException {
316
public void testAddExternalLibFolder3() throws CoreException {
317
	try {
317
	try {
318
		IJavaProject p =createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
318
		IJavaProject p =createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
319
		startDeltas();
319
		startDeltas();
320
		createExternalFolder("externalLib");
320
		createExternalFolder("externalLib");
321
		refresh(p);
321
		refresh(p);
Lines 326-332 Link Here
326
		);
326
		);
327
	} finally {
327
	} finally {
328
		stopDeltas();
328
		stopDeltas();
329
		deleteExternalFolder("externalLib");
329
		deleteExternalResource("externalLib");
330
		deleteProject("P");
330
		deleteProject("P");
331
	}
331
	}
332
}
332
}
Lines 337-343 Link Here
337
public void testAddExternalLibFolder4() throws CoreException {
337
public void testAddExternalLibFolder4() throws CoreException {
338
	try {
338
	try {
339
		simulateExitRestart();
339
		simulateExitRestart();
340
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
340
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
341
		startDeltas();
341
		startDeltas();
342
		createExternalFolder("externalLib");
342
		createExternalFolder("externalLib");
343
		refresh(p);
343
		refresh(p);
Lines 348-354 Link Here
348
		);
348
		);
349
	} finally {
349
	} finally {
350
		stopDeltas();
350
		stopDeltas();
351
		deleteExternalFolder("externalLib");
351
		deleteExternalResource("externalLib");
352
		deleteProject("P");
353
	}
354
}
355
356
/*
357
 * Ensures that adding a library entry for an existing external ZIP archive triggers the correct delta
358
 */
359
public void testAddZIPArchive1() throws CoreException {
360
	try {
361
		IJavaProject p = createJavaProject("P");
362
		createExternalFile("externalLib.abc", "");
363
		startDeltas();
364
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalResourcePath("externalLib.abc")), null, null)});
365
		assertDeltas(
366
			"Unexpected delta", 
367
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
368
			"	<project root>[*]: {REMOVED FROM CLASSPATH}\n" + 
369
			"	"+ getExternalPath() + "externalLib.abc[+]: {}\n" + 
370
			"	"+ getExternalJCLPathString() + "[*]: {REMOVED FROM CLASSPATH}\n" + 
371
			"	ResourceDelta(/P/.classpath)[*]"
372
		);
373
	} finally {
374
		stopDeltas();
375
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
376
		deleteProject("P");
377
	}
378
}
379
380
/*
381
 * Ensures that adding a library entry for a non-existing external ZIP archive triggers the correct delta
382
 */
383
public void testAddZIPArchive2() throws CoreException {
384
	try {
385
		IJavaProject p = createJavaProject("P");
386
		IPath path = new Path(getExternalResourcePath("externalLib.abc"));
387
		startDeltas();
388
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(path, null, null)});
389
		assertDeltas(
390
			"Unexpected delta", 
391
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
392
			"	<project root>[*]: {REMOVED FROM CLASSPATH}\n" + 
393
			"	"+ getExternalJCLPathString() + "[*]: {REMOVED FROM CLASSPATH}\n" + 
394
			"	ResourceDelta(/P/.classpath)[*]"
395
		);
396
	} finally {
397
		stopDeltas();
398
		deleteProject("P");
399
	}
400
}
401
402
/*
403
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing triggers the correct delta
404
 */
405
public void testAddZIPArchive3() throws CoreException {
406
	try {
407
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
408
		startDeltas();
409
		createExternalFile("externalLib.abc", "");
410
		refreshExternalArchives(p);
411
		assertDeltas(
412
			"Unexpected delta", 
413
			"P[*]: {CHILDREN}\n" + 
414
			"	"+ getExternalPath() + "externalLib.abc[+]: {}"
415
		);
416
	} finally {
417
		stopDeltas();
418
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
419
		deleteProject("P");
420
	}
421
}
422
423
/*
424
 * Ensures that creating an external ZIP archive referenced by a library entry and refreshing after a restart triggers the correct delta
425
 */
426
public void testAddZIPArchive4() throws CoreException {
427
	try {
428
		simulateExitRestart();
429
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
430
		startDeltas();
431
		createExternalFile("externalLib.abc", "");
432
		refreshExternalArchives(p);
433
		assertDeltas(
434
			"Unexpected delta", 
435
			"P[*]: {CHILDREN}\n" + 
436
			"	"+ getExternalPath() + "externalLib.abc[+]: {}"
437
		);
438
	} finally {
439
		stopDeltas();
440
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
441
		deleteProject("P");
442
	}
443
}
444
445
/*
446
 * Ensures that adding a library entry for an existing internal ZIP archive triggers the correct delta
447
 */
448
public void testAddZIPArchive5() throws CoreException {
449
	try {
450
		IJavaProject p = createJavaProject("P");
451
		createFile("/P/internalLib.abc", "");
452
		startDeltas();
453
		setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path("/P/internalLib.abc"), null, null)});
454
		assertDeltas(
455
			"Unexpected delta", 
456
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
457
			"	<project root>[*]: {REMOVED FROM CLASSPATH}\n" + 
458
			"	internalLib.abc[*]: {ADDED TO CLASSPATH}\n" + 
459
			"	"+ getExternalJCLPathString() + "[*]: {REMOVED FROM CLASSPATH}\n" + 
460
			"	ResourceDelta(/P/.classpath)[*]"
461
		);
462
	} finally {
463
		stopDeltas();
352
		deleteProject("P");
464
		deleteProject("P");
353
	}
465
	}
354
}
466
}
Lines 782-788 Link Here
782
public void testChangeExternalLibFolder1() throws CoreException {
894
public void testChangeExternalLibFolder1() throws CoreException {
783
	try {
895
	try {
784
		createExternalFolder("externalLib");
896
		createExternalFolder("externalLib");
785
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
897
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
786
		startDeltas();
898
		startDeltas();
787
		createExternalFolder("externalLib/p");
899
		createExternalFolder("externalLib/p");
788
		refresh(p);
900
		refresh(p);
Lines 794-800 Link Here
794
		);
906
		);
795
	} finally {
907
	} finally {
796
		stopDeltas();
908
		stopDeltas();
797
		deleteExternalFolder("externalLib");
909
		deleteExternalResource("externalLib");
798
		deleteProject("P");
910
		deleteProject("P");
799
	}
911
	}
800
}
912
}
Lines 805-811 Link Here
805
public void testChangeExternalLibFolder2() throws CoreException {
917
public void testChangeExternalLibFolder2() throws CoreException {
806
	try {
918
	try {
807
		createExternalFolder("externalLib/p");
919
		createExternalFolder("externalLib/p");
808
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
920
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
809
		startDeltas();
921
		startDeltas();
810
		createExternalFile("externalLib/p/X.class", "");
922
		createExternalFile("externalLib/p/X.class", "");
811
		refresh(p);
923
		refresh(p);
Lines 818-824 Link Here
818
		);
930
		);
819
	} finally {
931
	} finally {
820
		stopDeltas();
932
		stopDeltas();
821
		deleteExternalFolder("externalLib");
933
		deleteExternalResource("externalLib");
822
		deleteProject("P");
934
		deleteProject("P");
823
	}
935
	}
824
}
936
}
Lines 830-836 Link Here
830
	try {
942
	try {
831
		createExternalFolder("externalLib/p");
943
		createExternalFolder("externalLib/p");
832
		createExternalFile("externalLib/p/X.class", "");
944
		createExternalFile("externalLib/p/X.class", "");
833
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
945
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
834
		startDeltas();
946
		startDeltas();
835
		touch(getExternalFile("externalLib/p/X.class"));
947
		touch(getExternalFile("externalLib/p/X.class"));
836
		refresh(p);
948
		refresh(p);
Lines 843-849 Link Here
843
		);
955
		);
844
	} finally {
956
	} finally {
845
		stopDeltas();
957
		stopDeltas();
846
		deleteExternalFolder("externalLib");
958
		deleteExternalResource("externalLib");
847
		deleteProject("P");
959
		deleteProject("P");
848
	}
960
	}
849
}
961
}
Lines 854-860 Link Here
854
public void testChangeExternalLibFolder4() throws CoreException {
966
public void testChangeExternalLibFolder4() throws CoreException {
855
	try {
967
	try {
856
		createExternalFolder("externalLib");
968
		createExternalFolder("externalLib");
857
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
969
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
858
		startDeltas();
970
		startDeltas();
859
		createExternalFile("externalLib/test.txt", "test");
971
		createExternalFile("externalLib/test.txt", "test");
860
		refresh(p);
972
		refresh(p);
Lines 865-871 Link Here
865
		);
977
		);
866
	} finally {
978
	} finally {
867
		stopDeltas();
979
		stopDeltas();
868
		deleteExternalFolder("externalLib");
980
		deleteExternalResource("externalLib");
869
		deleteProject("P");
981
		deleteProject("P");
870
	}
982
	}
871
}
983
}
Lines 876-882 Link Here
876
public void testChangeExternalLibFolder5() throws CoreException {
988
public void testChangeExternalLibFolder5() throws CoreException {
877
	try {
989
	try {
878
		createExternalFolder("externalLib/p");
990
		createExternalFolder("externalLib/p");
879
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
991
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
880
		startDeltas();
992
		startDeltas();
881
		createExternalFile("externalLib/p/test.txt", "test");
993
		createExternalFile("externalLib/p/test.txt", "test");
882
		refresh(p);
994
		refresh(p);
Lines 888-894 Link Here
888
		);
1000
		);
889
	} finally {
1001
	} finally {
890
		stopDeltas();
1002
		stopDeltas();
891
		deleteExternalFolder("externalLib");
1003
		deleteExternalResource("externalLib");
1004
		deleteProject("P");
1005
	}
1006
}
1007
1008
/*
1009
 * Ensures that changing an external ZIP archive referenced by a library entry and refreshing triggers the correct delta
1010
 */
1011
public void testChangeZIPArchive1() throws CoreException {
1012
	try {
1013
		createExternalFile("externalLib.abc", "");
1014
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
1015
		refreshExternalArchives(p);
1016
		startDeltas();
1017
		touch(getExternalFile("externalLib.abc"));
1018
		refreshExternalArchives(p);
1019
		assertDeltas(
1020
			"Unexpected delta", 
1021
			"P[*]: {CHILDREN}\n" + 
1022
			"	"+ getExternalPath() + "externalLib.abc[*]: {CONTENT | ARCHIVE CONTENT CHANGED}"
1023
		);
1024
	} finally {
1025
		stopDeltas();
1026
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
1027
		deleteProject("P");
1028
	}
1029
}
1030
1031
/*
1032
 * Ensures that changing an internal ZIP archive referenced by a library entry triggers the correct delta
1033
 */
1034
public void testChangeZIPArchive2() throws CoreException {
1035
	try {
1036
		createJavaProject("P", new String[0], new String[] {"/P/internalLib.abc"}, "");
1037
		createFile("/P/internalLib.abc", "");
1038
		startDeltas();
1039
		editFile("/P/internalLib.abc", "");
1040
		assertDeltas(
1041
			"Unexpected delta", 
1042
			"P[*]: {CHILDREN}\n" + 
1043
			"	internalLib.abc[*]: {CONTENT | ARCHIVE CONTENT CHANGED}"
1044
		);
1045
	} finally {
1046
		stopDeltas();
892
		deleteProject("P");
1047
		deleteProject("P");
893
	}
1048
	}
894
}
1049
}
Lines 901-907 Link Here
901
		createExternalFolder("externalLib");
1056
		createExternalFolder("externalLib");
902
		createExternalFolder("externalSrc");
1057
		createExternalFolder("externalSrc");
903
		IJavaProject project = createJavaProject("P");
1058
		IJavaProject project = createJavaProject("P");
904
		addLibraryEntry(project, getExternalFolderPath("externalLib"), getExternalFolderPath("externalSrc"));
1059
		addLibraryEntry(project, getExternalResourcePath("externalLib"), getExternalResourcePath("externalSrc"));
905
		startDeltas();
1060
		startDeltas();
906
		createExternalFile("externalSrc/X.java", "public class X {}");
1061
		createExternalFile("externalSrc/X.java", "public class X {}");
907
		refresh(project);
1062
		refresh(project);
Lines 912-919 Link Here
912
			);
1067
			);
913
	} finally {
1068
	} finally {
914
		stopDeltas();
1069
		stopDeltas();
915
		deleteExternalFolder("externalLib");
1070
		deleteExternalResource("externalLib");
916
		deleteExternalFolder("externalSrc");
1071
		deleteExternalResource("externalSrc");
917
		deleteProject("P");
1072
		deleteProject("P");
918
	}
1073
	}
919
}
1074
}
Lines 2286-2292 Link Here
2286
public void testRemoveExternalLibFolder1() throws CoreException {
2441
public void testRemoveExternalLibFolder1() throws CoreException {
2287
	try {
2442
	try {
2288
		createExternalFolder("externalLib");
2443
		createExternalFolder("externalLib");
2289
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2444
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
2290
		startDeltas();
2445
		startDeltas();
2291
		setClasspath(p, new IClasspathEntry[] {});
2446
		setClasspath(p, new IClasspathEntry[] {});
2292
		assertDeltas(
2447
		assertDeltas(
Lines 2297-2303 Link Here
2297
		);
2452
		);
2298
	} finally {
2453
	} finally {
2299
		stopDeltas();
2454
		stopDeltas();
2300
		deleteExternalFolder("externalLib");
2455
		deleteExternalResource("externalLib");
2301
		deleteProject("P");
2456
		deleteProject("P");
2302
	}
2457
	}
2303
}
2458
}
Lines 2307-2313 Link Here
2307
 */
2462
 */
2308
public void testRemoveExternalLibFolder2() throws CoreException {
2463
public void testRemoveExternalLibFolder2() throws CoreException {
2309
	try {
2464
	try {
2310
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2465
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
2311
		startDeltas();
2466
		startDeltas();
2312
		setClasspath(p, new IClasspathEntry[] {});
2467
		setClasspath(p, new IClasspathEntry[] {});
2313
		assertDeltas(
2468
		assertDeltas(
Lines 2327-2335 Link Here
2327
public void testRemoveExternalLibFolder3() throws CoreException {
2482
public void testRemoveExternalLibFolder3() throws CoreException {
2328
	try {
2483
	try {
2329
		createExternalFolder("externalLib");
2484
		createExternalFolder("externalLib");
2330
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2485
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
2331
		startDeltas();
2486
		startDeltas();
2332
		deleteExternalFolder("externalLib");
2487
		deleteExternalResource("externalLib");
2333
		refresh(p);
2488
		refresh(p);
2334
		assertDeltas(
2489
		assertDeltas(
2335
			"Unexpected delta", 
2490
			"Unexpected delta", 
Lines 2338-2344 Link Here
2338
		);
2493
		);
2339
	} finally {
2494
	} finally {
2340
		stopDeltas();
2495
		stopDeltas();
2341
		deleteExternalFolder("externalLib");
2496
		deleteExternalResource("externalLib");
2342
		deleteProject("P");
2497
		deleteProject("P");
2343
	}
2498
	}
2344
}
2499
}
Lines 2351-2359 Link Here
2351
	try {
2506
	try {
2352
		simulateExitRestart();
2507
		simulateExitRestart();
2353
		createExternalFolder("externalLib");
2508
		createExternalFolder("externalLib");
2354
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
2509
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
2355
		startDeltas();
2510
		startDeltas();
2356
		deleteExternalFolder("externalLib");
2511
		deleteExternalResource("externalLib");
2357
		refresh(p);
2512
		refresh(p);
2358
		assertDeltas(
2513
		assertDeltas(
2359
			"Unexpected delta", 
2514
			"Unexpected delta", 
Lines 2362-2368 Link Here
2362
		);
2517
		);
2363
	} finally {
2518
	} finally {
2364
		stopDeltas();
2519
		stopDeltas();
2365
		deleteExternalFolder("externalLib");
2520
		deleteExternalResource("externalLib");
2521
		deleteProject("P");
2522
	}
2523
}
2524
2525
/*
2526
 * Ensures that removing a library entry for an existing external ZIP archive triggers the correct delta
2527
 */
2528
public void testRemoveZIPArchive1() throws CoreException {
2529
	try {
2530
		createExternalFile("externalLib.abc", "");
2531
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
2532
		startDeltas();
2533
		setClasspath(p, new IClasspathEntry[] {});
2534
		assertDeltas(
2535
			"Unexpected delta", 
2536
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
2537
			"	"+ getExternalPath() + "externalLib.abc[*]: {REMOVED FROM CLASSPATH}\n" + 
2538
			"	ResourceDelta(/P/.classpath)[*]"
2539
		);
2540
	} finally {
2541
		stopDeltas();
2542
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
2543
		deleteProject("P");
2544
	}
2545
}
2546
2547
/*
2548
 * Ensures that removing a library entry for a non-existing external ZIP archive triggers the correct delta
2549
 */
2550
public void testRemoveZIPArchive2() throws CoreException {
2551
	try {
2552
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
2553
		startDeltas();
2554
		setClasspath(p, new IClasspathEntry[] {});
2555
		assertDeltas(
2556
			"Unexpected delta", 
2557
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
2558
			"	"+ getExternalPath() + "externalLib.abc[*]: {REMOVED FROM CLASSPATH}\n" + 
2559
			"	ResourceDelta(/P/.classpath)[*]"		);
2560
	} finally {
2561
		stopDeltas();
2562
		deleteProject("P");
2563
	}
2564
}
2565
2566
/*
2567
 * Ensures that removing an external ZIP archive referenced by a library entry triggers the correct delta
2568
 */
2569
public void testRemoveZIPArchive3() throws CoreException {
2570
	try {
2571
		createExternalFile("externalLib.abc", "");
2572
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
2573
		startDeltas();
2574
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
2575
		assertDeltas(
2576
			"Unexpected delta", 
2577
			"P[*]: {CHILDREN}\n" + 
2578
			"	"+ getExternalPath() + "externalLib.abc[-]: {}"
2579
		);
2580
	} finally {
2581
		stopDeltas();
2582
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
2583
		deleteProject("P");
2584
	}
2585
}
2586
2587
/*
2588
 * Ensures that removing an external ZIP archive referenced by a library entry after a restart
2589
 * triggers the correct delta
2590
 */
2591
public void testRemoveZIPArchive4() throws CoreException {
2592
	try {
2593
		simulateExitRestart();
2594
		createExternalFile("externalLib.abc", "");
2595
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
2596
		startDeltas();
2597
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
2598
		assertDeltas(
2599
			"Unexpected delta", 
2600
			"P[*]: {CHILDREN}\n" + 
2601
			"	"+ getExternalPath() + "externalLib.abc[-]: {}"
2602
		);
2603
	} finally {
2604
		stopDeltas();
2605
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
2606
		deleteProject("P");
2607
	}
2608
}
2609
2610
/*
2611
 * Ensures that removing a library entry for an existing internal ZIP archive triggers the correct delta
2612
 */
2613
public void testRemoveZIPArchive5() throws CoreException {
2614
	try {
2615
		IJavaProject p = createJavaProject("P", new String[0], new String[] {"/P/internalLib.abc"}, "");
2616
		createFile("/P/internalLib.abc", "");
2617
		startDeltas();
2618
		setClasspath(p, new IClasspathEntry[] {});
2619
		assertDeltas(
2620
			"Unexpected delta", 
2621
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
2622
			"	internalLib.abc[*]: {REMOVED FROM CLASSPATH}\n" + 
2623
			"	ResourceDelta(/P/.classpath)[*]"
2624
		);
2625
	} finally {
2626
		stopDeltas();
2366
		deleteProject("P");
2627
		deleteProject("P");
2367
	}
2628
	}
2368
}
2629
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-6 / +76 lines)
Lines 528-533 Link Here
528
		"", 
528
		"", 
529
		this.resultCollector);
529
		this.resultCollector);
530
}
530
}
531
531
/*
532
/*
532
 * Ensures that a method declaration in an external library folder can be found
533
 * Ensures that a method declaration in an external library folder can be found
533
 */
534
 */
Lines 544-552 Link Here
544
				"}"
545
				"}"
545
			},
546
			},
546
			new HashMap(),
547
			new HashMap(),
547
			getExternalFolderPath("externalLib")
548
			getExternalResourcePath("externalLib")
548
		);
549
		);
549
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
550
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
550
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("P")});
551
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("P")});
551
		search("foo", METHOD, DECLARATIONS, scope);
552
		search("foo", METHOD, DECLARATIONS, scope);
552
		assertSearchResults(
553
		assertSearchResults(
Lines 554-560 Link Here
554
			this.resultCollector);
555
			this.resultCollector);
555
	} finally {
556
	} finally {
556
		deleteProject("P");
557
		deleteProject("P");
557
		deleteExternalFolder("externalLib");
558
		deleteExternalResource("externalLib");
558
	}
559
	}
559
}
560
}
560
561
Lines 572-580 Link Here
572
				"}"
573
				"}"
573
			},
574
			},
574
			new HashMap(),
575
			new HashMap(),
575
			getExternalFolderPath("externalLib")
576
			getExternalResourcePath("externalLib")
576
		);
577
		);
577
		createJavaProject("P", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
578
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
578
		
579
		
579
		TypeNameMatchCollector collector = new TypeNameMatchCollector();
580
		TypeNameMatchCollector collector = new TypeNameMatchCollector();
580
		new SearchEngine(this.workingCopies).searchAllTypeNames(
581
		new SearchEngine(this.workingCopies).searchAllTypeNames(
Lines 594-603 Link Here
594
		);
595
		);
595
	} finally {
596
	} finally {
596
		deleteProject("P");
597
		deleteProject("P");
597
		deleteExternalFolder("externalLib");
598
		deleteExternalResource("externalLib");
598
	}
599
	}
599
600
600
}
601
}
602
603
/*
604
 * Ensures that a method declaration in an external ZIP archive can be found
605
 */
606
public void testZIPArchive1() throws Exception {
607
	try {
608
		org.eclipse.jdt.core.tests.util.Util.createJar(
609
			new String[] {
610
				"p/X.java", 
611
				"package p;\n" +
612
				"public class X {\n" +
613
				"  public void foo() {\n" +
614
				"  }\n" +
615
				"}"
616
			},
617
			getExternalResourcePath("externalLib.abc"), 
618
			"1.4");
619
		createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
620
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("P")});
621
		search("foo", METHOD, DECLARATIONS, scope);
622
		assertSearchResults(
623
			getExternalPath() + "externalLib.abc void p.X.foo()",
624
			this.resultCollector);
625
	} finally {
626
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
627
		deleteProject("P");
628
	}
629
}
630
631
/*
632
 * Ensures that search all type names returns the types in an external ZIP archive
633
 */
634
public void testZIPArchive2() throws Exception {
635
	try {
636
		IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
637
		org.eclipse.jdt.core.tests.util.Util.createJar(
638
			new String[] {
639
				"p/ExternalType.java", 
640
				"package p;\n" +
641
				"public class ExternalType {\n" +
642
				"}"
643
			},
644
			getExternalResourcePath("externalLib.abc"), 
645
			"1.4");
646
		refreshExternalArchives(p);
647
		
648
		TypeNameMatchCollector collector = new TypeNameMatchCollector();
649
		new SearchEngine(this.workingCopies).searchAllTypeNames(
650
			null,
651
			SearchPattern.R_EXACT_MATCH,
652
			"ExternalType".toCharArray(),
653
			SearchPattern.R_EXACT_MATCH,
654
			TYPE,
655
			SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("P")}),
656
			collector,
657
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
658
			null
659
		);
660
		assertSearchResults(
661
			"ExternalType (not open) [in ExternalType.class [in p [in "+ getExternalPath() + "externalLib.abc]]]",
662
			collector
663
		);
664
	} finally {
665
		deleteAndRefreshExternalZIPArchive("externalLib.abc", "P");
666
		deleteProject("P");
667
	}
668
669
}
670
601
/**
671
/**
602
 * Simple field declaration test.
672
 * Simple field declaration test.
603
 */
673
 */
(-)src/org/eclipse/jdt/core/tests/model/ClassFileTests.java (-4 / +5 lines)
Lines 16-21 Link Here
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.Path;
19
import org.eclipse.jdt.core.*;
20
import org.eclipse.jdt.core.*;
20
import org.eclipse.jdt.core.search.IJavaSearchConstants;
21
import org.eclipse.jdt.core.search.IJavaSearchConstants;
21
import org.eclipse.jdt.core.search.IJavaSearchScope;
22
import org.eclipse.jdt.core.search.IJavaSearchScope;
Lines 790-803 Link Here
790
	try {
791
	try {
791
		createExternalFolder("externalLib/p");
792
		createExternalFolder("externalLib/p");
792
		createExternalFile("externalLib/p/X.class", "");
793
		createExternalFile("externalLib/p/X.class", "");
793
		createJavaProject("P1", new String[0], new String[] {getExternalFolderPath("externalLib")}, "");
794
		createJavaProject("P1", new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
794
		IClassFile classFile1 = getClassFile("P1", getExternalFolderPath("externalLib"), "p", "X.class");
795
		IClassFile classFile1 = getClassFile("P1", getExternalResourcePath("externalLib"), "p", "X.class");
795
		assertResourceEquals(
796
		assertResourceEquals(
796
			"Unexpected resource",
797
			"Unexpected resource",
797
			"<null>",
798
			"<null>",
798
			classFile1.getResource());
799
			classFile1.getResource());
799
	} finally {
800
	} finally {
800
		deleteExternalFolder("externalLib");
801
		deleteExternalResource("externalLib");
801
		deleteProject("P1");
802
		deleteProject("P1");
802
	}
803
	}
803
}
804
}
Lines 852-858 Link Here
852
		} catch (JavaModelException e) {
853
		} catch (JavaModelException e) {
853
			expected = e;
854
			expected = e;
854
		}
855
		}
855
		assertExceptionEquals("Unexpected exception", "classFolder.jar [in P1] does not exist", expected);
856
		assertExceptionEquals("Unexpected exception", new Path("/P1/classFolder.jar").toOSString() + " does not exist", expected);
856
	} finally {
857
	} finally {
857
		deleteProject("P1");
858
		deleteProject("P1");
858
	}
859
	}
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-6 / +17 lines)
Lines 1467-1476 Link Here
1467
		getWorkspace().run(create, null);	
1467
		getWorkspace().run(create, null);	
1468
		return project;
1468
		return project;
1469
	}
1469
	}
1470
	public void deleteFile(File file) {
1470
	public void deleteResource(File resource) {
1471
		int retryCount = 0;
1471
		int retryCount = 0;
1472
		while (++retryCount <= 60) { // wait 1 minute at most
1472
		while (++retryCount <= 60) { // wait 1 minute at most
1473
			if (org.eclipse.jdt.core.tests.util.Util.delete(file)) {
1473
			if (org.eclipse.jdt.core.tests.util.Util.delete(resource)) {
1474
				break;
1474
				break;
1475
			}
1475
			}
1476
		}
1476
		}
Lines 1649-1655 Link Here
1649
		return new File(getExternalPath(), relativePath);
1649
		return new File(getExternalPath(), relativePath);
1650
	}
1650
	}
1651
	
1651
	
1652
	protected String getExternalFolderPath(String name) {
1652
	protected String getExternalResourcePath(String name) {
1653
		return getExternalPath() + name;
1653
		return getExternalPath() + name;
1654
	}
1654
	}
1655
1655
Lines 2029-2034 Link Here
2029
		waitForManualRefresh();
2029
		waitForManualRefresh();
2030
	}
2030
	}
2031
2031
2032
	protected void refreshExternalArchives(IJavaProject p) throws JavaModelException {
2033
		getJavaModel().refreshExternalArchives(new IJavaElement[] {p}, null);
2034
	}
2035
	
2032
	protected void removeJavaNature(String projectName) throws CoreException {
2036
	protected void removeJavaNature(String projectName) throws CoreException {
2033
		IProject project = this.getProject(projectName);
2037
		IProject project = this.getProject(projectName);
2034
		IProjectDescription description = project.getDescription();
2038
		IProjectDescription description = project.getDescription();
Lines 2658-2667 Link Here
2658
		}
2662
		}
2659
		return result;
2663
		return result;
2660
	}
2664
	}
2661
	protected void touch(File f) {
2665
	protected synchronized void touch(File f) {
2662
		f.setLastModified(f.lastModified() + 10000);
2666
		f.setLastModified(f.lastModified() + 1000);
2667
		long start = System.currentTimeMillis();
2668
		do {
2669
			try {
2670
				wait(1000);
2671
			} catch (InterruptedException e) {
2672
			}
2673
		} while ((System.currentTimeMillis() - start) < 1000);
2663
	}
2674
	}
2664
protected String toString(String[] strings) {
2675
	protected String toString(String[] strings) {
2665
		return toString(strings, false/*don't add extra new line*/);
2676
		return toString(strings, false/*don't add extra new line*/);
2666
	}
2677
	}
2667
	protected String toString(String[] strings, boolean addExtraNewLine) {
2678
	protected String toString(String[] strings, boolean addExtraNewLine) {
(-)src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java (-6 / +2 lines)
Lines 257-263 Link Here
257
	public void addExternalJars(IPath projectPath, String[] jars, boolean isExported) throws JavaModelException {
257
	public void addExternalJars(IPath projectPath, String[] jars, boolean isExported) throws JavaModelException {
258
		for (int i = 0, max = jars.length; i < max; i++) {
258
		for (int i = 0, max = jars.length; i < max; i++) {
259
			String jar = jars[i];
259
			String jar = jars[i];
260
			checkAssertion("file name must end with .zip or .jar", jar.endsWith(".zip") || jar.endsWith(".jar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
261
			addEntry(projectPath, JavaCore.newLibraryEntry(new Path(jar), null, null, isExported));
260
			addEntry(projectPath, JavaCore.newLibraryEntry(new Path(jar), null, null, isExported));
262
		}
261
		}
263
	}
262
	}
Lines 265-271 Link Here
265
	/** Adds an external jar to the classpath of a project.
264
	/** Adds an external jar to the classpath of a project.
266
	 */
265
	 */
267
	public void addExternalJar(IPath projectPath, String jar, boolean isExported) throws JavaModelException {
266
	public void addExternalJar(IPath projectPath, String jar, boolean isExported) throws JavaModelException {
268
		checkAssertion("file name must end with .zip or .jar", jar.endsWith(".zip") || jar.endsWith(".jar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
269
		addEntry(projectPath, JavaCore.newLibraryEntry(new Path(jar), null, null, isExported));
267
		addEntry(projectPath, JavaCore.newLibraryEntry(new Path(jar), null, null, isExported));
270
	}
268
	}
271
	
269
	
Lines 274-280 Link Here
274
	addEntry(projectPath, 		
272
	addEntry(projectPath, 		
275
		JavaCore.newLibraryEntry(libraryPath, sourceAttachmentPath,	sourceAttachmentRootPath));
273
		JavaCore.newLibraryEntry(libraryPath, sourceAttachmentPath,	sourceAttachmentRootPath));
276
}
274
}
277
	private void addEntry(IPath projectPath, IClasspathEntry entryPath) throws JavaModelException {
275
	public void addEntry(IPath projectPath, IClasspathEntry entryPath) throws JavaModelException {
278
		IClasspathEntry[] classpath = getClasspath(projectPath);
276
		IClasspathEntry[] classpath = getClasspath(projectPath);
279
		IClasspathEntry[] newClaspath = new IClasspathEntry[classpath.length + 1];
277
		IClasspathEntry[] newClaspath = new IClasspathEntry[classpath.length + 1];
280
		System.arraycopy(classpath, 0, newClaspath, 0, classpath.length);
278
		System.arraycopy(classpath, 0, newClaspath, 0, classpath.length);
Lines 311-323 Link Here
311
309
312
	/** Adds a jar with the given contents to the the workspace.
310
	/** Adds a jar with the given contents to the the workspace.
313
	 * If a jar with the same name already exists, it is
311
	 * If a jar with the same name already exists, it is
314
	 * replaced.  A workspace must be open, and the given
312
	 * replaced.  A workspace must be open.  Returns the path of
315
	 * zip name must end with ".zip" or ".jar".  Returns the path of
316
	 * the added jar.
313
	 * the added jar.
317
	 */
314
	 */
318
	public IPath addInternalJar(IPath projectPath, String zipName, byte[] contents, boolean isExported) throws JavaModelException {
315
	public IPath addInternalJar(IPath projectPath, String zipName, byte[] contents, boolean isExported) throws JavaModelException {
319
		checkAssertion("a workspace must be open", fIsOpen); //$NON-NLS-1$
316
		checkAssertion("a workspace must be open", fIsOpen); //$NON-NLS-1$
320
		checkAssertion("zipName must end with .zip or .jar", zipName.endsWith(".zip") || zipName.endsWith(".jar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
321
		IPath path = projectPath.append(zipName);
317
		IPath path = projectPath.append(zipName);
322
		
318
		
323
		/* remove any existing zip from the java model */
319
		/* remove any existing zip from the java model */
(-)src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java (-1 / +128 lines)
Lines 259-265 Link Here
259
}
259
}
260
260
261
/*
261
/*
262
 * Ensures that the changing a type in an external folder and refreshing triggers a rebuild
262
 * Ensures that changing a type in an external folder and refreshing triggers a rebuild
263
 */
263
 */
264
public void testChangeExternalFolder() throws CoreException {
264
public void testChangeExternalFolder() throws CoreException {
265
	String externalLib = Util.getOutputDirectory() + File.separator + "externalLib";
265
	String externalLib = Util.getOutputDirectory() + File.separator + "externalLib";
Lines 329-334 Link Here
329
}
329
}
330
330
331
/*
331
/*
332
 * Ensures that changing a type in an external ZIP archive and refreshing triggers a rebuild
333
 */
334
public void testChangeZIPArchive1() throws Exception {
335
	String externalLib = Util.getOutputDirectory() + File.separator + "externalLib.abc";
336
	try {
337
		org.eclipse.jdt.core.tests.util.Util.createJar(
338
			new String[] {
339
				"p/X.java",
340
				"package p;\n" +
341
				"public class X {\n" +
342
				"  public void foo() {\n" +
343
				"  }\n" +
344
				"}"
345
			},
346
			externalLib, 
347
			"1.4");
348
		
349
		IPath projectPath = env.addProject("Project"); 
350
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
351
		env.addExternalJars(projectPath, new String[] {externalLib});
352
353
		IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
354
		env.setOutputFolder(projectPath, ""); 
355
356
		IPath classY = env.addClass(root, "q", "Y",  
357
			"package q;\n"+ 
358
			"public class Y {\n" +
359
			"  void bar(p.X x) {\n" +
360
			"    x.foo();\n" +
361
			"  }\n" +
362
			"}"
363
		); 
364
365
		fullBuild(projectPath);
366
		expectingNoProblems();
367
368
		long lastModified = new java.io.File(externalLib).lastModified();
369
		try {
370
			Thread.sleep(1000);
371
		} catch(InterruptedException e) {
372
		}
373
		org.eclipse.jdt.core.tests.util.Util.createJar(
374
			new String[] {
375
				"p/X.java",
376
				"package p;\n" +
377
				"public class X {\n" +
378
				"}"
379
			},
380
			externalLib, 
381
			"1.4");
382
		new java.io.File(externalLib).setLastModified(lastModified + 1000); // to be sure its different
383
		
384
		IJavaProject p = env.getJavaProject(projectPath);
385
		p.getJavaModel().refreshExternalArchives(new IJavaElement[] {p}, null);
386
387
		incrementalBuild(projectPath);
388
		expectingProblemsFor(
389
			classY,
390
			"Problem : The method foo() is undefined for the type X [ resource : </Project/q/Y.java> range : <54,57> category : <50> severity : <2>]"
391
		);
392
	} finally {
393
		new File(externalLib).delete();
394
	}
395
}
396
397
/*
398
 * Ensures that changing a type in an internal ZIP archive and refreshing triggers a rebuild
399
 */
400
public void testChangeZIPArchive2() throws Exception {
401
	IPath projectPath = env.addProject("Project"); 
402
	String internalLib = env.getProject("Project").getLocation().toOSString() + File.separator + "internalLib.abc";
403
	env.addExternalJars(projectPath, Util.getJavaClassLibs());
404
	env.addEntry(projectPath, JavaCore.newLibraryEntry(new Path("/Project/internalLib.abc"), null, null));
405
	org.eclipse.jdt.core.tests.util.Util.createJar(
406
		new String[] {
407
			"p/X.java",
408
			"package p;\n" +
409
			"public class X {\n" +
410
			"  public void foo() {\n" +
411
			"  }\n" +
412
			"}"
413
		},
414
		internalLib, 
415
		"1.4");
416
	env.getProject(projectPath).refreshLocal(IResource.DEPTH_INFINITE, null);
417
418
	IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
419
	env.setOutputFolder(projectPath, ""); 
420
421
	IPath classY = env.addClass(root, "q", "Y",  
422
		"package q;\n"+ 
423
		"public class Y {\n" +
424
		"  void bar(p.X x) {\n" +
425
		"    x.foo();\n" +
426
		"  }\n" +
427
		"}"
428
	); 
429
430
	fullBuild(projectPath);
431
	expectingNoProblems();
432
433
	long lastModified = new java.io.File(internalLib).lastModified();
434
	try {
435
		Thread.sleep(1000);
436
	} catch(InterruptedException e) {
437
	}
438
	org.eclipse.jdt.core.tests.util.Util.createJar(
439
		new String[] {
440
			"p/X.java",
441
			"package p;\n" +
442
			"public class X {\n" +
443
			"}"
444
		},
445
		internalLib, 
446
		"1.4");
447
	new java.io.File(internalLib).setLastModified(lastModified + 1000); // to be sure its different
448
	
449
	env.getProject(projectPath).refreshLocal(IResource.DEPTH_INFINITE, null);
450
451
	incrementalBuild(projectPath);
452
	expectingProblemsFor(
453
		classY,
454
		"Problem : The method foo() is undefined for the type X [ resource : </Project/q/Y.java> range : <54,57> category : <50> severity : <2>]"
455
	);
456
}
457
458
/*
332
 * Ensures that changing an external jar and refreshing the projects triggers a rebuild
459
 * Ensures that changing an external jar and refreshing the projects triggers a rebuild
333
 * (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states)
460
 * (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states)
334
 */
461
 */

Return to bug 182360