diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar index dade3bccfab..4270e97d59a 100644 Binary files a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar and b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar differ 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 8b91a666339..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; @@ -217,4 +218,81 @@ public void testBug530665() throws IOException { assertTrue(!preexistsFile.exists()); // deleted assertTrue(nonexistsFile.exists()); // rewritten } + public void testGHIssue2347_1() 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:full"); + options.add("-verbose"); + StringWriter stringWriter = new StringWriter(); + BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null); + folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + 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(); + 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:only"); + options.add("-proc:full"); + options.add("-verbose"); + StringWriter stringWriter = new StringWriter(); + BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null); + folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + 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(); + 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"); + options.add("-verbose"); + StringWriter stringWriter = new StringWriter(); + BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null); + folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090"); + 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(); + 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.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..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"); 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); }