Skip to content

Commit

Permalink
Add -proc:full to batch compiler eclipse-jdt#2347 (eclipse-jdt#3440)
Browse files Browse the repository at this point in the history
-proc:full is an explicit compiler argument to do full compilation and process annotations, which is the default compiler behavior.
eclipse-jdt#3440
  • Loading branch information
jarthana authored Dec 13, 2024
1 parent abe441a commit 93d8dc5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 5 deletions.
Binary file modified org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> 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<String> 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<String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public static void compileTree(JavaCompiler compiler, List<String> options, File
compileTree(compiler, options, targetFolder, false);
}

public static void compileTree(StringWriter stringWriter, JavaCompiler compiler, List<String> options, File targetFolder,
DiagnosticListener<? super JavaFileObject> listener) {
compileTree(stringWriter, compiler, options, targetFolder, false, listener);
}

public static void compileTree(JavaCompiler compiler, List<String> options, File targetFolder,
DiagnosticListener<? super JavaFileObject> listener) {
compileTree(compiler, options, targetFolder, false, listener);
Expand Down Expand Up @@ -230,13 +235,18 @@ public int compare(File f1, File f2) {
public static void compileTree(JavaCompiler compiler, List<String> options,
File targetFolder, boolean useJLS8Processors,
DiagnosticListener<? super JavaFileObject> listener) {
StringWriter stringWriter = new StringWriter();
compileTree(stringWriter, compiler, options, targetFolder, useJLS8Processors, listener);
}
public static void compileTree(StringWriter stringWriter, JavaCompiler compiler, List<String> options,
File targetFolder, boolean useJLS8Processors,
DiagnosticListener<? super JavaFileObject> listener) {
StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());

// create new list containing inputfile
List<File> files = new ArrayList<>();
findFilesUnder(targetFolder, files);
Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);

options.add("-d");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2471,20 +2471,30 @@ public void configure(String[] argv) {
continue;
}
if (currentArg.equals("-proc:only")) { //$NON-NLS-1$
disableAnnotationProcessing = false;
this.options.put(
CompilerOptions.OPTION_GenerateClassFiles,
CompilerOptions.DISABLED);
mode = DEFAULT;
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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 93d8dc5

Please sign in to comment.