aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2021-11-08 14:39:53 +0100
committerRawi01 <Rawi01@users.noreply.github.com>2022-05-20 00:08:05 +0200
commitd2d97539d26f6023ffc4565286f08427c4e8b41c (patch)
tree4a25e66e48b41143bb03d8c5ec9a6f7f8241ee61 /src/eclipseAgent/lombok
parent59717d0c95d62b0b1bedd49ac4a047663a55da22 (diff)
downloadlombok-d2d97539d26f6023ffc4565286f08427c4e8b41c.tar.gz
lombok-d2d97539d26f6023ffc4565286f08427c4e8b41c.tar.bz2
lombok-d2d97539d26f6023ffc4565286f08427c4e8b41c.zip
Add support for eclipse feature tests
Diffstat (limited to 'src/eclipseAgent/lombok')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java10
-rwxr-xr-xsrc/eclipseAgent/lombok/launch/PatchFixesHider.java25
2 files changed, 35 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index d893b724..c0bfbe09 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -109,6 +109,8 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
patchRenameField(sm);
patchNullCheck(sm);
+ patchForTests(sm);
+
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
@@ -1007,5 +1009,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.transplant()
.build());
}
+
+ private static void patchForTests(ScriptManager sm) {
+ sm.addScriptIfWitness(new String[] {"lombok/eclipse/EclipseTests"}, ScriptBuilder.wrapReturnValue()
+ .target(new MethodTarget("org.osgi.framework.FrameworkUtil", "getBundle", "org.osgi.framework.Bundle", "java.lang.Class"))
+ .request(StackRequest.RETURN_VALUE, StackRequest.PARAM1)
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$Tests", "getBundle", "java.lang.Object", "java.lang.Object", "java.lang.Class"))
+ .build());
+ }
}
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index a844239f..c7bdbc31 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -27,6 +27,7 @@ import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.security.CodeSource;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
@@ -854,4 +855,28 @@ final class PatchFixesHider {
return isGenerated(adjustment.getMember());
}
}
+
+ public static class Tests {
+ public static Object getBundle(Object original, Class<?> c) {
+ if (original != null) {
+ return original;
+ }
+
+ CodeSource codeSource = c.getProtectionDomain().getCodeSource();
+ if (codeSource == null) {
+ return null;
+ }
+
+ String jar = codeSource.getLocation().getFile();
+ String bundleName = jar.substring(jar.lastIndexOf("/") + 1, jar.indexOf("_"));
+
+ org.osgi.framework.Bundle[] bundles = org.eclipse.core.runtime.adaptor.EclipseStarter.getSystemBundleContext().getBundles();
+ for (org.osgi.framework.Bundle bundle : bundles) {
+ if (bundleName.equals(bundle.getSymbolicName())) {
+ return bundle;
+ }
+ }
+ return null;
+ }
+ }
}