Lines 1-12
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2008, 2010 IBM Corporation and others. |
2 |
* Copyright (c) 2008, 2011 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* IBM Corporation - fix for 342936 |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.compiler.tool.tests; |
12 |
package org.eclipse.jdt.compiler.tool.tests; |
12 |
|
13 |
|
Lines 45-51
Link Here
|
45 |
|
46 |
|
46 |
public class CompilerInvocationTests extends AbstractCompilerToolTest { |
47 |
public class CompilerInvocationTests extends AbstractCompilerToolTest { |
47 |
static { |
48 |
static { |
48 |
// TESTS_NAMES = new String[] { "test000" }; |
49 |
// TESTS_NAMES = new String[] { "test019_sourcepath_without_destination" }; |
49 |
// TESTS_NUMBERS = new int[] { 5 }; |
50 |
// TESTS_NUMBERS = new int[] { 5 }; |
50 |
// TESTS_RANGE = new int[] { 1, -1 }; |
51 |
// TESTS_RANGE = new int[] { 1, -1 }; |
51 |
} |
52 |
} |
Lines 325-330
Link Here
|
325 |
// exploring -d / FileManager interaction |
326 |
// exploring -d / FileManager interaction |
326 |
// -d changes CLASS_OUTPUT location |
327 |
// -d changes CLASS_OUTPUT location |
327 |
public void test002_dash_d_option() { |
328 |
public void test002_dash_d_option() { |
|
|
329 |
if (JAVAC_COMPILER == null) { |
330 |
System.out.println("No system java compiler available"); |
331 |
return; |
332 |
} |
328 |
StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up |
333 |
StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up |
329 |
runTest( |
334 |
runTest( |
330 |
true /* shouldCompileOK */, |
335 |
true /* shouldCompileOK */, |
Lines 348-353
Link Here
|
348 |
// exploring -d / FileManager interaction |
353 |
// exploring -d / FileManager interaction |
349 |
// -d changes CLASS_OUTPUT location (OUTPUT_DIR subdirectory) |
354 |
// -d changes CLASS_OUTPUT location (OUTPUT_DIR subdirectory) |
350 |
public void test003_dash_d_option() { |
355 |
public void test003_dash_d_option() { |
|
|
356 |
if (JAVAC_COMPILER == null) { |
357 |
System.out.println("No system java compiler available"); |
358 |
return; |
359 |
} |
351 |
StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up |
360 |
StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up |
352 |
String outputDir = OUTPUT_DIR + File.separator + "bin"; |
361 |
String outputDir = OUTPUT_DIR + File.separator + "bin"; |
353 |
runTest( |
362 |
runTest( |
Lines 373-378
Link Here
|
373 |
// ecj uses the output location from the javac standard Java file manager if it |
382 |
// ecj uses the output location from the javac standard Java file manager if it |
374 |
// is set |
383 |
// is set |
375 |
public void test004_no_dash_d_option() throws IOException { |
384 |
public void test004_no_dash_d_option() throws IOException { |
|
|
385 |
if (JAVAC_COMPILER == null) { |
386 |
System.out.println("No system java compiler available"); |
387 |
return; |
388 |
} |
376 |
File binDirectory = new File(OUTPUT_DIR + File.separator + "bin"); |
389 |
File binDirectory = new File(OUTPUT_DIR + File.separator + "bin"); |
377 |
binDirectory.mkdir(); |
390 |
binDirectory.mkdir(); |
378 |
StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up |
391 |
StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up |
Lines 401-406
Link Here
|
401 |
// ecj does not call setLocation on standard Java file managers; it uses |
414 |
// ecj does not call setLocation on standard Java file managers; it uses |
402 |
// handleOption instead; javac does the same |
415 |
// handleOption instead; javac does the same |
403 |
public void test005_dash_d_option_custom_file_manager() { |
416 |
public void test005_dash_d_option_custom_file_manager() { |
|
|
417 |
if (JAVAC_COMPILER == null) { |
418 |
System.out.println("No system java compiler available"); |
419 |
return; |
420 |
} |
404 |
StandardJavaFileManager javacJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); |
421 |
StandardJavaFileManager javacJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); |
405 |
SetLocationDetector customJavaFileManager = |
422 |
SetLocationDetector customJavaFileManager = |
406 |
new SetLocationDetector( |
423 |
new SetLocationDetector( |
Lines 425-431
Link Here
|
425 |
}); |
442 |
}); |
426 |
assertEquals(OUTPUT_DIR, customJavaFileManager.getLocation(StandardLocation.CLASS_OUTPUT).toString()); |
443 |
assertEquals(OUTPUT_DIR, customJavaFileManager.getLocation(StandardLocation.CLASS_OUTPUT).toString()); |
427 |
assertFalse(customJavaFileManager.matchFound()); |
444 |
assertFalse(customJavaFileManager.matchFound()); |
428 |
if (RUN_JAVAC) { |
445 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
429 |
customJavaFileManager = new SetLocationDetector(javacJavaFileManager, |
446 |
customJavaFileManager = new SetLocationDetector(javacJavaFileManager, |
430 |
StandardLocation.CLASS_OUTPUT); |
447 |
StandardLocation.CLASS_OUTPUT); |
431 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
448 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
Lines 438-443
Link Here
|
438 |
// exploring -d / FileManager interaction |
455 |
// exploring -d / FileManager interaction |
439 |
// ecj calls getLocation on a non-javac standard Java file manager |
456 |
// ecj calls getLocation on a non-javac standard Java file manager |
440 |
public void test006_no_dash_d_option_custom_file_manager() throws IOException { |
457 |
public void test006_no_dash_d_option_custom_file_manager() throws IOException { |
|
|
458 |
if (JAVAC_COMPILER == null) { |
459 |
System.out.println("No system java compiler available"); |
460 |
return; |
461 |
} |
441 |
File binDirectory = new File(OUTPUT_DIR + File.separator + "bin"); |
462 |
File binDirectory = new File(OUTPUT_DIR + File.separator + "bin"); |
442 |
binDirectory.mkdirs(); |
463 |
binDirectory.mkdirs(); |
443 |
GetLocationDetector customJavaFileManager = |
464 |
GetLocationDetector customJavaFileManager = |
Lines 476-482
Link Here
|
476 |
Iterator<String> remaining = remainingAsList.iterator(); |
497 |
Iterator<String> remaining = remainingAsList.iterator(); |
477 |
assertTrue("does not support -d option", ecjStandardJavaFileManager.handleOption("-d", remaining)); |
498 |
assertTrue("does not support -d option", ecjStandardJavaFileManager.handleOption("-d", remaining)); |
478 |
assertEquals("unexpected consumption rate", "remainder", remaining.next()); |
499 |
assertEquals("unexpected consumption rate", "remainder", remaining.next()); |
479 |
if (RUN_JAVAC) { |
500 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
480 |
StandardJavaFileManager javacStandardJavaFileManager = |
501 |
StandardJavaFileManager javacStandardJavaFileManager = |
481 |
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); // will pick defaults up |
502 |
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); // will pick defaults up |
482 |
remaining = remainingAsList.iterator(); |
503 |
remaining = remainingAsList.iterator(); |
Lines 536-542
Link Here
|
536 |
passed = false; |
557 |
passed = false; |
537 |
} |
558 |
} |
538 |
assertFalse("does not catch inappropriate -encoding option", passed); |
559 |
assertFalse("does not catch inappropriate -encoding option", passed); |
539 |
if (RUN_JAVAC) { |
560 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
540 |
// this fails, which may be deemed appropriate or not; but at least |
561 |
// this fails, which may be deemed appropriate or not; but at least |
541 |
// test #11 shows that the behavior that can be observed from the |
562 |
// test #11 shows that the behavior that can be observed from the |
542 |
// outside is inappropriate |
563 |
// outside is inappropriate |
Lines 573-579
Link Here
|
573 |
passed = false; |
594 |
passed = false; |
574 |
} |
595 |
} |
575 |
assertFalse("does not catch inappropriate -encoding option", passed); |
596 |
assertFalse("does not catch inappropriate -encoding option", passed); |
576 |
if (RUN_JAVAC) { |
597 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
577 |
// compared to what the command-line javac does, this is due to be a |
598 |
// compared to what the command-line javac does, this is due to be a |
578 |
// bug |
599 |
// bug |
579 |
passed = true; |
600 |
passed = true; |
Lines 584-596
Link Here
|
584 |
} catch (Throwable t) { |
605 |
} catch (Throwable t) { |
585 |
passed = false; |
606 |
passed = false; |
586 |
} |
607 |
} |
587 |
assertFalse("does not catch inappropriate -encoding option", passed); |
608 |
assertFalse("does not catch inappropriate -encoding option", passed); |
588 |
} |
609 |
} |
589 |
} |
610 |
} |
590 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=188796 |
611 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=188796 |
591 |
// files access must happen through the user-specified file manager |
612 |
// files access must happen through the user-specified file manager |
592 |
// simplest source read case |
613 |
// simplest source read case |
593 |
public void test012_files_access_read() throws IOException { |
614 |
public void test012_files_access_read() throws IOException { |
|
|
615 |
if (JAVAC_COMPILER == null) { |
616 |
System.out.println("No system java compiler available"); |
617 |
return; |
618 |
} |
594 |
GetJavaFileForInputDetector customJavaFileManager = |
619 |
GetJavaFileForInputDetector customJavaFileManager = |
595 |
new GetJavaFileForInputDetector( |
620 |
new GetJavaFileForInputDetector( |
596 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */)); |
621 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */)); |
Lines 612-618
Link Here
|
612 |
"X.class" |
637 |
"X.class" |
613 |
}); |
638 |
}); |
614 |
assertTrue(customJavaFileManager.matchFound); |
639 |
assertTrue(customJavaFileManager.matchFound); |
615 |
if (RUN_JAVAC) { |
640 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
616 |
customJavaFileManager.matchFound = false; |
641 |
customJavaFileManager.matchFound = false; |
617 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
642 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
618 |
Arrays.asList("-d", OUTPUT_DIR), null, |
643 |
Arrays.asList("-d", OUTPUT_DIR), null, |
Lines 625-633
Link Here
|
625 |
// files access must happen through the user-specified file manager |
650 |
// files access must happen through the user-specified file manager |
626 |
// source file accessed through the sourcepath |
651 |
// source file accessed through the sourcepath |
627 |
public void _test013_files_access_read() throws IOException { |
652 |
public void _test013_files_access_read() throws IOException { |
|
|
653 |
if (JAVAC_COMPILER == null) { |
654 |
System.out.println("No system java compiler available"); |
655 |
return; |
656 |
} |
628 |
GetJavaFileForInputDetector customJavaFileManager = |
657 |
GetJavaFileForInputDetector customJavaFileManager = |
629 |
new GetJavaFileForInputDetector( |
658 |
new GetJavaFileForInputDetector( |
630 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
659 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
631 |
"Y.java", Kind.SOURCE); |
660 |
"Y.java", Kind.SOURCE); |
632 |
List<String> options = Arrays.asList( |
661 |
List<String> options = Arrays.asList( |
633 |
"-d", OUTPUT_DIR, |
662 |
"-d", OUTPUT_DIR, |
Lines 654-660
Link Here
|
654 |
"X.class" |
683 |
"X.class" |
655 |
}); |
684 |
}); |
656 |
assertTrue(customJavaFileManager.matchFound); |
685 |
assertTrue(customJavaFileManager.matchFound); |
657 |
if (RUN_JAVAC) { |
686 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
658 |
customJavaFileManager.matchFound = false; |
687 |
customJavaFileManager.matchFound = false; |
659 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
688 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
660 |
options, null, |
689 |
options, null, |
Lines 669-675
Link Here
|
669 |
public void _test014_files_access_read() throws IOException { |
698 |
public void _test014_files_access_read() throws IOException { |
670 |
GetJavaFileForInputDetector customJavaFileManager = |
699 |
GetJavaFileForInputDetector customJavaFileManager = |
671 |
new GetJavaFileForInputDetector( |
700 |
new GetJavaFileForInputDetector( |
672 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
701 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
673 |
"Y.class", Kind.CLASS); |
702 |
"Y.class", Kind.CLASS); |
674 |
List<String> options = Arrays.asList( |
703 |
List<String> options = Arrays.asList( |
675 |
"-d", OUTPUT_DIR, |
704 |
"-d", OUTPUT_DIR, |
Lines 711-717
Link Here
|
711 |
"X.class" |
740 |
"X.class" |
712 |
}); |
741 |
}); |
713 |
assertTrue(customJavaFileManager.matchFound); |
742 |
assertTrue(customJavaFileManager.matchFound); |
714 |
if (RUN_JAVAC) { |
743 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
715 |
// javac merely throws an exception, which is due to be a bug on their |
744 |
// javac merely throws an exception, which is due to be a bug on their |
716 |
// side |
745 |
// side |
717 |
customJavaFileManager.matchFound = false; |
746 |
customJavaFileManager.matchFound = false; |
Lines 728-734
Link Here
|
728 |
public void test015_files_access_write() throws IOException { |
757 |
public void test015_files_access_write() throws IOException { |
729 |
GetJavaFileForOutputDetector customJavaFileManager = |
758 |
GetJavaFileForOutputDetector customJavaFileManager = |
730 |
new GetJavaFileForOutputDetector( |
759 |
new GetJavaFileForOutputDetector( |
731 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
760 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
732 |
"X.class"); |
761 |
"X.class"); |
733 |
List<String> options = Arrays.asList("-d", OUTPUT_DIR); |
762 |
List<String> options = Arrays.asList("-d", OUTPUT_DIR); |
734 |
runTest( |
763 |
runTest( |
Lines 750-756
Link Here
|
750 |
"X.class" |
779 |
"X.class" |
751 |
}); |
780 |
}); |
752 |
assertTrue(customJavaFileManager.matchFound); |
781 |
assertTrue(customJavaFileManager.matchFound); |
753 |
if (RUN_JAVAC) { |
782 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
754 |
customJavaFileManager.matchFound = false; |
783 |
customJavaFileManager.matchFound = false; |
755 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
784 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
756 |
options, null, |
785 |
options, null, |
Lines 765-771
Link Here
|
765 |
public void test016_files_access_write() throws IOException { |
794 |
public void test016_files_access_write() throws IOException { |
766 |
GetJavaFileForOutputDetector customJavaFileManager = |
795 |
GetJavaFileForOutputDetector customJavaFileManager = |
767 |
new GetJavaFileForOutputDetector( |
796 |
new GetJavaFileForOutputDetector( |
768 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
797 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
769 |
"Y.class"); |
798 |
"Y.class"); |
770 |
List<String> options = Arrays.asList( |
799 |
List<String> options = Arrays.asList( |
771 |
"-sourcepath", OUTPUT_DIR + File.separator + "src2"); |
800 |
"-sourcepath", OUTPUT_DIR + File.separator + "src2"); |
Lines 792-798
Link Here
|
792 |
"src/X.class" |
821 |
"src/X.class" |
793 |
}); |
822 |
}); |
794 |
assertTrue(customJavaFileManager.matchFound); |
823 |
assertTrue(customJavaFileManager.matchFound); |
795 |
if (RUN_JAVAC) { |
824 |
if (RUN_JAVAC && JAVAC_COMPILER != null) { |
796 |
customJavaFileManager.matchFound = false; |
825 |
customJavaFileManager.matchFound = false; |
797 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
826 |
assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, |
798 |
options, null, |
827 |
options, null, |
Lines 859-866
Link Here
|
859 |
} |
888 |
} |
860 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583 |
889 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583 |
861 |
public void test019_sourcepath_without_destination() throws IOException { |
890 |
public void test019_sourcepath_without_destination() throws IOException { |
|
|
891 |
String sourceDirectoryName = OUTPUT_DIR + "/src2"; |
892 |
File sourceFolder = new File(sourceDirectoryName); |
893 |
if (!sourceFolder.exists()) { |
894 |
if (!sourceFolder.mkdirs()) { |
895 |
// source folder could not be built |
896 |
return; |
897 |
} |
898 |
} |
862 |
StandardJavaFileManager ecjStandardJavaFileManager = |
899 |
StandardJavaFileManager ecjStandardJavaFileManager = |
863 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); |
900 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); |
864 |
assertTrue(ecjStandardJavaFileManager.handleOption( |
901 |
assertTrue(ecjStandardJavaFileManager.handleOption( |
865 |
"-sourcepath", |
902 |
"-sourcepath", |
866 |
Arrays.asList(OUTPUT_DIR + "/src2").iterator())); |
903 |
Arrays.asList(OUTPUT_DIR + "/src2").iterator())); |
Lines 890-896
Link Here
|
890 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583 |
927 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583 |
891 |
public void _test020_sourcepath_with_destination() throws IOException { |
928 |
public void _test020_sourcepath_with_destination() throws IOException { |
892 |
StandardJavaFileManager ecjStandardJavaFileManager = |
929 |
StandardJavaFileManager ecjStandardJavaFileManager = |
893 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); |
930 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); |
894 |
assertTrue(ecjStandardJavaFileManager.handleOption( |
931 |
assertTrue(ecjStandardJavaFileManager.handleOption( |
895 |
"-sourcepath", |
932 |
"-sourcepath", |
896 |
Arrays.asList("\"" + OUTPUT_DIR + "/src2\"[-d \"" + OUTPUT_DIR + "/bin2\"]").iterator())); |
933 |
Arrays.asList("\"" + OUTPUT_DIR + "/src2\"[-d \"" + OUTPUT_DIR + "/bin2\"]").iterator())); |
Lines 924-930
Link Here
|
924 |
errBuffer = new ByteArrayOutputStream(); |
961 |
errBuffer = new ByteArrayOutputStream(); |
925 |
CompilationTask task = COMPILER.getTask( |
962 |
CompilationTask task = COMPILER.getTask( |
926 |
new PrintWriter(outBuffer), |
963 |
new PrintWriter(outBuffer), |
927 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
964 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
928 |
new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), |
965 |
new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), |
929 |
Arrays.asList("-v"), null, null); |
966 |
Arrays.asList("-v"), null, null); |
930 |
assertTrue(task.call()); |
967 |
assertTrue(task.call()); |
Lines 953-959
Link Here
|
953 |
System.setErr(new PrintStream(errBuffer)); |
990 |
System.setErr(new PrintStream(errBuffer)); |
954 |
CompilationTask task = COMPILER.getTask( |
991 |
CompilationTask task = COMPILER.getTask( |
955 |
null, |
992 |
null, |
956 |
JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
993 |
COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), |
957 |
new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), |
994 |
new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), |
958 |
Arrays.asList("-v"), null, null); |
995 |
Arrays.asList("-v"), null, null); |
959 |
try { |
996 |
try { |