Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 216684
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-15 / +83 lines)
Lines 170-186 Link Here
170
			if (!outputDirectory.isDirectory()) {
170
			if (!outputDirectory.isDirectory()) {
171
				outputDirectory.mkdirs();
171
				outputDirectory.mkdirs();
172
			}
172
			}
173
			PrintWriter sourceFileWriter;
173
			if (testFiles != null) {
174
			for (int i = 0; i < testFiles.length; i += 2) {
174
				PrintWriter sourceFileWriter;
175
				String fileName = OUTPUT_DIR + File.separator + testFiles[i];
175
				for (int i = 0; i < testFiles.length; i += 2) {
176
				File file = new File(fileName), innerOutputDirectory = file
176
					String fileName = OUTPUT_DIR + File.separator + testFiles[i];
177
						.getParentFile();
177
					File file = new File(fileName), innerOutputDirectory = file
178
				if (!innerOutputDirectory.isDirectory()) {
178
							.getParentFile();
179
					innerOutputDirectory.mkdirs();
179
					if (!innerOutputDirectory.isDirectory()) {
180
						innerOutputDirectory.mkdirs();
181
					}
182
					sourceFileWriter = new PrintWriter(new FileOutputStream(file));
183
					sourceFileWriter.write(testFiles[i + 1]);
184
					sourceFileWriter.close();
180
				}
185
				}
181
				sourceFileWriter = new PrintWriter(new FileOutputStream(file));
182
				sourceFileWriter.write(testFiles[i + 1]);
183
				sourceFileWriter.close();
184
			}
186
			}
185
		} catch (FileNotFoundException e) {
187
		} catch (FileNotFoundException e) {
186
			e.printStackTrace();
188
			e.printStackTrace();
Lines 230-240 Link Here
230
		}
232
		}
231
		if (compileOK != shouldCompileOK || !compareOK) {
233
		if (compileOK != shouldCompileOK || !compareOK) {
232
			System.out.println(getClass().getName() + '#' + getName());
234
			System.out.println(getClass().getName() + '#' + getName());
233
			for (int i = 0; i < testFiles.length; i += 2) {
235
			if (testFiles != null) {
234
				System.out.print(testFiles[i]);
236
				for (int i = 0; i < testFiles.length; i += 2) {
235
				System.out.println(" [");
237
					System.out.print(testFiles[i]);
236
				System.out.println(testFiles[i + 1]);
238
					System.out.println(" [");
237
				System.out.println("]");
239
					System.out.println(testFiles[i + 1]);
240
					System.out.println("]");
241
				}
238
			}
242
			}
239
		}
243
		}
240
		if (compileOK != shouldCompileOK)
244
		if (compileOK != shouldCompileOK)
Lines 8350-8353 Link Here
8350
		"1 problem (1 warning)",
8354
		"1 problem (1 warning)",
8351
		true);
8355
		true);
8352
}
8356
}
8357
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=216684
8358
// .java/.class files precedence depending on sourcepath
8359
public void testONLY_230_sourcepath_vs_classpath() {
8360
	this.runConformTest(
8361
		new String[] {
8362
			"X.java",
8363
			"public class X {\n" + 
8364
			"}\n",
8365
		},
8366
		"\"" + OUTPUT_DIR +  File.separator + "X.java\""
8367
		+ " -verbose -warn:unusedThrown -proc:none -d \"" + OUTPUT_DIR + "\"",
8368
		"[parsing    ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + 
8369
		"[reading    java/lang/Object.class]\n" + 
8370
		"[analyzing  ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + 
8371
		"[writing    X.class - #1]\n" + 
8372
		"[completed  ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + 
8373
		"[1 unit compiled]\n" + 
8374
		"[1 .class file generated]\n",
8375
		"",
8376
		true);
8377
	// check that class file is newer than source file
8378
	assertTrue("class file not strictly newer than source file",
8379
		new File(OUTPUT_DIR + File.separator + "X.class").lastModified() >
8380
		new File(OUTPUT_DIR + File.separator + "X.java").lastModified());
8381
	// compile with classpath only: X.class gets selected
8382
	this.runConformTest(
8383
		new String[] {
8384
			"Y.java",
8385
			"public class Y {\n" +
8386
			"  X x;\n" + 
8387
			"}\n",
8388
		},
8389
		"\"" + OUTPUT_DIR +  File.separator + "Y.java\""
8390
		+ " -classpath \"" + OUTPUT_DIR + "\""
8391
		+ " -verbose -warn:unusedThrown -proc:none -d \"" + OUTPUT_DIR + "\"",
8392
		"[parsing    ---OUTPUT_DIR_PLACEHOLDER---/Y.java - #1/1]\n" + 
8393
		"[reading    java/lang/Object.class]\n" + 
8394
		"[analyzing  ---OUTPUT_DIR_PLACEHOLDER---/Y.java - #1/1]\n" + 
8395
		"[reading    X.class]\n" + 
8396
		"[writing    Y.class - #1]\n" + 
8397
		"[completed  ---OUTPUT_DIR_PLACEHOLDER---/Y.java - #1/1]\n" + 
8398
		"[1 unit compiled]\n" + 
8399
		"[1 .class file generated]\n",
8400
		"",
8401
		false);
8402
	// compile with sourcepath and classpath: since X.class is newer, it
8403
	// should be preferred
8404
	this.runConformTest(
8405
		null,
8406
		"\"" + OUTPUT_DIR +  File.separator + "Y.java\""
8407
		+ " -classpath \"" + OUTPUT_DIR + "\""
8408
		+ " -sourcepath \"" + OUTPUT_DIR + "\""
8409
		+ " -verbose -warn:unusedThrown -proc:none -d \"" + OUTPUT_DIR + "\"",
8410
		"[parsing    ---OUTPUT_DIR_PLACEHOLDER---/Y.java - #1/1]\n" + 
8411
		"[reading    java/lang/Object.class]\n" + 
8412
		"[analyzing  ---OUTPUT_DIR_PLACEHOLDER---/Y.java - #1/1]\n" + 
8413
		"[reading    X.class]\n" + 
8414
		"[writing    Y.class - #1]\n" + 
8415
		"[completed  ---OUTPUT_DIR_PLACEHOLDER---/Y.java - #1/1]\n" + 
8416
		"[1 unit compiled]\n" + 
8417
		"[1 .class file generated]\n",
8418
		"",
8419
		false);
8420
}
8353
}
8421
}

Return to bug 216684