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

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-2 / +2 lines)
Lines 107-114 Link Here
107
\    -bootclasspath <directories and zip/jar files separated by {0}>\n\
107
\    -bootclasspath <directories and zip/jar files separated by {0}>\n\
108
\                       specify location for system classes. Each directory or file can\n\
108
\                       specify location for system classes. Each directory or file can\n\
109
\                       specify access rules for types between ''['' and '']''\n\
109
\                       specify access rules for types between ''['' and '']''\n\
110
\    -sourcepath <directories separated by {0}>\n\
110
\    -sourcepath <directories and zip/jar files separated by {0}>\n\
111
\                       specify location for application sources. Each directory can\n\
111
\                       specify location for application sources. Each directory or file can\n\
112
\                       specify access rules for types between ''['' and '']''\n\
112
\                       specify access rules for types between ''['' and '']''\n\
113
\    -extdirs <directories separated by {0}>\n\
113
\    -extdirs <directories separated by {0}>\n\
114
\                       specify location for extension zip/jar files\n\
114
\                       specify location for extension zip/jar files\n\
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java (-10 / +9 lines)
Lines 19-44 Link Here
19
19
20
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.core.compiler.CharOperation;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
22
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
22
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
23
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
23
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
24
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
24
25
25
public class ClasspathJar extends ClasspathLocation {
26
public class ClasspathJar extends ClasspathLocation {
26
	
27
	
27
private File file;
28
protected File file;
28
private ZipFile zipFile;
29
protected ZipFile zipFile;
29
private boolean closeZipFileAtEnd;
30
protected boolean closeZipFileAtEnd;
30
private Hashtable packageCache;
31
protected Hashtable packageCache;
31
private char[] normalizedPath;
32
protected char[] normalizedPath;
32
33
33
public ClasspathJar(File file) throws IOException {
34
	this(file, true, null);
35
}
36
public ClasspathJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet) {
34
public ClasspathJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet) {
37
	super(accessRuleSet);
35
	super(accessRuleSet);
38
	this.file = file;
36
	this.file = file;
39
	this.closeZipFileAtEnd = closeZipFileAtEnd;
37
	this.closeZipFileAtEnd = closeZipFileAtEnd;
40
}
38
}
41
42
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
39
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
43
	if (!isPackage(qualifiedPackageName)) 
40
	if (!isPackage(qualifiedPackageName)) 
44
		return null; // most common case
41
		return null; // most common case
Lines 47-53 Link Here
47
		ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
44
		ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
48
		if (reader != null) return new NameEnvironmentAnswer(reader, 
45
		if (reader != null) return new NameEnvironmentAnswer(reader, 
49
				fetchAccessRestriction(qualifiedBinaryFileName));
46
				fetchAccessRestriction(qualifiedBinaryFileName));
50
	} catch (Exception e) {
47
	} catch(ClassFormatException e) {
48
		// treat as if class file is missing
49
	} catch (IOException e) {
51
		// treat as if class file is missing
50
		// treat as if class file is missing
52
	}
51
	}
53
	return null;
52
	return null;
(-)batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java (-13 / +13 lines)
Lines 56-73 Link Here
56
	classPathNames is a collection is Strings representing the full path of each class path
56
	classPathNames is a collection is Strings representing the full path of each class path
57
	initialFileNames is a collection is Strings, the trailing '.java' will be removed if its not already.
57
	initialFileNames is a collection is Strings, the trailing '.java' will be removed if its not already.
58
*/
58
*/
59
60
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding) {
59
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding) {
61
	this(classpathNames, initialFileNames, encoding, null);
62
}
63
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, int[] classpathDirectoryModes) {
64
	final int classpathSize = classpathNames.length;
60
	final int classpathSize = classpathNames.length;
65
	this.classpaths = new Classpath[classpathSize];
61
	this.classpaths = new Classpath[classpathSize];
66
	int counter = 0;
62
	int counter = 0;
67
	for (int i = 0; i < classpathSize; i++) {
63
	for (int i = 0; i < classpathSize; i++) {
68
		Classpath classpath = getClasspath(classpathNames[i], encoding,
64
		Classpath classpath = getClasspath(classpathNames[i], encoding, null);
69
					classpathDirectoryModes == null ? 0
70
							: classpathDirectoryModes[i], null);
71
		try {
65
		try {
72
			classpath.initialize();
66
			classpath.initialize();
73
			this.classpaths[counter++] = classpath;
67
			this.classpaths[counter++] = classpath;
Lines 99-119 Link Here
99
	}
93
	}
100
	initializeKnownFileNames(initialFileNames);
94
	initializeKnownFileNames(initialFileNames);
101
}
95
}
102
static Classpath getClasspath(String classpathName, String encoding,
96
static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet) {
103
		int classpathDirectoryMode, AccessRuleSet accessRuleSet) {
97
	return getClasspath(classpathName, encoding, ClasspathLocation.SOURCE | ClasspathLocation.BINARY, accessRuleSet);
98
}
99
static Classpath getClasspath(String classpathName, String encoding, int mode, AccessRuleSet accessRuleSet) {
104
	Classpath result = null;
100
	Classpath result = null;
105
	File file = new File(convertPathSeparators(classpathName));
101
	File file = new File(convertPathSeparators(classpathName));
106
	if (file.isDirectory()) {
102
	if (file.isDirectory()) {
107
		if (file.exists()) {
103
		if (file.exists()) {
108
			result = new ClasspathDirectory(file, encoding,
104
			result = new ClasspathDirectory(file, encoding, mode, accessRuleSet);
109
					classpathDirectoryMode, accessRuleSet);
110
		}
105
		}
111
	} else {
106
	} else {
112
		String lowercaseClasspathName = classpathName.toLowerCase();
107
		String lowercaseClasspathName = classpathName.toLowerCase();
113
		if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar)
108
		if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar)
114
				|| lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) {
109
				|| lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) {
115
			result = new ClasspathJar(file, true, accessRuleSet);
110
			if (mode == ClasspathLocation.SOURCE) {
116
			// will throw an IOException if file does not exist
111
				// will throw an IOException if file does not exist
112
				result = new ClasspathSourceJar(file, true, accessRuleSet, encoding);			
113
			} else {
114
				// will throw an IOException if file does not exist
115
				result = new ClasspathJar(file, true, accessRuleSet);
116
			}
117
		}
117
		}
118
	}
118
	}
119
	return result;
119
	return result;
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-13 / +10 lines)
Lines 1257-1272 Link Here
1257
			"template.restrictedAccess.field", //$NON-NLS-1$
1257
			"template.restrictedAccess.field", //$NON-NLS-1$
1258
			new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ 
1258
			new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ 
1259
		AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules, templates);
1259
		AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules, templates);
1260
		FileSystem.Classpath currentClasspath = FileSystem
1260
		FileSystem.Classpath currentClasspath = FileSystem.getClasspath(
1261
				.getClasspath(currentClasspathName,
1261
				currentClasspathName,
1262
						customEncoding, 0, accessRuleSet);
1262
				customEncoding,
1263
				isSource ? ClasspathLocation.SOURCE : ClasspathLocation.BINARY | ClasspathLocation.SOURCE,
1264
				accessRuleSet);
1263
		if (currentClasspath != null) {
1265
		if (currentClasspath != null) {
1264
			paths.add(currentClasspath);
1266
			paths.add(currentClasspath);
1265
			if (isSource && currentClasspath instanceof ClasspathDirectory) {
1266
				((ClasspathDirectory) currentClasspath).mode = 
1267
					ClasspathDirectory.SOURCE;
1268
				// TODO may consider adding this attribute to other classpath natures
1269
			}
1270
		} else {
1267
		} else {
1271
			this.logger.logIncorrectClasspath(currentClasspathName);
1268
			this.logger.logIncorrectClasspath(currentClasspathName);
1272
			// we go on anyway
1269
			// we go on anyway
Lines 2378-2385 Link Here
2378
						for (int j = 0, max2 = current.length; j < max2; j++) {
2375
						for (int j = 0, max2 = current.length; j < max2; j++) {
2379
							FileSystem.Classpath classpath = 
2376
							FileSystem.Classpath classpath = 
2380
								FileSystem.getClasspath(
2377
								FileSystem.getClasspath(
2381
										current[j].getAbsolutePath(),
2378
									current[j].getAbsolutePath(),
2382
										null, 0, null); 
2379
									null, null); 
2383
							if (classpath != null) {
2380
							if (classpath != null) {
2384
								bootclasspaths.add(classpath);
2381
								bootclasspaths.add(classpath);
2385
							}
2382
							}
Lines 2402-2415 Link Here
2402
		String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
2399
		String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
2403
		if ((classProp == null) || (classProp.length() == 0)) {
2400
		if ((classProp == null) || (classProp.length() == 0)) {
2404
			this.logger.logNoClasspath();
2401
			this.logger.logNoClasspath();
2405
			classpaths.add(FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, 0, null));//$NON-NLS-1$
2402
			classpaths.add(FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null));//$NON-NLS-1$
2406
		} else {
2403
		} else {
2407
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
2404
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
2408
			String token;
2405
			String token;
2409
			while (tokenizer.hasMoreTokens()) {
2406
			while (tokenizer.hasMoreTokens()) {
2410
				token = tokenizer.nextToken();
2407
				token = tokenizer.nextToken();
2411
				FileSystem.Classpath currentClasspath = FileSystem
2408
				FileSystem.Classpath currentClasspath = FileSystem
2412
						.getClasspath(token, customEncoding, 0, null);
2409
						.getClasspath(token, customEncoding, null);
2413
				if (currentClasspath != null) {
2410
				if (currentClasspath != null) {
2414
					classpaths.add(currentClasspath);
2411
					classpaths.add(currentClasspath);
2415
				} else {
2412
				} else {
Lines 2471-2477 Link Here
2471
						FileSystem.Classpath classpath = 
2468
						FileSystem.Classpath classpath = 
2472
							FileSystem.getClasspath(
2469
							FileSystem.getClasspath(
2473
									current[j].getAbsolutePath(),
2470
									current[j].getAbsolutePath(),
2474
									null, 0, null); 
2471
									null, null); 
2475
						if (classpath != null) {
2472
						if (classpath != null) {
2476
							extdirsClasspaths.add(classpath);
2473
							extdirsClasspaths.add(classpath);
2477
						}
2474
						}
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java (-3 / +9 lines)
Lines 20-28 Link Here
20
public abstract class ClasspathLocation implements FileSystem.Classpath,
20
public abstract class ClasspathLocation implements FileSystem.Classpath,
21
		SuffixConstants {
21
		SuffixConstants {
22
22
23
	private AccessRuleSet accessRuleSet;
23
	public static final int SOURCE = 1;
24
	public static final int BINARY = 2;
25
	
26
	protected int mode; // ability to only consider one kind of files (source vs. binaries), by default use both
24
27
25
	public ClasspathLocation(AccessRuleSet accessRuleSet) {
28
	protected AccessRuleSet accessRuleSet;
29
	protected String encoding; // only useful if referenced in the source path
30
31
	protected ClasspathLocation(AccessRuleSet accessRuleSet) {
26
		this.accessRuleSet = accessRuleSet;
32
		this.accessRuleSet = accessRuleSet;
27
	}
33
	}
28
34
Lines 38-44 Link Here
38
	 * @return the first access rule which is violated when accessing a given
44
	 * @return the first access rule which is violated when accessing a given
39
	 *         type, or null if none applies
45
	 *         type, or null if none applies
40
	 */
46
	 */
41
	AccessRestriction fetchAccessRestriction(String qualifiedBinaryFileName) {
47
	protected AccessRestriction fetchAccessRestriction(String qualifiedBinaryFileName) {
42
		if (this.accessRuleSet == null)
48
		if (this.accessRuleSet == null)
43
			return null;
49
			return null;
44
		char [] qualifiedTypeName = qualifiedBinaryFileName.
50
		char [] qualifiedTypeName = qualifiedBinaryFileName.
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java (-17 / +2 lines)
Lines 26-55 Link Here
26
private String path;
26
private String path;
27
private Hashtable directoryCache;
27
private Hashtable directoryCache;
28
private String[] missingPackageHolder = new String[1];
28
private String[] missingPackageHolder = new String[1];
29
private String encoding;
30
public int mode; // ability to only consider one kind of files (source vs. binaries), by default use both
31
32
public static final int SOURCE = 1;
33
public static final int BINARY = 2;
34
29
35
ClasspathDirectory(File directory, String encoding, int mode, AccessRuleSet accessRuleSet) {
30
ClasspathDirectory(File directory, String encoding, int mode, AccessRuleSet accessRuleSet) {
36
	super(accessRuleSet);
31
	super(accessRuleSet);
37
	if (mode == 0){
32
	this.mode = mode;
38
		this.mode = SOURCE | BINARY;
39
	}
40
	else {
41
	    this.mode = mode;
42
	}
43
	this.path = directory.getAbsolutePath();
33
	this.path = directory.getAbsolutePath();
44
	if (!this.path.endsWith(File.separator))
34
	if (!this.path.endsWith(File.separator))
45
		this.path += File.separator;
35
		this.path += File.separator;
46
	this.directoryCache = new Hashtable(11);
36
	this.directoryCache = new Hashtable(11);
47
	this.encoding = encoding;
37
	this.encoding = encoding;
48
}
38
}
49
50
ClasspathDirectory(File directory, String encoding) {
51
	this(directory, encoding, SOURCE | BINARY, null); // by default consider both sources and binaries
52
}
53
String[] directoryList(String qualifiedPackageName) {
39
String[] directoryList(String qualifiedPackageName) {
54
	String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName);
40
	String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName);
55
	if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar
41
	if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar
Lines 112-119 Link Here
112
	}
98
	}
113
	if (binaryExists) {
99
	if (binaryExists) {
114
		try {
100
		try {
115
			ClassFileReader reader = ClassFileReader.read(this.path
101
			ClassFileReader reader = ClassFileReader.read(this.path + qualifiedBinaryFileName);
116
					+ qualifiedBinaryFileName);
117
			if (reader != null)
102
			if (reader != null)
118
				return new NameEnvironmentAnswer(
103
				return new NameEnvironmentAnswer(
119
						reader,
104
						reader,
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathSourceJar.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.batch;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.util.zip.ZipEntry;
16
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
18
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
19
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
20
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
21
import org.eclipse.jdt.internal.compiler.util.Util;
22
23
public class ClasspathSourceJar extends ClasspathJar {
24
	public ClasspathSourceJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet, String encoding) {
25
		super(file, closeZipFileAtEnd, accessRuleSet);
26
		this.encoding = encoding;
27
	}
28
29
	public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
30
		if (!isPackage(qualifiedPackageName)) 
31
			return null; // most common case
32
33
		ZipEntry sourceEntry = this.zipFile.getEntry(qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java);
34
		if (sourceEntry != null) {
35
			ZipEntry binaryEntry = this.zipFile.getEntry(qualifiedBinaryFileName);
36
			if (binaryEntry != null) {
37
				if (sourceEntry.getTime() > binaryEntry.getTime()) {
38
					try {
39
						return new NameEnvironmentAnswer(new CompilationUnit(Util.getInputStreamAsCharArray(this.zipFile.getInputStream(sourceEntry), -1, this.encoding),
40
								qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java, this.encoding),
41
								fetchAccessRestriction(qualifiedBinaryFileName));
42
					} catch (IOException e) {
43
						// treat as if source file is missing
44
					}
45
				} else {
46
					try {
47
						ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
48
						if (reader != null) return new NameEnvironmentAnswer(reader, 
49
								fetchAccessRestriction(qualifiedBinaryFileName));
50
					} catch(ClassFormatException e) {
51
						// treat as if class file is missing
52
					} catch (IOException e) {
53
						// treat as if class file is missing
54
					}
55
				}
56
			} else {
57
				try {
58
					return new NameEnvironmentAnswer(new CompilationUnit(Util.getInputStreamAsCharArray(this.zipFile.getInputStream(sourceEntry), -1, this.encoding),
59
							qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java, this.encoding),
60
							fetchAccessRestriction(qualifiedBinaryFileName));
61
				} catch (IOException e) {
62
					// treat as if source file is missing
63
				}
64
			}
65
		}
66
		return null;
67
	}
68
}

Return to bug 133848