From 0bbedd092a1f0f506d106943b4b400c7986c5f36 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 29 May 2020 00:17:20 +0200 Subject: [build] rewriting the build system --- test/core/src/lombok/DirectoryRunner.java | 12 ++++++++-- test/core/src/lombok/RunAllTests.java | 31 -------------------------- test/core/src/lombok/RunTestsViaDelombok.java | 4 ++++ test/core/src/lombok/RunTestsViaEcj.java | 20 ++++++++--------- test/core/src/lombok/TestBase.java | 31 ++++++++++++++++++++++++++ test/core/src/lombok/TestEclipse.java | 31 ++++++++++++++++++++++++++ test/core/src/lombok/TestJavac.java | 32 +++++++++++++++++++++++++++ 7 files changed, 117 insertions(+), 44 deletions(-) delete mode 100644 test/core/src/lombok/RunAllTests.java create mode 100644 test/core/src/lombok/TestBase.java create mode 100644 test/core/src/lombok/TestEclipse.java create mode 100644 test/core/src/lombok/TestJavac.java (limited to 'test/core/src/lombok') diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index b8b1da43..e4792ca9 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -82,8 +82,16 @@ public class DirectoryRunner extends Runner { private static final FileFilter JAVA_FILE_FILTER = new FileFilter() { @Override public boolean accept(File file) { - return file.isFile() && file.getName().endsWith(".java") && - (DEBUG_FOCUS_ON_FILE.isEmpty() || DEBUG_FOCUS_ON_FILE.contains(file.getName())); + if (!file.isFile() || !file.getName().endsWith(".java")) return false; + boolean positiveFilter = false; + for (String dfof : DEBUG_FOCUS_ON_FILE) { + if (!dfof.endsWith(".java")) dfof = dfof + ".java"; + boolean invert = dfof.startsWith("!"); + if (invert) dfof = dfof.substring(1); + positiveFilter = positiveFilter || !invert; + if (file.getName().equals(dfof)) return !invert; + } + return !positiveFilter; } }; diff --git a/test/core/src/lombok/RunAllTests.java b/test/core/src/lombok/RunAllTests.java deleted file mode 100644 index 1ca76af5..00000000 --- a/test/core/src/lombok/RunAllTests.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2011-2015 The Project Lombok Authors. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({lombok.transform.RunTransformTests.class, lombok.bytecode.RunBytecodeTests.class, lombok.core.configuration.RunConfigurationTests.class, lombok.core.RunCoreTests.class}) -public class RunAllTests { -} diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 0887de32..b766e7a4 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -29,16 +29,20 @@ import java.io.UnsupportedEncodingException; import java.util.Collection; import java.util.Locale; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; +import lombok.javac.Javac; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); + private static AtomicBoolean compilerVersionReported = new AtomicBoolean(); @Override public boolean transformCode(Collection messages, StringWriter result, final File file, String encoding, Map formatPreferences) throws Throwable { + if (!compilerVersionReported.getAndSet(true)) System.out.println("Javac version: " + Javac.getJavaCompilerVersion()); delombok.setVerbose(true); ChangedChecker cc = new ChangedChecker(); delombok.setFeedback(cc.feedback); diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 3efe38f5..77d1b75e 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -69,7 +69,8 @@ public class RunTestsViaEcj extends AbstractRunTests { warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore"); warnings.put(CompilerOptions.OPTION_ReportUnusedImport, "ignore"); warnings.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, "ignore"); - warnings.put(CompilerOptions.OPTION_Source, "1." + Eclipse.getEcjCompilerVersion()); + int ecjVersion = Eclipse.getEcjCompilerVersion(); + warnings.put(CompilerOptions.OPTION_Source, (ecjVersion < 9 ? "1." : "") + ecjVersion); options.set(warnings); return options; } @@ -137,16 +138,13 @@ public class RunTestsViaEcj extends AbstractRunTests { } if (new File("bin").exists()) classpath.add("bin"); classpath.add("dist/lombok.jar"); - classpath.add("lib/oracleJDK8Environment/rt.jar"); - classpath.add("lib/test/commons-logging-commons-logging.jar"); - classpath.add("lib/test/org.slf4j-slf4j-api.jar"); - classpath.add("lib/test/org.slf4j-slf4j-ext.jar"); - classpath.add("lib/test/log4j-log4j.jar"); - classpath.add("lib/test/org.apache.logging.log4j-log4j-api.jar"); - classpath.add("lib/test/org.jboss.logging-jboss-logging.jar"); - classpath.add("lib/test/com.google.guava-guava.jar"); - classpath.add("lib/test/com.google.code.findbugs-findbugs.jar"); - classpath.add("lib/test/com.google.flogger-flogger.jar"); + classpath.add("lib/openjdk6_rt.jar"); + for (File f : new File("lib/test").listFiles()) { + String fn = f.getName(); + if (fn.length() < 4) continue; + if (!fn.substring(fn.length() - 4).toLowerCase().equals(".jar")) continue; + classpath.add("lib/test/" + fn); + } return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8"); } } diff --git a/test/core/src/lombok/TestBase.java b/test/core/src/lombok/TestBase.java new file mode 100644 index 00000000..4b0c02f3 --- /dev/null +++ b/test/core/src/lombok/TestBase.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2011-2020 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({lombok.core.configuration.RunConfigurationTests.class, lombok.core.RunCoreTests.class}) +public class TestBase { +} diff --git a/test/core/src/lombok/TestEclipse.java b/test/core/src/lombok/TestEclipse.java new file mode 100644 index 00000000..9fe798bc --- /dev/null +++ b/test/core/src/lombok/TestEclipse.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2011-2020 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({lombok.transform.TestWithEcj.class}) +public class TestEclipse { +} diff --git a/test/core/src/lombok/TestJavac.java b/test/core/src/lombok/TestJavac.java new file mode 100644 index 00000000..340abb35 --- /dev/null +++ b/test/core/src/lombok/TestJavac.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2011-2020 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +//@SuiteClasses({lombok.bytecode.RunBytecodeTests.class, lombok.transform.TestLombokFilesIdempotent.class, lombok.transform.TestSourceFiles.class, lombok.transform.TestWithDelombok.class}) +@SuiteClasses({lombok.transform.TestLombokFilesIdempotent.class}) +public class TestJavac { +} -- cgit From cb7e4a9ef3f02d5a543f99d013b5034f50732293 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 3 Jul 2020 05:31:34 +0200 Subject: [build] propagate chosen bootclasspath into eclipse test targets --- buildScripts/compile.ant.xml | 18 +++++++++--------- buildScripts/create-eclipse-project.ant.xml | 2 ++ buildScripts/setup.ant.xml | 10 +++++----- buildScripts/tests.ant.xml | 6 +++--- .../lombok/eclipseCreate/CreateEclipseDebugTarget.java | 18 ++++++++++++++++-- test/core/src/lombok/AbstractRunTests.java | 4 ++-- test/core/src/lombok/LombokTestSource.java | 4 ++++ test/core/src/lombok/RunTestsViaDelombok.java | 2 +- test/core/src/lombok/RunTestsViaEcj.java | 11 +++++++---- 9 files changed, 49 insertions(+), 26 deletions(-) (limited to 'test/core/src/lombok') diff --git a/buildScripts/compile.ant.xml b/buildScripts/compile.ant.xml index 0bcc55bb..f0c0ef7e 100644 --- a/buildScripts/compile.ant.xml +++ b/buildScripts/compile.ant.xml @@ -30,7 +30,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil - + @@ -73,11 +73,11 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil However, the stubs themselves also have a ton of dependencies; to avoid _that_, we have stubs for stubs, too! --> - + - + @@ -108,19 +108,19 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil - + - + - + @@ -129,7 +129,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil - + @@ -141,7 +141,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil use API that didn't exist in those versions yet. --> - + @@ -157,7 +157,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil - + diff --git a/buildScripts/create-eclipse-project.ant.xml b/buildScripts/create-eclipse-project.ant.xml index 386ed3de..89e2f91f 100644 --- a/buildScripts/create-eclipse-project.ant.xml +++ b/buildScripts/create-eclipse-project.ant.xml @@ -69,6 +69,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede + @@ -82,6 +83,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede + diff --git a/buildScripts/setup.ant.xml b/buildScripts/setup.ant.xml index d6713222..6ab23897 100644 --- a/buildScripts/setup.ant.xml +++ b/buildScripts/setup.ant.xml @@ -29,9 +29,9 @@ This buildfile is part of projectlombok.org. It sets up the build itself. - + - + @@ -121,10 +121,10 @@ This buildfile is part of projectlombok.org. It sets up the build itself. - + To ensure stable builds and avoid accessing API that was not available in JDK6, most of lombok is set up to build against OpenJDK6's runtime, which will now be downloaded... - + @@ -133,7 +133,7 @@ This buildfile is part of projectlombok.org. It sets up the build itself. - + Supply ant with -Ddeps.conf=confname to pick the configuration you want to fetch diff --git a/buildScripts/tests.ant.xml b/buildScripts/tests.ant.xml index 67edf28a..d8559c5c 100644 --- a/buildScripts/tests.ant.xml +++ b/buildScripts/tests.ant.xml @@ -30,7 +30,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn - + @@ -77,9 +77,9 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn Running TestJavac on JVM${ant.java.version}, with lowest supported javac: 1.6. - + - + diff --git a/src/support/lombok/eclipseCreate/CreateEclipseDebugTarget.java b/src/support/lombok/eclipseCreate/CreateEclipseDebugTarget.java index d3b314cb..d00524f7 100644 --- a/src/support/lombok/eclipseCreate/CreateEclipseDebugTarget.java +++ b/src/support/lombok/eclipseCreate/CreateEclipseDebugTarget.java @@ -93,6 +93,8 @@ public class CreateEclipseDebugTarget { throw new InvalidCommandLineException("Cannot obtain canonical path to parent directory", e); } + String bootpath = getBootPath(); + launchContent.append("\t\t\n"); for (Map.Entry entry : args.entrySet()) { if (!entry.getKey().startsWith("conf.")) continue; @@ -111,7 +113,7 @@ public class CreateEclipseDebugTarget { } } } - launchContent.append("\t\t\n"); + if (bootpath != null) launchContent.append("\t\t\n"); launchContent.append("\t\n"); } @@ -120,6 +122,7 @@ public class CreateEclipseDebugTarget { launchContent.append("\t\n"); String jvmTarget = getArgString("jvmTarget"); + String bootpath = getBootPath(); launchContent.append("\t\n"); launchContent.append("\t\n"); launchContent.append("\t\n"); @@ -129,10 +132,21 @@ public class CreateEclipseDebugTarget { if (!entry.getKey().startsWith("conf.")) continue; launchContent.append(File.pathSeparator).append(entry.getValue()); } - launchContent.append(" -Ddelombok.bootclasspath=lib/openjdk6_rt.jar\"/>\n"); + if (bootpath != null) launchContent.append(" -Ddelombok.bootclasspath=" + bootpath + "\"/>\n"); launchContent.append("\n"); } + private String getBootPath() { + String bp = args.get("bootpath"); + if (bp == null) return null; + File f = new File(bp); + if (!f.isAbsolute()) return bp; + String r = new File(".").getAbsolutePath(); + if (r.endsWith(".")) r = r.substring(0, r.length() - 1); + if (bp.startsWith(r)) return bp.substring(r.length()); + throw new IllegalStateException("Cannot reconstruct relative path; base: " + r + " is not a parent of " + bp); + } + private String getArgString(String key) throws InvalidCommandLineException { String v = args.get(key); if (v == null) throw new InvalidCommandLineException("mandatory argument '" + key + "' missing"); diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index d223ae03..6d2b6312 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -91,7 +91,7 @@ public abstract class AbstractRunTests { } }); - boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences()); + boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion()); boolean forceUnchanged = sourceDirectives_.forceUnchanged() || sourceDirectives_.isSkipCompareContent(); if (params.expectChanges() && !forceUnchanged && !changed) messages.add(new CompilerMessage(-1, -1, true, "not flagged modified")); if (!params.expectChanges() && changed) messages.add(new CompilerMessage(-1, -1, true, "unexpected modification")); @@ -101,7 +101,7 @@ public abstract class AbstractRunTests { }; } - protected abstract boolean transformCode(Collection messages, StringWriter result, File file, String encoding, Map formatPreferences) throws Throwable; + protected abstract boolean transformCode(Collection messages, StringWriter result, File file, String encoding, Map formatPreferences, int minVersion) throws Throwable; protected String readFile(File file) throws IOException { BufferedReader reader; diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java index b04f0ba0..57a32333 100644 --- a/test/core/src/lombok/LombokTestSource.java +++ b/test/core/src/lombok/LombokTestSource.java @@ -358,4 +358,8 @@ public class LombokTestSource { if (specifiedEncoding == null || specifiedEncoding.equalsIgnoreCase(encoding)) return source; return read0(sourceFolder, messagesFolder, fileName, specifiedEncoding); } + + public int minVersion() { + return Math.max(6, versionLowerLimit); + } } diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index b766e7a4..4260f2da 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -41,7 +41,7 @@ public class RunTestsViaDelombok extends AbstractRunTests { private static AtomicBoolean compilerVersionReported = new AtomicBoolean(); @Override - public boolean transformCode(Collection messages, StringWriter result, final File file, String encoding, Map formatPreferences) throws Throwable { + public boolean transformCode(Collection messages, StringWriter result, final File file, String encoding, Map formatPreferences, int version) throws Throwable { if (!compilerVersionReported.getAndSet(true)) System.out.println("Javac version: " + Javac.getJavaCompilerVersion()); delombok.setVerbose(true); ChangedChecker cc = new ChangedChecker(); diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 77d1b75e..ab28cb0c 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -93,7 +93,7 @@ public class RunTestsViaEcj extends AbstractRunTests { } @Override - public boolean transformCode(Collection messages, StringWriter result, File file, String encoding, Map formatPreferences) throws Throwable { + public boolean transformCode(Collection messages, StringWriter result, File file, String encoding, Map formatPreferences, int minVersion) throws Throwable { final AtomicReference compilationResult_ = new AtomicReference(); final AtomicReference compilationUnit_ = new AtomicReference(); ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { @@ -105,7 +105,7 @@ public class RunTestsViaEcj extends AbstractRunTests { String source = readFile(file); final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding); - Compiler ecjCompiler = new Compiler(createFileSystem(file), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) { + Compiler ecjCompiler = new Compiler(createFileSystem(file, minVersion), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) { @Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) { if (inUnit == sourceUnit) compilationUnit_.set(parsedUnit); super.addCompilationUnit(inUnit, parsedUnit); @@ -129,7 +129,9 @@ public class RunTestsViaEcj extends AbstractRunTests { return true; } - private FileSystem createFileSystem(File file) { + private static final String bootRuntimePath = System.getProperty("delombok.bootclasspath"); + + private FileSystem createFileSystem(File file, int minVersion) { List classpath = new ArrayList(); for (Iterator i = classpath.iterator(); i.hasNext();) { if (FileSystem.getClasspath(i.next(), "UTF-8", null) == null) { @@ -138,7 +140,8 @@ public class RunTestsViaEcj extends AbstractRunTests { } if (new File("bin").exists()) classpath.add("bin"); classpath.add("dist/lombok.jar"); - classpath.add("lib/openjdk6_rt.jar"); + if (bootRuntimePath == null || bootRuntimePath.isEmpty()) throw new IllegalStateException("System property delombok.bootclasspath is not set; set it to the rt of java6 or java8"); + classpath.add(bootRuntimePath); for (File f : new File("lib/test").listFiles()) { String fn = f.getName(); if (fn.length() < 4) continue; -- cgit From 933d75c2fe1dc69e2d0b08649e26d4d5939c2a64 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 3 Jul 2020 05:32:16 +0200 Subject: [test] [bugfix] far too few tests were being selected for the 'javac' target. --- test/core/src/lombok/TestJavac.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/core/src/lombok') diff --git a/test/core/src/lombok/TestJavac.java b/test/core/src/lombok/TestJavac.java index 340abb35..fbc495ad 100644 --- a/test/core/src/lombok/TestJavac.java +++ b/test/core/src/lombok/TestJavac.java @@ -26,7 +26,6 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -//@SuiteClasses({lombok.bytecode.RunBytecodeTests.class, lombok.transform.TestLombokFilesIdempotent.class, lombok.transform.TestSourceFiles.class, lombok.transform.TestWithDelombok.class}) -@SuiteClasses({lombok.transform.TestLombokFilesIdempotent.class}) +@SuiteClasses({lombok.bytecode.RunBytecodeTests.class, lombok.transform.TestLombokFilesIdempotent.class, lombok.transform.TestSourceFiles.class, lombok.transform.TestWithDelombok.class}) public class TestJavac { } -- cgit From 1fd2401bade3db3bb3a1bd88727823776f39be0c Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 10 Jul 2020 02:50:38 +0200 Subject: [test] more flexible options for limiting your tests. --- .../eclipse/handlers/HandleSuperBuilder.java | 23 +++++++++++----------- test/core/src/lombok/AbstractRunTests.java | 18 +++++++++++++++++ test/core/src/lombok/DirectoryRunner.java | 10 ++++++++-- 3 files changed, 38 insertions(+), 13 deletions(-) (limited to 'test/core/src/lombok') diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 2ba456da..b1e7c419 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -145,9 +145,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { generateBuilderMethod = true; } if (!checkName("buildMethodName", buildMethodName, annotationNode)) return; - + boolean toBuilder = superbuilderAnnotation.toBuilder(); - + EclipseNode tdParent = annotationNode.up(); java.util.List builderFields = new ArrayList(); @@ -234,7 +234,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { TypeReference extendsClause = td.superclass; TypeReference superclassBuilderClass = null; TypeReference[] typeArguments = new TypeReference[] { - new SingleTypeReference(classGenericName.toCharArray(), 0), + new SingleTypeReference(classGenericName.toCharArray(), 0), new SingleTypeReference(builderGenericName.toCharArray(), 0) }; if (extendsClause instanceof QualifiedTypeReference) { @@ -333,14 +333,14 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { cleanDecl.type = TypeReference.baseTypeReference(TypeIds.T_boolean, 0); injectFieldAndMarkGenerated(builderType, cleanDecl); } - + if (toBuilder) { // Generate $fillValuesFrom() method in the abstract builder. injectMethod(builderType, generateFillValuesMethod(tdParent, superclassBuilderClass != null, builderGenericName, classGenericName, builderClassName, typeParams)); // Generate $fillValuesFromInstanceIntoBuilder() method in the builder implementation class. injectMethod(builderType, generateStaticFillValuesMethod(tdParent, builderClassName, typeParams, builderFields, ast, superbuilderAnnotation.setterPrefix())); } - + // Generate abstract self() and build() methods in the abstract builder. injectMethod(builderType, generateAbstractSelfMethod(cfv, tdParent, superclassBuilderClass != null, builderGenericName)); injectMethod(builderType, generateAbstractBuildMethod(cfv, builderType, buildMethodName, builderFields, superclassBuilderClass != null, classGenericName, ast)); @@ -386,7 +386,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { } sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(builderImplType, annotationNode); } - + if (toBuilder) { // Add the toBuilder() method to the annotated class. switch (methodExists(TO_BUILDER_METHOD_NAME_STRING, tdParent, 0)) { @@ -399,9 +399,10 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { // Should not happen. } } - + // Create the self() and build() methods in the BuilderImpl. injectMethod(builderImplType, generateSelfMethod(cfv, builderImplType, typeParams, p)); + if (methodExists(buildMethodName, builderImplType, -1) == MemberExistsResult.NOT_EXISTS) { injectMethod(builderImplType, generateBuildMethod(cfv, builderImplType, buildMethodName, returnType, builderFields, ast)); } @@ -419,7 +420,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { } } } - + private EclipseNode generateBuilderAbstractClass(EclipseNode tdParent, String builderClass, TypeReference superclassBuilderClass, TypeParameter[] typeParams, ASTNode source, String classGenericName, String builderGenericName) { @@ -448,7 +449,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { builder.superclass = copyType(superclassBuilderClass, source); builder.createDefaultConstructor(false, true); - + builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return injectType(tdParent, builder); } @@ -806,8 +807,8 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.modifiers = ClassFileConstants.AccProtected; Annotation overrideAnn = makeMarkerAnnotation(TypeConstants.JAVA_LANG_OVERRIDE, builderImplType.get()); - Annotation rrAnn = cfv.generateReturnsReceiver() ? generateNamedAnnotation(builderImplType.get(), CheckerFrameworkVersion.NAME__RETURNS_RECEIVER): null; - Annotation sefAnn = cfv.generatePure() ? generateNamedAnnotation(builderImplType.get(), CheckerFrameworkVersion.NAME__PURE): null; + Annotation rrAnn = cfv.generateReturnsReceiver() ? generateNamedAnnotation(builderImplType.get(), CheckerFrameworkVersion.NAME__RETURNS_RECEIVER) : null; + Annotation sefAnn = cfv.generatePure() ? generateNamedAnnotation(builderImplType.get(), CheckerFrameworkVersion.NAME__PURE) : null; if (rrAnn != null && sefAnn != null) out.annotations = new Annotation[] {overrideAnn, rrAnn, sefAnn}; else if (rrAnn != null) out.annotations = new Annotation[] {overrideAnn, rrAnn}; else if (sefAnn != null) out.annotations = new Annotation[] {overrideAnn, sefAnn}; diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 6d2b6312..8e73e122 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -190,6 +190,8 @@ public abstract class AbstractRunTests { for (CompilerMessage actualMessage : actualMessages) { System.out.println(actualMessage); } + System.out.println("**** Actual File ******"); + System.out.println(lineNumber(actualFile)); System.out.println("*******************"); } if (dumpActualFilesHere != null) { @@ -199,6 +201,22 @@ public abstract class AbstractRunTests { } } + private CharSequence lineNumber(String content) { + StringBuilder out = new StringBuilder(); + int pos = 0; + int ln = 1; + while (true) { + out.append(String.format("%4d ", ln)); + int idx = content.indexOf('\n', pos); + if (idx == -1) { + return out.append(content.substring(pos)); + } + out.append(content.substring(pos, idx + 1)); + ln++; + pos = idx + 1; + } + } + @SuppressWarnings("null") /* eclipse bug workaround; it falsely thinks stuffAc will always be null. */ private static void compareMessages(String name, LombokImmutableList expected, LinkedHashSet actual) { Iterator expectedIterator = expected.iterator(); diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index e4792ca9..a174355d 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -47,7 +47,7 @@ public class DirectoryRunner extends Runner { @Override public int getVersion() { return Javac.getJavaCompilerVersion(); } - }, + }, JAVAC { @Override public int getVersion() { return DELOMBOK.getVersion(); @@ -85,11 +85,17 @@ public class DirectoryRunner extends Runner { if (!file.isFile() || !file.getName().endsWith(".java")) return false; boolean positiveFilter = false; for (String dfof : DEBUG_FOCUS_ON_FILE) { + if (dfof.isEmpty()) continue; if (!dfof.endsWith(".java")) dfof = dfof + ".java"; boolean invert = dfof.startsWith("!"); if (invert) dfof = dfof.substring(1); positiveFilter = positiveFilter || !invert; - if (file.getName().equals(dfof)) return !invert; + int starIdx = dfof.indexOf('*'); + if (starIdx == -1) { + if (file.getName().equals(dfof)) return !invert; + } else { + if (file.getName().startsWith(dfof.substring(0, starIdx)) && file.getName().endsWith(dfof.substring(starIdx + 1))) return !invert; + } } return !positiveFilter; } -- cgit From e6cbb7fbe66f618c8ec9b43c7995c512b25c975f Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 23 Jul 2020 22:49:21 +0200 Subject: [tests] [trivial] stop printing the javac version ... when running javac tests --- test/core/src/lombok/RunTestsViaDelombok.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'test/core/src/lombok') diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 4260f2da..ffac8372 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -29,20 +29,16 @@ import java.io.UnsupportedEncodingException; import java.util.Collection; import java.util.Locale; import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; -import lombok.javac.Javac; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); - private static AtomicBoolean compilerVersionReported = new AtomicBoolean(); @Override public boolean transformCode(Collection messages, StringWriter result, final File file, String encoding, Map formatPreferences, int version) throws Throwable { - if (!compilerVersionReported.getAndSet(true)) System.out.println("Javac version: " + Javac.getJavaCompilerVersion()); delombok.setVerbose(true); ChangedChecker cc = new ChangedChecker(); delombok.setFeedback(cc.feedback); -- cgit From d4bd359d21c223d6f8dc012c409f7262c4f51bb4 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Wed, 29 Jul 2020 09:42:07 +0200 Subject: [test] [bugfix] Compare full line instead of ignoring the last character --- test/core/src/lombok/AbstractRunTests.java | 2 +- test/transform/resource/after-delombok/GetterSetterJavadoc.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/core/src/lombok') diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 8e73e122..448f77ab 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -285,7 +285,7 @@ public abstract class AbstractRunTests { endIdx--; } - return in.substring(0, endIdx); + return in.substring(0, endIdx + 1); } private static String[] removeBlanks(String[] in) { diff --git a/test/transform/resource/after-delombok/GetterSetterJavadoc.java b/test/transform/resource/after-delombok/GetterSetterJavadoc.java index ae662da7..78d120a4 100644 --- a/test/transform/resource/after-delombok/GetterSetterJavadoc.java +++ b/test/transform/resource/after-delombok/GetterSetterJavadoc.java @@ -115,7 +115,7 @@ class GetterSetterJavadoc4 { /** * Some text * - * @param fieldName Hello, World5 + * @param fieldName Hello, World4 * @return {@code this}. */ @java.lang.SuppressWarnings("all") -- cgit From 9148294f78a8e646ee131ca182a9b692bc028fdb Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sat, 29 Aug 2020 04:14:10 +0200 Subject: [testing] [eclipse] [#2413] Eclipse tests now more expansive We now test generating a level2-DOM from our level1-AST (eclipse has 3 levels of ASTs, more or less), only if that is possible, i.e. only if the full eclipse is available. This requires using a test target named `eclipse-X`, and not one of the `ecjX` ones. This is the change that requires the massive update to the build system. About 6 tests, including a newly added one about @Delegate, now fail. These failures would usually not cause instant failure in eclipse, but can cause errors during save actions and will likely mess with other things in weird ways, such as messing up syntax highlighting. Yes, this commit now makes a bunch of cases fail the unit tests, but that is representative of actual errors in lombok, so I'm checking it in as is (without this commit, the problem is still there, the tests are just incapable of detecting it). --- buildScripts/ivy.xml | 1 + test/core/src/lombok/RunTestsViaEcj.java | 79 +++++++++++++++++++++- .../after-delombok/DelegateWithVarargs2.java | 12 ++++ .../resource/after-ecj/DelegateWithVarargs2.java | 17 +++++ .../resource/before/DelegateWithVarargs2.java | 9 +++ 5 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 test/transform/resource/after-delombok/DelegateWithVarargs2.java create mode 100644 test/transform/resource/after-ecj/DelegateWithVarargs2.java create mode 100644 test/transform/resource/before/DelegateWithVarargs2.java (limited to 'test/core/src/lombok') diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 40bbad08..3dfbde7e 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -94,6 +94,7 @@ + diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index ab28cb0c..739d6316 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 The Project Lombok Authors. + * Copyright (C) 2010-2020 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,25 +23,33 @@ package lombok; import java.io.File; import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; +import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; import lombok.eclipse.Eclipse; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.Compiler; import org.eclipse.jdt.internal.compiler.ICompilerRequestor; import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; -import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; import org.eclipse.jdt.internal.compiler.batch.FileSystem; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; @@ -103,7 +111,8 @@ public class RunTestsViaEcj extends AbstractRunTests { }; String source = readFile(file); - final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding); + char[] sourceArray = source.toCharArray(); + final org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(sourceArray, file.getName(), encoding == null ? "UTF-8" : encoding); Compiler ecjCompiler = new Compiler(createFileSystem(file, minVersion), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) { @Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) { @@ -126,11 +135,75 @@ public class RunTestsViaEcj extends AbstractRunTests { if (cud == null) result.append("---- No CompilationUnit provided by ecj ----"); else result.append(cud.toString()); + if (eclipseAvailable()) { + EclipseDomConversion.toDomAst(cud, sourceArray); + } + + return true; + } + + private boolean eclipseAvailable() { + try { + Class.forName("org.eclipse.jdt.core.dom.CompilationUnit"); + } catch (Throwable t) { + return false; + } + return true; } private static final String bootRuntimePath = System.getProperty("delombok.bootclasspath"); + private static class EclipseDomConversion { + static CompilationUnit toDomAst(CompilationUnitDeclaration cud, final char[] source) { + Map options = new HashMap(); + options.put(JavaCore.COMPILER_SOURCE, "11"); + options.put("org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures", "enabled"); + try { + org.eclipse.jdt.internal.core.CompilationUnit ccu = new org.eclipse.jdt.internal.core.CompilationUnit(null, null, null) { + @Override public char[] getContents() { + return source; + } + }; + return AST.convertCompilationUnit(4, cud, options, false, ccu, 0, null); + } catch (SecurityException e) { + try { + debugClasspathConflicts("org/eclipse/jdt/internal/compiler"); + } catch (Exception e2) { + throw Lombok.sneakyThrow(e2); + } + throw e; + } + } + } + + @SuppressWarnings({"all"}) + private static void debugClasspathConflicts(String prefixToLookFor) throws Exception { + String[] paths = System.getProperty("java.class.path").split(":"); + for (String p : paths) { + Path cp = Paths.get(p); + if (Files.isDirectory(cp)) { + if (Files.isDirectory(cp.resolve(prefixToLookFor))) System.out.println("** DIR-BASED: " + cp); + } else if (Files.isRegularFile(cp)) { + JarFile jf = new JarFile(cp.toFile()); + try { + Enumeration jes = jf.entries(); + while (jes.hasMoreElements()) { + JarEntry je = jes.nextElement(); + if (je.getName().startsWith(prefixToLookFor)) { + System.out.println("** JAR-BASED: " + cp); + break; + } + } + } finally { + jf.close(); + } + } else { + System.out.println("** MISSING: " + cp); + } + } + } + private FileSystem createFileSystem(File file, int minVersion) { List classpath = new ArrayList(); for (Iterator i = classpath.iterator(); i.hasNext();) { diff --git a/test/transform/resource/after-delombok/DelegateWithVarargs2.java b/test/transform/resource/after-delombok/DelegateWithVarargs2.java new file mode 100644 index 00000000..a8ff6e3b --- /dev/null +++ b/test/transform/resource/after-delombok/DelegateWithVarargs2.java @@ -0,0 +1,12 @@ +class DelegateWithVarargs2 { + private DelegateWithVarargs2.B bar; + public class B { + public void varargs(Object[]... keys) { + } + } + @java.lang.SuppressWarnings("all") + public void varargs(final java.lang.Object[]... keys) { + this.bar.varargs(keys); + } +} + diff --git a/test/transform/resource/after-ecj/DelegateWithVarargs2.java b/test/transform/resource/after-ecj/DelegateWithVarargs2.java new file mode 100644 index 00000000..ed0cddf5 --- /dev/null +++ b/test/transform/resource/after-ecj/DelegateWithVarargs2.java @@ -0,0 +1,17 @@ +import lombok.experimental.Delegate; +class DelegateWithVarargs2 { + public class B { + public B() { + super(); + } + public void varargs(Object[]... keys) { + } + } + private @Delegate DelegateWithVarargs2.B bar; + DelegateWithVarargs2() { + super(); + } + public @java.lang.SuppressWarnings("all") void varargs(final java.lang.Object[]... keys) { + this.bar.varargs(keys); + } +} diff --git a/test/transform/resource/before/DelegateWithVarargs2.java b/test/transform/resource/before/DelegateWithVarargs2.java new file mode 100644 index 00000000..8a3dbf14 --- /dev/null +++ b/test/transform/resource/before/DelegateWithVarargs2.java @@ -0,0 +1,9 @@ +import lombok.experimental.Delegate; + +class DelegateWithVarargs2 { + @Delegate private DelegateWithVarargs2.B bar; + + public class B { + public void varargs(Object[]... keys) {} + } +} -- cgit