mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 02:16:18 +00:00
Integrated lombok.jar and lombok.eclipse.agent.jar into one jar that installs, is a javac apt processor, and an agent, all at once.
This commit is contained in:
1 parent
e2ffd58f81
commit
310862d94e
9 files changed
+69
-128
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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
-2
@@ -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.
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
Empty dir placeholder
|
||||
@@ -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
|
||||
|
||||
@@ -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 ) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>" +
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user