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

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java (-6 / +44 lines)
Lines 19-26 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;
25
import org.eclipse.jdt.internal.compiler.util.Util;
24
26
25
public class ClasspathJar extends ClasspathLocation {
27
public class ClasspathJar extends ClasspathLocation {
26
	
28
	
Lines 30-53 Link Here
30
private Hashtable packageCache;
32
private Hashtable packageCache;
31
private char[] normalizedPath;
33
private char[] normalizedPath;
32
34
33
public ClasspathJar(File file) throws IOException {
35
public ClasspathJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet, int mode, String encoding) {
34
	this(file, true, null);
35
}
36
public ClasspathJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet) {
37
	super(accessRuleSet);
36
	super(accessRuleSet);
38
	this.file = file;
37
	this.file = file;
39
	this.closeZipFileAtEnd = closeZipFileAtEnd;
38
	this.closeZipFileAtEnd = closeZipFileAtEnd;
39
	this.mode = mode;
40
}
40
}
41
42
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
41
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
43
	if (!isPackage(qualifiedPackageName)) 
42
	if (!isPackage(qualifiedPackageName)) 
44
		return null; // most common case
43
		return null; // most common case
45
44
45
	if (this.mode == ClasspathLocation.SOURCE) {
46
		ZipEntry sourceEntry = this.zipFile.getEntry(qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java);
47
		if (sourceEntry != null) {
48
			ZipEntry binaryEntry = this.zipFile.getEntry(qualifiedBinaryFileName);
49
			if (binaryEntry != null) {
50
				if (sourceEntry.getTime() > binaryEntry.getTime()) {
51
					try {
52
						return new NameEnvironmentAnswer(new CompilationUnit(Util.getInputStreamAsCharArray(this.zipFile.getInputStream(sourceEntry), -1, this.encoding),
53
								qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java, this.encoding),
54
								fetchAccessRestriction(qualifiedBinaryFileName));
55
					} catch (IOException e) {
56
						// treat as if source file is missing
57
					}
58
				} else {
59
					try {
60
						ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
61
						if (reader != null) return new NameEnvironmentAnswer(reader, 
62
								fetchAccessRestriction(qualifiedBinaryFileName));
63
					} catch(ClassFormatException e) {
64
						// treat as if class file is missing
65
					} catch (IOException e) {
66
						// treat as if class file is missing
67
					}
68
				}
69
			} else {
70
				try {
71
					return new NameEnvironmentAnswer(new CompilationUnit(Util.getInputStreamAsCharArray(this.zipFile.getInputStream(sourceEntry), -1, this.encoding),
72
							qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java, this.encoding),
73
							fetchAccessRestriction(qualifiedBinaryFileName));
74
				} catch (IOException e) {
75
					// treat as if source file is missing
76
				}
77
			}
78
		}
79
		return null;
80
	}
81
46
	try {
82
	try {
47
		ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
83
		ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
48
		if (reader != null) return new NameEnvironmentAnswer(reader, 
84
		if (reader != null) return new NameEnvironmentAnswer(reader, 
49
				fetchAccessRestriction(qualifiedBinaryFileName));
85
				fetchAccessRestriction(qualifiedBinaryFileName));
50
	} catch (Exception e) {
86
	} catch(ClassFormatException e) {
87
		// treat as if class file is missing
88
	} catch (IOException e) {
51
		// treat as if class file is missing
89
		// treat as if class file is missing
52
	}
90
	}
53
	return null;
91
	return null;
(-)batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java (-15 / +7 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-118 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
			result = new ClasspathJar(file, true, accessRuleSet, mode, encoding);
116
			// will throw an IOException if file does not exist
111
			// will throw an IOException if file does not exist
117
		}
112
		}
118
	}
113
	}
Lines 211-219 Link Here
211
			typeName);
206
			typeName);
212
	return null;
207
	return null;
213
}
208
}
214
public ClasspathJar getClasspathJar(File file) throws IOException {
215
	return new ClasspathJar(file, true, null);
216
}
217
public boolean isPackage(char[][] compoundName, char[] packageName) {
209
public boolean isPackage(char[][] compoundName, char[] packageName) {
218
	String qualifiedPackageName = new String(CharOperation.concatWith(compoundName, packageName, '/'));
210
	String qualifiedPackageName = new String(CharOperation.concatWith(compoundName, packageName, '/'));
219
	String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar);
211
	String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar);
(-)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 (+6 lines)
Lines 20-26 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
	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
27
23
	private AccessRuleSet accessRuleSet;
28
	private AccessRuleSet accessRuleSet;
29
	protected String encoding; // only useful if referenced in the source path
24
30
25
	public ClasspathLocation(AccessRuleSet accessRuleSet) {
31
	public ClasspathLocation(AccessRuleSet accessRuleSet) {
26
		this.accessRuleSet = accessRuleSet;
32
		this.accessRuleSet = accessRuleSet;
(-)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,

Return to bug 133848