aboutsummaryrefslogtreecommitdiff
path: root/test/core
diff options
context:
space:
mode:
Diffstat (limited to 'test/core')
-rw-r--r--test/core/src/lombok/DirectoryRunner.java3
-rw-r--r--test/core/src/lombok/LombokTestSource.java5
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java96
3 files changed, 97 insertions, 7 deletions
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index a174355d..93b18039 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -180,7 +180,8 @@ public class DirectoryRunner extends Runner {
case DELOMBOK:
return new RunTestsViaDelombok().createTester(params, file, "javac", params.getVersion());
case ECJ:
- return new RunTestsViaEcj().createTester(params, file, "ecj", params.getVersion());
+ String platform = RunTestsViaEcj.eclipseAvailable() ? "eclipse" : "ecj";
+ return new RunTestsViaEcj().createTester(params, file, platform, params.getVersion());
default:
case JAVAC:
throw new UnsupportedOperationException();
diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java
index a0a6407a..e23a0f57 100644
--- a/test/core/src/lombok/LombokTestSource.java
+++ b/test/core/src/lombok/LombokTestSource.java
@@ -65,7 +65,10 @@ public class LombokTestSource {
public boolean runOnPlatform(String platform) {
if (platforms == null || platforms.isEmpty()) return true;
- for (String pl : platforms) if (pl.equalsIgnoreCase(platform)) return true;
+ for (String pl : platforms) {
+ if (pl.startsWith("!") && pl.regionMatches(true, 1, platform, 0, platform.length())) return false;
+ if (pl.equalsIgnoreCase(platform)) return true;
+ }
return false;
}
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index b98c19b7..1d840a21 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -35,6 +35,14 @@ import java.util.concurrent.atomic.AtomicReference;
import lombok.eclipse.Eclipse;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
+import org.eclipse.core.internal.registry.ExtensionRegistry;
+import org.eclipse.core.internal.runtime.Activator;
+import org.eclipse.core.internal.runtime.PlatformActivator;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.eclipse.core.runtime.spi.IRegistryProvider;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.CharOperation;
@@ -49,6 +57,9 @@ import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+import org.eclipse.jdt.internal.core.JavaModelManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
public class RunTestsViaEcj extends AbstractRunTests {
protected CompilerOptions ecjCompilerOptions() {
@@ -107,7 +118,17 @@ public class RunTestsViaEcj extends AbstractRunTests {
String source = readFile(file);
char[] sourceArray = source.toCharArray();
- final ICompilationUnit sourceUnit = new TestCompilationUnit(file.getName(), source);
+ final ICompilationUnit sourceUnit;
+ try {
+ if (eclipseAvailable()) {
+ sourceUnit = new TestCompilationUnitEclipse(file.getName(), source);
+ } else {
+ sourceUnit = new TestCompilationUnitEcj(file.getName(), source);
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return false;
+ }
Compiler ecjCompiler = new Compiler(createFileSystem(file, minVersion), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {
@Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) {
@@ -116,6 +137,8 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
};
+ // initializeEclipseBundles();
+
ecjCompiler.compile(new ICompilationUnit[] {sourceUnit});
CompilationResult compilationResult = compilationResult_.get();
@@ -137,7 +160,37 @@ public class RunTestsViaEcj extends AbstractRunTests {
return true;
}
- private boolean eclipseAvailable() {
+ @SuppressWarnings("unused")
+ private static class EclipseInitializer {
+ static void initializeEclipseBundles() throws Exception {
+ // This code does not work yet, it's research-in-progress.
+ // The problem is that parts of the eclipse handler (in `PatchValEclipse` and friends) do not work unless
+ // an actual eclipse exists; PatchVal causes code to run that will end up running `ResourcesPlugin.getWorkspace()`, which
+ // goes down a rabbit hole of pinging off of various static fields (or `getX()` calls which return static fields), all
+ // of which are `null` until the plugin they belong to is properly initialized.
+ // This code is work in progress to 'hack' the initialization of each plugin one-by-one, but I doubt this is the right
+ // way to do it, as I bet it's fragile (will break when eclipse updates rather easily), and who knows how many fields
+ // and things need to be initialized.
+ // A better plan would be to start an actual, real eclipse, by telling `EclipseStarter.startup` to launch some sort of
+ // application (or at least a bunch of bundles/products/apps, including the JDT). This will then take long enough that
+ // it'll need to be cached and re-used for each test or the Eclipse test run would take far too long.
+
+ BundleContext context = EclipseStarter.startup(new String[0], null);
+ RegistryFactory.setDefaultRegistryProvider(new IRegistryProvider() {
+ private final ExtensionRegistry REG = new ExtensionRegistry(null, null, null);
+ @Override public IExtensionRegistry getRegistry() {
+ return REG;
+ }
+ });
+ new Activator().start(context);
+ new PlatformActivator().start(context);
+ for (Bundle b : context.getBundles()) System.out.println("BUNDLE: " + b.getSymbolicName());
+ new ResourcesPlugin().start(context);
+ JavaModelManager.getJavaModelManager().startup();
+ }
+ }
+
+ static boolean eclipseAvailable() {
try {
Class.forName("org.eclipse.jdt.core.dom.CompilationUnit");
} catch (Throwable t) {
@@ -171,7 +224,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
i.remove();
}
}
- if (new File("bin").exists()) classpath.add("bin");
+ if (new File("bin/main").exists()) classpath.add("bin/main");
classpath.add("dist/lombok.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);
@@ -184,11 +237,44 @@ public class RunTestsViaEcj extends AbstractRunTests {
return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8");
}
- private static final class TestCompilationUnit extends org.eclipse.jdt.internal.core.CompilationUnit {
+ private static final class TestCompilationUnitEcj implements ICompilationUnit {
+ private final char[] name, source, mainTypeName;
+
+ TestCompilationUnitEcj(String name, String source) {
+ this.source = source.toCharArray();
+ this.name = name.toCharArray();
+
+ char[] fileNameCharArray = getFileName();
+ int start = CharOperation.lastIndexOf(File.separatorChar, fileNameCharArray) + 1;
+ int end = CharOperation.lastIndexOf('.', fileNameCharArray);
+ if (end == -1) {
+ end = fileNameCharArray.length;
+ }
+ mainTypeName = CharOperation.subarray(fileNameCharArray, start, end);
+ }
+
+ @Override public char[] getFileName() {
+ return name;
+ }
+
+ @Override public char[] getContents() {
+ return source;
+ }
+
+ @Override public char[] getMainTypeName() {
+ return mainTypeName;
+ }
+
+ @Override public char[][] getPackageName() {
+ return null;
+ }
+ }
+
+ private static final class TestCompilationUnitEclipse extends org.eclipse.jdt.internal.core.CompilationUnit {
private final char[] source;
private final char[] mainTypeName;
- private TestCompilationUnit(String name, String source) {
+ private TestCompilationUnitEclipse(String name, String source) {
super(null, name, null);
this.source = source.toCharArray();