Merge branch 'lombokpatcher'

This commit is contained in:
Reinier Zwitserloot
2009-10-07 23:54:12 +02:00
24 changed files with 797 additions and 1260 deletions
+2 -2
View File
@@ -3,7 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src_eclipseagent"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/eclipse.agent/asm-3.1.jar"/>
<classpathentry kind="lib" path="deps/lombok/org.eclipse.jdt.apt.core_3.3.200.v20090528-1135.jar"/>
<classpathentry kind="lib" path="deps/lombok/org.eclipse.jdt.apt.pluggable.core_1.0.200.v20090526-2130.jar"/>
<classpathentry kind="lib" path="deps/lombok/org.eclipse.jdt.compiler.apt_1.0.200.v20090528-1135.jar"/>
@@ -17,6 +16,7 @@
<classpathentry kind="lib" path="deps/lombok/org.eclipse.osgi_3.5.0.v20090520.jar"/>
<classpathentry kind="lib" path="deps/lombok/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar"/>
<classpathentry kind="lib" path="deps/lombok/spi-0.2.3-pre.jar"/>
<classpathentry kind="lib" path="deps/tools.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/lombok.patcher"/>
<classpathentry kind="lib" path="deps/lombok/tools.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+30 -389
View File
@@ -20,208 +20,14 @@
THE SOFTWARE.
-->
<project name="lombok" default="dist">
<property name="SNIPPET_TAB_STOP" value="2" />
<property name="build.compiler" value="javac1.6" />
<fileset dir="src" id="eclipse.agent.main.deps">
<include name="lombok/core/SpiLoadUtil.java" />
<include name="lombok/Lombok.java" />
</fileset>
<path id="lombok.deps.path">
<fileset dir="deps">
<include name="*.jar" />
</fileset>
<fileset dir="deps/lombok">
<include name="**/*.jar" />
</fileset>
</path>
<path id="lombok.libs.path">
<fileset dir="lib/lombok">
<include name="**/*.jar" />
</fileset>
</path>
<path id="eclipse.agent.deps.path">
<fileset dir="deps">
<include name="*.jar" />
</fileset>
<fileset dir="deps/eclipse.agent">
<include name="**/*.jar" />
</fileset>
</path>
<path id="eclipse.agent.libs.path">
<fileset dir="lib/eclipse.agent">
<include name="**/*.jar" />
</fileset>
</path>
<description>This buildfile is part of projectlombok.org. It is the main entry point that contains
the common tasks and can be called on to run the main aspects of all the sub-scripts.</description>
<target name="clean" description="Removes all generated files">
<delete dir="build" quiet="true" />
<delete dir="dist" quiet="true" />
</target>
<target name="-website-clean">
<delete dir="build/website" quiet="true" />
</target>
<target name="website" description="Prepares the website for distribution" depends="-website-main, -website-videos, -website-dist" />
<target name="website-novideo" description="Prepares the website for distribution, but does not add the videos to the zip." depends="-website-main, -website-dist" />
<target name="-website-videos" depends="-website-clean">
<mkdir dir="build/website/videos" />
<copy todir="build/website/videos">
<fileset dir="website/videos" />
</copy>
</target>
<target name="-website-main" depends="-website-clean, version, javadoc, changelogToHtml">
<taskdef classpath="deps/website/java2html.jar" name="java2html" classname="de.java2html.anttasks.Java2HtmlTask" />
<mkdir dir="build/website" />
<copy todir="build/website">
<fileset dir="website">
<exclude name="**/*.jpage" />
<exclude name="**/*.svg" />
<exclude name="**/*.psd" />
<exclude name="**/*.ai" />
<exclude name="**/publish" />
<exclude name="**/*unused*" />
<exclude name="videos/**" />
</fileset>
</copy>
<copy todir="build/website" overwrite="true">
<fileset dir="website">
<include name="index.html" />
<include name="download.html" />
<include name="slideshow.html" />
<include name="mavenrepo/index.html" />
</fileset>
<filterchain>
<replacetokens>
<token key="VERSION" value="${lombok.version}" />
</replacetokens>
</filterchain>
</copy>
<antcall target="-integrateSnippet">
<param name="transformationName" value="GetterSetter" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="ToString" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="EqualsAndHashCode" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="Data" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="Cleanup" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="Synchronized" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="SneakyThrows" />
</antcall>
<mkdir dir="dist" />
</target>
<target name="-website-dist">
<tar destfile="dist/website.tar.bz2" compression="bzip2">
<tarfileset dir="build/website" />
<tarfileset dir="doc/api" prefix="api" />
</tar>
<echo>Now upload dist/website.tar.bz2 to the webserver.</echo>
<echo>If you want to host projectlombok.org on github, run the website/publish script, but this is not where the site is currently hosted.</echo>
</target>
<target name="-integrateSnippet">
<mkdir dir="build/website" />
<property name="prefile" location="usage_examples/${transformationName}Example_pre.jpage" />
<property name="postfile" location="usage_examples/${transformationName}Example_post.jpage" />
<property name="htmlfile" location="website/features/${transformationName}.html" />
<mkdir dir="build/temp" />
<property name="preout" location="build/temp/${transformationName}Example_pre.jpage.html" />
<property name="postout" location="build/temp/${transformationName}Example_post.jpage.html" />
<java2html srcdir="usage_examples" includes="${transformationName}Example_*.jpage" destdir="build/temp" tabs="${SNIPPET_TAB_STOP}"
showLineNumbers="true" overwrite="true" />
<loadfile property="pre" encoding="UTF-8" srcFile="${preout}">
<filterchain>
<linecontainsregexp>
<regexp pattern="(code>)|(font>)" />
</linecontainsregexp>
<striplinebreaks />
</filterchain>
</loadfile>
<loadfile property="post" encoding="UTF-8" srcFile="${postout}">
<filterchain>
<linecontainsregexp>
<regexp pattern="(code>)|(font>)" />
</linecontainsregexp>
<striplinebreaks />
</filterchain>
</loadfile>
<delete dir="build/temp" quiet="true" />
<copy file="${htmlfile}" todir="build/website/features" overwrite="true">
<filterchain>
<replacetokens>
<token key="HTML_PRE" value="${pre}" />
<token key="HTML_POST" value="${post}" />
</replacetokens>
</filterchain>
</copy>
</target>
<target name="compile" description="Compiles the code">
<mkdir dir="build/lombok" />
<!-- This version trickery is so that an eclipse running in a JVM 1.5 will run
properly (It'll never touch the javac files and hence never trigger a
Bad Class Version Number error, but for javac we definitely cannot support
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/**">
<classpath refid="lombok.deps.path" />
<classpath refid="lombok.libs.path" />
</javac>
<javac srcdir="src" debug="on" destdir="build/lombok" target="1.6" includes="lombok/javac/**">
<classpath refid="lombok.deps.path" />
<classpath refid="lombok.libs.path" />
</javac>
<copy todir="build/lombok">
<fileset dir="src">
<exclude name="**/*.java" />
<exclude name="**/*.class" />
<exclude name="**/*.svg" />
</fileset>
</copy>
<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="eclipse.agent.deps.path" />
<classpath refid="eclipse.agent.libs.path" />
</javac>
</target>
<target name="-unpackLibs">
<unjar dest="build/lombok">
<path refid="lombok.libs.path" />
</unjar>
<unjar dest="build/eclipse.agent">
<path refid="eclipse.agent.libs.path" />
</unjar>
</target>
<target name="version" description="Shows the version number">
<target name="version" description="Shows the version number" unless="lombok.version">
<mkdir dir="build/lombok" />
<javac srcdir="src" debug="on" destdir="build/lombok" target="1.5" includes="lombok/core/Version.java" />
<java
@@ -238,209 +44,44 @@
<echo level="info">Lombok version: ${lombok.version}</echo>
</target>
<target name="javadoc" description="Generates the javadoc" depends="version">
<delete dir="build/api" quiet="true" />
<delete dir="doc/api" quiet="true" />
<mkdir dir="build/api" />
<property name="javadoc.overview.html" location="build/javadoc.overview.html" />
<echo file="${javadoc.overview.html}"><![CDATA[<html><body>
Welcome to the lombok javadoc.&nbsp;If you're just looking to learn more about using lombok
You probably want to look at <a href="http://projectlombok.org/features/index.html">the feature documentation</a>.&nbsp;Otherwise,
check the <a href="lombok/package-summary.html">lombok</a> package.&nbsp;If you're trying to extend lombok or
write your own plugins, the other packages are what you're looking for.</body></html>
]]></echo>
<javadoc sourcepath="src" defaultexcludes="yes" destdir="build/api" windowtitle="Lombok" Overview="${javadoc.overview.html}">
<classpath refid="lombok.deps.path" />
<classpath refid="lombok.libs.path" />
<link href="http://java.sun.com/javase/6/docs/api/" offline="true" packagelistLoc="./deps/javadoc/java6"/>
<header><![CDATA[<a href='http://projectlombok.org/'>Lombok</a> - ]]>v${lombok.version}</header>
<bottom><![CDATA[<i>Copyright &#169; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT licence</a>.]]></bottom>
</javadoc>
<mkdir dir="doc/api" />
<copy todir="doc/api">
<fileset dir="build/api" includes="**/*.html" />
<filterchain>
<linecontainsregexp negate="true">
<regexp pattern="(Generated by javadoc)|(.META NAME=.date.)" />
</linecontainsregexp>
</filterchain>
</copy>
<copy todir="doc/api">
<fileset dir="build/api" excludes="**/*.html" />
</copy>
<target name="buildDeps" description="Builds dependencies">
<ant antfile="buildScripts/deps.ant.xml" target="buildDeps" inheritAll="false" />
</target>
<target name="dist" description="Builds THE lombok.jar file which contains everything " depends="clean, 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="Main-Class" value="lombok.installer.Installer" />
<attribute name="Lombok-Version" value="${lombok.version}" />
</manifest>
</jar>
<copy file="dist/lombok-${lombok.version}.jar" tofile="dist/lombok.jar" />
<target name="dist" depends="version, buildDeps" description="Builds THE lombok.jar file which contains everything">
<ant antfile="buildScripts/compile.ant.xml" target="dist" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
<property name="lombok.dist.built" value="true" />
</target>
<property name="credentialsFile" value="google.properties" />
<target name="-credentials">
<available property="hasCredentialsFile" file="${credentialsFile}"/>
<target name="compile" description="Compiles the code">
<ant antfile="buildScripts/compile.ant.xml" target="compile" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
</target>
<target name="-checkCredentialsFile" depends="-credentials" unless="hasCredentialsFile">
<echo file="${credentialsFile}">#username=[your google account name without @gmail.com]
#password=[your googlecode password, is NOT your gmail password]</echo>
<fail message="fill in ${credentialsFile} to provide your credentials"/>
<target name="maven" description="Build a maven repository">
<ant antfile="buildScripts/maven.ant.xml" target="maven" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
</target>
<target name="publish" description="Publishes the latest build to googlecode" depends="-checkCredentialsFile, dist">
<taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask" classpath="deps/website/ant-googlecode-0.0.2.jar" name="gcupload"/>
<property file="${credentialsFile}" prefix="google" />
<gcupload
username="${google.username}"
password="${google.password}"
projectname="projectlombok"
filename="dist/lombok.jar"
targetfilename="lombok-${lombok.version}.jar"
summary="Version ${lombok.version}"
labels=""
verbose="true" />
<gcupload
username="${google.username}"
password="${google.password}"
projectname="projectlombok"
filename="dist/lombok.jar"
targetfilename="lombok.jar"
summary="Version ${lombok.version} - The everything jar - doubleclick it to install, or just include it in your projects."
labels="Featured"
verbose="true" />
<target name="publish" description="Publishes the latest build to googlecode">
<ant antfile="buildScripts/publish.ant.xml" target="publish" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
</target>
<target name="changelogToHtml">
<mkdir dir="build/changelog" />
<echo file="build/changelog/CompileChangelog.java"><![CDATA[
import com.petebevin.markdown.MarkdownProcessor;
import java.io.*;
public class CompileChangelog {
public static void main(String[] args) {
try {
FileInputStream in = new FileInputStream(args[0]);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] b = new byte[65536];
while ( true ) {
int r = in.read(b);
if ( r == -1 ) break;
out.write(b, 0, r);
}
in.close();
String markdown = new String(out.toByteArray(), "UTF-8");
String html = new MarkdownProcessor().markdown(markdown);
FileOutputStream file = new FileOutputStream(args[1]);
file.write(html.getBytes("UTF-8"));
file.close();
System.exit(0);
} catch ( Throwable e ) {
e.printStackTrace();
System.exit(1);
}
}
}
]]></echo>
<mkdir dir="build/website" />
<javac srcdir="build/changelog" destdir="build/changelog" classpath="deps/website/markdownj.jar" debug="on" />
<property name="CHANGELOG_FILE" location="doc/changelog.markdown" />
<property name="CHANGELOG_HTML" location="build/website/changelog.html" />
<java fork="true" classname="CompileChangelog" failonerror="true">
<classpath>
<pathelement location="deps/website/markdownj.jar" />
<pathelement location="build/changelog" />
</classpath>
<arg value="${CHANGELOG_FILE}" />
<arg value="${CHANGELOG_HTML}" />
</java>
<target name="website" description="Prepares the website for distribution">
<ant antfile="buildScripts/website.ant.xml" target="website" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
</target>
<target name="maven" depends="version, dist" description="Build a maven repository.">
<loadresource property="mvn.oldversions">
<url url="http://projectlombok.org/mavenrepo/org/projectlombok/lombok/maven-metadata.xml" />
<filterchain>
<linecontains><contains value="/version>" /></linecontains>
<headfilter lines="-1" skip="1" />
</filterchain>
</loadresource>
<mkdir dir="build" />
<echo file="build/version.tagged.tmp">&lt;version&gt;${lombok.version}&lt;/version&gt;</echo>
<loadfile srcFile="build/version.tagged.tmp" property="lombok.version.tagged" />
<delete file="build/version.tagged.tmp" />
<fail message="You already created a maven target for this version. You'll have to update the version to something new!">
<condition>
<contains string="${mvn.oldversions}" substring="${lombok.version.tagged}" />
</condition>
</fail>
<delete dir="build/maven" quiet="true" />
<property name="mvn.dir" value="build/maven/org/projectlombok/lombok" />
<property name="mvn.bin" value="${mvn.dir}/${lombok.version}" />
<property name="mvn.pom" value="${mvn.bin}/lombok-${lombok.version}.pom" />
<mkdir dir="${mvn.bin}" />
<tstamp>
<format property="now.millis" pattern="yyyyMMddHHmmss" timezone="UTC" />
</tstamp>
<copy todir="${mvn.bin}" file="dist/lombok-${lombok.version}.jar" />
<checksum property="mvn.bin.md5" file="${mvn.bin}/lombok-${lombok.version}.jar" algorithm="MD5" />
<checksum property="mvn.bin.sha1" file="${mvn.bin}/lombok-${lombok.version}.jar" algorithm="SHA1" />
<echo file="${mvn.bin}/lombok-${lombok.version}.jar.md5">${mvn.bin.md5}</echo>
<echo file="${mvn.bin}/lombok-${lombok.version}.jar.sha1">${mvn.bin.sha1}</echo>
<jar destfile="${mvn.bin}/lombok-${lombok.version}-sources.jar" basedir="src" excludes="**/.DS_Store" />
<checksum property="mvn.src.md5" file="${mvn.bin}/lombok-${lombok.version}-sources.jar" algorithm="MD5" />
<checksum property="mvn.src.sha1" file="${mvn.bin}/lombok-${lombok.version}-sources.jar" algorithm="SHA1" />
<echo file="${mvn.bin}/lombok-${lombok.version}-sources.jar.md5">${mvn.src.md5}</echo>
<echo file="${mvn.bin}/lombok-${lombok.version}-sources.jar.sha1">${mvn.src.sha1}</echo>
<copy tofile="${mvn.pom}" file="doc/maven-pom.xml">
<filterchain>
<replacetokens>
<token key="VERSION" value="${lombok.version}" />
</replacetokens>
</filterchain>
</copy>
<checksum property="mvn.pom.md5" file="${mvn.pom}" algorithm="MD5" />
<checksum property="mvn.pom.sha1" file="${mvn.pom}" algorithm="SHA1" />
<echo file="${mvn.pom}.md5">${mvn.pom.md5}</echo>
<echo file="${mvn.pom}.sha1">${mvn.pom.sha1}</echo>
<echo file="${mvn.dir}/maven-metadata.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<versioning>
<versions>
<version>${lombok.version}</version>
${mvn.oldversions}
</versions>
<lastUpdated>${now.millis}</lastUpdated>
</versioning>
</metadata>
]]></echo>
<checksum property="mvn.manifest.md5" file="${mvn.dir}/maven-metadata.xml" algorithm="MD5" />
<checksum property="mvn.manifest.sha1" file="${mvn.dir}/maven-metadata.xml" algorithm="SHA1" />
<echo file="${mvn.dir}/maven-metadata.xml.md5">${mvn.manifest.md5}</echo>
<echo file="${mvn.dir}/maven-metadata.xml.sha1">${mvn.manifest.sha1}</echo>
<tar destfile="dist/maven.tar.bz2" compression="bzip2">
<tarfileset dir="build/maven" />
</tar>
<echo>Now copy maven.tar.bz2 to the website and unpack it in the mavenrepo directory, overwriting whatever's there.</echo>
<target name="website-novideo" description="Prepares the website for distribution, but does not add the videos to the zip.">
<ant antfile="buildScripts/website.ant.xml" target="website-novideo" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
</target>
</project>
+131
View File
@@ -0,0 +1,131 @@
<!--
Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
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.
-->
<project name="lombok-compile" basedir=".." default="dist">
<description>This buildfile is part of projectlombok.org. It responsible for compiling the main
lombok code including the various agents.</description>
<property name="build.compiler" value="javac1.6" />
<target name="version" unless="lombok.version">
<ant antfile="build.xml" target="version" inheritAll="false" />
<loadresource property="lombok.version">
<file file="build/version.txt" />
<filterchain>
<striplinebreaks />
</filterchain>
</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">
<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" />
</unjar>
</target>
<target name="compile" description="Compiles the code">
<mkdir dir="build/lombok" />
<!-- This version trickery is so that an eclipse running in a JVM 1.5 will run
properly (It'll never touch the javac files and hence never trigger a
Bad Class Version Number error, but for javac we definitely cannot support
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/**">
<classpath refid="deps.path" />
<classpath refid="lombok.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" />
</javac>
<copy todir="build/lombok">
<fileset dir="src">
<exclude name="**/*.java" />
<exclude name="**/*.class" />
<exclude name="**/*.svg" />
</fileset>
</copy>
<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="Main-Class" value="lombok.installer.Installer" />
<attribute name="Lombok-Version" value="${lombok.version}" />
</manifest>
</jar>
<copy file="dist/lombok-${lombok.version}.jar" tofile="dist/lombok.jar" />
</target>
</project>
+46
View File
@@ -0,0 +1,46 @@
<!--
Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
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.
-->
<project name="lombok-deps" basedir=".." default="buildDeps">
<description>This buildfile is part of projectlombok.org. It responsible for finding, downloading,
and building dependencies.</description>
<property name="dir.lombok.patcher" location="../lombok.patcher" />
<target name="buildDeps" description="Builds dependencies" depends="build-lombok.patcher" />
<target name="-check-lombok.patcher">
<ant dir="${dir.lombok.patcher}" target="dist" inheritAll="false" />
<condition property="replace-lombok.patcher">
<or>
<not><available file="lib/eclipse.agent/lombok-patcher.jar" /></not>
<not><uptodate
srcfile="${dir.lombok.patcher}/dist/lombok-patcher.jar"
targetfile="lib/eclipse.agent/lombok-patcher.jar" /></not>
</or>
</condition>
</target>
<target name="build-lombok.patcher" depends="-check-lombok.patcher" if="replace-lombok.patcher">
<copy file="${dir.lombok.patcher}/dist/lombok-patcher.jar" todir="lib/eclipse.agent" />
<echo>** UPDATED: lib/eclipse.agent/lombok-patcher.jar</echo>
</target>
</project>
+111
View File
@@ -0,0 +1,111 @@
<!--
Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
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.
-->
<project name="lombok-maven" basedir=".." default="maven">
<description>This buildfile is part of projectlombok.org. It is responsible for creating and maintaining
the maven repository that contains lombok's deliverables for those using maven.</description>
<target name="version" unless="lombok.version">
<ant antfile="build.xml" target="version" inheritAll="false" />
<loadresource property="lombok.version">
<file file="build/version.txt" />
<filterchain>
<striplinebreaks />
</filterchain>
</loadresource>
</target>
<target name="dist" unless="lombok.dist.built" depends="version">
<ant antfile="buildScripts/compile.xml" target="dist" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
</target>
<target name="maven" depends="version, dist" description="Build a maven repository.">
<loadresource property="mvn.oldversions">
<url url="http://projectlombok.org/mavenrepo/org/projectlombok/lombok/maven-metadata.xml" />
<filterchain>
<linecontains><contains value="/version>" /></linecontains>
<headfilter lines="-1" skip="1" />
</filterchain>
</loadresource>
<mkdir dir="build" />
<echo file="build/version.tagged.tmp">&lt;version&gt;${lombok.version}&lt;/version&gt;</echo>
<loadfile srcFile="build/version.tagged.tmp" property="lombok.version.tagged" />
<delete file="build/version.tagged.tmp" />
<fail message="You already created a maven target for this version. You'll have to update the version to something new!">
<condition>
<contains string="${mvn.oldversions}" substring="${lombok.version.tagged}" />
</condition>
</fail>
<delete dir="build/maven" quiet="true" />
<property name="mvn.dir" value="build/maven/org/projectlombok/lombok" />
<property name="mvn.bin" value="${mvn.dir}/${lombok.version}" />
<property name="mvn.pom" value="${mvn.bin}/lombok-${lombok.version}.pom" />
<mkdir dir="${mvn.bin}" />
<tstamp>
<format property="now.millis" pattern="yyyyMMddHHmmss" timezone="UTC" />
</tstamp>
<copy todir="${mvn.bin}" file="dist/lombok-${lombok.version}.jar" />
<checksum property="mvn.bin.md5" file="${mvn.bin}/lombok-${lombok.version}.jar" algorithm="MD5" />
<checksum property="mvn.bin.sha1" file="${mvn.bin}/lombok-${lombok.version}.jar" algorithm="SHA1" />
<echo file="${mvn.bin}/lombok-${lombok.version}.jar.md5">${mvn.bin.md5}</echo>
<echo file="${mvn.bin}/lombok-${lombok.version}.jar.sha1">${mvn.bin.sha1}</echo>
<jar destfile="${mvn.bin}/lombok-${lombok.version}-sources.jar" basedir="src" excludes="**/.DS_Store" />
<checksum property="mvn.src.md5" file="${mvn.bin}/lombok-${lombok.version}-sources.jar" algorithm="MD5" />
<checksum property="mvn.src.sha1" file="${mvn.bin}/lombok-${lombok.version}-sources.jar" algorithm="SHA1" />
<echo file="${mvn.bin}/lombok-${lombok.version}-sources.jar.md5">${mvn.src.md5}</echo>
<echo file="${mvn.bin}/lombok-${lombok.version}-sources.jar.sha1">${mvn.src.sha1}</echo>
<copy tofile="${mvn.pom}" file="doc/maven-pom.xml">
<filterchain>
<replacetokens>
<token key="VERSION" value="${lombok.version}" />
</replacetokens>
</filterchain>
</copy>
<checksum property="mvn.pom.md5" file="${mvn.pom}" algorithm="MD5" />
<checksum property="mvn.pom.sha1" file="${mvn.pom}" algorithm="SHA1" />
<echo file="${mvn.pom}.md5">${mvn.pom.md5}</echo>
<echo file="${mvn.pom}.sha1">${mvn.pom.sha1}</echo>
<echo file="${mvn.dir}/maven-metadata.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<versioning>
<versions>
<version>${lombok.version}</version>
${mvn.oldversions}
</versions>
<lastUpdated>${now.millis}</lastUpdated>
</versioning>
</metadata>
]]></echo>
<checksum property="mvn.manifest.md5" file="${mvn.dir}/maven-metadata.xml" algorithm="MD5" />
<checksum property="mvn.manifest.sha1" file="${mvn.dir}/maven-metadata.xml" algorithm="SHA1" />
<echo file="${mvn.dir}/maven-metadata.xml.md5">${mvn.manifest.md5}</echo>
<echo file="${mvn.dir}/maven-metadata.xml.sha1">${mvn.manifest.sha1}</echo>
<tar destfile="dist/maven.tar.bz2" compression="bzip2">
<tarfileset dir="build/maven" />
</tar>
<echo>Now copy maven.tar.bz2 to the website and unpack it in the mavenrepo directory. Let it overwrite files.</echo>
</target>
</project>
+75
View File
@@ -0,0 +1,75 @@
<!--
Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
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.
-->
<project name="lombok-publish" basedir=".." default="publish">
<description>This buildfile is part of projectlombok.org. It is responsible for turning the build results
into the actual deliverable form, and uploading it to the distribution websites.</description>
<property name="credentialsFile" value="google.properties" />
<target name="version" unless="lombok.version">
<ant antfile="build.xml" target="version" inheritAll="false" />
<loadresource property="lombok.version">
<file file="build/version.txt" />
<filterchain>
<striplinebreaks />
</filterchain>
</loadresource>
</target>
<target name="dist" unless="lombok.dist.built" depends="version">
<ant antfile="buildScripts/compile.xml" target="dist" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
</ant>
</target>
<target name="-credentials">
<available property="hasCredentialsFile" file="${credentialsFile}"/>
</target>
<target name="-checkCredentialsFile" depends="-credentials" unless="hasCredentialsFile">
<echo file="${credentialsFile}">#username=[your google account name without @gmail.com]
#password=[your googlecode password, is NOT your gmail password]</echo>
<fail message="fill in ${credentialsFile} to provide your credentials"/>
</target>
<target name="publish" description="Publishes the latest build to googlecode" depends="version, -checkCredentialsFile, dist">
<taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask" classpath="deps/website/ant-googlecode-0.0.2.jar" name="gcupload"/>
<property file="${credentialsFile}" prefix="google" />
<gcupload
username="${google.username}"
password="${google.password}"
projectname="projectlombok"
filename="dist/lombok.jar"
targetfilename="lombok-${lombok.version}.jar"
summary="Version ${lombok.version}"
labels=""
verbose="true" />
<gcupload
username="${google.username}"
password="${google.password}"
projectname="projectlombok"
filename="dist/lombok.jar"
targetfilename="lombok.jar"
summary="Version ${lombok.version} - The everything jar - doubleclick it to install, or just include it in your projects."
labels="Featured"
verbose="true" />
</target>
</project>
+224
View File
@@ -0,0 +1,224 @@
<!--
Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
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.
-->
<project name="lombok-website" basedir=".." default="website">
<description>
This buildfile is part of projectlombok.org. It is responsible for building the website and all website-related aspects,
such as converting the changelog into HTML, and creating javadoc.</description>
<property name="SNIPPET_TAB_STOP" value="2" />
<target name="-website-clean">
<delete dir="build/website" quiet="true" />
</target>
<target name="website" description="Prepares the website for distribution" depends="-website-main, -website-videos, -website-dist" />
<target name="website-novideo" description="Prepares the website for distribution, but does not add the videos to the zip." depends="-website-main, -website-dist" />
<target name="version" unless="lombok.version">
<ant antfile="build.xml" target="version" inheritAll="false" />
<loadresource property="lombok.version">
<file file="build/version.txt" />
<filterchain>
<striplinebreaks />
</filterchain>
</loadresource>
</target>
<target name="-website-videos" depends="-website-clean">
<mkdir dir="build/website/videos" />
<copy todir="build/website/videos">
<fileset dir="website/videos" />
</copy>
</target>
<target name="-website-main" depends="-website-clean, version, javadoc, changelogToHtml">
<taskdef classpath="deps/website/java2html.jar" name="java2html" classname="de.java2html.anttasks.Java2HtmlTask" />
<mkdir dir="build/website" />
<copy todir="build/website">
<fileset dir="website">
<exclude name="**/*.jpage" />
<exclude name="**/*.svg" />
<exclude name="**/*.psd" />
<exclude name="**/*.ai" />
<exclude name="**/publish" />
<exclude name="**/*unused*" />
<exclude name="videos/**" />
</fileset>
</copy>
<copy todir="build/website" overwrite="true">
<fileset dir="website">
<include name="index.html" />
<include name="download.html" />
<include name="slideshow.html" />
<include name="mavenrepo/index.html" />
</fileset>
<filterchain>
<replacetokens>
<token key="VERSION" value="${lombok.version}" />
</replacetokens>
</filterchain>
</copy>
<antcall target="-integrateSnippet">
<param name="transformationName" value="GetterSetter" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="ToString" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="EqualsAndHashCode" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="Data" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="Cleanup" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="Synchronized" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="SneakyThrows" />
</antcall>
<mkdir dir="dist" />
</target>
<target name="-website-dist">
<tar destfile="dist/website.tar.bz2" compression="bzip2">
<tarfileset dir="build/website" />
<tarfileset dir="doc/api" prefix="api" />
</tar>
<echo>Now upload dist/website.tar.bz2 to the webserver.</echo>
</target>
<target name="-integrateSnippet">
<mkdir dir="build/website" />
<property name="prefile" location="usage_examples/${transformationName}Example_pre.jpage" />
<property name="postfile" location="usage_examples/${transformationName}Example_post.jpage" />
<property name="htmlfile" location="website/features/${transformationName}.html" />
<mkdir dir="build/temp" />
<property name="preout" location="build/temp/${transformationName}Example_pre.jpage.html" />
<property name="postout" location="build/temp/${transformationName}Example_post.jpage.html" />
<java2html srcdir="usage_examples" includes="${transformationName}Example_*.jpage" destdir="build/temp" tabs="${SNIPPET_TAB_STOP}"
showLineNumbers="true" overwrite="true" />
<loadfile property="pre" encoding="UTF-8" srcFile="${preout}">
<filterchain>
<linecontainsregexp>
<regexp pattern="(code>)|(font>)" />
</linecontainsregexp>
<striplinebreaks />
</filterchain>
</loadfile>
<loadfile property="post" encoding="UTF-8" srcFile="${postout}">
<filterchain>
<linecontainsregexp>
<regexp pattern="(code>)|(font>)" />
</linecontainsregexp>
<striplinebreaks />
</filterchain>
</loadfile>
<delete dir="build/temp" quiet="true" />
<copy file="${htmlfile}" todir="build/website/features" overwrite="true">
<filterchain>
<replacetokens>
<token key="HTML_PRE" value="${pre}" />
<token key="HTML_POST" value="${post}" />
</replacetokens>
</filterchain>
</copy>
</target>
<target name="changelogToHtml">
<mkdir dir="build/changelog" />
<echo file="build/changelog/CompileChangelog.java"><![CDATA[
import com.petebevin.markdown.MarkdownProcessor;
import java.io.*;
public class CompileChangelog {
public static void main(String[] args) {
try {
FileInputStream in = new FileInputStream(args[0]);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] b = new byte[65536];
while ( true ) {
int r = in.read(b);
if ( r == -1 ) break;
out.write(b, 0, r);
}
in.close();
String markdown = new String(out.toByteArray(), "UTF-8");
String html = new MarkdownProcessor().markdown(markdown);
FileOutputStream file = new FileOutputStream(args[1]);
file.write(html.getBytes("UTF-8"));
file.close();
System.exit(0);
} catch ( Throwable e ) {
e.printStackTrace();
System.exit(1);
}
}
}
]]></echo>
<mkdir dir="build/website" />
<javac srcdir="build/changelog" destdir="build/changelog" classpath="deps/website/markdownj.jar" debug="on" />
<property name="CHANGELOG_FILE" location="doc/changelog.markdown" />
<property name="CHANGELOG_HTML" location="build/website/changelog.html" />
<java fork="true" classname="CompileChangelog" failonerror="true">
<classpath>
<pathelement location="deps/website/markdownj.jar" />
<pathelement location="build/changelog" />
</classpath>
<arg value="${CHANGELOG_FILE}" />
<arg value="${CHANGELOG_HTML}" />
</java>
</target>
<target name="javadoc" description="Generates the javadoc" depends="version">
<delete dir="build/api" quiet="true" />
<delete dir="doc/api" quiet="true" />
<mkdir dir="build/api" />
<property name="javadoc.overview.html" location="build/javadoc.overview.html" />
<echo file="${javadoc.overview.html}"><![CDATA[<html><body>
Welcome to the lombok javadoc.&nbsp;If you're just looking to learn more about using lombok
You probably want to look at <a href="http://projectlombok.org/features/index.html">the feature documentation</a>.&nbsp;Otherwise,
check the <a href="lombok/package-summary.html">lombok</a> package.&nbsp;If you're trying to extend lombok or
write your own plugins, the other packages are what you're looking for.</body></html>
]]></echo>
<javadoc sourcepath="src" defaultexcludes="yes" destdir="build/api" windowtitle="Lombok" Overview="${javadoc.overview.html}">
<classpath refid="lombok.deps.path" />
<classpath refid="lombok.libs.path" />
<link href="http://java.sun.com/javase/6/docs/api/" offline="true" packagelistLoc="./deps/javadoc/java6"/>
<header><![CDATA[<a href='http://projectlombok.org/'>Lombok</a> - ]]>v${lombok.version}</header>
<bottom><![CDATA[<i>Copyright &#169; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT licence</a>.]]></bottom>
</javadoc>
<mkdir dir="doc/api" />
<copy todir="doc/api">
<fileset dir="build/api" includes="**/*.html" />
<filterchain>
<linecontainsregexp negate="true">
<regexp pattern="(Generated by javadoc)|(.META NAME=.date.)" />
</linecontainsregexp>
</filterchain>
</copy>
<copy todir="doc/api">
<fileset dir="build/api" excludes="**/*.html" />
</copy>
</target>
</project>
Vendored
+1 -2
View File
@@ -1,5 +1,4 @@
'deps' are defined as those things which are required to compile or develop lombok, but which aren't required when
actually running lombok. The main lombok code is dependent on all libraries in the 'lombok' directory, whilst the agents
are dependent on both the contents of the 'agent' directory and the agent's specific directory (e.g. 'eclipse.agent').
actually running lombok.
For dependencies which need to be available at runtime, see the 'lib' directory.
Binary file not shown.
View File
Binary file not shown.
Binary file not shown.
@@ -95,6 +95,10 @@ public class TransformEclipseAST {
//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);
}
/**
* This method is called immediately after Eclipse finishes building a CompilationUnitDeclaration, which is
* the top-level AST node when Eclipse parses a source file. The signature is 'magic' - you should not
@@ -1,130 +0,0 @@
/*
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
*
* 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 java.lombok.eclipse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* Allows you to inject the lombok classes into any classloader, even if that classloader does not
* know how to find the lombok classes.
*
* Example: Injecting lombok's Eclipse Parser patching code into eclipse's OSGi BundleLoader.
*
* @author rzwitserloot
*/
public class ClassLoaderWorkaround {
static RuntimeException sneakyThrow(Throwable t) {
if ( t == null ) throw new NullPointerException("t");
ClassLoaderWorkaround.<RuntimeException>sneakyThrow0(t);
return null;
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
throw (T)t;
}
private static final Map<ClassLoader, Method> transform = new HashMap<ClassLoader, Method>();
public static void transformCompilationUnitDeclaration(Object parser, Object cud) throws Exception {
Method transformMethod = getTransformMethod(cud);
try {
transformMethod.invoke(null, parser, cud);
} catch ( InvocationTargetException e ) {
throw sneakyThrow(e.getCause());
}
}
private static Method getTransformMethod(Object cud) throws ClassNotFoundException {
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
synchronized ( transform ) {
if ( !transform.containsKey(contextLoader)) {
transform.put(contextLoader, findTransformMethod(cud));
}
Method m = transform.get(contextLoader);
if ( m == null ) throw new ClassNotFoundException("lombok.eclipse.TransformEclipseAST");
return m;
}
}
private static Method findTransformMethod(Object cud) throws ClassNotFoundException {
final ClassLoader parent = cud.getClass().getClassLoader();
ClassLoader loader = new ClassLoader() {
@Override public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if ( name.startsWith("lombok.") ) {
InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(name.replace(".", "/") + ".class");
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] b = new byte[65536];
try {
while ( true ) {
int r = in.read(b);
if ( r == -1 ) break;
if ( r > 0 ) out.write(b, 0, r);
}
in.close();
byte[] data = out.toByteArray();
Class<?> result = defineClass(name, data, 0, data.length);
if ( resolve ) resolveClass(result);
return result;
} catch ( IOException e ) {
throw new ClassNotFoundException();
}
} else {
try {
Class<?> result = ClassLoader.getSystemClassLoader().loadClass(name);
if ( resolve ) resolveClass(result);
return result;
} catch ( ClassNotFoundException e ) {
Class<?> result = parent.loadClass(name);
if ( resolve ) resolveClass(result);
return result;
}
}
}
};
Class<?> c = loader.loadClass("lombok.eclipse.TransformEclipseAST");
for ( Method method : c.getMethods() ) {
if ( method.getName().equals("transform") ) {
Class<?>[] types = method.getParameterTypes();
if ( types.length != 2 ) continue;
if ( !types[0].getName().equals("org.eclipse.jdt.internal.compiler.parser.Parser") ) continue;
if ( !types[1].getName().equals("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration") ) continue;
return method;
}
}
throw new ClassNotFoundException("lombok.eclipse.TransformEclipseAST");
}
}
@@ -1,27 +0,0 @@
/*
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
*
* 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.
*/
/**
* Workaround package to avoid the OSGi class loader system, which will always refer to the system class loader for any classes in a package
* that starts with <code>java.</code>
*/
package java.lombok.eclipse;
@@ -1,95 +0,0 @@
/*
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
*
* 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.eclipse.agent;
import org.mangosdk.spi.ProviderFor;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
/**
* Transforms Eclipse's <code>org.eclipse.jdt.core.dom.ASTConverter</code> class, which sometimes rescans bits and pieces
* of source files because Eclipse's own AST doesn't actually have enough information for eclipse (why they don't just fix
* the AST tree generator is beyond me). At any rate, for catch blocks generated by lombok, eclipse tries to rescan the
* source file to find the source position of the catch statement, which will of course fail as there's nothing there.
* We will fix the code to return the original starting position, which is a pretty good simile, instead of '-1', which
* screws up all sorts of things.
*
* Transformations applied:<ul>
* <li>The <code>retrieveStartingCatchPosition(int, int)</code> method is instrumented to return its first parameter
* instead of the constant -1.</li></ul>
*/
@ProviderFor(EclipseTransformer.class)
public class EclipseASTConverterTransformer implements EclipseTransformer {
public byte[] transform(byte[] classfileBuffer) {
ClassReader reader = new ClassReader(classfileBuffer);
ClassWriter writer = new ClassWriter(reader, 0);
ClassAdapter adapter = new ASTConverterPatcherAdapter(writer);
reader.accept(adapter, 0);
return writer.toByteArray();
}
private static class ASTConverterPatcherAdapter extends ClassAdapter {
public ASTConverterPatcherAdapter(ClassVisitor cv) {
super(cv);
}
@Override public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
MethodVisitor writerVisitor = super.visitMethod(access, name, desc, signature, exceptions);
if ( !name.equals("retrieveStartingCatchPosition") ) return writerVisitor;
return new RetrieveStartingCatchPositionPatcher(writerVisitor);
}
}
static class RetrieveStartingCatchPositionPatcher extends MethodAdapter {
RetrieveStartingCatchPositionPatcher(MethodVisitor mv) {
super(mv);
}
int count = 0;
@Override public void visitInsn(int opcode) {
if ( opcode == Opcodes.IRETURN ) {
if ( count++ == 0 ) {
super.visitInsn(opcode);
return;
}
//replaces: "return -1" with "return [firstParam]";
super.visitInsn(Opcodes.POP);
super.visitVarInsn(Opcodes.ILOAD, 1);
super.visitInsn(Opcodes.IRETURN);
} else {
super.visitInsn(opcode);
}
}
}
@Override public String getTargetClassName() {
return "org/eclipse/jdt/core/dom/ASTConverter";
}
}
@@ -1,68 +0,0 @@
/*
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
*
* 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.eclipse.agent;
import org.mangosdk.spi.ProviderFor;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;
/**
* Transforms Eclipse's {@code org.eclipse.jdt.internal.compiler.ast.ASTNode} class,
* which is the super-class of all AST Node class for Eclipse.
*
* Transformations applied:<ul>
* <li>A field is added: 'public transient ASTNode $generatedBy = null;'. It is set to something other than {@code null} if
* this node is generated; the reference then points at the node that is responsible for its generation (example: a {@code @Data} annotation).</li></ul>
*/
@ProviderFor(EclipseTransformer.class)
public class EclipseASTNodeTransformer implements EclipseTransformer {
private static final String ASTNODE = "org/eclipse/jdt/internal/compiler/ast/ASTNode";
public byte[] transform(byte[] classfileBuffer) {
ClassReader reader = new ClassReader(classfileBuffer);
ClassWriter writer = new ClassWriter(reader, 0);
ClassAdapter adapter = new ASTNodePatcherAdapter(writer);
reader.accept(adapter, 0);
return writer.toByteArray();
}
private static class ASTNodePatcherAdapter extends ClassAdapter {
ASTNodePatcherAdapter(ClassVisitor cv) {
super(cv);
}
@Override public void visitEnd() {
FieldVisitor fv = cv.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$generatedBy", "L" + ASTNODE + ";", null, null);
fv.visitEnd();
cv.visitEnd();
}
}
@Override public String getTargetClassName() {
return ASTNODE;
}
}
@@ -1,66 +0,0 @@
/*
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
*
* 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.eclipse.agent;
import org.mangosdk.spi.ProviderFor;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;
/**
* Transforms Eclipse's <code>org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration</code> class,
* which is the top-level AST Node class for Eclipse.
*
* Transformations applied:<ul>
* <li>A field is added: 'public transient Object $lombokAST = null;'. We use it to cache our own AST object,
* usually of type <code>lombok.eclipse.EclipseAST.</code></li></ul>
*/
@ProviderFor(EclipseTransformer.class)
public class EclipseCUDTransformer implements EclipseTransformer {
public byte[] transform(byte[] classfileBuffer) {
ClassReader reader = new ClassReader(classfileBuffer);
ClassWriter writer = new ClassWriter(reader, 0);
ClassAdapter adapter = new CUDPatcherAdapter(writer);
reader.accept(adapter, 0);
return writer.toByteArray();
}
private static class CUDPatcherAdapter extends ClassAdapter {
CUDPatcherAdapter(ClassVisitor cv) {
super(cv);
}
@Override public void visitEnd() {
FieldVisitor fv = cv.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$lombokAST", "Ljava/lang/Object;", null, null);
fv.visitEnd();
cv.visitEnd();
}
}
@Override public String getTargetClassName() {
return "org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration";
}
}
@@ -1,169 +0,0 @@
package lombok.eclipse.agent;
import org.mangosdk.spi.ProviderFor;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import static org.objectweb.asm.Opcodes.*;
@ProviderFor(EclipseTransformer.class)
public class EclipseLinkedNodeFinderTransformer implements EclipseTransformer {
private static final String LINKED_NODE_FINDER = "org/eclipse/jdt/core/internal/corext/dom/LinkedNodeFinder";
@Override public String getTargetClassName() {
return LINKED_NODE_FINDER;
}
@Override public byte[] transform(byte[] in) {
ClassReader reader = new ClassReader(in);
ClassWriter writer = new ClassWriter(reader, 0);
ClassAdapter adapter = new LinkedNodeFinderPatcherAdapter(writer);
reader.accept(adapter, 0);
return writer.toByteArray();
}
private static class LinkedNodeFinderPatcherAdapter extends ClassAdapter {
private int originalAccess;
private String originalDesc;
private String originalSignature;
private String[] originalExceptions;
LinkedNodeFinderPatcherAdapter(ClassVisitor cv) {
super(cv);
}
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if ( !name.equals("findByNode") ) return super.visitMethod(access, name, desc, signature, exceptions);
originalAccess = access;
originalDesc = desc;
originalSignature = signature;
originalExceptions = exceptions;
return super.visitMethod(0, "findByNode0", desc, signature, exceptions);
}
private static final String SIMPLENAME = "org/eclipse/jdt/core/dom/SimpleName";
private static final String SIMPLENAME_ARRAY = "[L" + SIMPLENAME + ";";
private static final String ASTNODE = "Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;";
/*
* code generated by running ASMifier on:
*
public SimpleName[] findByNode(ASTNode a, SimpleName b) {
SimpleName[] ps = this.findByNode0(a, b);
int count = 0;
for (int i = 0; i < ps.length; i++) {
if ( ps[i] == null || ps[i].$generatedBy == null ) count++;
}
if (count == ps.length) return ps;
SimpleName[] newPs = new SimpleName[count];
count = 0;
for (int i = 0; i < ps.length; i++) {
if ( ps[i] == null || ps[i].p == null ) newPs[count++] = ps[i];
}
return newPs;
}
*/
@Override public void visitEnd() {
MethodVisitor mv = super.visitMethod(originalAccess, "findByNode", originalDesc, originalSignature, originalExceptions);
mv.visitCode();
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKESPECIAL, LINKED_NODE_FINDER, "findByNode0", originalDesc);
mv.visitVarInsn(ASTORE, 3);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ISTORE, 4);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ISTORE, 5);
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitFrame(F_APPEND,3, new Object[] {SIMPLENAME_ARRAY, INTEGER, INTEGER}, 0, null);
mv.visitVarInsn(ILOAD, 5);
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(ARRAYLENGTH);
Label l1 = new Label();
mv.visitJumpInsn(IF_ICMPGE, l1);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ILOAD, 5);
mv.visitInsn(AALOAD);
Label l2 = new Label();
mv.visitJumpInsn(IFNULL, l2);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ILOAD, 5);
mv.visitInsn(AALOAD);
mv.visitFieldInsn(GETFIELD, SIMPLENAME, "$generatedBy", ASTNODE);
Label l3 = new Label();
mv.visitJumpInsn(IFNONNULL, l3);
mv.visitLabel(l2);
mv.visitFrame(F_SAME, 0, null, 0, null);
mv.visitIincInsn(4, 1);
mv.visitLabel(l3);
mv.visitFrame(F_SAME, 0, null, 0, null);
mv.visitIincInsn(5, 1);
mv.visitJumpInsn(GOTO, l0);
mv.visitLabel(l1);
mv.visitFrame(F_CHOP,1, null, 0, null);
mv.visitVarInsn(ILOAD, 4);
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(ARRAYLENGTH);
Label l4 = new Label();
mv.visitJumpInsn(IF_ICMPNE, l4);
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(ARETURN);
mv.visitLabel(l4);
mv.visitFrame(F_SAME, 0, null, 0, null);
mv.visitVarInsn(ILOAD, 4);
mv.visitTypeInsn(ANEWARRAY, SIMPLENAME);
mv.visitVarInsn(ASTORE, 5);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ISTORE, 4);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ISTORE, 6);
Label l5 = new Label();
mv.visitLabel(l5);
mv.visitFrame(F_APPEND,2, new Object[] {SIMPLENAME_ARRAY, INTEGER}, 0, null);
mv.visitVarInsn(ILOAD, 6);
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(ARRAYLENGTH);
Label l6 = new Label();
mv.visitJumpInsn(IF_ICMPGE, l6);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ILOAD, 6);
mv.visitInsn(AALOAD);
Label l7 = new Label();
mv.visitJumpInsn(IFNULL, l7);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ILOAD, 6);
mv.visitInsn(AALOAD);
mv.visitFieldInsn(GETFIELD, SIMPLENAME, "$generatedBy", ASTNODE);
Label l8 = new Label();
mv.visitJumpInsn(IFNONNULL, l8);
mv.visitLabel(l7);
mv.visitFrame(F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 5);
mv.visitVarInsn(ILOAD, 4);
mv.visitIincInsn(4, 1);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ILOAD, 6);
mv.visitInsn(AALOAD);
mv.visitInsn(AASTORE);
mv.visitLabel(l8);
mv.visitFrame(F_SAME, 0, null, 0, null);
mv.visitIincInsn(6, 1);
mv.visitJumpInsn(GOTO, l5);
mv.visitLabel(l6);
mv.visitFrame(F_CHOP,1, null, 0, null);
mv.visitVarInsn(ALOAD, 5);
mv.visitInsn(ARETURN);
mv.visitMaxs(4, 7);
super.visitEnd();
}
}
}
@@ -1,178 +0,0 @@
/*
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
*
* 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.eclipse.agent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import lombok.Lombok;
import org.mangosdk.spi.ProviderFor;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
/**
* Transforms Eclipse's <code>org.eclipse.jdt.internal.compiler.parser.Parser</code> class,
* which handles all the actual java source to AST tree conversion in eclipse.
*
* Transformations applied:<ul>
* <li>The <code>CompilationUnitDeclaration endParse(int)</code> method is instrumented to call
* the lombok framework via ClassLoaderWorkaround to TransformEclipseAST with the CompilationUnitDeclaration
* right before it returns the CompilationUnitDeclaration.</li>
* <li>The <code>getMethodBodies(CompilationUnitDeclaration)</code> is similarly instrumented; eclipse uses a
* 2-step parsing system, where the bodies of methods aren't filled in until its actually neccessary. Lombok
* gets a chance to change the AST immediately after either step.</li>
* <li>The <code>parse(MethodDeclaration, CUD)</code>, <code>parse(ConstructorDeclaration, CUD)</code> and
* <code>parse(Initializer, TypeDeclaration, CUD)</code> methods are all instrumented to not attempt to
* complete parsing a method generated by lombok, as the source positions are obviously all wrong
* (the method content isn't in the source file!) - lombok has already filled in the complete AST.
*
* Bit24 on the flags field on all ASTNode objects is used as a marker.</li></ul>
*/
@ProviderFor(EclipseTransformer.class)
public class EclipseParserTransformer implements EclipseTransformer {
private static final String COMPILER_PKG =
"Lorg/eclipse/jdt/internal/compiler/ast/";
private static final String TARGET_STATIC_CLASS = "java/lombok/eclipse/ClassLoaderWorkaround";
private static final String TARGET_STATIC_METHOD_NAME = "transformCompilationUnitDeclaration";
private static final String TARGET_STATIC_METHOD_DESC = "(Ljava/lang/Object;Ljava/lang/Object;)V";
private static final Map<String, Class<? extends MethodVisitor>> rewriters;
static {
Map<String, Class<? extends MethodVisitor>> map = new HashMap<String, Class<? extends MethodVisitor>>();
map.put(String.format("endParse(I)%sCompilationUnitDeclaration;", COMPILER_PKG), EndParsePatcher.class);
map.put(String.format("getMethodBodies(%sCompilationUnitDeclaration;)V", COMPILER_PKG), GetMethodBodiesPatcher.class);
map.put(String.format("parse(%1$sMethodDeclaration;%1$sCompilationUnitDeclaration;)V", COMPILER_PKG), ParseBlockContainerPatcher.class);
map.put(String.format("parse(%1$sConstructorDeclaration;%1$sCompilationUnitDeclaration;Z)V", COMPILER_PKG), ParseBlockContainerPatcher.class);
map.put(String.format("parse(%1$sInitializer;%1$sTypeDeclaration;%1$sCompilationUnitDeclaration;)V", COMPILER_PKG), ParseBlockContainerPatcher.class);
rewriters = Collections.unmodifiableMap(map);
}
public byte[] transform(byte[] classfileBuffer) {
ClassReader reader = new ClassReader(classfileBuffer);
ClassWriter writer = new ClassWriter(reader, 0);
ClassAdapter adapter = new ParserPatcherAdapter(writer);
reader.accept(adapter, 0);
return writer.toByteArray();
}
private static class ParserPatcherAdapter extends ClassAdapter {
public ParserPatcherAdapter(ClassVisitor cv) {
super(cv);
}
@Override public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
MethodVisitor writerVisitor = super.visitMethod(access, name, desc, signature, exceptions);
Class<? extends MethodVisitor> targetVisitorClass = rewriters.get(name+desc);
if ( targetVisitorClass == null ) return writerVisitor;
try {
Constructor<? extends MethodVisitor> c = targetVisitorClass.getDeclaredConstructor(MethodVisitor.class);
c.setAccessible(true);
return c.newInstance(writerVisitor);
} catch ( InvocationTargetException e ) {
throw Lombok.sneakyThrow(e.getCause());
} catch ( Exception e ) {
//NoSuchMethodException: We know they exist.
//IllegalAccessException: We called setAccessible.
//InstantiationException: None of these classes are abstract.
throw Lombok.sneakyThrow(e);
}
}
}
private static final int BIT24 = 0x800000;
static class GetMethodBodiesPatcher extends MethodAdapter {
GetMethodBodiesPatcher(MethodVisitor mv) {
super(mv);
}
@Override public void visitInsn(int opcode) {
if ( opcode == Opcodes.RETURN ) {
//injects: ClassLoaderWorkaround.transformCUD(parser, compilationUnitDeclaration);
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitVarInsn(Opcodes.ALOAD, 1);
super.visitMethodInsn(Opcodes.INVOKESTATIC, TARGET_STATIC_CLASS,
TARGET_STATIC_METHOD_NAME, TARGET_STATIC_METHOD_DESC);
}
super.visitInsn(opcode);
}
}
static class ParseBlockContainerPatcher extends MethodAdapter {
ParseBlockContainerPatcher(MethodVisitor mv) {
super(mv);
}
@Override public void visitCode() {
//injects: if ( constructorDeclaration.bits & BIT24 > 0 ) return;
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitFieldInsn(Opcodes.GETFIELD, "org/eclipse/jdt/internal/compiler/ast/ASTNode", "bits", "I");
mv.visitLdcInsn(Integer.valueOf(BIT24));
mv.visitInsn(Opcodes.IAND);
Label l0 = new Label();
mv.visitJumpInsn(Opcodes.IFLE, l0);
mv.visitInsn(Opcodes.RETURN);
mv.visitLabel(l0);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
super.visitCode();
}
}
static class EndParsePatcher extends MethodAdapter {
private static final String TARGET_STATIC_METHOD_NAME = "transformCompilationUnitDeclaration";
EndParsePatcher(MethodVisitor mv) {
super(mv);
}
@Override public void visitInsn(int opcode) {
if ( opcode == Opcodes.ARETURN ) {
//injects: ClassLoaderWorkaround.transformCUD(parser, compilationUnitDeclaration);
super.visitInsn(Opcodes.DUP);
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitInsn(Opcodes.SWAP);
super.visitMethodInsn(Opcodes.INVOKESTATIC, TARGET_STATIC_CLASS,
TARGET_STATIC_METHOD_NAME, TARGET_STATIC_METHOD_DESC);
}
super.visitInsn(opcode);
}
}
@Override public String getTargetClassName() {
return "org/eclipse/jdt/internal/compiler/parser/Parser";
}
}
@@ -21,24 +21,18 @@
*/
package lombok.eclipse.agent;
import java.io.File;
import java.io.IOException;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.security.ProtectionDomain;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import lombok.Lombok;
import lombok.core.SpiLoadUtil;
import lombok.patcher.Hook;
import lombok.patcher.MethodTarget;
import lombok.patcher.ScriptManager;
import lombok.patcher.StackRequest;
import lombok.patcher.TargetMatcher;
import lombok.patcher.equinox.EquinoxClassLoader;
import lombok.patcher.scripts.ScriptBuilder;
/**
* This is a java-agent that patches some of eclipse's classes so AST Nodes are handed off to Lombok
@@ -50,85 +44,127 @@ import lombok.core.SpiLoadUtil;
public class EclipsePatcher {
private EclipsePatcher() {}
private static Map<String, EclipseTransformer> transformers = new HashMap<String, EclipseTransformer>();
static {
try {
for ( EclipseTransformer transformer : SpiLoadUtil.findServices(EclipseTransformer.class) ) {
String targetClassName = transformer.getTargetClassName();
transformers.put(targetClassName, transformer);
}
} catch ( Throwable t ) {
throw Lombok.sneakyThrow(t);
}
}
private static class Patcher implements ClassFileTransformer {
public byte[] transform(ClassLoader loader, String className,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer)
throws IllegalClassFormatException {
// ClassLoader classLoader = Patcher.class.getClassLoader();
// if ( classLoader == null ) classLoader = ClassLoader.getSystemClassLoader();
EclipseTransformer transformer = transformers.get(className);
if ( transformer != null ) return transformer.transform(classfileBuffer);
return null;
}
}
public static void agentmain(String agentArgs, Instrumentation instrumentation) throws Exception {
registerPatcher(instrumentation, true);
addLombokToSearchPaths(instrumentation);
}
private static void addLombokToSearchPaths(Instrumentation instrumentation) throws Exception {
String path = findPathOfOurClassloader();
//On java 1.5, you don't have these methods, so you'll be forced to manually -Xbootclasspath/a them in.
tryCallMethod(instrumentation, "appendToSystemClassLoaderSearch", path + "/lombok.jar");
tryCallMethod(instrumentation, "appendToBootstrapClassLoaderSearch", path + "/lombok.eclipse.agent.jar");
}
private static void tryCallMethod(Object o, String methodName, String path) {
try {
Instrumentation.class.getMethod(methodName, JarFile.class).invoke(o, new JarFile(path));
} catch ( Throwable ignore ) {}
}
private static String findPathOfOurClassloader() throws Exception {
URI uri = EclipsePatcher.class.getResource("/" + EclipsePatcher.class.getName().replace('.', '/') + ".class").toURI();
Pattern p = Pattern.compile("^jar:file:([^\\!]+)\\!.*\\.class$");
Matcher m = p.matcher(uri.toString());
if ( !m.matches() ) return ".";
String rawUri = m.group(1);
return new File(URLDecoder.decode(rawUri, Charset.defaultCharset().name())).getParent();
registerPatchScripts(instrumentation, true);
}
public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception {
registerPatcher(instrumentation, false);
addLombokToSearchPaths(instrumentation);
registerPatchScripts(instrumentation, false);
}
private static void registerPatcher(Instrumentation instrumentation, boolean transformExisting) throws IOException {
instrumentation.addTransformer(new Patcher()/*, true*/);
private static void registerPatchScripts(Instrumentation instrumentation, boolean reloadExistingClasses) {
ScriptManager sm = new ScriptManager();
sm.registerTransformer(instrumentation);
EquinoxClassLoader.getInstance().addPrefix("lombok.");
EquinoxClassLoader.getInstance().registerScripts(sm);
if ( transformExisting ) for ( Class<?> c : instrumentation.getAllLoadedClasses() ) {
if ( transformers.containsKey(c.getName()) ) {
try {
//instrumentation.retransformClasses(c); - //not in java 1.5.
Instrumentation.class.getMethod("retransformClasses", Class[].class).invoke(instrumentation,
new Object[] { new Class[] {c }});
} catch ( InvocationTargetException e ) {
throw new UnsupportedOperationException(
"The eclipse parser class is already loaded and cannot be modified. " +
"You'll have to restart eclipse in order to use Lombok in eclipse.");
} catch ( Throwable t ) {
throw new UnsupportedOperationException(
"This appears to be a java 1.5 instance, which cannot reload already loaded classes. " +
"You'll have to restart eclipse in order to use Lombok in eclipse.");
}
}
}
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());
sm.addScript(ScriptBuilder.addField()
.targetClass("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration")
.fieldName("$lombokAST").fieldType("Ljava/lang/Object;")
.setPublic().setTransient().build());
final String PARSER_SIG1 = "org.eclipse.jdt.internal.compiler.parser.Parser";
final String PARSER_SIG2 = "Lorg/eclipse/jdt/internal/compiler/parser/Parser;";
final String CUD_SIG1 = "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration";
final String CUD_SIG2 = "Lorg/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration;";
sm.addScript(ScriptBuilder.wrapReturnValue()
.target(new MethodTarget(PARSER_SIG1, "getMethodBodies", "void", CUD_SIG1))
.wrapMethod(new Hook("lombok/eclipse/TransformEclipseAST", "transform",
"(" + PARSER_SIG2 + CUD_SIG2 + ")V"))
.request(StackRequest.THIS, StackRequest.PARAM1).build());
sm.addScript(ScriptBuilder.wrapReturnValue()
.target(new MethodTarget(PARSER_SIG1, "endParse", CUD_SIG1, "int"))
.wrapMethod(new Hook("lombok/eclipse/TransformEclipseAST", "transform_swapped",
"(" + CUD_SIG2 + PARSER_SIG2 + ")V"))
.request(StackRequest.THIS, StackRequest.RETURN_VALUE).build());
sm.addScript(ScriptBuilder.exitEarly()
.target(new MethodTarget(PARSER_SIG1, "parse", "void",
"org.eclipse.jdt.internal.compiler.ast.MethodDeclaration",
"org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"))
.decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z"))
.transplant().request(StackRequest.PARAM1).build());
sm.addScript(ScriptBuilder.exitEarly()
.target(new MethodTarget(PARSER_SIG1, "parse", "void",
"org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration",
"org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "boolean"))
.decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z"))
.transplant().request(StackRequest.PARAM1).build());
sm.addScript(ScriptBuilder.exitEarly()
.target(new MethodTarget(PARSER_SIG1, "parse", "void",
"org.eclipse.jdt.internal.compiler.ast.Initializer",
"org.eclipse.jdt.internal.compiler.ast.TypeDeclaration",
"org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"))
.decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z"))
.transplant().request(StackRequest.PARAM1).build());
sm.addScript(ScriptBuilder.addField()
.targetClass("org.eclipse.jdt.internal.compiler.ast.ASTNode")
.fieldName("$generatedBy")
.fieldType("Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;")
.setPublic().setTransient().build());
sm.addScript(ScriptBuilder.addField()
.targetClass("org.eclipse.jdt.core.dom.ASTNode")
.fieldName("$isGenerated").fieldType("Z")
.setPublic().setTransient().build());
sm.addScript(ScriptBuilder.wrapReturnValue()
.target(new TargetMatcher() {
@Override public boolean matches(String classSpec, String methodName, String descriptor) {
if (!"convert".equals(methodName)) return false;
List<String> fullDesc = MethodTarget.decomposeFullDesc(descriptor);
if ("V".equals(fullDesc.get(0))) return false;
if (fullDesc.size() < 2) return false;
if (!fullDesc.get(1).startsWith("Lorg/eclipse/jdt/internal/compiler/ast/")) return false;
return true;
}
@Override public Collection<String> getAffectedClasses() {
return Collections.singleton("org.eclipse.jdt.core.dom.ASTConverter");
}
}).request(StackRequest.PARAM1, StackRequest.RETURN_VALUE)
.wrapMethod(new Hook("lombok/eclipse/agent/PatchFixes", "setIsGeneratedFlag",
"(Lorg/eclipse/jdt/core/dom/ASTNode;Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;)V"))
.transplant().build());
sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new TargetMatcher() {
@Override public boolean matches(String classSpec, String methodName, String descriptor) {
if (!methodName.startsWith("convert")) return false;
List<String> fullDesc = MethodTarget.decomposeFullDesc(descriptor);
if (fullDesc.size() < 2) return false;
if (!fullDesc.get(1).startsWith("Lorg/eclipse/jdt/internal/compiler/ast/")) return false;
return true;
}
@Override public Collection<String> getAffectedClasses() {
return Collections.singleton("org.eclipse.jdt.core.dom.ASTConverter");
}
}).methodToWrap(new Hook("org/eclipse/jdt/core/dom/SimpleName", "<init>", "(Lorg/eclipse/jdt/core/dom/AST;)V"))
.requestExtra(StackRequest.PARAM1)
.replacementMethod(new Hook("lombok/eclipse/agent/PatchFixes", "setIsGeneratedFlagForSimpleName",
"(Lorg/eclipse/jdt/core/dom/SimpleName;Ljava/lang/Object;)V"))
.transplant().build());
sm.addScript(ScriptBuilder.wrapReturnValue()
.target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode"))
.wrapMethod(new Hook("lombok/eclipse/agent/PatchFixes", "removeGeneratedSimpleNames",
"([Lorg/eclipse/jdt/core/dom/SimpleName;)[Lorg/eclipse/jdt/core/dom/SimpleName;"))
.request(StackRequest.RETURN_VALUE).build());
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
}
@@ -1,8 +0,0 @@
package lombok.eclipse.agent;
public interface EclipseTransformer {
/** slash and not dot separated */
String getTargetClassName();
byte[] transform(byte[] in);
}
@@ -0,0 +1,48 @@
package lombok.eclipse.agent;
import java.lang.reflect.Field;
import org.eclipse.jdt.core.dom.SimpleName;
public class PatchFixes {
public static int fixRetrieveStartingCatchPosition(int in) {
return in;
}
private static final int BIT24 = 0x800000;
public static boolean checkBit24(Object node) throws Exception {
int bits = (Integer)(node.getClass().getField("bits").get(node));
return (bits & BIT24) != 0;
}
public static void setIsGeneratedFlag(org.eclipse.jdt.core.dom.ASTNode domNode,
org.eclipse.jdt.internal.compiler.ast.ASTNode internalNode) throws Exception {
boolean isGenerated = internalNode.getClass().getField("$generatedBy").get(internalNode) != null;
if (isGenerated) domNode.getClass().getField("$isGenerated").set(domNode, true);
}
public static void setIsGeneratedFlagForSimpleName(SimpleName name, Object internalNode) throws Exception {
if (internalNode instanceof org.eclipse.jdt.internal.compiler.ast.ASTNode) {
if (internalNode.getClass().getField("$generatedBy").get(internalNode) != null) {
name.getClass().getField("$isGenerated").set(name, true);
}
}
}
public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception {
Field f = SimpleName.class.getField("$isGenerated");
int count = 0;
for (int i = 0; i < in.length; i++) {
if ( in[i] == null || !((Boolean)f.get(in[i])).booleanValue() ) count++;
}
if (count == in.length) return in;
SimpleName[] newSimpleNames = new SimpleName[count];
count = 0;
for (int i = 0; i < in.length; i++) {
if ( in[i] == null || !((Boolean)f.get(in[i])).booleanValue() ) newSimpleNames[count++] = in[i];
}
return newSimpleNames;
}
}
-37
View File
@@ -1,37 +0,0 @@
#!/bin/bash
if [ ! -e src/lombok/core/Version.java ]; then
echo Run this script from the lombok project home directory.
exit
fi
if [ ! -e dist/website.tar.bz2 ]; then
echo There is no dist/website.tar.bz2 file! Run:
echo ant website
echo then restart this script
exit
fi
mkdir -p build/temp || exit
cd build/temp || exit
git clone -l -n ../.. websitegit || exit
cd websitegit || exit
BRANCHOK="foo"
git branch gh-pages origin/gh-pages || BRANCHOK="bar"
if [ $BRANCHOK == "bar" ]; then
echo If you get error fatal: Not a valid object name: origin/gh-pages.
echo then run: git branch gh-pages origin/gh-pages
echo first before running this script
exit
fi
git checkout gh-pages || exit
rm -r * || exit
tar xfj ../../../dist/website.tar.bz2 || exit
git add . || exit
git commit -a -m website || exit
git push origin gh-pages || exit
cd .. || exit
rm -rf websitegit || exit
echo Your gh-pages branch has been updated. Do not forget to run:
echo git push origin gh-pages