From d87edbae6e52607dcca82bf28e8d1c430a7a9100 Mon Sep 17 00:00:00 2001 From: Jay Arthanareeswaran Date: Thu, 12 Dec 2024 11:45:53 +0530 Subject: [PATCH 1/4] Add -proc:full to batch compiler #2347 --- .../lib/apttestprocessors8.jar | Bin 330091 -> 330091 bytes .../apt/tests/AnnotationProcessorTests.java | 54 ++++++++++++++++++ .../jdt/internal/compiler/batch/Main.java | 17 ++++-- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar index dade3bccfab462cd604952654d7d1646775a2d14..4270e97d59a810eb7947911631f147426113b698 100644 GIT binary patch delta 137 zcmaDoN#yk;5#9iAW)=|!4h{~6m$5yKyjyu06S options = new ArrayList<>(); + final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc"; + options.add("-processorpath"); + options.add(" "); + options.add("-processor"); + options.add(PROC); + options.add("-proc:only"); + options.add("-proc:full"); + BatchTestUtils.compileTree(compiler, options, folder, null); + folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + File classfile = new File(folder, "B.class"); + assertTrue(classfile.exists()); + } + public void testGHIssue2347_2() throws IOException { + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder); + List options = new ArrayList<>(); + final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc"; + options.add("-processorpath"); + options.add(" "); + options.add("-processor"); + options.add(PROC); + options.add("-proc:none"); + options.add("-proc:full"); + BatchTestUtils.compileTree(compiler, options, folder, null); + folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + File classfile = new File(folder, "B.class"); + assertTrue(classfile.exists()); + } + public void testGHIssue2347_3() throws IOException { + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder); + List options = new ArrayList<>(); + final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc"; + options.add("-processorpath"); + options.add(" "); + options.add("-processor"); + options.add(PROC); + options.add("-proc:none"); + options.add("-proc:only"); + BatchTestUtils.compileTree(compiler, options, folder, null); + folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + File classfile = new File(folder, "B.class"); + assertFalse(classfile.exists()); + folder = TestUtils.concatPath(BatchTestUtils.getGenFolderName(), "gen"); + classfile = new File(folder, "GenClass.java"); + assertTrue(classfile.exists()); + } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java index aa14a6cc1d1..1f413ea4892 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -1783,7 +1783,7 @@ public void configure(String[] argv) { boolean didSpecifyDeprecation = false; boolean didSpecifyCompliance = false; - boolean didSpecifyDisabledAnnotationProcessing = false; + boolean disableAnnotationProcessing = false; String customEncoding = null; String customDestinationPath = null; @@ -2471,6 +2471,7 @@ public void configure(String[] argv) { continue; } if (currentArg.equals("-proc:only")) { //$NON-NLS-1$ + disableAnnotationProcessing = false; this.options.put( CompilerOptions.OPTION_GenerateClassFiles, CompilerOptions.DISABLED); @@ -2478,13 +2479,22 @@ public void configure(String[] argv) { continue; } if (currentArg.equals("-proc:none")) { //$NON-NLS-1$ - didSpecifyDisabledAnnotationProcessing = true; + disableAnnotationProcessing = true; this.options.put( CompilerOptions.OPTION_Process_Annotations, CompilerOptions.DISABLED); mode = DEFAULT; continue; } + if (currentArg.equals("-proc:full")) { //$NON-NLS-1$ + // Enable, just in case we had a -proc:only before this that disabled this + this.options.put( + CompilerOptions.OPTION_GenerateClassFiles, + CompilerOptions.ENABLED); + disableAnnotationProcessing = false; + mode = DEFAULT; + continue; + } if (currentArg.equals("-s")) { //$NON-NLS-1$ mode = INSIDE_S_start; continue; @@ -2942,8 +2952,7 @@ public void configure(String[] argv) { // Enable annotation processing by default in batch mode when compliance is at least 1.6 // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=185768 - if (!didSpecifyDisabledAnnotationProcessing - && CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) >= ClassFileConstants.JDK1_6) { + if (!disableAnnotationProcessing) { this.options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); } From 9f92d801e8b7eecbbd840ccd44e28aca70ec81a3 Mon Sep 17 00:00:00 2001 From: Jay Arthanareeswaran Date: Thu, 12 Dec 2024 17:39:40 +0530 Subject: [PATCH 2/4] Troubleshoot logs --- .../apt/tests/AnnotationProcessorTests.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java index 2ce4c2e0e88..b15a96e4706 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java @@ -227,10 +227,15 @@ public void testGHIssue2347_1() throws IOException { options.add(" "); options.add("-processor"); options.add(PROC); - options.add("-proc:only"); options.add("-proc:full"); BatchTestUtils.compileTree(compiler, options, folder, null); folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + List files = new ArrayList<>(); + BatchTestUtils.findFilesUnder(folder, files); + System.out.println("testGHIssue2347_1(): Files found under binary folder: <" + folder + ">"); + for (File file : files) { + System.out.println(file); + } File classfile = new File(folder, "B.class"); assertTrue(classfile.exists()); } @@ -244,14 +249,43 @@ public void testGHIssue2347_2() throws IOException { options.add(" "); options.add("-processor"); options.add(PROC); - options.add("-proc:none"); + options.add("-proc:only"); options.add("-proc:full"); BatchTestUtils.compileTree(compiler, options, folder, null); folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + List files = new ArrayList<>(); + BatchTestUtils.findFilesUnder(folder, files); + System.out.println("testGHIssue2347_2(): Files found under binary folder: <" + folder + ">"); + for (File file : files) { + System.out.println(file); + } File classfile = new File(folder, "B.class"); assertTrue(classfile.exists()); } public void testGHIssue2347_3() throws IOException { + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder); + List options = new ArrayList<>(); + final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc"; + options.add("-processorpath"); + options.add(" "); + options.add("-processor"); + options.add(PROC); + options.add("-proc:none"); + options.add("-proc:full"); + BatchTestUtils.compileTree(compiler, options, folder, null); + folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + List files = new ArrayList<>(); + BatchTestUtils.findFilesUnder(folder, files); + System.out.println("testGHIssue2347_3(): Files found under binary folder: <" + folder + ">"); + for (File file : files) { + System.out.println(file); + } + File classfile = new File(folder, "B.class"); + assertTrue(classfile.exists()); + } + public void testGHIssue2347_4() throws IOException { JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder); From 6cf7c880041b5affd443f7d459586ab965a01309 Mon Sep 17 00:00:00 2001 From: Jay Arthanareeswaran Date: Thu, 12 Dec 2024 19:17:30 +0530 Subject: [PATCH 3/4] More troubleshooting --- .../jdt/compiler/apt/tests/AnnotationProcessorTests.java | 1 + .../src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java index b15a96e4706..d81a4853aa5 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java @@ -228,6 +228,7 @@ public void testGHIssue2347_1() throws IOException { options.add("-processor"); options.add(PROC); options.add("-proc:full"); + options.add("-verbose"); BatchTestUtils.compileTree(compiler, options, folder, null); folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); List files = new ArrayList<>(); diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java index 49ac68913dd..e33b4c9b02b 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java @@ -245,7 +245,7 @@ public static void compileTree(JavaCompiler compiler, List options, options.add(_tmpGenFolderName); addProcessorPaths(options, useJLS8Processors, true); options.add("-XprintRounds"); - CompilationTask task = compiler.getTask(printWriter, manager, listener, options, null, units); + CompilationTask task = compiler.getTask(null, manager, listener, options, null, units); Boolean result = task.call(); if (!result.booleanValue()) { From 2c8796e1a3232b495cb4a03017f3cf0373b27289 Mon Sep 17 00:00:00 2001 From: Jay Arthanareeswaran Date: Thu, 12 Dec 2024 22:22:13 +0530 Subject: [PATCH 4/4] Look for verbose output rather than looking for .class files --- .../apt/tests/AnnotationProcessorTests.java | 43 +++++++------------ .../compiler/apt/tests/BatchTestUtils.java | 14 +++++- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java index d81a4853aa5..fc4d67452ca 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; +import java.io.StringWriter; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -229,16 +230,11 @@ public void testGHIssue2347_1() throws IOException { options.add(PROC); options.add("-proc:full"); options.add("-verbose"); - BatchTestUtils.compileTree(compiler, options, folder, null); + StringWriter stringWriter = new StringWriter(); + BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null); folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); - List files = new ArrayList<>(); - BatchTestUtils.findFilesUnder(folder, files); - System.out.println("testGHIssue2347_1(): Files found under binary folder: <" + folder + ">"); - for (File file : files) { - System.out.println(file); - } - File classfile = new File(folder, "B.class"); - assertTrue(classfile.exists()); + String output = stringWriter.getBuffer().toString(); + assertTrue("Files not generated as expected", output.contains("[3 .class files generated]")); } public void testGHIssue2347_2() throws IOException { JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); @@ -252,16 +248,13 @@ public void testGHIssue2347_2() throws IOException { options.add(PROC); options.add("-proc:only"); options.add("-proc:full"); - BatchTestUtils.compileTree(compiler, options, folder, null); + options.add("-verbose"); + StringWriter stringWriter = new StringWriter(); + BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null); folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); - List files = new ArrayList<>(); - BatchTestUtils.findFilesUnder(folder, files); - System.out.println("testGHIssue2347_2(): Files found under binary folder: <" + folder + ">"); - for (File file : files) { - System.out.println(file); - } - File classfile = new File(folder, "B.class"); - assertTrue(classfile.exists()); + String output = stringWriter.getBuffer().toString(); + assertTrue("Files not generated as expected", output.contains("[3 .class files generated]")); + } public void testGHIssue2347_3() throws IOException { JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); @@ -275,16 +268,12 @@ public void testGHIssue2347_3() throws IOException { options.add(PROC); options.add("-proc:none"); options.add("-proc:full"); - BatchTestUtils.compileTree(compiler, options, folder, null); + options.add("-verbose"); + StringWriter stringWriter = new StringWriter(); + BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null); folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); - List files = new ArrayList<>(); - BatchTestUtils.findFilesUnder(folder, files); - System.out.println("testGHIssue2347_3(): Files found under binary folder: <" + folder + ">"); - for (File file : files) { - System.out.println(file); - } - File classfile = new File(folder, "B.class"); - assertTrue(classfile.exists()); + String output = stringWriter.getBuffer().toString(); + assertTrue("Files not generated as expected", output.contains("[3 .class files generated]")); } public void testGHIssue2347_4() throws IOException { JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java index e33b4c9b02b..65be47f0cd6 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java @@ -137,6 +137,11 @@ public static void compileTree(JavaCompiler compiler, List options, File compileTree(compiler, options, targetFolder, false); } + public static void compileTree(StringWriter stringWriter, JavaCompiler compiler, List options, File targetFolder, + DiagnosticListener listener) { + compileTree(stringWriter, compiler, options, targetFolder, false, listener); + } + public static void compileTree(JavaCompiler compiler, List options, File targetFolder, DiagnosticListener listener) { compileTree(compiler, options, targetFolder, false, listener); @@ -230,13 +235,18 @@ public int compare(File f1, File f2) { public static void compileTree(JavaCompiler compiler, List options, File targetFolder, boolean useJLS8Processors, DiagnosticListener listener) { + StringWriter stringWriter = new StringWriter(); + compileTree(stringWriter, compiler, options, targetFolder, useJLS8Processors, listener); + } + public static void compileTree(StringWriter stringWriter, JavaCompiler compiler, List options, + File targetFolder, boolean useJLS8Processors, + DiagnosticListener listener) { StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); // create new list containing inputfile List files = new ArrayList<>(); findFilesUnder(targetFolder, files); Iterable units = manager.getJavaFileObjectsFromFiles(files); - StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); options.add("-d"); @@ -245,7 +255,7 @@ public static void compileTree(JavaCompiler compiler, List options, options.add(_tmpGenFolderName); addProcessorPaths(options, useJLS8Processors, true); options.add("-XprintRounds"); - CompilationTask task = compiler.getTask(null, manager, listener, options, null, units); + CompilationTask task = compiler.getTask(printWriter, manager, listener, options, null, units); Boolean result = task.call(); if (!result.booleanValue()) {