diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-10-11 07:54:25 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-10-11 07:54:25 +0200 |
commit | 310862d94e3a4705faf0d2b6ed9cdb40247b39ca (patch) | |
tree | 473e2aa65e2cf064181193a15bab633e81bb0c11 | |
parent | e2ffd58f81b6762429d0f27dc9977aa0e1721ae6 (diff) | |
download | lombok-310862d94e3a4705faf0d2b6ed9cdb40247b39ca.tar.gz lombok-310862d94e3a4705faf0d2b6ed9cdb40247b39ca.tar.bz2 lombok-310862d94e3a4705faf0d2b6ed9cdb40247b39ca.zip |
Integrated lombok.jar and lombok.eclipse.agent.jar into one jar that installs, is a javac apt processor, and an agent, all at once.
-rw-r--r-- | buildScripts/compile.ant.xml | 49 | ||||
-rw-r--r-- | buildScripts/deps.ant.xml | 8 | ||||
-rw-r--r-- | lib/README | 3 | ||||
-rw-r--r-- | lib/lombok/lombok-patcher.jar (renamed from lib/eclipse.agent/lombok-patcher.jar) | bin | 1490329 -> 1497998 bytes | |||
-rw-r--r-- | lib/netbeans.agent/.gitkeep | 1 | ||||
-rw-r--r-- | src/lombok/eclipse/TransformEclipseAST.java | 36 | ||||
-rw-r--r-- | src/lombok/installer/EclipseLocation.java | 71 | ||||
-rw-r--r-- | src/lombok/installer/Installer.java | 4 | ||||
-rw-r--r-- | src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java | 25 |
9 files changed, 69 insertions, 128 deletions
diff --git a/buildScripts/compile.ant.xml b/buildScripts/compile.ant.xml index 82ee07f7..075bc394 100644 --- a/buildScripts/compile.ant.xml +++ b/buildScripts/compile.ant.xml @@ -34,35 +34,21 @@ lombok code including the various agents.</description> </loadresource> </target> - <fileset dir="src" id="eclipse.agent.main.deps"> - <include name="lombok/core/SpiLoadUtil.java" /> - <include name="lombok/Lombok.java" /> - </fileset> - <path id="deps.path"> <fileset dir="deps/lombok"> <include name="**/*.jar" /> </fileset> </path> - <path id="lombok.libs.path"> + <path id="libs.path"> <fileset dir="lib/lombok"> <include name="**/*.jar" /> </fileset> </path> - <path id="eclipse.agent.libs.path"> - <fileset dir="lib/eclipse.agent"> - <include name="**/*.jar" /> - </fileset> - </path> - <target name="-unpackLibs"> <unjar dest="build/lombok"> - <path refid="lombok.libs.path" /> - </unjar> - <unjar dest="build/eclipse.agent"> - <path refid="eclipse.agent.libs.path" /> + <path refid="libs.path" /> </unjar> </target> @@ -74,13 +60,16 @@ lombok code including the various agents.</description> javac 1.5, partly because they completely rewrote large swaths of javac, and partly because our injection mechanism (annotations) doesn't work very well on javac 1.5, hence, when using javac, we do demand you're on 1.6. --> - <javac srcdir="src" debug="on" destdir="build/lombok" target="1.5" excludes="lombok/javac/**"> + <javac debug="on" destdir="build/lombok" target="1.5"> + <src path="src" /> + <src path="src_eclipseagent" /> + <exclude name="lombok/javac/**" /> <classpath refid="deps.path" /> - <classpath refid="lombok.libs.path" /> + <classpath refid="libs.path" /> </javac> <javac srcdir="src" debug="on" destdir="build/lombok" target="1.6" includes="lombok/javac/**"> <classpath refid="deps.path" /> - <classpath refid="lombok.libs.path" /> + <classpath refid="libs.path" /> </javac> <copy todir="build/lombok"> <fileset dir="src"> @@ -93,35 +82,17 @@ lombok code including the various agents.</description> <mkdir dir="build/lombok/META-INF" /> <mkdir dir="build/lombok/META-INF/services" /> <echo file="build/lombok/META-INF/services/javax.annotation.processing.Processor">lombok.javac.apt.Processor</echo> - - <mkdir dir="build/eclipse.agent" /> - <mkdir dir="build/eclipse.agent.src" /> - <copy todir="build/eclipse.agent.src"> - <fileset dir="src_eclipseagent" /> - <fileset refid="eclipse.agent.main.deps" /> - </copy> - - <javac debug="on" destdir="build/eclipse.agent" target="1.5" srcdir="build/eclipse.agent.src"> - <classpath refid="deps.path" /> - <classpath refid="eclipse.agent.libs.path" /> - </javac> </target> <target name="dist" description="Builds THE lombok.jar file which contains everything" depends="compile, version, -unpackLibs"> <mkdir dir="dist" /> - <jar basedir="build/eclipse.agent" destfile="dist/lombok.eclipse.agent-${lombok.version}.jar"> - <manifest> - <attribute name="Premain-Class" value="lombok.eclipse.agent.EclipsePatcher" /> - <attribute name="Can-Redefine-Classes" value="true" /> - </manifest> - </jar> - <copy file="dist/lombok.eclipse.agent-${lombok.version}.jar" tofile="dist/lombok.eclipse.agent.jar" /> <copy file="doc/changelog.markdown" tofile="build/changelog.txt" /> <jar destfile="dist/lombok-${lombok.version}.jar"> <fileset dir="build/lombok" /> - <fileset dir="dist" includes="lombok.eclipse.agent.jar" /> <fileset dir="build" includes="changelog.txt" /> <manifest> + <attribute name="Premain-Class" value="lombok.eclipse.agent.EclipsePatcher" /> + <attribute name="Can-Redefine-Classes" value="true" /> <attribute name="Main-Class" value="lombok.installer.Installer" /> <attribute name="Lombok-Version" value="${lombok.version}" /> </manifest> diff --git a/buildScripts/deps.ant.xml b/buildScripts/deps.ant.xml index 1c6919ee..b9d447f8 100644 --- a/buildScripts/deps.ant.xml +++ b/buildScripts/deps.ant.xml @@ -36,16 +36,16 @@ and building dependencies.</description> <ant dir="${lombok.patcher.dir}" target="dist" inheritAll="false" /> <condition property="lombok.patcher.replace"> <or> - <not><available file="lib/eclipse.agent/lombok-patcher.jar" /></not> + <not><available file="lib/lombok/lombok-patcher.jar" /></not> <not><uptodate srcfile="${lombok.patcher.dir}/dist/lombok-patcher.jar" - targetfile="lib/eclipse.agent/lombok-patcher.jar" /></not> + targetfile="lib/lombok/lombok-patcher.jar" /></not> </or> </condition> </target> <target name="build-lombok.patcher" depends="-check-lombok.patcher" if="lombok.patcher.replace"> - <copy file="${lombok.patcher.dir}/dist/lombok-patcher.jar" todir="lib/eclipse.agent" /> - <echo level="info">** UPDATED: lib/eclipse.agent/lombok-patcher.jar</echo> + <copy file="${lombok.patcher.dir}/dist/lombok-patcher.jar" todir="lib/lombok" /> + <echo level="info">** UPDATED: lib/lombok/lombok-patcher.jar</echo> </target> </project> @@ -1,5 +1,4 @@ 'lib' is defined as those things which are required when actually running lombok. -The main lombok code requires all libraries in the 'lombok' directory, whilst the agents -require the contents of both the 'agent' directory and the agent's specific directory (e.g. 'eclipse.agent'). +The main lombok code requires all libraries in the 'lombok' directory. For dependencies which are required only at compile time, see the 'deps' directory. diff --git a/lib/eclipse.agent/lombok-patcher.jar b/lib/lombok/lombok-patcher.jar Binary files differindex ec614176..86d4a889 100644 --- a/lib/eclipse.agent/lombok-patcher.jar +++ b/lib/lombok/lombok-patcher.jar diff --git a/lib/netbeans.agent/.gitkeep b/lib/netbeans.agent/.gitkeep deleted file mode 100644 index 2ded1cf3..00000000 --- a/lib/netbeans.agent/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Empty dir placeholder diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java index 691327b1..6eac4196 100644 --- a/src/lombok/eclipse/TransformEclipseAST.java +++ b/src/lombok/eclipse/TransformEclipseAST.java @@ -22,11 +22,9 @@ package lombok.eclipse; import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; import lombok.eclipse.EclipseAST.Node; +import lombok.patcher.Symbols; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; @@ -77,24 +75,6 @@ public class TransformEclipseAST { handlers = l; } - private static final List<String> DONT_RUN_LIST = Collections.unmodifiableList(Arrays.asList( - "org.eclipse.jdt.internal.corext.util.CodeFormatterUtil." - )); - - - /** - * Returns 'true' if the stack trace indicates lombok definitely SHOULD run for this parse job, by checking the context, - * and returns 'false' if the stack trace indicates lombok should definitely NOT run. - * - * Returns null if it can't tell (you probably should default to running lombok if you don't know). - */ - private static Boolean analyzeStackTrace(StackTraceElement[] trace) { - for ( StackTraceElement e : trace ) - if ( e.toString().contains(DONT_RUN_LIST.get(0)) ) return false; - return null; - //potential speedup: if trace contains org.eclipse.swt.widgets. -> stop - nothing interesting ever follows that. I think. - } - public static void transform_swapped(CompilationUnitDeclaration ast, Parser parser) { transform(parser, ast); } @@ -111,29 +91,27 @@ public class TransformEclipseAST { * @param ast The AST node belonging to the compilation unit (java speak for a single source file). */ public static void transform(Parser parser, CompilationUnitDeclaration ast) { - if ( disableLombok ) return; + if (disableLombok) return; - Boolean parse = analyzeStackTrace(new Throwable().getStackTrace()); - - if ( parse != null && parse == false ) return; + if (Symbols.hasSymbol("lombok.disable")) return; try { EclipseAST existing = getCache(ast); - if ( existing == null ) { + if (existing == null) { existing = new EclipseAST(ast); setCache(ast, existing); } else existing.reparse(); new TransformEclipseAST(existing).go(); - } catch ( Throwable t ) { + } catch (Throwable t) { try { String message = "Lombok can't parse this source: " + t.toString(); EclipseAST.addProblemToCompilationResult(ast, false, message, 0, 0); t.printStackTrace(); - } catch ( Throwable t2 ) { + } catch (Throwable t2) { try { Eclipse.error(ast, "Can't create an error in the problems dialog while adding: " + t.toString(), t2); - } catch ( Throwable t3 ) { + } catch (Throwable t3) { //This seems risky to just silently turn off lombok, but if we get this far, something pretty //drastic went wrong. For example, the eclipse help system's JSP compiler will trigger a lombok call, //but due to class loader shenanigans we'll actually get here due to a cascade of diff --git a/src/lombok/installer/EclipseLocation.java b/src/lombok/installer/EclipseLocation.java index d6a2f4b7..2b7e021d 100644 --- a/src/lombok/installer/EclipseLocation.java +++ b/src/lombok/installer/EclipseLocation.java @@ -31,10 +31,8 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.jar.JarFile; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.zip.ZipEntry; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -205,12 +203,15 @@ final class EclipseLocation { null); } - File agentJar = new File(dir, "lombok.eclipse.agent.jar"); - if ( agentJar.exists() ) { - if ( !agentJar.delete() ) throw new UninstallException( - "Can't delete " + agentJar.getAbsolutePath() + - " - perhaps the installer does not have the access rights to do so.", - null); + /* legacy code - lombok at one point used to have a separate jar for the eclipse agent. + * Leave this code in to delete it for those upgrading from an old version. */ { + File agentJar = new File(dir, "lombok.eclipse.agent.jar"); + if ( agentJar.exists() ) { + if ( !agentJar.delete() ) throw new UninstallException( + "Can't delete " + agentJar.getAbsolutePath() + + " - perhaps the installer does not have the access rights to do so.", + null); + } } File iniFile = new File(dir, "eclipse.ini"); @@ -230,7 +231,9 @@ final class EclipseLocation { boolean first = true; for ( String elem : m.group(1).split(Pattern.quote(File.pathSeparator)) ) { if ( elem.toLowerCase().endsWith("lombok.jar") ) continue; - if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + /* legacy code -see previous comment that starts with 'legacy' */ { + if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + } if ( first ) first = false; else elemBuilder.append(File.pathSeparator); elemBuilder.append(elem); @@ -295,33 +298,11 @@ final class EclipseLocation { //is no less bad than aborting, and this situation should be rare to the point of non-existence. File lombokJar = new File(iniFile.getParentFile(), "lombok.jar"); - File agentJar = new File(iniFile.getParentFile(), "lombok.eclipse.agent.jar"); File ourJar = EclipseFinder.findOurJar(); byte[] b = new byte[524288]; boolean readSucceeded = false; try { - JarFile jar = new JarFile(ourJar); - - try { - ZipEntry entry = jar.getEntry("lombok.eclipse.agent.jar"); - InputStream in = jar.getInputStream(entry); - FileOutputStream out = new FileOutputStream(agentJar); - try { - while ( true ) { - int r = in.read(b); - if ( r == -1 ) break; - readSucceeded = true; - out.write(b, 0, r); - } - } finally { - out.close(); - } - } finally { - jar.close(); - - } - FileOutputStream out = new FileOutputStream(lombokJar); InputStream in = new FileInputStream(ourJar); try { @@ -336,13 +317,16 @@ final class EclipseLocation { } catch ( IOException e ) { try { lombokJar.delete(); - agentJar.delete(); } catch ( Throwable ignore ) {} if ( !readSucceeded ) throw new InstallException("I can't read my own jar file. I think you've found a bug in this installer! I suggest you restart it " + "and use the 'what do I do' link, to manually install lombok. And tell us about this. Thanks!", e); throw new InstallException("I can't write to your Eclipse directory, probably because this installer does not have the access rights.", e); } + /* legacy - delete lombok.eclipse.agent.jar if its there, which lombok no longer uses. */ { + new File(lombokJar.getParentFile(), "lombok.eclipse.agent.jar").delete(); + } + try { FileInputStream fis = new FileInputStream(iniFile); try { @@ -357,7 +341,9 @@ final class EclipseLocation { boolean first = true; for ( String elem : m.group(1).split(Pattern.quote(File.pathSeparator)) ) { if ( elem.toLowerCase().endsWith("lombok.jar") ) continue; - if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + /* legacy code -see previous comment that starts with 'legacy' */ { + if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + } if ( first ) first = false; else elemBuilder.append(File.pathSeparator); elemBuilder.append(elem); @@ -374,13 +360,11 @@ final class EclipseLocation { } String fullPathToLombok = fullPathRequired ? (lombokJar.getParentFile().getCanonicalPath() + File.separator) : ""; - String fullPathToAgent = fullPathRequired ? (agentJar.getParentFile().getCanonicalPath() + File.separator) : ""; newContents.append(String.format( - "-javaagent:%slombok.eclipse.agent.jar", fullPathToLombok)).append(OS_NEWLINE); + "-javaagent:%slombok.jar", fullPathToLombok)).append(OS_NEWLINE); newContents.append(String.format( - "-Xbootclasspath/a:%slombok.jar" + File.pathSeparator + "%slombok.eclipse.agent.jar", - fullPathToLombok, fullPathToAgent)).append(OS_NEWLINE); + "-Xbootclasspath/a:%slombok.jar", fullPathToLombok)).append(OS_NEWLINE); FileOutputStream fos = new FileOutputStream(iniFile); try { @@ -395,7 +379,6 @@ final class EclipseLocation { } finally { if ( !installSucceeded ) try { lombokJar.delete(); - agentJar.delete(); } catch ( Throwable ignore ) {} } } @@ -406,12 +389,12 @@ final class EclipseLocation { } for ( File dir : failedDirs ) { - //If we're updating the old installation might have worked by putting the lombok jars in a different place. - //We'll delete these old files. - try { - new File(dir, "lombok.jar").delete(); - new File(dir, "lombok.eclipse.agent.jar").delete(); - } catch ( Throwable ignore ) {} + /* Legacy code - lombok's installer used to install in other places. To keep the user's eclipse dir clean, we'll delete these. */ { + try { + new File(dir, "lombok.jar").delete(); + new File(dir, "lombok.eclipse.agent.jar").delete(); + } catch ( Throwable ignore ) {} + } } } } diff --git a/src/lombok/installer/Installer.java b/src/lombok/installer/Installer.java index 89ebfc37..695de4b7 100644 --- a/src/lombok/installer/Installer.java +++ b/src/lombok/installer/Installer.java @@ -810,10 +810,8 @@ public class Installer { private static final String HOW_I_WORK_EXPLANATION = "<html><ol>" + "<li>First, I copy myself (lombok.jar) to your Eclipse install directory.</li>" + - "<li>Then, I unpack lombok.eclipse.agent.jar like so:<br>" + - "<pre>jar xvf lombok.jar lombok.eclipse.agent.jar</pre></li>" + "<li>Then, I edit the eclipse.ini file to add the following two entries:<br>" + - "<pre>-Xbootclasspath/a:lombok.jar%1$slombok.eclipse.agent.jar<br>" + + "<pre>-Xbootclasspath/a:lombok.jar<br>" + "-javaagent:lombok.jar</pre></li></ol>" + "<br>" + "That's all there is to it. Note that on Mac OS X, eclipse.ini is hidden in<br>" + diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java index 6efddf61..d1759127 100644 --- a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java @@ -56,7 +56,7 @@ public class EclipsePatcher { ScriptManager sm = new ScriptManager(); sm.registerTransformer(instrumentation); EquinoxClassLoader.getInstance().addPrefix("lombok."); - EquinoxClassLoader.getInstance().registerScripts(sm); + EquinoxClassLoader.registerScripts(sm); patchLombokizeAST(sm); patchAvoidReparsingGeneratedCode(sm); @@ -66,7 +66,7 @@ public class EclipsePatcher { if (reloadExistingClasses) sm.reloadClasses(instrumentation); } - + private static void patchHideGeneratedNodes(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode")) @@ -75,6 +75,19 @@ public class EclipsePatcher { "([Lorg/eclipse/jdt/core/dom/SimpleName;)[Lorg/eclipse/jdt/core/dom/SimpleName;")) .request(StackRequest.RETURN_VALUE).build()); + patchRefactorScripts(sm); + patchFormatters(sm); + } + + private static void patchFormatters(ScriptManager sm) { + sm.addScript(ScriptBuilder.setSymbolDuringMethodCall() + .target(new MethodTarget("org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy", "format", "void")) + .callToWrap(new Hook("org/eclipse/jdt/internal/corext/util/CodeFormatterUtil", "reformat", + "(ILjava/lang/String;IIILjava/lang/String;Ljava/util/Map;)Lorg/eclipse/text/edits/TextEdit;")) + .symbol("lombok.disable").build()); + } + + private static void patchRefactorScripts(ScriptManager sm) { sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget("org.eclipse.jdt.core.dom.rewrite.ASTRewrite", "replace")) .target(new MethodTarget("org.eclipse.jdt.core.dom.rewrite.ASTRewrite", "remove")) @@ -89,14 +102,14 @@ public class EclipsePatcher { "([Lorg/eclipse/jdt/core/IMethod;)[Lorg/eclipse/jdt/core/IMethod;")) .transplant().build()); } - + private static void patchCatchReparse(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveStartingCatchPosition")) .wrapMethod(new Hook("lombok/eclipse/agent/PatchFixes", "fixRetrieveStartingCatchPosition", "(I)I")) .transplant().request(StackRequest.PARAM1).build()); } - + private static void patchSetGeneratedFlag(ScriptManager sm) { sm.addScript(ScriptBuilder.addField() .targetClass("org.eclipse.jdt.internal.compiler.ast.ASTNode") @@ -150,7 +163,7 @@ public class EclipsePatcher { "(Lorg/eclipse/jdt/core/dom/SimpleName;Ljava/lang/Object;)V")) .transplant().build()); } - + private static void patchAvoidReparsingGeneratedCode(ScriptManager sm) { final String PARSER_SIG1 = "org.eclipse.jdt.internal.compiler.parser.Parser"; sm.addScript(ScriptBuilder.exitEarly() @@ -175,7 +188,7 @@ public class EclipsePatcher { .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) .transplant().request(StackRequest.PARAM1).build()); } - + private static void patchLombokizeAST(ScriptManager sm) { sm.addScript(ScriptBuilder.addField() .targetClass("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration") |