93 import toolbox.Task.OutputKind; |
93 import toolbox.Task.OutputKind; |
94 |
94 |
95 public class AnnotationProcessing extends ModuleTestBase { |
95 public class AnnotationProcessing extends ModuleTestBase { |
96 |
96 |
97 public static void main(String... args) throws Exception { |
97 public static void main(String... args) throws Exception { |
|
98 System.out.println(System.getProperties()); |
98 new AnnotationProcessing().runTests(); |
99 new AnnotationProcessing().runTests(); |
99 } |
100 } |
100 |
101 |
101 @Test |
102 @Test |
102 public void testAPSingleModule(Path base) throws Exception { |
103 public void testAPSingleModule(Path base) throws Exception { |
566 classes, |
567 classes, |
567 "createClass(() -> filer.createClassFile(\"" + module + "api1.Impl\"" + originating + "), \"api1.Impl\", \"package api1; public class Impl {}\")", |
568 "createClass(() -> filer.createClassFile(\"" + module + "api1.Impl\"" + originating + "), \"api1.Impl\", \"package api1; public class Impl {}\")", |
568 "--module-source-path", moduleSrc.toString()); |
569 "--module-source-path", moduleSrc.toString()); |
569 assertFileExists(classes, "m1x", "api1", "Impl.class"); |
570 assertFileExists(classes, "m1x", "api1", "Impl.class"); |
570 |
571 |
571 deleteFile(m1.resolve("test").resolve("Test.java")); |
572 tb.deleteFiles(m1.resolve("test").resolve("Test.java")); |
572 |
573 |
573 //resource class output: |
574 //resource class output: |
574 runCompiler(base, |
575 runCompiler(base, |
575 moduleSrc, |
576 moduleSrc, |
576 classes, |
577 classes, |
621 "--module-source-path", moduleSrc.toString(), |
622 "--module-source-path", moduleSrc.toString(), |
622 "--default-module-for-created-files=m1x"); |
623 "--default-module-for-created-files=m1x"); |
623 assertFileExists(classes, "m1x", pack, "Pass.class"); |
624 assertFileExists(classes, "m1x", pack, "Pass.class"); |
624 assertFileNotExists(classes, "m2x", pack, "Pass.class"); |
625 assertFileNotExists(classes, "m2x", pack, "Pass.class"); |
625 |
626 |
626 deleteFile(m1.resolve("test").resolve("Test.java")); |
627 tb.deleteFiles(m1.resolve("test").resolve("Test.java")); |
627 |
628 |
628 runCompiler(base, |
629 runCompiler(base, |
629 moduleSrc, |
630 moduleSrc, |
630 classes, |
631 classes, |
631 "createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT," + |
632 "createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT," + |
692 failingCode, |
693 failingCode, |
693 "--module-source-path", moduleSrc.toString()); |
694 "--module-source-path", moduleSrc.toString()); |
694 } |
695 } |
695 } |
696 } |
696 |
697 |
697 private void deleteFile(Path file) throws IOException { |
|
698 long startTime = System.currentTimeMillis(); |
|
699 |
|
700 do { |
|
701 Files.delete(file); |
|
702 if (!Files.exists(file)) { |
|
703 return; |
|
704 } |
|
705 System.err.println("!! File not deleted !!"); |
|
706 System.gc(); // allow finalizers and cleaners to run |
|
707 try { |
|
708 Thread.sleep(RETRY_DELETE_MILLIS); |
|
709 } catch (InterruptedException e) { |
|
710 throw new IOException("Interrupted while deleting " + file, e); |
|
711 } |
|
712 } while ((System.currentTimeMillis() - startTime) <= MAX_RETRY_DELETE_MILLIS); |
|
713 |
|
714 throw new IOException("Can't delete " + file); |
|
715 } |
|
716 |
|
717 |
|
718 private static final int RETRY_DELETE_MILLIS; |
|
719 private static final int MAX_RETRY_DELETE_MILLIS; |
|
720 |
|
721 static { |
|
722 boolean isWindows = System.getProperty("os.name").startsWith("Windows"); |
|
723 RETRY_DELETE_MILLIS = isWindows ? 500 : 0; |
|
724 MAX_RETRY_DELETE_MILLIS = isWindows ? 15 * 1000 : 0; |
|
725 } |
|
726 |
|
727 public static abstract class GeneratingAP extends AbstractProcessor { |
698 public static abstract class GeneratingAP extends AbstractProcessor { |
728 |
699 |
729 public void createSource(CreateFileObject file, String name, String content) { |
700 public void createSource(CreateFileObject file, String name, String content) { |
730 try (Writer out = file.create().openWriter()) { |
701 try (Writer out = file.create().openWriter()) { |
731 out.write(content); |
702 out.write(content); |
870 classes, |
841 classes, |
871 "createClass(() -> filer.createClassFile(\"" + module + "impl.Impl\"" + originating + "), \"impl.Impl\", \"package impl; public class Impl {}\")", |
842 "createClass(() -> filer.createClassFile(\"" + module + "impl.Impl\"" + originating + "), \"impl.Impl\", \"package impl; public class Impl {}\")", |
872 options); |
843 options); |
873 assertFileExists(classes, modulePath, "impl", "Impl.class"); |
844 assertFileExists(classes, modulePath, "impl", "Impl.class"); |
874 |
845 |
875 deleteFile(m1.resolve("test").resolve("Test.java")); |
846 tb.deleteFiles(m1.resolve("test").resolve("Test.java")); |
876 |
847 |
877 //resource class output: |
848 //resource class output: |
878 runCompiler(base, |
849 runCompiler(base, |
879 m1, |
850 m1, |
880 classes, |
851 classes, |
897 m1, |
868 m1, |
898 classes, |
869 classes, |
899 "expectFilerException(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"m1x/impl\", \"resource\"))", |
870 "expectFilerException(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"m1x/impl\", \"resource\"))", |
900 "-sourcepath", m1.toString()); |
871 "-sourcepath", m1.toString()); |
901 |
872 |
902 deleteFile(m1.resolve("impl").resolve("resource")); |
873 tb.deleteFiles(m1.resolve("impl").resolve("resource")); |
903 |
874 |
904 //can read resources from the system module path if module name given: |
875 //can read resources from the system module path if module name given: |
905 runCompiler(base, |
876 runCompiler(base, |
906 m1, |
877 m1, |
907 classes, |
878 classes, |