[Git][java-team/lombok-patcher][upstream] 2 commits: New upstream version 0.38
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Tue May 10 17:17:37 BST 2022
Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / lombok-patcher
Commits:
c7231444 by Emmanuel Bourg at 2022-05-10T16:35:57+02:00
New upstream version 0.38
- - - - -
229013a8 by Emmanuel Bourg at 2022-05-10T16:42:57+02:00
New upstream version 0.40
- - - - -
17 changed files:
- build.xml
- buildScripts/ivy.xml
- buildScripts/ivysettings.xml
- propagateDistToLombok
- src/injector/lombok/patcher/inject/LiveInjector.java
- src/patcher/lombok/patcher/MethodTarget.java
- src/patcher/lombok/patcher/PatchScript.java
- src/patcher/lombok/patcher/ScriptManager.java
- src/patcher/lombok/patcher/TargetMatcher.java
- src/patcher/lombok/patcher/Version.java
- src/patcher/lombok/patcher/scripts/AddFieldScript.java
- src/patcher/lombok/patcher/scripts/ExitFromMethodEarlyScript.java
- src/patcher/lombok/patcher/scripts/MethodLevelPatchScript.java
- src/patcher/lombok/patcher/scripts/ReplaceMethodCallScript.java
- src/patcher/lombok/patcher/scripts/SetSymbolDuringMethodCallScript.java
- src/patcher/lombok/patcher/scripts/WrapMethodCallScript.java
- src/patcher/lombok/patcher/scripts/WrapReturnValuesScript.java
Changes:
=====================================
build.xml
=====================================
@@ -30,7 +30,7 @@
<target name="load-ipp" depends="download-ipp">
<taskdef classpath="lib/ivyplusplus.jar" resource="com/zwitserloot/ivyplusplus/antlib.xml" uri="antlib:com.zwitserloot.ivyplusplus" />
- <ivy:ensureippversion version="1.26" property="ivyplusplus.minimumAvailable" />
+ <ivy:ensureippversion version="1.38" property="ivyplusplus.minimumAvailable" />
</target>
<target name="redownload-ipp" unless="ivyplusplus.minimumAvailable">
@@ -112,7 +112,11 @@
<target name="compile" depends="unpackLibs, ensureBuildDeps" description="Compiles lombok.patcher" unless="pointless">
<ivy:compile destdir="build/pack" target="1.5" source="1.5" ecj="true">
<src path="src/patcher" />
+ <classpath refid="build.path" />
+ </ivy:compile>
+ <ivy:compile destdir="build/pack" target="1.5" source="1.5" ecj="true">
<src path="src/injector" />
+ <classpath path="build/pack" />
<classpath refid="build.path" />
</ivy:compile>
</target>
=====================================
buildScripts/ivy.xml
=====================================
@@ -8,12 +8,12 @@
<conf name="contrib" />
</configurations>
<dependencies>
- <dependency org="junit" name="junit" rev="4.12" conf="test -> default"/>
+ <dependency org="junit" name="junit" rev="4.13" conf="test -> default"/>
<dependency org="com.jcraft" name="jsch" rev="0.1.42" conf="build->default" />
<dependency org="projectlombok.org" name="jsch-ant-fixed" rev="0.1.45" conf="build" />
- <dependency org="org.ow2.asm" name="asm" rev="7.2" conf="runtime, build -> default; contrib->sources" />
- <dependency org="org.ow2.asm" name="asm-tree" rev="7.2" conf="runtime, build->default; contrib->sources" />
- <dependency org="org.ow2.asm" name="asm-commons" rev="7.2" conf="runtime, build->default; contrib->sources" />
- <dependency org="net.java.dev.jna" name="jna" rev="5.5.0" conf="runtimeInjector, build->master" />
+ <dependency org="org.ow2.asm" name="asm" rev="9.0" conf="runtime, build -> default; contrib->sources" />
+ <dependency org="org.ow2.asm" name="asm-tree" rev="9.0" conf="runtime, build->default; contrib->sources" />
+ <dependency org="org.ow2.asm" name="asm-commons" rev="9.0" conf="runtime, build->default; contrib->sources" />
+ <dependency org="net.java.dev.jna" name="jna" rev="5.6.0" conf="runtimeInjector, build->master" />
</dependencies>
</ivy-module>
=====================================
buildScripts/ivysettings.xml
=====================================
@@ -4,7 +4,7 @@
<filesystem name="projectLocalRepo">
<ivy pattern="${ivy.settings.dir}/ivy-repo/[organisation]-[module]-[revision].xml" />
</filesystem>
- <ibiblio name="maven-repo2" m2compatible="true" root="http://repo2.maven.org/maven2" />
+ <ibiblio name="maven-repo2" m2compatible="true" root="https://repo1.maven.org/maven2" />
</chain>
</resolvers>
<settings defaultResolver="projectRepos" />
=====================================
propagateDistToLombok
=====================================
@@ -26,4 +26,8 @@ if [ -d ../lombok/lib/build ]; then
cp dist/lombok.patcher.jar ../lombok/lib/build/org.projectlombok-lombok.patcher.jar
fi
+if [ -d ../lombok/lib/stripe ]; then
+ cp dist/lombok.patcher.jar ../lombok/lib/stripe/org.projectlombok-lombok.patcher.jar
+fi
+
cp dist/lombok.patcher.jar ../lombok/ivyCache/org.projectlombok/lombok.patcher/jars/lombok.patcher-$VERSION.jar
=====================================
src/injector/lombok/patcher/inject/LiveInjector.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2019 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -95,11 +95,11 @@ public class LiveInjector {
throw new IllegalStateException("agent injection only works on a sun-derived 1.6 or higher VM");
}
- LibJVM libjvm = (LibJVM) Native.loadLibrary(LibJVM.class);
+ LibJVM libjvm = Native.load(LibJVM.class);
PointerByReference vms = new PointerByReference();
IntByReference found = new IntByReference();
libjvm.JNI_GetCreatedJavaVMs(vms, 1, found);
- LibInstrument libinstrument = (LibInstrument)Native.loadLibrary(LibInstrument.class);
+ LibInstrument libinstrument = Native.load(LibInstrument.class);
Pointer vm = vms.getValue();
libinstrument.Agent_OnAttach(vm, jarFile, null);
}
=====================================
src/patcher/lombok/patcher/MethodTarget.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2017 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -44,6 +44,15 @@ public final class MethodTarget implements TargetMatcher {
private final List<String> parameterSpec;
private boolean hasDescription;
+ public String describe() {
+ int sci1 = classSpec.lastIndexOf('.');
+ int sci2 = classSpec.lastIndexOf('$');
+ int sci3 = classSpec.lastIndexOf('/');
+ int sci = sci1 > sci2 ? sci1 : sci2;
+ if (sci < sci3) sci = sci3;
+ return (sci == -1 ? classSpec : classSpec.substring(sci + 1)) + ":" + methodName;
+ }
+
public String getClassSpec() {
return classSpec;
}
=====================================
src/patcher/lombok/patcher/PatchScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2017 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -67,6 +67,8 @@ public abstract class PatchScript {
return false;
}
+ public abstract boolean wouldPatch(String className);
+
/**
* Transforms the class. You may return {@code null} if you have no interest in transforming this particular class.
*/
=====================================
src/patcher/lombok/patcher/ScriptManager.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2016 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,13 +31,23 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.ProtectionDomain;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.jar.JarFile;
public class ScriptManager {
+ private static final class WitnessAction {
+ boolean triggered;
+ boolean ifWitnessRemove;
+ PatchScript script;
+ }
+
private final List<PatchScript> scripts = new ArrayList<PatchScript>();
+ private final Map<String, List<WitnessAction>> witnessActions = new HashMap<String, List<WitnessAction>>(); // maps FQNs to actions
+
private TransplantMapper transplantMapper = TransplantMapper.IDENTITY_MAPPER;
private Filter filter = Filter.ALWAYS;
@@ -45,6 +55,35 @@ public class ScriptManager {
scripts.add(script);
}
+ public void addScriptIfWitness(String[] witness, PatchScript script) {
+ WitnessAction wa = new WitnessAction();
+ wa.ifWitnessRemove = false;
+ wa.script = script;
+ for (String w : witness) {
+ List<WitnessAction> list = witnessActions.get(w);
+ if (list == null) {
+ list = new ArrayList<WitnessAction>();
+ witnessActions.put(w, list);
+ }
+ list.add(wa);
+ }
+ }
+
+ public void addScriptIfNotWitness(String[] witness, PatchScript script) {
+ WitnessAction wa = new WitnessAction();
+ wa.ifWitnessRemove = true;
+ wa.script = script;
+ scripts.add(script);
+ for (String w : witness) {
+ List<WitnessAction> list = witnessActions.get(w);
+ if (list == null) {
+ list = new ArrayList<WitnessAction>();
+ witnessActions.put(w, list);
+ }
+ list.add(wa);
+ }
+ }
+
public void setFilter(Filter filter) {
this.filter = filter == null ? Filter.ALWAYS : filter;
}
@@ -84,7 +123,7 @@ public class ScriptManager {
}
private static final String DEBUG_PATCHING;
-
+ private static final boolean LOG_TO_STANDARD_ERR = false;
static {
DEBUG_PATCHING = System.getProperty("lombok.patcher.patchDebugDir", null);
}
@@ -95,15 +134,46 @@ public class ScriptManager {
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if (className == null) return null;
+ List<WitnessAction> actions = witnessActions.get(className);
+ if (actions != null) {
+ for (WitnessAction wa : actions) {
+ if (wa.triggered) continue;
+ wa.triggered = true;
+ if (wa.ifWitnessRemove) {
+ scripts.remove(wa.script);
+ if (LOG_TO_STANDARD_ERR) System.err.println("Removed script: " + wa.script.getPatchScriptName() + " because I saw " + className);
+ } else {
+ scripts.add(wa.script);
+ if (LOG_TO_STANDARD_ERR) System.err.println("Added script: " + wa.script.getPatchScriptName() + " because I saw " + className);
+ }
+ }
+ }
+
if (!filter.shouldTransform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer)) return null;
+ if (LOG_TO_STANDARD_ERR) for (List<WitnessAction> list : witnessActions.values()) {
+ for (WitnessAction wa : list) {
+ if (wa.triggered || wa.ifWitnessRemove) continue;
+ if (wa.script.wouldPatch(className)) {
+ System.err.println("[SKIPPING] " + wa.script.getPatchScriptName());
+ }
+ }
+ }
+
byte[] byteCode = classfileBuffer;
boolean patched = false;
for (PatchScript script : scripts) {
byte[] transformed = null;
try {
- transformed = script.patch(className, byteCode, transplantMapper);
+ if (LOG_TO_STANDARD_ERR) {
+ if (script.wouldPatch(className)) {
+ System.err.println("[RUNNING] " + script.getPatchScriptName());
+ transformed = script.patch(className, byteCode, transplantMapper);
+ }
+ } else {
+ transformed = script.patch(className, byteCode, transplantMapper);
+ }
} catch (Throwable t) {
//Exceptions get silently swallowed by instrumentation, so this is a slight improvement.
System.err.printf("Transformer %s failed on %s. Trace:\n", script.getPatchScriptName(), className);
=====================================
src/patcher/lombok/patcher/TargetMatcher.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,4 +39,5 @@ public interface TargetMatcher {
*/
public abstract boolean matches(String classSpec, String methodName, String descriptor);
+ public abstract String describe();
}
\ No newline at end of file
=====================================
src/patcher/lombok/patcher/Version.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2019 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,7 @@ package lombok.patcher;
*/
public class Version {
// ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries).
- private static final String VERSION = "0.36";
+ private static final String VERSION = "0.40";
private Version() {
//Prevent instantiation
=====================================
src/patcher/lombok/patcher/scripts/AddFieldScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -43,6 +43,10 @@ public class AddFieldScript extends PatchScript {
private final String fieldType;
private final Object value;
+ @Override public String getPatchScriptName() {
+ return "AddField: " + fieldType + " " + fieldName + "to "+ targetClasses;
+ }
+
/**
* @param targetClasses The class(es) to add the field to, separated with dots (e.g. java.lang.String).
* @param fieldName the name of the field to create.
@@ -59,6 +63,11 @@ public class AddFieldScript extends PatchScript {
this.value = value;
}
+ @Override public boolean wouldPatch(String className) {
+ for (String tc : targetClasses) if (MethodTarget.typeMatches(className, tc)) return true;
+ return false;
+ }
+
@Override public byte[] patch(String className, byte[] byteCode, TransplantMapper transplantMapper) {
for (String tc : targetClasses) if (MethodTarget.typeMatches(className, tc)) return runASM(byteCode, false, transplantMapper);
return null;
=====================================
src/patcher/lombok/patcher/scripts/ExitFromMethodEarlyScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -45,6 +45,10 @@ public class ExitFromMethodEarlyScript extends MethodLevelPatchScript {
private final boolean transplant, insert;
private final boolean insertCallOnly;
+ @Override public String getPatchScriptName() {
+ return "Exit Early from " + describeMatchers();
+ }
+
ExitFromMethodEarlyScript(List<TargetMatcher> matchers, Hook decisionWrapper, Hook valueWrapper, boolean transplant, boolean insert, Set<StackRequest> requests) {
super(matchers);
this.decisionWrapper = decisionWrapper;
=====================================
src/patcher/lombok/patcher/scripts/MethodLevelPatchScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,6 +37,15 @@ public abstract class MethodLevelPatchScript extends PatchScript {
private final Set<String> affectedClasses;
private final Collection<TargetMatcher> matchers;
+ public String describeMatchers() {
+ if (matchers.size() == 0) return "(No matchers)";
+ if (matchers.size() == 1) return matchers.iterator().next().describe();
+ StringBuilder out = new StringBuilder("(");
+ for (TargetMatcher tm : matchers) out.append(tm.describe()).append(", ");
+ out.setLength(out.length() - 2);
+ return out.append(")").toString();
+ }
+
public MethodLevelPatchScript(Collection<TargetMatcher> matchers) {
this.matchers = matchers;
Set<String> affected = new HashSet<String>();
@@ -48,6 +57,10 @@ public abstract class MethodLevelPatchScript extends PatchScript {
return affectedClasses;
}
+ @Override public boolean wouldPatch(String className) {
+ return classMatches(className, affectedClasses);
+ }
+
@Override public byte[] patch(String className, byte[] byteCode, TransplantMapper transplantMapper) {
if (!classMatches(className, affectedClasses)) return null;
return runASM(byteCode, true, transplantMapper);
=====================================
src/patcher/lombok/patcher/scripts/ReplaceMethodCallScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -44,7 +44,11 @@ public class ReplaceMethodCallScript extends MethodLevelPatchScript {
private final Hook methodToReplace;
private final boolean transplant, insert;
private final Set<StackRequest> extraRequests;
-
+
+ @Override public String getPatchScriptName() {
+ return "replace " + methodToReplace.getMethodName() + " with " + wrapper.getMethodName() + " in " + describeMatchers();
+ }
+
ReplaceMethodCallScript(List<TargetMatcher> matchers, Hook callToReplace, Hook wrapper, boolean transplant, boolean insert, Set<StackRequest> extraRequests) {
super(matchers);
if (callToReplace == null) throw new NullPointerException("callToReplace");
=====================================
src/patcher/lombok/patcher/scripts/SetSymbolDuringMethodCallScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -45,6 +45,10 @@ public class SetSymbolDuringMethodCallScript extends MethodLevelPatchScript {
private final String symbol;
private final boolean report;
+ @Override public String getPatchScriptName() {
+ return "set symbol " + symbol + " if " + callToWrap.getMethodName() + " is invoked in " + describeMatchers();
+ }
+
SetSymbolDuringMethodCallScript(List<TargetMatcher> matchers, Hook callToWrap, String symbol, boolean report) {
super(matchers);
if (callToWrap == null) throw new NullPointerException("callToWrap");
=====================================
src/patcher/lombok/patcher/scripts/WrapMethodCallScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -50,6 +50,10 @@ public class WrapMethodCallScript extends MethodLevelPatchScript {
private final boolean leaveReturnValueIntact;
private final Set<StackRequest> extraRequests;
+ @Override public String getPatchScriptName() {
+ return "wrap " + callToWrap.getMethodName() + " with " + wrapper.getMethodName() + " in " + describeMatchers();
+ }
+
WrapMethodCallScript(List<TargetMatcher> matchers, Hook callToWrap, Hook wrapper, boolean transplant, boolean insert, Set<StackRequest> extraRequests) {
super(matchers);
if (callToWrap == null) throw new NullPointerException("callToWrap");
=====================================
src/patcher/lombok/patcher/scripts/WrapReturnValuesScript.java
=====================================
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2019 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -43,6 +43,10 @@ public final class WrapReturnValuesScript extends MethodLevelPatchScript {
private final boolean hijackReturnValue;
private final boolean transplant, insert, cast;
+ @Override public String getPatchScriptName() {
+ return "wrap returns with " + wrapper.getMethodName() + " in " + describeMatchers();
+ }
+
/**
* @param targetMethod The target method to patch.
* @param wrapper A call to this method will be inserted in front of each return in the target method (must be static).
View it on GitLab: https://salsa.debian.org/java-team/lombok-patcher/-/compare/da9aadc1e6e91f62adaa11d4e2201124dc53314d...229013a87464d43544986ff8595c8304c96b4fb5
--
View it on GitLab: https://salsa.debian.org/java-team/lombok-patcher/-/compare/da9aadc1e6e91f62adaa11d4e2201124dc53314d...229013a87464d43544986ff8595c8304c96b4fb5
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20220510/e78f3f59/attachment.htm>
More information about the pkg-java-commits
mailing list