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

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java (-1 / +1 lines)
Lines 86-92 Link Here
86
			return true;
86
			return true;
87
	return false;
87
	return false;
88
}
88
}
89
public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
89
public List fetchLinkedJars(FileSystem.ClasspathProblemReporter problemReporter) {
90
	return null;
90
	return null;
91
}
91
}
92
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
92
public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java (-1 / +1 lines)
Lines 43-49 Link Here
43
	this.closeZipFileAtEnd = closeZipFileAtEnd;
43
	this.closeZipFileAtEnd = closeZipFileAtEnd;
44
}
44
}
45
45
46
public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
46
public List fetchLinkedJars(FileSystem.ClasspathProblemReporter problemReporter) {
47
	// expected to be called once only - if multiple calls desired, consider
47
	// expected to be called once only - if multiple calls desired, consider
48
	// using a cache
48
	// using a cache
49
	InputStream inputStream = null;
49
	InputStream inputStream = null;
(-)batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java (-9 / +42 lines)
Lines 13-21 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.HashMap;
16
import java.util.HashSet;
17
import java.util.HashSet;
17
import java.util.Iterator;
18
import java.util.Iterator;
18
import java.util.List;
19
import java.util.List;
20
import java.util.Map;
19
import java.util.Set;
21
import java.util.Set;
20
22
21
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.core.compiler.CharOperation;
Lines 40-46 Link Here
40
		 * @return a list of the jar file names defined in the Class-Path
42
		 * @return a list of the jar file names defined in the Class-Path
41
		 *         section of the jar file manifest if any
43
		 *         section of the jar file manifest if any
42
		 */
44
		 */
43
		List fetchLinkedJars(ClasspathSectionProblemReporter problemReporter);
45
		List fetchLinkedJars(ClasspathProblemReporter problemReporter);
44
		/**
46
		/**
45
		 * This method resets the environment. The resulting state is equivalent to
47
		 * This method resets the environment. The resulting state is equivalent to
46
		 * a new name environment without creating a new object.
48
		 * a new name environment without creating a new object.
Lines 68-76 Link Here
68
		 */
70
		 */
69
		void initialize() throws IOException;
71
		void initialize() throws IOException;
70
	}
72
	}
71
	public interface ClasspathSectionProblemReporter {
73
	public interface ClasspathProblemReporter {
72
		void invalidClasspathSection(String jarFilePath);
74
		void invalidClasspathSection(String jarFilePath);
73
		void multipleClasspathSections(String jarFilePath);
75
		void multipleClasspathSections(String jarFilePath);
76
		void nestedClasspath(String classpathOne, String classpathTwo);
74
	}
77
	}
75
78
76
	/**
79
	/**
Lines 103-116 Link Here
103
106
104
	Classpath[] classpaths;
107
	Classpath[] classpaths;
105
	Set knownFileNames;
108
	Set knownFileNames;
109
	private ClasspathProblemReporter problemReporter;
106
110
107
/*
111
/*
108
	classPathNames is a collection is Strings representing the full path of each class path
112
	classPathNames is a collection is Strings representing the full path of each class path
109
	initialFileNames is a collection is Strings, the trailing '.java' will be removed if its not already.
113
	initialFileNames is a collection is Strings, the trailing '.java' will be removed if its not already.
110
*/
114
*/
111
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding) {
115
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding) {
116
	this(classpathNames, initialFileNames, encoding, null);
117
}	
118
119
public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, ClasspathProblemReporter problemReporter) {
112
	final int classpathSize = classpathNames.length;
120
	final int classpathSize = classpathNames.length;
113
	this.classpaths = new Classpath[classpathSize];
121
	this.classpaths = new Classpath[classpathSize];
122
	this.problemReporter = problemReporter;
114
	int counter = 0;
123
	int counter = 0;
115
	for (int i = 0; i < classpathSize; i++) {
124
	for (int i = 0; i < classpathSize; i++) {
116
		Classpath classpath = getClasspath(classpathNames[i], encoding, null);
125
		Classpath classpath = getClasspath(classpathNames[i], encoding, null);
Lines 126-135 Link Here
126
	}
135
	}
127
	initializeKnownFileNames(initialFileNames);
136
	initializeKnownFileNames(initialFileNames);
128
}
137
}
129
protected FileSystem(Classpath[] paths, String[] initialFileNames) {
138
protected FileSystem(Classpath[] paths, String[] initialFileNames, ClasspathProblemReporter problemReporter) {
130
	final int length = paths.length;
139
	final int length = paths.length;
131
	int counter = 0;
140
	int counter = 0;
132
	this.classpaths = new FileSystem.Classpath[length];
141
	this.classpaths = new FileSystem.Classpath[length];
142
	this.problemReporter = problemReporter;
133
	for (int i = 0; i < length; i++) {
143
	for (int i = 0; i < length; i++) {
134
		final Classpath classpath = paths[i];
144
		final Classpath classpath = paths[i];
135
		try {
145
		try {
Lines 145-150 Link Here
145
	}
155
	}
146
	initializeKnownFileNames(initialFileNames);
156
	initializeKnownFileNames(initialFileNames);
147
}
157
}
158
protected FileSystem(Classpath[] paths, String[] initialFileNames) {
159
	this(paths, initialFileNames, null);
160
}
148
public static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet) {
161
public static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet) {
149
	return getClasspath(classpathName, encoding, false, accessRuleSet, null);
162
	return getClasspath(classpathName, encoding, false, accessRuleSet, null);
150
}
163
}
Lines 185-191 Link Here
185
		this.knownFileNames = new HashSet(0);
198
		this.knownFileNames = new HashSet(0);
186
		return;
199
		return;
187
	}
200
	}
201
	if (this.problemReporter == null) {
202
		this.problemReporter = new ClasspathProblemReporter() {
203
			public void nestedClasspath(String classpathOne, String classpathTwo) {
204
				System.err.println("Nested classpath " + classpathOne + " and " + classpathTwo); //$NON-NLS-1$ //$NON-NLS-2$
205
			}
206
			public void multipleClasspathSections(String jarFilePath) {
207
				System.err.println("Multiple classpath sections in " + jarFilePath); //$NON-NLS-1$
208
			}
209
			public void invalidClasspathSection(String jarFilePath) {
210
				System.err.println("Invalid classpath section in " + jarFilePath); //$NON-NLS-1$
211
			}
212
		};
213
	}
214
	
188
	this.knownFileNames = new HashSet(initialFileNames.length * 2);
215
	this.knownFileNames = new HashSet(initialFileNames.length * 2);
216
	
217
	Map conflictingClasspath = new HashMap();
218
	
189
	for (int i = initialFileNames.length; --i >= 0;) {
219
	for (int i = initialFileNames.length; --i >= 0;) {
190
		File compilationUnitFile = new File(initialFileNames[i]);
220
		File compilationUnitFile = new File(initialFileNames[i]);
191
		char[] fileName = null;
221
		char[] fileName = null;
Lines 204-219 Link Here
204
		for (int j = 0, max = this.classpaths.length; j < max; j++) {
234
		for (int j = 0, max = this.classpaths.length; j < max; j++) {
205
			char[] matchCandidate = this.classpaths[j].normalizedPath();
235
			char[] matchCandidate = this.classpaths[j].normalizedPath();
206
			if (this.classpaths[j] instanceof  ClasspathDirectory &&
236
			if (this.classpaths[j] instanceof  ClasspathDirectory &&
207
					CharOperation.prefixEquals(matchCandidate, fileName) &&
237
					CharOperation.prefixEquals(matchCandidate, fileName)) {
208
					(matchingPathName == null ||
238
					this.knownFileNames.add(new String(CharOperation.subarray(fileName, matchCandidate.length, fileName.length)));
209
							matchCandidate.length < matchingPathName.length)) {
239
					if (matchingPathName != null && matchingPathName.length != matchCandidate.length) {
210
				matchingPathName = matchCandidate;
240
						if (!conflictingClasspath.containsKey(matchCandidate)) {
241
							conflictingClasspath.put(matchCandidate, matchingPathName);
242
							this.problemReporter.nestedClasspath(new String(matchCandidate), new String(matchingPathName));
243
						}
244
					}
245
					matchingPathName = matchCandidate;
211
			}
246
			}
212
		}
247
		}
213
		if (matchingPathName == null) {
248
		if (matchingPathName == null) {
214
			this.knownFileNames.add(new String(fileName)); // leave as is...
249
			this.knownFileNames.add(new String(fileName)); // leave as is...
215
		} else {
216
			this.knownFileNames.add(new String(CharOperation.subarray(fileName, matchingPathName.length, fileName.length)));
217
		}
250
		}
218
		matchingPathName = null;
251
		matchingPathName = null;
219
	}
252
	}
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-11 / +15 lines)
Lines 62-67 Link Here
62
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
62
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
63
import org.eclipse.jdt.internal.compiler.IProblemFactory;
63
import org.eclipse.jdt.internal.compiler.IProblemFactory;
64
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
64
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
65
import org.eclipse.jdt.internal.compiler.batch.FileSystem.ClasspathProblemReporter;
65
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
66
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
66
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
67
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
67
import org.eclipse.jdt.internal.compiler.env.AccessRule;
68
import org.eclipse.jdt.internal.compiler.env.AccessRule;
Lines 1329-1334 Link Here
1329
	private PrintWriter err;
1330
	private PrintWriter err;
1330
1331
1331
	ArrayList extraProblems;
1332
	ArrayList extraProblems;
1333
	ClasspathProblemReporter problemReporter = null;
1332
	public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$
1334
	public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$
1333
	// two uses: recognize 'none' in options; code the singleton none
1335
	// two uses: recognize 'none' in options; code the singleton none
1334
	// for the '-d none' option (wherever it may be found)
1336
	// for the '-d none' option (wherever it may be found)
Lines 1452-1457 Link Here
1452
public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions, CompilationProgress compilationProgress) {
1454
public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions, CompilationProgress compilationProgress) {
1453
	this.initialize(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, compilationProgress);
1455
	this.initialize(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, compilationProgress);
1454
	this.relocalize();
1456
	this.relocalize();
1457
	this.problemReporter = 	new FileSystem.ClasspathProblemReporter() {
1458
		public void invalidClasspathSection(String jarFilePath) {
1459
			addPendingErrors(bind("configure.invalidClasspathSection", jarFilePath)); //$NON-NLS-1$
1460
		}
1461
		public void multipleClasspathSections(String jarFilePath) {
1462
			addPendingErrors(bind("configure.multipleClasspathSections", jarFilePath)); //$NON-NLS-1$
1463
		}
1464
		public void nestedClasspath(String classpathOne, String classpathTwo) {
1465
			Main.this.logger.logWarning(bind("configure.nestedClasspathEntries", classpathOne, classpathTwo)); //$NON-NLS-1$
1466
		}
1467
	};
1455
}
1468
}
1456
1469
1457
public void addExtraProblems(CategorizedProblem problem) {
1470
public void addExtraProblems(CategorizedProblem problem) {
Lines 2935-2941 Link Here
2935
}
2948
}
2936
2949
2937
public FileSystem getLibraryAccess() {
2950
public FileSystem getLibraryAccess() {
2938
	return new FileSystem(this.checkedClasspaths, this.filenames);
2951
	return new FileSystem(this.checkedClasspaths, this.filenames, this.problemReporter);
2939
}
2952
}
2940
2953
2941
/*
2954
/*
Lines 3011-3032 Link Here
3011
	}
3024
	}
3012
	ArrayList result = new ArrayList();
3025
	ArrayList result = new ArrayList();
3013
	HashMap knownNames = new HashMap();
3026
	HashMap knownNames = new HashMap();
3014
	FileSystem.ClasspathSectionProblemReporter problemReporter =
3015
		new FileSystem.ClasspathSectionProblemReporter() {
3016
			public void invalidClasspathSection(String jarFilePath) {
3017
				addPendingErrors(bind("configure.invalidClasspathSection", jarFilePath)); //$NON-NLS-1$
3018
			}
3019
			public void multipleClasspathSections(String jarFilePath) {
3020
				addPendingErrors(bind("configure.multipleClasspathSections", jarFilePath)); //$NON-NLS-1$
3021
			}
3022
		};
3023
	while (! classpaths.isEmpty()) {
3027
	while (! classpaths.isEmpty()) {
3024
		Classpath current = (Classpath) classpaths.remove(0);
3028
		Classpath current = (Classpath) classpaths.remove(0);
3025
		String currentPath = current.getPath();
3029
		String currentPath = current.getPath();
3026
		if (knownNames.get(currentPath) == null) {
3030
		if (knownNames.get(currentPath) == null) {
3027
			knownNames.put(currentPath, current);
3031
			knownNames.put(currentPath, current);
3028
			result.add(current);
3032
			result.add(current);
3029
			List linkedJars = current.fetchLinkedJars(problemReporter);
3033
			List linkedJars = current.fetchLinkedJars(this.problemReporter);
3030
			if (linkedJars != null) {
3034
			if (linkedJars != null) {
3031
				classpaths.addAll(0, linkedJars);
3035
				classpaths.addAll(0, linkedJars);
3032
			}
3036
			}
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+1 lines)
Lines 95-100 Link Here
95
configure.incompatibleComplianceForCldcTarget=Target level ''{0}'' is incompatible with compliance level ''{1}''. A compliance level ''1.4''or lower is required
95
configure.incompatibleComplianceForCldcTarget=Target level ''{0}'' is incompatible with compliance level ''{1}''. A compliance level ''1.4''or lower is required
96
configure.invalidClasspathSection = invalid Class-Path header in manifest of jar file: {0}
96
configure.invalidClasspathSection = invalid Class-Path header in manifest of jar file: {0}
97
configure.multipleClasspathSections = multiple Class-Path headers in manifest of jar file: {0}
97
configure.multipleClasspathSections = multiple Class-Path headers in manifest of jar file: {0}
98
configure.nestedClasspathEntries = Nested classpath entries found: {0} and {1}
98
configure.missingwarningspropertiesfile=properties file {0} does not exist
99
configure.missingwarningspropertiesfile=properties file {0} does not exist
99
configure.ioexceptionwarningspropertiesfile=An IOException occurred while reading the properties file {0}
100
configure.ioexceptionwarningspropertiesfile=An IOException occurred while reading the properties file {0}
100
configure.multipleencodings=Multiple encoding specified: {1}. The default encoding has been set to {0}
101
configure.multipleencodings=Multiple encoding specified: {1}. The default encoding has been set to {0}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+54 lines)
Lines 11789-11792 Link Here
11789
		System.setProperty("user.dir", javaUserDir);
11789
		System.setProperty("user.dir", javaUserDir);
11790
	}
11790
	}
11791
}
11791
}
11792
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=322789
11793
public void test322789() throws IOException {
11794
	final String javaClassspath = System.getProperty("java.class.path");
11795
	final String javaUserDir = System.getProperty("user.dir");
11796
	try {
11797
		
11798
		File outputDir = new File(OUTPUT_DIR);
11799
		File srcDir = new File(outputDir, "src");
11800
		srcDir.mkdirs();
11801
11802
		System.setProperty("user.dir", OUTPUT_DIR);
11803
		System.setProperty("java.class.path", srcDir.getCanonicalPath()+";"+outputDir.getCanonicalPath());
11804
		char[] srcPath = srcDir.getCanonicalPath().toCharArray();
11805
		char[] outputPath = outputDir.getCanonicalPath().toCharArray();
11806
		if (File.separatorChar == '\\') {
11807
			CharOperation.replace(srcPath, '\\', '/');
11808
			CharOperation.replace(outputPath, '\\', '/');
11809
		}
11810
		
11811
		this.runConformTest(
11812
				new String[] {
11813
					"src/p/AbstractJavaSourceClassLoader.java",
11814
					"package p;\n" +
11815
					"public abstract class AbstractJavaSourceClassLoader {\n" +
11816
					"	public interface ProtectionDomainFactory {}\n" +
11817
					"}\n",
11818
					"src/p/" + PACKAGE_INFO_NAME + ".java",
11819
					"/*  \n" +
11820
					" * Package information : p  \n" +
11821
					" */ \n" +
11822
					"package p;\n",					
11823
				},
11824
				"\"" + OUTPUT_DIR + File.separator + "src" + File.separator + "p" + File.separator + "AbstractJavaSourceClassLoader.java\""
11825
				+ " \"" + OUTPUT_DIR + File.separator + "src" + File.separator + "p" + File.separator + PACKAGE_INFO_NAME + ".java\""
11826
		        + " -1.5 -g -preserveAllLocals"
11827
		        + " -proceedOnError -referenceInfo"
11828
		        + " -d \"" + OUTPUT_DIR + "\"",
11829
				"Nested classpath entries found: "+ new String(outputPath) +"/ and "+ new String(srcPath) +"/\r\n",
11830
		        "",
11831
		        true);
11832
		final String userDir = System.getProperty("user.dir");
11833
		File f = new File(userDir, "p" + File.separator + "AbstractJavaSourceClassLoader.java");
11834
		if (!Util.delete(f)) {
11835
			System.out.println("Could not delete AbstractJavaSourceClassLoader.java");
11836
		}
11837
		f = new File(userDir, "p" + File.separator + "package-info.java");
11838
		if (!Util.delete(f)) {
11839
			System.out.println("Could not delete package-info.java");
11840
		}
11841
	} finally {
11842
		System.setProperty("java.class.path", javaClassspath);
11843
		System.setProperty("user.dir", javaUserDir);
11844
	}
11845
}
11792
}
11846
}

Return to bug 322789