From a295c4fc12247eedfe5747b547d8ac7079f33533 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 22 Oct 2012 09:47:56 +0200 Subject: Ever since we do a lot more than just calling 'parse' when running delombok in our tests, the tests are in the unfortunate scenario where we always compile against a given javac (lib/build/javac6.jar), and always run the tests against a given javac, but that javac tries to use the bootclasspath of the host JRE, and if that is JRE7, you get all sorts of errors. I fixed it by still compiling against a given javac (we can only ship one lombok.jar after all), but having the test task run with a given bootclasspath and a given javac.jar. There are 2 tasks that download both rt.jar and javac.jar for either OpenJDK6 or OpenJDK7, and it writes a properties file with those locations. The test task will use this property file, and explain what you need to do if it is not there. Incidentally, this brought to light issue 422: Delombok in java7 produces VerifyErrors. --- .gitignore | 3 +- build.xml | 51 +++++++++++++++++++++++++-- src/delombok/lombok/delombok/Delombok.java | 16 +++++---- test/core/src/lombok/RunTestsViaDelombok.java | 2 ++ 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index a85c2d04..bc8b4ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/testenvironment.properties /bin /build /dist @@ -16,4 +17,4 @@ /lombok.iml /.idea *.markdown.html -/junit*.properties \ No newline at end of file +/junit*.properties diff --git a/build.xml b/build.xml index 5083bedf..960d4644 100644 --- a/build.xml +++ b/build.xml @@ -327,13 +327,60 @@ the common tasks and can be called on to run the main aspects of all the sub-scr - + + + + + + + + + + + + + Tests will now run against OpenJDK6 + + + + + + + + + + + Tests will now run against OpenJDK7 + + + + ERROR: No test environment set up. + +You need to set up a test environment, which consists of a version of javac, and a JRE runtime classpath ('rt.jar'). +Eventually, this environment concept will be extended to also includes an ecj and/or eclipse to test against. + +You can let this ant script set them up for you: + +* ant setupJava6TestEnvironment +* ant setupJava7TestEnvironment + +These will set up test environments based on OpenJDK6 and OpenJDK7 and some recent version of eclipse, and download all required files automatically. This will be a relatively large download. You can switch by running this command again; the downloads are cached so switching is fast. + +You can also create your own by writing a 'testenvironment.properties' file. The relevant properties are: + +* test.location.javac = /path/to/javac6.jar +* test.location.bootclasspath = /path/to/rt.jar + + + + + - + diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 3f521274..f67e3724 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -68,15 +68,11 @@ public class Delombok { this.presetWriter = writer; } - public Delombok() { -// context.put(DeleteLombokAnnotations.class, new DeleteLombokAnnotations(true)); - } - private PrintStream feedback = System.err; private boolean verbose; private boolean noCopy; private boolean force = false; - private String classpath, sourcepath; + private String classpath, sourcepath, bootclasspath; private LinkedHashMap fileToBase = new LinkedHashMap(); private List filesToParse = new ArrayList(); @@ -115,6 +111,9 @@ public class Delombok { @Description("Sourcepath (analogous to javac -sourcepath option)") private String sourcepath; + @Description("override Bootclasspath (analogous to javac -bootclasspath option)") + private String bootclasspath; + @Description("Files to delombok. Provide either a file, or a directory. If you use a directory, all files in it (recursive) are delombok-ed") @Sequential private List input = new ArrayList(); @@ -173,6 +172,7 @@ public class Delombok { if (args.classpath != null) delombok.setClasspath(args.classpath); if (args.sourcepath != null) delombok.setSourcepath(args.sourcepath); + if (args.bootclasspath != null) delombok.setBootclasspath(args.bootclasspath); try { for (String in : args.input) { @@ -230,6 +230,10 @@ public class Delombok { this.sourcepath = sourcepath; } + public void setBootclasspath(String bootclasspath) { + this.bootclasspath = bootclasspath; + } + public void setVerbose(boolean verbose) { this.verbose = verbose; } @@ -355,6 +359,7 @@ public class Delombok { options.put(OptionName.ENCODING, charset.name()); if (classpath != null) options.put(OptionName.CLASSPATH, classpath); if (sourcepath != null) options.put(OptionName.SOURCEPATH, sourcepath); + if (bootclasspath != null) options.put(OptionName.BOOTCLASSPATH, bootclasspath); options.put("compilePolicy", "attr"); CommentCatcher catcher = CommentCatcher.create(context); @@ -363,7 +368,6 @@ public class Delombok { List roots = new ArrayList(); Map baseMap = new IdentityHashMap(); - compiler.initProcessAnnotations(Collections.singleton(new lombok.javac.apt.Processor())); for (File fileToParse : filesToParse) { diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 52653e2e..e58cffc0 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -55,6 +55,8 @@ public class RunTestsViaDelombok extends AbstractRunTests { delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName()); delombok.setSourcepath(file.getAbsoluteFile().getParent()); + String bcp = System.getProperty("delombok.bootclasspath"); + if (bcp != null) delombok.setBootclasspath(bcp); delombok.setWriter(result); Locale originalLocale = Locale.getDefault(); try { -- cgit