From 2ee2dbd8f9993a08e9ad281bfa73e2b6c5d01ee8 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 30 Sep 2014 13:46:30 +0200 Subject: first take on the shadow classloader. All seems to be in order, but we still have to solve the problem with adding our shadow loader to the equinox infrastructure (solved in lombok currently by adding all of lombok to the bootclasspath), and all the public API still has to be kept as actual class files by build.xml. Currently it is all shadowed away. --- src/core/lombok/core/Agent.java | 138 ---------------------------------------- src/core/lombok/core/Main.java | 1 + 2 files changed, 1 insertion(+), 138 deletions(-) delete mode 100644 src/core/lombok/core/Agent.java (limited to 'src/core') diff --git a/src/core/lombok/core/Agent.java b/src/core/lombok/core/Agent.java deleted file mode 100644 index 49c03bf3..00000000 --- a/src/core/lombok/core/Agent.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2009 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.core; - -import java.lang.instrument.ClassFileTransformer; -import java.lang.instrument.IllegalClassFormatException; -import java.lang.instrument.Instrumentation; -import java.security.ProtectionDomain; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - -public abstract class Agent { - protected abstract void runAgent(String agentArgs, Instrumentation instrumentation, boolean injected) throws Exception; - - public static void agentmain(String agentArgs, Instrumentation instrumentation) throws Throwable { - runAgents(agentArgs, instrumentation, true); - } - - public static void premain(String agentArgs, Instrumentation instrumentation) throws Throwable { - runAgents(agentArgs, instrumentation, false); - } - - private static final List AGENTS = Collections.unmodifiableList(Arrays.asList( - new NetbeansPatcherInfo(), - new EclipsePatcherInfo() - )); - - private static void runAgents(String agentArgs, Instrumentation instrumentation, boolean injected) throws Throwable { - for (AgentInfo info : AGENTS) { - try { - Class agentClass = Class.forName(info.className()); - Agent agent = (Agent) agentClass.newInstance(); - agent.runAgent(agentArgs, instrumentation, injected); - } catch (Throwable t) { - info.problem(t, instrumentation); - } - } - } - - private static abstract class AgentInfo { - abstract String className(); - - /** - * Called if an exception occurs while loading the agent represented by this AgentInfo object. - * - * @param t The throwable. - * @param instrumentation In case you want to take an alternative action. - */ - void problem(Throwable t, Instrumentation instrumentation) throws Throwable { - if (t instanceof ClassNotFoundException) { - //That's okay - this lombok evidently is a version with support for something stripped out. - return; - } - - if (t instanceof ClassCastException) { - throw new InternalError("Lombok bug. Class: " + className() + " is not an implementation of lombok.core.Agent"); - } - - if (t instanceof IllegalAccessError) { - throw new InternalError("Lombok bug. Class: " + className() + " is not public"); - } - - if (t instanceof InstantiationException) { - throw new InternalError("Lombok bug. Class: " + className() + " is not concrete or has no public no-args constructor"); - } - - throw t; - } - } - - private static class NetbeansPatcherInfo extends AgentInfo { - @Override String className() { - return "lombok.netbeans.agent.NetbeansPatcher"; - } - - @Override void problem(Throwable in, Instrumentation instrumentation) throws Throwable { - try { - super.problem(in, instrumentation); - } catch (InternalError ie) { - throw ie; - } catch (Throwable t) { - final String error; - - if (t instanceof UnsupportedClassVersionError) { - error = "Lombok only works on netbeans if you start netbeans using a 1.6 or higher JVM.\n" + - "Change your platform's default JVM, or edit etc/netbeans.conf\n" + - "and explicitly tell netbeans your 1.6 JVM's location."; - } else { - error = "Lombok disabled due to error: " + t; - } - - instrumentation.addTransformer(new ClassFileTransformer() { - @Override public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { - if ("org/netbeans/modules/java/source/parsing/JavacParser".equals(className)) { - //If that class gets loaded, this is definitely a netbeans(-esque) environment, and thus we SHOULD tell the user that lombok is not in fact loaded. - SwingUtilities.invokeLater(new Runnable() { - @Override public void run() { - JOptionPane.showMessageDialog(null, error, "Lombok Disabled", JOptionPane.ERROR_MESSAGE); - } - }); - } - - return null; - } - }); - } - } - } - - private static class EclipsePatcherInfo extends AgentInfo { - @Override String className() { - return "lombok.eclipse.agent.EclipsePatcher"; - } - } -} diff --git a/src/core/lombok/core/Main.java b/src/core/lombok/core/Main.java index d62fe3e4..0856d3b3 100644 --- a/src/core/lombok/core/Main.java +++ b/src/core/lombok/core/Main.java @@ -38,6 +38,7 @@ public class Main { )); public static void main(String[] args) throws IOException { + Thread.currentThread().setContextClassLoader(Main.class.getClassLoader()); int err = new Main(SpiLoadUtil.readAllFromIterator( SpiLoadUtil.findServices(LombokApp.class)), Arrays.asList(args)).go(); System.exit(err); -- cgit From 5407d0d253baa0cba1e5b7374f9ca45b5c50f622 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 24 Oct 2014 00:11:43 +0200 Subject: Making SCL work right is more complicated than it first seemed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now the rules are: * _IF_ a class is being loaded, sourced by a lombok-jar originating class, we FIRST search the lombok jar, and if we can’t find it, farm out the job to the originating equinox-side loader. * _IF_ the equinox-side loader attempts to load a class, and it does NOT start with lombok, we don’t interfere and would never serve up any content from the lombok-jar (so if we have deps, they do NOT get loaded, by design). If it DOES start with lombok, we load it, and the loading class is SCL, not the equinox-side loader. * getResource() to load classes did not work (because internally classes end in .SCL.lombok and not .class). This breaks a bunch of things. Fixed by having getResource() be aware that it should try rewriting any request for a .class to .SCL.lombok. * launchified annotationprocessor, and cleaned up the launchified agent, which now, like all other launchers, just sets up classloader stuff and then calls into the lombok loader side to finish the actual processing, instead of trying to do it itself in a handicapped environment that can’t load much. --- src/core/lombok/core/AgentLauncher.java | 86 +++++++++++++++++++++++++++++++++ src/core/lombok/core/PostCompiler.java | 8 ++- 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/core/lombok/core/AgentLauncher.java (limited to 'src/core') diff --git a/src/core/lombok/core/AgentLauncher.java b/src/core/lombok/core/AgentLauncher.java new file mode 100644 index 00000000..1d5ab3e6 --- /dev/null +++ b/src/core/lombok/core/AgentLauncher.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2009-2014 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.core; + +import java.lang.instrument.Instrumentation; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class AgentLauncher { + public interface AgentLaunchable { + void runAgent(String agentArgs, Instrumentation instrumentation, boolean injected, Class launchingContext) throws Exception; + } + + public static void runAgents(String agentArgs, Instrumentation instrumentation, boolean injected, Class launchingContext) throws Throwable { + for (AgentInfo info : AGENTS) { + try { + Class agentClass = Class.forName(info.className()); + AgentLaunchable agent = (AgentLaunchable) agentClass.newInstance(); + agent.runAgent(agentArgs, instrumentation, injected, launchingContext); + } catch (Throwable t) { + info.problem(t, instrumentation); + } + } + } + + private static final List AGENTS = Collections.unmodifiableList(Arrays.asList( + new EclipsePatcherInfo() + )); + + private static abstract class AgentInfo { + abstract String className(); + + /** + * Called if an exception occurs while loading the agent represented by this AgentInfo object. + * + * @param t The throwable. + * @param instrumentation In case you want to take an alternative action. + */ + void problem(Throwable t, Instrumentation instrumentation) throws Throwable { + if (t instanceof ClassNotFoundException) { + //That's okay - this lombok evidently is a version with support for something stripped out. + return; + } + + if (t instanceof ClassCastException) { + throw new InternalError("Lombok bug. Class: " + className() + " is not an implementation of lombok.core.Agent"); + } + + if (t instanceof IllegalAccessError) { + throw new InternalError("Lombok bug. Class: " + className() + " is not public"); + } + + if (t instanceof InstantiationException) { + throw new InternalError("Lombok bug. Class: " + className() + " is not concrete or has no public no-args constructor"); + } + + throw t; + } + } + + private static class EclipsePatcherInfo extends AgentInfo { + @Override String className() { + return "lombok.eclipse.agent.EclipsePatcher"; + } + } +} diff --git a/src/core/lombok/core/PostCompiler.java b/src/core/lombok/core/PostCompiler.java index 11091cb8..237867cb 100644 --- a/src/core/lombok/core/PostCompiler.java +++ b/src/core/lombok/core/PostCompiler.java @@ -24,6 +24,8 @@ package lombok.core; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.Collections; import java.util.List; @@ -55,10 +57,12 @@ public final class PostCompiler { transformations = SpiLoadUtil.readAllFromIterator(SpiLoadUtil.findServices(PostCompilerTransformation.class, PostCompilerTransformation.class.getClassLoader())); } catch (IOException e) { transformations = Collections.emptyList(); - diagnostics.addWarning("Could not load post-compile transformers: " + e.getMessage()); + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw, true)); + diagnostics.addWarning("Could not load post-compile transformers: " + e.getMessage() + "\n" + sw.toString()); } } - + public static OutputStream wrapOutputStream(final OutputStream originalStream, final String fileName, final DiagnosticsReceiver diagnostics) throws IOException { if (System.getProperty("lombok.disablePostCompiler", null) != null) return originalStream; return new ByteArrayOutputStream() { -- cgit From 6959fa42a0830b848bae2205977409ed17f12990 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 28 Oct 2014 22:20:27 +0100 Subject: Installer updated to no longer add -Xbootclasspath. --- src/core/lombok/core/Version.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/lombok/core/Version.java b/src/core/lombok/core/Version.java index 9f810525..02bc1af0 100644 --- a/src/core/lombok/core/Version.java +++ b/src/core/lombok/core/Version.java @@ -30,7 +30,7 @@ public class Version { // ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries). // Note: In 'X.Y.Z', if Z is odd, its a snapshot build built from the repository, so many different 0.10.3 versions can exist, for example. // Official builds always end in an even number. (Since 0.10.2). - private static final String VERSION = "1.14.9"; + private static final String VERSION = "1.14.9.shadow"; private static final String RELEASE_NAME = "Edgy Guinea Pig"; // private static final String RELEASE_NAME = "Branching Cobra"; -- cgit From 932dc55b1ab88f66c64bba62d4181ee6e044490f Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 4 Dec 2014 02:10:35 +0100 Subject: fix for lombok not compiling if JDK8’s javac is used as default compiler. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/lombok/eclipse/handlers/HandlePrintAST.java | 2 +- src/core/lombok/javac/handlers/HandlePrintAST.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/lombok/eclipse/handlers/HandlePrintAST.java b/src/core/lombok/eclipse/handlers/HandlePrintAST.java index 0b61bc4d..234e29b8 100644 --- a/src/core/lombok/eclipse/handlers/HandlePrintAST.java +++ b/src/core/lombok/eclipse/handlers/HandlePrintAST.java @@ -59,7 +59,7 @@ public class HandlePrintAST extends EclipseAnnotationHandler { try { stream.close(); } catch (Exception e) { - Lombok.sneakyThrow(e); + throw Lombok.sneakyThrow(e); } } } diff --git a/src/core/lombok/javac/handlers/HandlePrintAST.java b/src/core/lombok/javac/handlers/HandlePrintAST.java index 9a52b9d9..0826d1d1 100644 --- a/src/core/lombok/javac/handlers/HandlePrintAST.java +++ b/src/core/lombok/javac/handlers/HandlePrintAST.java @@ -59,7 +59,7 @@ public class HandlePrintAST extends JavacAnnotationHandler { try { stream.close(); } catch (Exception e) { - Lombok.sneakyThrow(e); + throw Lombok.sneakyThrow(e); } } } -- cgit