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

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java (-12 / +27 lines)
Lines 14-23 Link Here
14
import java.util.Hashtable;
14
import java.util.Hashtable;
15
15
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
17
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
17
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
18
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
18
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
19
19
20
public class ClasspathDirectory implements FileSystem.Classpath, SuffixConstants {
20
public class ClasspathDirectory extends ClasspathLocation {
21
21
22
String path;
22
String path;
23
Hashtable directoryCache;
23
Hashtable directoryCache;
Lines 28-35 Link Here
28
public static final int SOURCE = 1;
28
public static final int SOURCE = 1;
29
public static final int BINARY = 2;
29
public static final int BINARY = 2;
30
30
31
ClasspathDirectory(File directory, String encoding, int mode) {
31
ClasspathDirectory(File directory, String encoding, int mode, AccessRuleSet accessRuleSet) {
32
	this.mode = mode;
32
	super(accessRuleSet);
33
	if (mode == 0){
34
		this.mode = SOURCE | BINARY;
35
	}
36
	else {
37
	    this.mode = mode;
38
	}
33
	this.path = directory.getAbsolutePath();
39
	this.path = directory.getAbsolutePath();
34
	if (!this.path.endsWith(File.separator))
40
	if (!this.path.endsWith(File.separator))
35
		this.path += File.separator;
41
		this.path += File.separator;
Lines 38-46 Link Here
38
}
44
}
39
45
40
ClasspathDirectory(File directory, String encoding) {
46
ClasspathDirectory(File directory, String encoding) {
41
	this(directory, encoding, SOURCE | BINARY); // by default consider both sources and binaries
47
	this(directory, encoding, SOURCE | BINARY, null); // by default consider both sources and binaries
42
}
48
}
43
44
String[] directoryList(String qualifiedPackageName) {
49
String[] directoryList(String qualifiedPackageName) {
45
	String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName);
50
	String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName);
46
	if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar
51
	if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar
Lines 90-108 Link Here
90
	if (sourceExists) {
95
	if (sourceExists) {
91
		String fullSourcePath = this.path + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java;
96
		String fullSourcePath = this.path + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6)  + SUFFIX_STRING_java;
92
		if (!binaryExists)
97
		if (!binaryExists)
93
			return new NameEnvironmentAnswer(new CompilationUnit(null, fullSourcePath, this.encoding), null/* TODO no access restriction*/);
98
			return new NameEnvironmentAnswer(new CompilationUnit(null,
94
99
					fullSourcePath, this.encoding),
100
					fetchAccessRestriction(qualifiedBinaryFileName));
95
		String fullBinaryPath = this.path + qualifiedBinaryFileName;
101
		String fullBinaryPath = this.path + qualifiedBinaryFileName;
96
		long binaryModified = new File(fullBinaryPath).lastModified();
102
		long binaryModified = new File(fullBinaryPath).lastModified();
97
		long sourceModified = new File(fullSourcePath).lastModified();
103
		long sourceModified = new File(fullSourcePath).lastModified();
98
		if (sourceModified > binaryModified)
104
		if (sourceModified > binaryModified)
99
			return new NameEnvironmentAnswer(new CompilationUnit(null, fullSourcePath, this.encoding), null/* TODO no access restriction*/);
105
			return new NameEnvironmentAnswer(new CompilationUnit(null,
106
					fullSourcePath, this.encoding),
107
					fetchAccessRestriction(qualifiedBinaryFileName));
100
	}
108
	}
101
	if (binaryExists) {
109
	if (binaryExists) {
102
		try {
110
		try {
103
			ClassFileReader reader = ClassFileReader.read(this.path + qualifiedBinaryFileName);
111
			ClassFileReader reader = ClassFileReader.read(this.path
104
			if (reader != null) return new NameEnvironmentAnswer(reader, null/* TODO no access restriction*/);
112
					+ qualifiedBinaryFileName);
105
		} catch (Exception e) { 
113
			if (reader != null)
114
				return new NameEnvironmentAnswer(
115
						reader,
116
						fetchAccessRestriction(qualifiedBinaryFileName));
117
		} catch (Exception e) {
106
			// treat as if file is missing
118
			// treat as if file is missing
107
		}
119
		}
108
	}
120
	}
Lines 117-120 Link Here
117
public String toString() {
129
public String toString() {
118
	return "ClasspathDirectory " + this.path; //$NON-NLS-1$
130
	return "ClasspathDirectory " + this.path; //$NON-NLS-1$
119
}
131
}
132
public String normalizedPath() {
133
	return this.path;
134
}
120
}
135
}
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java (-7 / +14 lines)
Lines 18-46 Link Here
18
import java.util.zip.ZipFile;
18
import java.util.zip.ZipFile;
19
19
20
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
20
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
21
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
21
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
22
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
22
23
23
public class ClasspathJar implements FileSystem.Classpath {
24
public class ClasspathJar extends ClasspathLocation {
24
	
25
	
25
ZipFile zipFile;
26
ZipFile zipFile;
26
Hashtable packageCache;
27
boolean closeZipFileAtEnd;
27
boolean closeZipFileAtEnd;
28
Hashtable packageCache;
28
29
29
public ClasspathJar(File file) throws IOException {
30
public ClasspathJar(File file) throws IOException {
30
	this(new ZipFile(file), true);
31
	this(new ZipFile(file), true, null);
31
}
32
}
32
public ClasspathJar(ZipFile zipFile, boolean closeZipFileAtEnd) {
33
public ClasspathJar(ZipFile zipFile, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet) {
34
	super(accessRuleSet);
33
	this.zipFile = zipFile;
35
	this.zipFile = zipFile;
34
	this.packageCache = null;
35
	this.closeZipFileAtEnd = closeZipFileAtEnd;
36
	this.closeZipFileAtEnd = closeZipFileAtEnd;
36
}	
37
}
38
37
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
39
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
38
	if (!isPackage(qualifiedPackageName)) 
40
	if (!isPackage(qualifiedPackageName)) 
39
		return null; // most common case
41
		return null; // most common case
40
42
41
	try {
43
	try {
42
		ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
44
		ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
43
		if (reader != null) return new NameEnvironmentAnswer(reader, null /*no access restriction*/);
45
		if (reader != null) return new NameEnvironmentAnswer(reader, 
46
				fetchAccessRestriction(qualifiedBinaryFileName));
44
	} catch (Exception e) {
47
	} catch (Exception e) {
45
		// treat as if class file is missing
48
		// treat as if class file is missing
46
	}
49
	}
Lines 82-85 Link Here
82
public String toString() {
85
public String toString() {
83
	return "Classpath for jar file " + this.zipFile.getName(); //$NON-NLS-1$
86
	return "Classpath for jar file " + this.zipFile.getName(); //$NON-NLS-1$
84
}
87
}
88
public String normalizedPath(){
89
	String rawName = this.zipFile.getName();
90
	return rawName.substring(0, rawName.lastIndexOf('.'));
91
}
85
}
92
}
(-)batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java (-32 / +53 lines)
Lines 15-20 Link Here
15
import java.util.zip.ZipFile;
15
import java.util.zip.ZipFile;
16
16
17
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
18
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
19
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
19
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
20
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
20
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
21
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
Lines 31-36 Link Here
31
		 * a new name environment without creating a new object.
32
		 * a new name environment without creating a new object.
32
		 */
33
		 */
33
		void reset();
34
		void reset();
35
		/**
36
		 * Return a normalized path for file based classpath entries. This is an absolute path
37
		 * ending with a file separator for directories, an absolute path deprived from the '.jar'
38
		 * (resp. '.zip') extension for jar (resp. zip) files.
39
		 * @return a normalized path for file based classpath entries
40
		 */
41
		String normalizedPath();
34
	}
42
	}
35
/*
43
/*
36
	classPathNames is a collection is Strings representing the full path of each class path
44
	classPathNames is a collection is Strings representing the full path of each class path
Lines 43-89 Link Here
43
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, int[] classpathDirectoryModes) {
51
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, int[] classpathDirectoryModes) {
44
	int classpathSize = classpathNames.length;
52
	int classpathSize = classpathNames.length;
45
	this.classpaths = new Classpath[classpathSize];
53
	this.classpaths = new Classpath[classpathSize];
46
	String[] pathNames = new String[classpathSize];
47
	int problemsOccured = 0;
54
	int problemsOccured = 0;
48
	for (int i = 0; i < classpathSize; i++) {
55
	for (int i = 0; i < classpathSize; i++) {
49
		try {
56
		this.classpaths[i] = getClasspath(classpathNames[i], encoding,
50
			File file = new File(convertPathSeparators(classpathNames[i]));
57
					classpathDirectoryModes == null ? 0
51
			if (file.isDirectory()) {
58
							: classpathDirectoryModes[i], null);
52
				if (file.exists()) {
53
					if (classpathDirectoryModes == null){
54
						this.classpaths[i] = new ClasspathDirectory(file, encoding);
55
					} else {
56
						this.classpaths[i] = new ClasspathDirectory(file, encoding, classpathDirectoryModes[i]);
57
					}
58
					pathNames[i] = ((ClasspathDirectory) this.classpaths[i]).path;
59
				}
60
			} else {
61
				String lowercaseClasspathName = classpathNames[i].toLowerCase();
62
				if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar)
63
					  || lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) {
64
					this.classpaths[i] = this.getClasspathJar(file); // will throw an IOException if file does not exist
65
					pathNames[i] = classpathNames[i].substring(0, classpathNames[i].lastIndexOf('.'));
66
				}
67
			}
68
		} catch (IOException e) {
69
			this.classpaths[i] = null;
70
		}
71
		if (this.classpaths[i] == null)
59
		if (this.classpaths[i] == null)
72
			problemsOccured++;
60
			problemsOccured++;
73
	}
61
	}
74
	if (problemsOccured > 0) {
62
	if (problemsOccured > 0) {
75
		Classpath[] newPaths = new Classpath[classpathSize - problemsOccured];
63
		Classpath[] newPaths = new Classpath[classpathSize - problemsOccured];
76
		String[] newNames = new String[classpathSize - problemsOccured];
77
		for (int i = 0, current = 0; i < classpathSize; i++)
64
		for (int i = 0, current = 0; i < classpathSize; i++)
78
			if (this.classpaths[i] != null) {
65
			if (this.classpaths[i] != null) {
79
				newPaths[current] = this.classpaths[i];
66
				newPaths[current] = this.classpaths[i];
80
				newNames[current++] = pathNames[i];
81
			}
67
			}
82
		classpathSize = newPaths.length;
68
		classpathSize = newPaths.length;
83
		this.classpaths = newPaths;
69
		this.classpaths = newPaths;
84
		pathNames = newNames;
85
	}
70
	}
86
71
	initializeKnownFileNames(initialFileNames);
72
}
73
FileSystem(Classpath[] classpaths, String[] initialFileNames) {
74
	this.classpaths = classpaths;
75
	initializeKnownFileNames(initialFileNames);
76
}
77
static Classpath getClasspath(String classpathName, String encoding,
78
		int classpathDirectoryMode, AccessRuleSet accessRuleSet) {
79
	Classpath result = null;
80
	try {
81
			File file = new File(convertPathSeparators(classpathName));
82
			if (file.isDirectory()) {
83
				if (file.exists()) {
84
					result = new ClasspathDirectory(file, encoding,
85
							classpathDirectoryMode, accessRuleSet);
86
				}
87
			} else {
88
				String lowercaseClasspathName = classpathName.toLowerCase();
89
				if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar)
90
						|| lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) {
91
					result = new ClasspathJar(new ZipFile(file), true,
92
							accessRuleSet);
93
					// will throw an IOException if file does not exist
94
				}
95
			}
96
		} catch (IOException e) {
97
			// result = null; -- this is already the case
98
		}
99
	return result;
100
}
101
private void initializeKnownFileNames(String[] initialFileNames) {
87
	this.knownFileNames = new String[initialFileNames.length];
102
	this.knownFileNames = new String[initialFileNames.length];
88
	for (int i = initialFileNames.length; --i >= 0;) {
103
	for (int i = initialFileNames.length; --i >= 0;) {
89
		String fileName = initialFileNames[i];
104
		String fileName = initialFileNames[i];
Lines 92-111 Link Here
92
			fileName = fileName.substring(0, fileName.lastIndexOf('.')); // remove trailing ".java"
107
			fileName = fileName.substring(0, fileName.lastIndexOf('.')); // remove trailing ".java"
93
108
94
		fileName = convertPathSeparators(fileName);
109
		fileName = convertPathSeparators(fileName);
95
		for (int j = 0; j < classpathSize; j++)
110
		for (int j = 0; j < classpaths.length; j++){
96
			if (fileName.startsWith(pathNames[j]))
111
			String matchCandidate = this.classpaths[j].normalizedPath();
97
				matchingPathName = pathNames[j];
112
			if (this.classpaths[j] instanceof  ClasspathDirectory && 
113
					fileName.startsWith(matchCandidate) && 
114
					(matchingPathName == null || 
115
							matchCandidate.length() < matchingPathName.length()))
116
				matchingPathName = matchCandidate;
117
		}
98
		if (matchingPathName == null)
118
		if (matchingPathName == null)
99
			this.knownFileNames[i] = fileName; // leave as is...
119
			this.knownFileNames[i] = fileName; // leave as is...
100
		else
120
		else
101
			this.knownFileNames[i] = fileName.substring(matchingPathName.length());
121
			this.knownFileNames[i] = fileName.substring(matchingPathName.length());
122
		matchingPathName = null;
102
	}
123
	}
103
}
124
}
104
public void cleanup() {
125
public void cleanup() {
105
	for (int i = 0, max = this.classpaths.length; i < max; i++)
126
	for (int i = 0, max = this.classpaths.length; i < max; i++)
106
		this.classpaths[i].reset();
127
		this.classpaths[i].reset();
107
}
128
}
108
private String convertPathSeparators(String path) {
129
private static String convertPathSeparators(String path) {
109
	return File.separatorChar == '/'
130
	return File.separatorChar == '/'
110
		? path.replace('\\', '/')
131
		? path.replace('\\', '/')
111
		 : path.replace('/', '\\');
132
		 : path.replace('/', '\\');
Lines 153-159 Link Here
153
	return null;
174
	return null;
154
}
175
}
155
public ClasspathJar getClasspathJar(File file) throws IOException {
176
public ClasspathJar getClasspathJar(File file) throws IOException {
156
	return new ClasspathJar(new ZipFile(file), true);
177
	return new ClasspathJar(new ZipFile(file), true, null);
157
}
178
}
158
public boolean isPackage(char[][] compoundName, char[] packageName) {
179
public boolean isPackage(char[][] compoundName, char[] packageName) {
159
	String qualifiedPackageName = new String(CharOperation.concatWith(compoundName, packageName, '/'));
180
	String qualifiedPackageName = new String(CharOperation.concatWith(compoundName, packageName, '/'));
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-95 / +168 lines)
Lines 23-28 Link Here
23
import java.io.UnsupportedEncodingException;
23
import java.io.UnsupportedEncodingException;
24
import java.lang.reflect.Field;
24
import java.lang.reflect.Field;
25
import java.text.MessageFormat;
25
import java.text.MessageFormat;
26
import java.util.ArrayList;
26
import java.util.Arrays;
27
import java.util.Arrays;
27
import java.util.Collections;
28
import java.util.Collections;
28
import java.util.Enumeration;
29
import java.util.Enumeration;
Lines 45-50 Link Here
45
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
46
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
46
import org.eclipse.jdt.internal.compiler.IProblemFactory;
47
import org.eclipse.jdt.internal.compiler.IProblemFactory;
47
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
48
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
49
import org.eclipse.jdt.internal.compiler.env.AccessRule;
50
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
48
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
51
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
49
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
52
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
50
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
53
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
Lines 311-317 Link Here
311
					String.valueOf(time),
314
					String.valueOf(time),
312
					String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) }));
315
					String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) }));
313
		}
316
		}
314
		public void logClasspath(String[] classpaths) {
317
		public void logClasspath(FileSystem.Classpath[] classpaths) {
315
			if (classpaths == null) return;
318
			if (classpaths == null) return;
316
			if (this.isXml) {
319
			if (this.isXml) {
317
				final int length = classpaths.length;
320
				final int length = classpaths.length;
Lines 320-326 Link Here
320
					this.printTag(CLASSPATHS, null, true, false);
323
					this.printTag(CLASSPATHS, null, true, false);
321
					for (int i = 0; i < length; i++) {
324
					for (int i = 0; i < length; i++) {
322
						this.parameters.clear();
325
						this.parameters.clear();
323
						String classpath = classpaths[i];
326
						String classpath = classpaths[i].normalizedPath();
324
						parameters.put(PATH, classpath);
327
						parameters.put(PATH, classpath);
325
						File f = new File(classpath);
328
						File f = new File(classpath);
326
						String id = null;
329
						String id = null;
Lines 925-931 Link Here
925
	public final static String bundleName =
928
	public final static String bundleName =
926
		"org.eclipse.jdt.internal.compiler.batch.messages"; 	//$NON-NLS-1$
929
		"org.eclipse.jdt.internal.compiler.batch.messages"; 	//$NON-NLS-1$
927
930
928
	public String[] classpaths;
931
	ArrayList checkedClasspaths;
929
	public String destinationPath;
932
	public String destinationPath;
930
	public String[] encodings;
933
	public String[] encodings;
931
	public Logger logger;
934
	public Logger logger;
Lines 1185-1194 Link Here
1185
		final int InsideBootClasspath = 128;
1188
		final int InsideBootClasspath = 128;
1186
		final int InsideMaxProblems = 256;
1189
		final int InsideMaxProblems = 256;
1187
		final int Default = 0;
1190
		final int Default = 0;
1188
		String[] bootclasspaths = null;
1189
		int DEFAULT_SIZE_CLASSPATH = 4;
1191
		int DEFAULT_SIZE_CLASSPATH = 4;
1190
		int pathCount = 0;
1192
		ArrayList bootclasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
1191
		int bootclasspathCount = 0;
1193
		checkedClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
1194
		String currentClasspathName = null;
1195
		ArrayList currentRuleSpecs = new ArrayList(DEFAULT_SIZE_CLASSPATH);
1192
		int index = -1, filesCount = 0, argCount = argv.length;
1196
		int index = -1, filesCount = 0, argCount = argv.length;
1193
		int mode = Default;
1197
		int mode = Default;
1194
		this.repetitions = 0;
1198
		this.repetitions = 0;
Lines 1264-1270 Link Here
1264
			currentArg = newCommandLineArgs[index];
1268
			currentArg = newCommandLineArgs[index];
1265
1269
1266
			customEncoding = null;
1270
			customEncoding = null;
1267
			if (currentArg.endsWith("]")) { //$NON-NLS-1$ 
1271
			if (currentArg.endsWith("]") && !(mode == InsideBootClasspath || mode == InsideClasspath) ) { //$NON-NLS-1$ 
1268
				// look for encoding specification
1272
				// look for encoding specification
1269
				int encodingStart = currentArg.indexOf('[') + 1;
1273
				int encodingStart = currentArg.indexOf('[') + 1;
1270
				int encodingEnd = currentArg.length() - 1;
1274
				int encodingEnd = currentArg.length() - 1;
Lines 1376-1392 Link Here
1376
			}
1380
			}
1377
			if (currentArg.equals("-classpath") //$NON-NLS-1$
1381
			if (currentArg.equals("-classpath") //$NON-NLS-1$
1378
				|| currentArg.equals("-cp")) { //$NON-NLS-1$ //$NON-NLS-2$
1382
				|| currentArg.equals("-cp")) { //$NON-NLS-1$ //$NON-NLS-2$
1379
				if (pathCount == 0) {
1380
					this.classpaths = new String[DEFAULT_SIZE_CLASSPATH];
1381
				}
1382
				mode = InsideClasspath;
1383
				mode = InsideClasspath;
1383
				continue;
1384
				continue;
1384
			}
1385
			}
1385
			if (currentArg.equals("-bootclasspath")) {//$NON-NLS-1$
1386
			if (currentArg.equals("-bootclasspath")) {//$NON-NLS-1$
1386
				if (bootclasspathCount > 0)
1387
				if (bootclasspaths.size() > 0)
1387
					throw new InvalidInputException(
1388
					throw new InvalidInputException(
1388
						Main.bind("configure.duplicateBootClasspath", currentArg)); //$NON-NLS-1$
1389
						Main.bind("configure.duplicateBootClasspath", currentArg)); //$NON-NLS-1$
1389
				bootclasspaths = new String[DEFAULT_SIZE_CLASSPATH];
1390
				mode = InsideBootClasspath;
1390
				mode = InsideBootClasspath;
1391
				continue;
1391
				continue;
1392
			}
1392
			}
Lines 1921-1960 Link Here
1921
				mode = Default;
1921
				mode = Default;
1922
				continue;
1922
				continue;
1923
			}
1923
			}
1924
			if (mode == InsideClasspath) {
1924
			if (mode == InsideClasspath || mode == InsideBootClasspath) {
1925
				StringTokenizer tokenizer = new StringTokenizer(currentArg, File.pathSeparator);
1925
				StringTokenizer tokenizer = new StringTokenizer(currentArg,
1926
						File.pathSeparator + "[]", true); //$NON-NLS-1$
1927
				// state machine
1928
				final int start = 0; 
1929
				final int readyToClose = 1;
1930
				// 'path' 'path1[rule];path2'
1931
				final int readyToCloseEndingWithRules = 2;
1932
				// 'path[rule]' 'path1;path2[rule]'
1933
				final int readyToCloseOrOtherEntry = 3;
1934
				// 'path[rule];' 'path;' 'path1;path2;'
1935
				final int rulesNeedAnotherRule = 4;
1936
				// 'path[rule1;'
1937
				final int rulesStart = 5;
1938
				// 'path[' 'path1;path2['
1939
				final int rulesReadyToClose = 6;
1940
				// 'path[rule' 'path[rule1;rule2'
1941
				final int error = 99;
1942
				int state = start;
1943
				String token = null;
1926
				while (tokenizer.hasMoreTokens()) {
1944
				while (tokenizer.hasMoreTokens()) {
1927
					int length;
1945
					token = tokenizer.nextToken();
1928
					if ((length = this.classpaths.length) <= pathCount) {
1946
					if (token.equals(File.pathSeparator)) {
1929
						System.arraycopy(
1947
						switch (state) {
1930
							this.classpaths,
1948
						case readyToClose:
1931
							0,
1949
						case readyToCloseEndingWithRules:
1932
							(this.classpaths = new String[length * 2]),
1950
						case readyToCloseOrOtherEntry:
1933
							0,
1951
							state = readyToCloseOrOtherEntry;
1934
							length);
1952
							break;
1953
						case rulesReadyToClose:
1954
							state = rulesNeedAnotherRule;
1955
							break;
1956
						default:
1957
							state = error;
1958
						}
1959
					} else if (token.equals("[")) { //$NON-NLS-1$
1960
						switch (state) {
1961
						case readyToClose:
1962
							state = rulesStart;
1963
							break;
1964
						default:
1965
							state = error;
1966
						}
1967
					} else if (token.equals("]")) { //$NON-NLS-1$
1968
						switch (state) {
1969
						case rulesReadyToClose:
1970
							state = readyToCloseEndingWithRules;
1971
							break;
1972
						default:
1973
							state = error;
1974
						}
1975
1976
					} else // regular word
1977
					{
1978
						switch (state) {
1979
						case start:
1980
						case readyToCloseOrOtherEntry:
1981
							state = readyToClose;
1982
							currentClasspathName = token;
1983
							break;
1984
						case rulesNeedAnotherRule:
1985
						case rulesStart:
1986
							state = rulesReadyToClose;
1987
							currentRuleSpecs.add(token);
1988
							break;
1989
						default:
1990
							state = error;
1991
						}
1935
					}
1992
					}
1936
					this.classpaths[pathCount++] = tokenizer.nextToken();
1937
				}
1993
				}
1938
				mode = Default;
1994
				if (state == readyToClose
1939
				continue;
1995
						|| state == readyToCloseEndingWithRules 
1940
			}
1996
						|| state == readyToCloseOrOtherEntry) {
1941
			if (mode == InsideBootClasspath) {
1997
					AccessRule[] accessRules = new AccessRule[currentRuleSpecs
1942
				StringTokenizer tokenizer = new StringTokenizer(currentArg, File.pathSeparator);
1998
							.size()];
1943
				while (tokenizer.hasMoreTokens()) {
1999
					boolean rulesOK = true;
1944
					int length;
2000
					Iterator i = currentRuleSpecs.iterator();
1945
					if ((length = bootclasspaths.length) <= bootclasspathCount) {
2001
					int j = 0;
1946
						System.arraycopy(
2002
					while (i.hasNext()) {
1947
							bootclasspaths,
2003
						String ruleSpec = (String) i.next();
1948
							0,
2004
						char key = ruleSpec.charAt(0);
1949
							(bootclasspaths = new String[length * 2]),
2005
						String pattern = ruleSpec.substring(1);
1950
							0,
2006
						if (pattern.length() > 0) {
1951
							length);
2007
							switch (key) {
2008
							case '+':
2009
								accessRules[j++] = new AccessRule(pattern
2010
										.toCharArray(), -1);
2011
								break;
2012
							case '~':
2013
								accessRules[j++] = new AccessRule(pattern
2014
										.toCharArray(),
2015
										IProblem.DiscouragedReference);
2016
								break;
2017
							case '-':
2018
								accessRules[j++] = new AccessRule(pattern
2019
										.toCharArray(),
2020
										IProblem.ForbiddenReference);
2021
								break;
2022
							default:
2023
								rulesOK = false;
2024
							}
2025
						} else {
2026
							rulesOK = false;
2027
						}
2028
					}
2029
					if (rulesOK) {
2030
						AccessRuleSet accessRuleSet = new AccessRuleSet(
2031
								accessRules, "{0}"); //$NON-NLS-1$
2032
						FileSystem.Classpath currentClasspath = FileSystem
2033
								.getClasspath(currentClasspathName,
2034
										customEncoding, 0, accessRuleSet);
2035
						if (currentClasspath != null) {
2036
							if (mode == InsideClasspath) {
2037
								this.checkedClasspaths.add(currentClasspath);
2038
							} else { // inside bootclasspath
2039
								bootclasspaths.add(currentClasspath);
2040
							}
2041
						} else {
2042
							this.logger.logIncorrectClasspath(currentArg);
2043
							// we go on anyway
2044
						}
2045
					} else {
2046
						this.logger.logIncorrectClasspath(currentArg);
2047
						// we go on anyway
1952
					}
2048
					}
1953
					bootclasspaths[bootclasspathCount++] = tokenizer.nextToken();
2049
				} else {
2050
					this.logger.logIncorrectClasspath(currentArg);
2051
					// we go on anyway
1954
				}
2052
				}
1955
				mode = Default;
2053
				mode = Default;
1956
				continue;
2054
				continue;
1957
			}			
2055
			}
1958
			//default is input directory
2056
			//default is input directory
1959
			currentArg = currentArg.replace('/', File.separatorChar);
2057
			currentArg = currentArg.replace('/', File.separatorChar);
1960
			if (currentArg.endsWith(File.separator))
2058
			if (currentArg.endsWith(File.separator))
Lines 2020-2041 Link Here
2020
				(this.filenames = new String[filesCount]),
2118
				(this.filenames = new String[filesCount]),
2021
				0,
2119
				0,
2022
				filesCount);
2120
				filesCount);
2023
		if (pathCount == 0) {
2121
		if (checkedClasspaths.size() == 0) {
2024
			// no user classpath specified.
2122
			// no user classpath specified.
2025
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
2123
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
2026
			if ((classProp == null) || (classProp.length() == 0)) {
2124
			if ((classProp == null) || (classProp.length() == 0)) {
2027
				this.logger.logNoClasspath(); //$NON-NLS-1$
2125
				this.logger.logNoClasspath(); //$NON-NLS-1$
2028
				classProp = System.getProperty("user.dir"); //$NON-NLS-1$
2029
			}
2126
			}
2030
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
2127
			else {
2031
			this.classpaths = new String[tokenizer.countTokens() + 1];
2128
				StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
2032
			while (tokenizer.hasMoreTokens()) {
2129
				String token;
2033
				this.classpaths[pathCount++] = tokenizer.nextToken();
2130
				while (tokenizer.hasMoreTokens()) {
2131
					token = tokenizer.nextToken();
2132
					FileSystem.Classpath currentClasspath = FileSystem
2133
							.getClasspath(token, customEncoding, 0, null);
2134
					if (currentClasspath != null) {
2135
						this.checkedClasspaths.add(currentClasspath);
2136
					} else {
2137
						this.logger.logIncorrectClasspath(token);
2138
						// should not happen - we go on anyway
2139
					}
2140
				}
2034
			}
2141
			}
2035
			this.classpaths[pathCount++] = System.getProperty("user.dir");//$NON-NLS-1$
2036
		}
2142
		}
2037
		
2143
		
2038
		if (bootclasspathCount == 0) {
2144
		if (bootclasspaths.size() == 0) {
2039
			/* no bootclasspath specified
2145
			/* no bootclasspath specified
2040
			 * we can try to retrieve the default librairies of the VM used to run
2146
			 * we can try to retrieve the default librairies of the VM used to run
2041
			 * the batch compiler
2147
			 * the batch compiler
Lines 2060-2072 Link Here
2060
						File[] directoriesToCheck = new File[] { new File(javaHomeFile, "lib"), new File(javaHomeFile, "lib/ext")};//$NON-NLS-1$//$NON-NLS-2$
2166
						File[] directoriesToCheck = new File[] { new File(javaHomeFile, "lib"), new File(javaHomeFile, "lib/ext")};//$NON-NLS-1$//$NON-NLS-2$
2061
						File[][] systemLibrariesJars = getLibrariesFiles(directoriesToCheck);
2167
						File[][] systemLibrariesJars = getLibrariesFiles(directoriesToCheck);
2062
						if (systemLibrariesJars != null) {
2168
						if (systemLibrariesJars != null) {
2063
							int length = getLength(systemLibrariesJars);
2064
							bootclasspaths = new String[length];
2065
							for (int i = 0, max = systemLibrariesJars.length; i < max; i++) {
2169
							for (int i = 0, max = systemLibrariesJars.length; i < max; i++) {
2066
								File[] current = systemLibrariesJars[i];
2170
								File[] current = systemLibrariesJars[i];
2067
								if (current != null) {
2171
								if (current != null) {
2068
									for (int j = 0, max2 = current.length; j < max2; j++) {
2172
									for (int j = 0, max2 = current.length; j < max2; j++) {
2069
										bootclasspaths[bootclasspathCount++] = current[j].getAbsolutePath();
2173
										FileSystem.Classpath classpath = 
2174
											FileSystem.getClasspath(
2175
													current[j].getAbsolutePath(),
2176
													null, 0, null); 
2177
										if (classpath != null) {
2178
											bootclasspaths.add(classpath);
2179
										}
2070
									}
2180
									}
2071
								}
2181
								}
2072
							}
2182
							}
Lines 2084-2123 Link Here
2084
			this.showProgress = false;
2194
			this.showProgress = false;
2085
		}
2195
		}
2086
2196
2087
		if (this.classpaths == null) {
2088
			this.classpaths = new String[0];
2089
		}
2090
		/* 
2197
		/* 
2091
		 * We put the bootclasspath at the beginning of the classpath entries
2198
		 * We put the bootclasspath at the beginning of the classpath entries
2092
		 */
2199
		 */
2093
		String[] newclasspaths = null;
2200
		bootclasspaths.addAll(this.checkedClasspaths);
2094
		if ((pathCount + bootclasspathCount) != this.classpaths.length) {
2201
		this.checkedClasspaths = bootclasspaths;
2095
			newclasspaths = new String[pathCount + bootclasspathCount];
2202
		this.checkedClasspaths.trimToSize();
2096
		} else {
2097
			newclasspaths = this.classpaths;
2098
		}
2099
		System.arraycopy(
2100
			this.classpaths,
2101
			0,
2102
			newclasspaths,
2103
			bootclasspathCount,
2104
			pathCount);
2105
2106
		if (bootclasspathCount != 0) {
2107
			System.arraycopy(
2108
				bootclasspaths,
2109
				0,
2110
				newclasspaths,
2111
				0,
2112
				bootclasspathCount);
2113
		}
2114
		this.classpaths = newclasspaths;
2115
		for (int i = 0, max = this.classpaths.length; i < max; i++) {
2116
			File file = new File(this.classpaths[i]);
2117
			if (!file.exists()) { // signal missing classpath entry file
2118
				this.logger.logIncorrectClasspath(this.classpaths[i]); //$NON-NLS-1$
2119
			}
2120
		}
2121
		if (this.destinationPath == null) {
2203
		if (this.destinationPath == null) {
2122
			this.generatePackagesStructure = false;
2204
			this.generatePackagesStructure = false;
2123
		} else if ("none".equals(this.destinationPath)) { //$NON-NLS-1$
2205
		} else if ("none".equals(this.destinationPath)) { //$NON-NLS-1$
Lines 2198-2204 Link Here
2198
		}
2280
		}
2199
		this.logger.logCommandLineArguments(newCommandLineArgs);
2281
		this.logger.logCommandLineArguments(newCommandLineArgs);
2200
		this.logger.logOptions(this.options);
2282
		this.logger.logOptions(this.options);
2201
		this.logger.logClasspath(this.classpaths);
2283
		this.logger.logClasspath((FileSystem.Classpath[])this.checkedClasspaths.toArray(new FileSystem.Classpath[0]));
2202
		if (this.repetitions == 0) {
2284
		if (this.repetitions == 0) {
2203
			this.repetitions = 1;
2285
			this.repetitions = 1;
2204
		}
2286
		}
Lines 2319-2336 Link Here
2319
		return result;
2401
		return result;
2320
	}
2402
	}
2321
	
2403
	
2322
	private int getLength(File[][] libraries) {
2323
		int sum = 0;
2324
		if (libraries != null) {
2325
			for (int i = 0, max = libraries.length; i < max; i++) {
2326
				final File[] currentFiles = libraries[i];
2327
				if (currentFiles != null) {
2328
					sum+= currentFiles.length;
2329
				}
2330
			}
2331
		}
2332
		return sum;
2333
	}
2334
	/*
2404
	/*
2335
	 *  Low-level API performing the actual compilation
2405
	 *  Low-level API performing the actual compilation
2336
	 */
2406
	 */
Lines 2351-2357 Link Here
2351
		String defaultEncoding = (String) this.options.get(CompilerOptions.OPTION_Encoding);
2421
		String defaultEncoding = (String) this.options.get(CompilerOptions.OPTION_Encoding);
2352
		if ("".equals(defaultEncoding)) //$NON-NLS-1$
2422
		if ("".equals(defaultEncoding)) //$NON-NLS-1$
2353
			defaultEncoding = null; //$NON-NLS-1$	
2423
			defaultEncoding = null; //$NON-NLS-1$	
2354
		return new FileSystem(this.classpaths, this.filenames, defaultEncoding);
2424
		return new FileSystem(
2425
				(FileSystem.Classpath[])this.checkedClasspaths.toArray(
2426
						new FileSystem.Classpath[0]), 
2427
				this.filenames);
2355
	}
2428
	}
2356
	/*
2429
	/*
2357
	 *  Low-level API performing the actual compilation
2430
	 *  Low-level API performing the actual compilation
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-2 / +6 lines)
Lines 92-100 Link Here
92
\ \n\
92
\ \n\
93
\ Classpath options:\n\
93
\ Classpath options:\n\
94
\    -cp -classpath <directories and zip/jar files separated by {0}>\n\
94
\    -cp -classpath <directories and zip/jar files separated by {0}>\n\
95
\                       specify location for application classes and sources\n\
95
\                       specify location for application classes and sources. Each\n\
96
\                       directory or file can specify access rules for types between\n\
97
\                       ''['' and '']'' (e.g. [-X.java] to deny access to type X)\n\
96
\    -bootclasspath <directories and zip/jar files separated by {0}>\n\
98
\    -bootclasspath <directories and zip/jar files separated by {0}>\n\
97
\                       specify location for system classes\n\
99
\                       specify location for system classes. Each directory or file can\n\
100
\                       specify access rules for types between ''['' and '']'' (e.g. [-X.java]\n\
101
\                       to deny access to type X)\n\
98
\    -d <dir>           destination directory (if omitted, no directory is created)\n\
102
\    -d <dir>           destination directory (if omitted, no directory is created)\n\
99
\    -d none            generate no .class files\n\
103
\    -d none            generate no .class files\n\
100
\    -encoding <enc>    specify custom encoding for all sources. Each file/directory can override it\n\
104
\    -encoding <enc>    specify custom encoding for all sources. Each file/directory can override it\n\
(-)compiler/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java (+4 lines)
Lines 25-30 Link Here
25
	public AccessRuleSet(AccessRule[] accessRules) {
25
	public AccessRuleSet(AccessRule[] accessRules) {
26
		this.accessRules = accessRules;
26
		this.accessRules = accessRules;
27
	}
27
	}
28
	public AccessRuleSet(AccessRule[] accessRules, String messageTemplate) {
29
		this.accessRules = accessRules;
30
		this.messageTemplate = messageTemplate;
31
	}
28
	/**
32
	/**
29
	 * @see java.lang.Object#equals(java.lang.Object)
33
	 * @see java.lang.Object#equals(java.lang.Object)
30
	 */
34
	 */
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 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 org.eclipse.jdt.internal.compiler.env.AccessRestriction;
14
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
15
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
16
17
public abstract class ClasspathLocation implements FileSystem.Classpath,
18
		SuffixConstants {
19
20
	private AccessRuleSet accessRuleSet;
21
22
	public ClasspathLocation(AccessRuleSet accessRuleSet) {
23
		this.accessRuleSet = accessRuleSet;
24
	}
25
26
	/**
27
	 * Return the first access rule which is violated when accessing a given
28
	 * type, or null if no 'non accessible' access rule applies.
29
	 * 
30
	 * @param qualifiedBinaryFileName
31
	 *            tested type specification, formed as:
32
	 *            "org/eclipse/jdt/core/JavaCore.class"
33
	 * @return the first access rule which is violated when accessing a given
34
	 *         type, or null if none applies
35
	 */
36
	AccessRestriction fetchAccessRestriction(String qualifiedBinaryFileName) {
37
		if (this.accessRuleSet == null)
38
			return null;
39
		return this.accessRuleSet
40
				.getViolatedRestriction((qualifiedBinaryFileName.substring(0,
41
						qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java)
42
						.toCharArray());
43
	}
44
}

Return to bug 92398