misc minor changes
This commit is contained in:
parent
0f02264e50
commit
192b0fd478
|
@ -6,7 +6,7 @@ import net.bytebuddy.build.Plugin;
|
||||||
import net.bytebuddy.description.type.TypeDefinition;
|
import net.bytebuddy.description.type.TypeDefinition;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||||
import net.bytebuddy.dynamic.DynamicType.Builder;
|
import net.bytebuddy.dynamic.DynamicType;
|
||||||
|
|
||||||
/** Bytebuddy gradle plugin which creates muzzle-references at compile time. */
|
/** Bytebuddy gradle plugin which creates muzzle-references at compile time. */
|
||||||
public class MuzzleGradlePlugin implements Plugin {
|
public class MuzzleGradlePlugin implements Plugin {
|
||||||
|
@ -32,8 +32,8 @@ public class MuzzleGradlePlugin implements Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder<?> apply(
|
public DynamicType.Builder<?> apply(
|
||||||
final Builder<?> builder,
|
final DynamicType.Builder<?> builder,
|
||||||
final TypeDescription typeDescription,
|
final TypeDescription typeDescription,
|
||||||
final ClassFileLocator classFileLocator) {
|
final ClassFileLocator classFileLocator) {
|
||||||
return builder.visit(new MuzzleVisitor());
|
return builder.visit(new MuzzleVisitor());
|
||||||
|
@ -50,8 +50,8 @@ public class MuzzleGradlePlugin implements Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder<?> apply(
|
public DynamicType.Builder<?> apply(
|
||||||
final Builder<?> builder,
|
final DynamicType.Builder<?> builder,
|
||||||
final TypeDescription typeDescription,
|
final TypeDescription typeDescription,
|
||||||
final ClassFileLocator classFileLocator) {
|
final ClassFileLocator classFileLocator) {
|
||||||
return builder;
|
return builder;
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class MuzzleVersionScanPlugin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertInstrumentationMuzzled(ClassLoader cl, boolean assertPass)
|
public static void assertInstrumentationMuzzled(final ClassLoader cl, final boolean assertPass)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
// muzzle validate all instrumenters
|
// muzzle validate all instrumenters
|
||||||
for (Instrumenter instrumenter :
|
for (Instrumenter instrumenter :
|
||||||
|
@ -49,17 +49,20 @@ public class MuzzleVersionScanPlugin {
|
||||||
try {
|
try {
|
||||||
m = instrumenter.getClass().getDeclaredMethod("getInstrumentationMuzzle");
|
m = instrumenter.getClass().getDeclaredMethod("getInstrumentationMuzzle");
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
ReferenceMatcher muzzle = (ReferenceMatcher) m.invoke(instrumenter);
|
final ReferenceMatcher muzzle = (ReferenceMatcher) m.invoke(instrumenter);
|
||||||
List<Reference.Mismatch> mismatches = muzzle.getMismatchedReferenceSources(cl);
|
final List<Reference.Mismatch> mismatches = muzzle.getMismatchedReferenceSources(cl);
|
||||||
boolean passed = mismatches.size() == 0;
|
final boolean passed = mismatches.size() == 0;
|
||||||
if (mismatches.size() > 0) {}
|
if (mismatches.size() > 0) {}
|
||||||
if (passed && !assertPass) {
|
if (passed && !assertPass) {
|
||||||
System.err.println("MUZZLE PASSED BUT FAILURE WAS EXPECTED");
|
System.err.println(
|
||||||
|
"MUZZLE PASSED "
|
||||||
|
+ instrumenter.getClass().getSimpleName()
|
||||||
|
+ " BUT FAILURE WAS EXPECTED");
|
||||||
throw new RuntimeException("Instrumentation unexpectedly passed Muzzle validation");
|
throw new RuntimeException("Instrumentation unexpectedly passed Muzzle validation");
|
||||||
} else if (!passed && assertPass) {
|
} else if (!passed && assertPass) {
|
||||||
System.err.println(
|
System.err.println(
|
||||||
"FAILED MUZZLE VALIDATION: " + instrumenter.getClass().getName() + " mismatches:");
|
"FAILED MUZZLE VALIDATION: " + instrumenter.getClass().getName() + " mismatches:");
|
||||||
for (Reference.Mismatch mismatch : mismatches) {
|
for (final Reference.Mismatch mismatch : mismatches) {
|
||||||
System.err.println("-- " + mismatch);
|
System.err.println("-- " + mismatch);
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Instrumentation failed Muzzle validation");
|
throw new RuntimeException("Instrumentation failed Muzzle validation");
|
||||||
|
@ -95,7 +98,7 @@ public class MuzzleVersionScanPlugin {
|
||||||
new HelperInjector(helperClassNames).transform(null, null, cl, null);
|
new HelperInjector(helperClassNames).transform(null, null, cl, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
System.err.println(
|
System.err.println(
|
||||||
"FAILED HELPER INJECTION. Are Helpers being injected in the correct order?");
|
"FAILED HELPER INJECTION. Are Helpers being injected in the correct order?");
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -105,7 +108,7 @@ public class MuzzleVersionScanPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printMuzzleReferences() {
|
public static void printMuzzleReferences() {
|
||||||
for (Instrumenter instrumenter :
|
for (final Instrumenter instrumenter :
|
||||||
ServiceLoader.load(Instrumenter.class, MuzzleGradlePlugin.class.getClassLoader())) {
|
ServiceLoader.load(Instrumenter.class, MuzzleGradlePlugin.class.getClassLoader())) {
|
||||||
if (instrumenter instanceof Instrumenter.Default) {
|
if (instrumenter instanceof Instrumenter.Default) {
|
||||||
try {
|
try {
|
||||||
|
@ -119,10 +122,10 @@ public class MuzzleVersionScanPlugin {
|
||||||
getMuzzleMethod.setAccessible(false);
|
getMuzzleMethod.setAccessible(false);
|
||||||
}
|
}
|
||||||
System.out.println(instrumenter.getClass().getName());
|
System.out.println(instrumenter.getClass().getName());
|
||||||
for (Reference ref : muzzle.getReferences()) {
|
for (final Reference ref : muzzle.getReferences()) {
|
||||||
System.out.println(prettyPrint(" ", ref));
|
System.out.println(prettyPrint(" ", ref));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Unexpected exception printing references for " + instrumenter.getClass().getName());
|
"Unexpected exception printing references for " + instrumenter.getClass().getName());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -136,14 +139,14 @@ public class MuzzleVersionScanPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String prettyPrint(String prefix, Reference ref) {
|
private static String prettyPrint(final String prefix, final Reference ref) {
|
||||||
final StringBuilder builder = new StringBuilder(prefix).append(ref.getClassName());
|
final StringBuilder builder = new StringBuilder(prefix).append(ref.getClassName());
|
||||||
if (ref.getSuperName() != null) {
|
if (ref.getSuperName() != null) {
|
||||||
builder.append(" extends<").append(ref.getSuperName()).append(">");
|
builder.append(" extends<").append(ref.getSuperName()).append(">");
|
||||||
}
|
}
|
||||||
if (ref.getInterfaces().size() > 0) {
|
if (ref.getInterfaces().size() > 0) {
|
||||||
builder.append(" implements ");
|
builder.append(" implements ");
|
||||||
for (String iface : ref.getInterfaces()) {
|
for (final String iface : ref.getInterfaces()) {
|
||||||
builder.append(" <").append(iface).append(">");
|
builder.append(" <").append(iface).append(">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +157,7 @@ public class MuzzleVersionScanPlugin {
|
||||||
for (final Reference.Field field : ref.getFields()) {
|
for (final Reference.Field field : ref.getFields()) {
|
||||||
builder.append("\n").append(prefix).append(prefix);
|
builder.append("\n").append(prefix).append(prefix);
|
||||||
builder.append("Field: ");
|
builder.append("Field: ");
|
||||||
for (Reference.Flag flag : field.getFlags()) {
|
for (final Reference.Flag flag : field.getFlags()) {
|
||||||
builder.append(flag).append(" ");
|
builder.append(flag).append(" ");
|
||||||
}
|
}
|
||||||
builder.append(field.toString());
|
builder.append(field.toString());
|
||||||
|
@ -162,7 +165,7 @@ public class MuzzleVersionScanPlugin {
|
||||||
for (final Reference.Method method : ref.getMethods()) {
|
for (final Reference.Method method : ref.getMethods()) {
|
||||||
builder.append("\n").append(prefix).append(prefix);
|
builder.append("\n").append(prefix).append(prefix);
|
||||||
builder.append("Method: ");
|
builder.append("Method: ");
|
||||||
for (Reference.Flag flag : method.getFlags()) {
|
for (final Reference.Flag flag : method.getFlags()) {
|
||||||
builder.append(flag).append(" ");
|
builder.append(flag).append(" ");
|
||||||
}
|
}
|
||||||
builder.append(method.toString());
|
builder.append(method.toString());
|
||||||
|
|
|
@ -22,13 +22,13 @@ public class Reference {
|
||||||
private final Set<Method> methods;
|
private final Set<Method> methods;
|
||||||
|
|
||||||
private Reference(
|
private Reference(
|
||||||
Set<Source> sources,
|
final Set<Source> sources,
|
||||||
Set<Flag> flags,
|
final Set<Flag> flags,
|
||||||
String className,
|
final String className,
|
||||||
String superName,
|
final String superName,
|
||||||
Set<String> interfaces,
|
final Set<String> interfaces,
|
||||||
Set<Field> fields,
|
final Set<Field> fields,
|
||||||
Set<Method> methods) {
|
final Set<Method> methods) {
|
||||||
this.sources = sources;
|
this.sources = sources;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
this.className = Utils.getClassName(className);
|
this.className = Utils.getClassName(className);
|
||||||
|
@ -59,11 +59,11 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Method> getMethods() {
|
public Set<Method> getMethods() {
|
||||||
return this.methods;
|
return methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Field> getFields() {
|
public Set<Field> getFields() {
|
||||||
return this.fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,11 +72,11 @@ public class Reference {
|
||||||
* @param anotherReference A reference to the same class
|
* @param anotherReference A reference to the same class
|
||||||
* @return a new Reference which merges the two references
|
* @return a new Reference which merges the two references
|
||||||
*/
|
*/
|
||||||
public Reference merge(Reference anotherReference) {
|
public Reference merge(final Reference anotherReference) {
|
||||||
if (!anotherReference.getClassName().equals(className)) {
|
if (!anotherReference.getClassName().equals(className)) {
|
||||||
throw new IllegalStateException("illegal merge " + this + " != " + anotherReference);
|
throw new IllegalStateException("illegal merge " + this + " != " + anotherReference);
|
||||||
}
|
}
|
||||||
String superName = null == this.superName ? anotherReference.superName : this.superName;
|
final String superName = null == this.superName ? anotherReference.superName : this.superName;
|
||||||
|
|
||||||
return new Reference(
|
return new Reference(
|
||||||
merge(sources, anotherReference.sources),
|
merge(sources, anotherReference.sources),
|
||||||
|
@ -88,17 +88,17 @@ public class Reference {
|
||||||
mergeMethods(methods, anotherReference.methods));
|
mergeMethods(methods, anotherReference.methods));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Set<T> merge(Set<T> set1, Set<T> set2) {
|
private static <T> Set<T> merge(final Set<T> set1, final Set<T> set2) {
|
||||||
final Set<T> set = new HashSet<>();
|
final Set<T> set = new HashSet<>();
|
||||||
set.addAll(set1);
|
set.addAll(set1);
|
||||||
set.addAll(set2);
|
set.addAll(set2);
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<Method> mergeMethods(Set<Method> methods1, Set<Method> methods2) {
|
private static Set<Method> mergeMethods(final Set<Method> methods1, final Set<Method> methods2) {
|
||||||
List<Method> merged = new ArrayList<>(methods1);
|
final List<Method> merged = new ArrayList<>(methods1);
|
||||||
for (Method method : methods2) {
|
for (final Method method : methods2) {
|
||||||
int i = merged.indexOf(method);
|
final int i = merged.indexOf(method);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
merged.add(method);
|
merged.add(method);
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,10 +108,10 @@ public class Reference {
|
||||||
return new HashSet<>(merged);
|
return new HashSet<>(merged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<Field> mergeFields(Set<Field> fields1, Set<Field> fields2) {
|
private static Set<Field> mergeFields(final Set<Field> fields1, final Set<Field> fields2) {
|
||||||
List<Field> merged = new ArrayList<>(fields1);
|
final List<Field> merged = new ArrayList<>(fields1);
|
||||||
for (Field field : fields2) {
|
for (final Field field : fields2) {
|
||||||
int i = merged.indexOf(field);
|
final int i = merged.indexOf(field);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
merged.add(field);
|
merged.add(field);
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,8 +121,8 @@ public class Reference {
|
||||||
return new HashSet<>(merged);
|
return new HashSet<>(merged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<Flag> mergeFlags(Set<Flag> flags1, Set<Flag> flags2) {
|
private static Set<Flag> mergeFlags(final Set<Flag> flags1, final Set<Flag> flags2) {
|
||||||
Set<Flag> merged = merge(flags1, flags2);
|
final Set<Flag> merged = merge(flags1, flags2);
|
||||||
// TODO: Assert flags are non-contradictory and resolve
|
// TODO: Assert flags are non-contradictory and resolve
|
||||||
// public > protected > package-private > private
|
// public > protected > package-private > private
|
||||||
return merged;
|
return merged;
|
||||||
|
@ -137,7 +137,7 @@ public class Reference {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int line;
|
private final int line;
|
||||||
|
|
||||||
public Source(String name, int line) {
|
public Source(final String name, final int line) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
}
|
}
|
||||||
|
@ -156,9 +156,9 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(final Object o) {
|
||||||
if (o instanceof Source) {
|
if (o instanceof Source) {
|
||||||
Source other = (Source) o;
|
final Source other = (Source) o;
|
||||||
return name.equals(other.name) && line == other.line;
|
return name.equals(other.name) && line == other.line;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -180,7 +180,7 @@ public class Reference {
|
||||||
/** Instrumentation sources which caused the mismatch. */
|
/** Instrumentation sources which caused the mismatch. */
|
||||||
private final Source[] mismatchSources;
|
private final Source[] mismatchSources;
|
||||||
|
|
||||||
Mismatch(Source[] mismatchSources) {
|
Mismatch(final Source[] mismatchSources) {
|
||||||
this.mismatchSources = mismatchSources;
|
this.mismatchSources = mismatchSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ public class Reference {
|
||||||
public static class MissingClass extends Mismatch {
|
public static class MissingClass extends Mismatch {
|
||||||
private final String className;
|
private final String className;
|
||||||
|
|
||||||
public MissingClass(Source[] sources, String className) {
|
public MissingClass(final Source[] sources, final String className) {
|
||||||
super(sources);
|
super(sources);
|
||||||
this.className = className;
|
this.className = className;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,10 @@ public class Reference {
|
||||||
private final int foundAccess;
|
private final int foundAccess;
|
||||||
|
|
||||||
public MissingFlag(
|
public MissingFlag(
|
||||||
Source[] sources, String classMethodOrFieldDesc, Flag expectedFlag, int foundAccess) {
|
final Source[] sources,
|
||||||
|
final String classMethodOrFieldDesc,
|
||||||
|
final Flag expectedFlag,
|
||||||
|
final int foundAccess) {
|
||||||
super(sources);
|
super(sources);
|
||||||
this.classMethodOrFieldDesc = classMethodOrFieldDesc;
|
this.classMethodOrFieldDesc = classMethodOrFieldDesc;
|
||||||
this.expectedFlag = expectedFlag;
|
this.expectedFlag = expectedFlag;
|
||||||
|
@ -236,9 +239,11 @@ public class Reference {
|
||||||
private final ClassLoader classLoaderBeingChecked;
|
private final ClassLoader classLoaderBeingChecked;
|
||||||
|
|
||||||
public ReferenceCheckError(
|
public ReferenceCheckError(
|
||||||
Exception e, Reference referenceBeingChecked, ClassLoader classLoaderBeingChecked) {
|
final Exception e,
|
||||||
|
final Reference referenceBeingChecked,
|
||||||
|
final ClassLoader classLoaderBeingChecked) {
|
||||||
super(new Source[0]);
|
super(new Source[0]);
|
||||||
this.referenceCheckException = e;
|
referenceCheckException = e;
|
||||||
this.referenceBeingChecked = referenceBeingChecked;
|
this.referenceBeingChecked = referenceBeingChecked;
|
||||||
this.classLoaderBeingChecked = classLoaderBeingChecked;
|
this.classLoaderBeingChecked = classLoaderBeingChecked;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +268,11 @@ public class Reference {
|
||||||
private final String fieldName;
|
private final String fieldName;
|
||||||
private final String fieldDesc;
|
private final String fieldDesc;
|
||||||
|
|
||||||
public MissingField(Source[] sources, String className, String fieldName, String fieldDesc) {
|
public MissingField(
|
||||||
|
final Source[] sources,
|
||||||
|
final String className,
|
||||||
|
final String fieldName,
|
||||||
|
final String fieldDesc) {
|
||||||
super(sources);
|
super(sources);
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
|
@ -280,7 +289,7 @@ public class Reference {
|
||||||
private final String className;
|
private final String className;
|
||||||
private final String method;
|
private final String method;
|
||||||
|
|
||||||
public MissingMethod(Source[] sources, String className, String method) {
|
public MissingMethod(final Source[] sources, final String className, final String method) {
|
||||||
super(sources);
|
super(sources);
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
|
@ -297,7 +306,7 @@ public class Reference {
|
||||||
public enum Flag {
|
public enum Flag {
|
||||||
PUBLIC {
|
PUBLIC {
|
||||||
@Override
|
@Override
|
||||||
public boolean supersedes(Flag anotherFlag) {
|
public boolean supersedes(final Flag anotherFlag) {
|
||||||
switch (anotherFlag) {
|
switch (anotherFlag) {
|
||||||
case PRIVATE_OR_HIGHER:
|
case PRIVATE_OR_HIGHER:
|
||||||
case PROTECTED_OR_HIGHER:
|
case PROTECTED_OR_HIGHER:
|
||||||
|
@ -309,112 +318,112 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_PUBLIC & asmFlags) != 0;
|
return (Opcodes.ACC_PUBLIC & asmFlags) != 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PACKAGE_OR_HIGHER {
|
PACKAGE_OR_HIGHER {
|
||||||
@Override
|
@Override
|
||||||
public boolean supersedes(Flag anotherFlag) {
|
public boolean supersedes(final Flag anotherFlag) {
|
||||||
return anotherFlag == PRIVATE_OR_HIGHER;
|
return anotherFlag == PRIVATE_OR_HIGHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_PUBLIC & asmFlags) != 0
|
return (Opcodes.ACC_PUBLIC & asmFlags) != 0
|
||||||
|| ((Opcodes.ACC_PRIVATE & asmFlags) == 0 && (Opcodes.ACC_PROTECTED & asmFlags) == 0);
|
|| ((Opcodes.ACC_PRIVATE & asmFlags) == 0 && (Opcodes.ACC_PROTECTED & asmFlags) == 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PROTECTED_OR_HIGHER {
|
PROTECTED_OR_HIGHER {
|
||||||
@Override
|
@Override
|
||||||
public boolean supersedes(Flag anotherFlag) {
|
public boolean supersedes(final Flag anotherFlag) {
|
||||||
return anotherFlag == PRIVATE_OR_HIGHER;
|
return anotherFlag == PRIVATE_OR_HIGHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return PUBLIC.matches(asmFlags) || (Opcodes.ACC_PROTECTED & asmFlags) != 0;
|
return PUBLIC.matches(asmFlags) || (Opcodes.ACC_PROTECTED & asmFlags) != 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PRIVATE_OR_HIGHER {
|
PRIVATE_OR_HIGHER {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
// you can't out-private a private
|
// you can't out-private a private
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NON_FINAL {
|
NON_FINAL {
|
||||||
@Override
|
@Override
|
||||||
public boolean contradicts(Flag anotherFlag) {
|
public boolean contradicts(final Flag anotherFlag) {
|
||||||
return anotherFlag == FINAL;
|
return anotherFlag == FINAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_FINAL & asmFlags) == 0;
|
return (Opcodes.ACC_FINAL & asmFlags) == 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
FINAL {
|
FINAL {
|
||||||
@Override
|
@Override
|
||||||
public boolean contradicts(Flag anotherFlag) {
|
public boolean contradicts(final Flag anotherFlag) {
|
||||||
return anotherFlag == NON_FINAL;
|
return anotherFlag == NON_FINAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_FINAL & asmFlags) != 0;
|
return (Opcodes.ACC_FINAL & asmFlags) != 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
STATIC {
|
STATIC {
|
||||||
@Override
|
@Override
|
||||||
public boolean contradicts(Flag anotherFlag) {
|
public boolean contradicts(final Flag anotherFlag) {
|
||||||
return anotherFlag == NON_STATIC;
|
return anotherFlag == NON_STATIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_STATIC & asmFlags) != 0;
|
return (Opcodes.ACC_STATIC & asmFlags) != 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NON_STATIC {
|
NON_STATIC {
|
||||||
@Override
|
@Override
|
||||||
public boolean contradicts(Flag anotherFlag) {
|
public boolean contradicts(final Flag anotherFlag) {
|
||||||
return anotherFlag == STATIC;
|
return anotherFlag == STATIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_STATIC & asmFlags) == 0;
|
return (Opcodes.ACC_STATIC & asmFlags) == 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
INTERFACE {
|
INTERFACE {
|
||||||
@Override
|
@Override
|
||||||
public boolean contradicts(Flag anotherFlag) {
|
public boolean contradicts(final Flag anotherFlag) {
|
||||||
return anotherFlag == NON_INTERFACE;
|
return anotherFlag == NON_INTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_INTERFACE & asmFlags) != 0;
|
return (Opcodes.ACC_INTERFACE & asmFlags) != 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NON_INTERFACE {
|
NON_INTERFACE {
|
||||||
@Override
|
@Override
|
||||||
public boolean contradicts(Flag anotherFlag) {
|
public boolean contradicts(final Flag anotherFlag) {
|
||||||
return anotherFlag == INTERFACE;
|
return anotherFlag == INTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int asmFlags) {
|
public boolean matches(final int asmFlags) {
|
||||||
return (Opcodes.ACC_INTERFACE & asmFlags) == 0;
|
return (Opcodes.ACC_INTERFACE & asmFlags) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public boolean contradicts(Flag anotherFlag) {
|
public boolean contradicts(final Flag anotherFlag) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supersedes(Flag anotherFlag) {
|
public boolean supersedes(final Flag anotherFlag) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +437,7 @@ public class Reference {
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
private final List<Type> parameterTypes;
|
private final List<Type> parameterTypes;
|
||||||
|
|
||||||
public Method(String name, String descriptor) {
|
public Method(final String name, final String descriptor) {
|
||||||
this(
|
this(
|
||||||
new Source[0],
|
new Source[0],
|
||||||
new Flag[0],
|
new Flag[0],
|
||||||
|
@ -438,7 +447,11 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method(
|
public Method(
|
||||||
Source[] sources, Flag[] flags, String name, Type returnType, Type[] parameterTypes) {
|
final Source[] sources,
|
||||||
|
final Flag[] flags,
|
||||||
|
final String name,
|
||||||
|
final Type returnType,
|
||||||
|
final Type[] parameterTypes) {
|
||||||
this(
|
this(
|
||||||
new HashSet<>(Arrays.asList(sources)),
|
new HashSet<>(Arrays.asList(sources)),
|
||||||
new HashSet<>(Arrays.asList(flags)),
|
new HashSet<>(Arrays.asList(flags)),
|
||||||
|
@ -448,11 +461,11 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method(
|
public Method(
|
||||||
Set<Source> sources,
|
final Set<Source> sources,
|
||||||
Set<Flag> flags,
|
final Set<Flag> flags,
|
||||||
String name,
|
final String name,
|
||||||
Type returnType,
|
final Type returnType,
|
||||||
List<Type> parameterTypes) {
|
final List<Type> parameterTypes) {
|
||||||
this.sources = sources;
|
this.sources = sources;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -480,8 +493,8 @@ public class Reference {
|
||||||
return parameterTypes;
|
return parameterTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method merge(Method anotherMethod) {
|
public Method merge(final Method anotherMethod) {
|
||||||
if (!this.equals(anotherMethod)) {
|
if (!equals(anotherMethod)) {
|
||||||
throw new IllegalStateException("illegal merge " + this + " != " + anotherMethod);
|
throw new IllegalStateException("illegal merge " + this + " != " + anotherMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +519,7 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(final Object o) {
|
||||||
if (o instanceof Method) {
|
if (o instanceof Method) {
|
||||||
final Method m = (Method) o;
|
final Method m = (Method) o;
|
||||||
return name.equals(m.name) && getDescriptor().equals(m.getDescriptor());
|
return name.equals(m.name) && getDescriptor().equals(m.getDescriptor());
|
||||||
|
@ -526,11 +539,12 @@ public class Reference {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
public Field(Source[] sources, Flag[] flags, String name, Type fieldType) {
|
public Field(
|
||||||
|
final Source[] sources, final Flag[] flags, final String name, final Type fieldType) {
|
||||||
this.sources = new HashSet<>(Arrays.asList(sources));
|
this.sources = new HashSet<>(Arrays.asList(sources));
|
||||||
this.flags = new HashSet<>(Arrays.asList(flags));
|
this.flags = new HashSet<>(Arrays.asList(flags));
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = fieldType;
|
type = fieldType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -549,8 +563,8 @@ public class Reference {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Field merge(Field anotherField) {
|
public Field merge(final Field anotherField) {
|
||||||
if (!this.equals(anotherField) || (!type.equals(anotherField.type))) {
|
if (!equals(anotherField) || !type.equals(anotherField.type)) {
|
||||||
throw new IllegalStateException("illegal merge " + this + " != " + anotherField);
|
throw new IllegalStateException("illegal merge " + this + " != " + anotherField);
|
||||||
}
|
}
|
||||||
return new Field(
|
return new Field(
|
||||||
|
@ -566,9 +580,9 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(final Object o) {
|
||||||
if (o instanceof Field) {
|
if (o instanceof Field) {
|
||||||
Field other = (Field) o;
|
final Field other = (Field) o;
|
||||||
return name.equals(other.name);
|
return name.equals(other.name);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -593,30 +607,33 @@ public class Reference {
|
||||||
this.className = className;
|
this.className = className;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withSuperName(String superName) {
|
public Builder withSuperName(final String superName) {
|
||||||
this.superName = superName;
|
this.superName = superName;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withInterface(String interfaceName) {
|
public Builder withInterface(final String interfaceName) {
|
||||||
interfaces.add(interfaceName);
|
interfaces.add(interfaceName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withSource(String sourceName, int line) {
|
public Builder withSource(final String sourceName, final int line) {
|
||||||
sources.add(new Source(sourceName, line));
|
sources.add(new Source(sourceName, line));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withFlag(Flag flag) {
|
public Builder withFlag(final Flag flag) {
|
||||||
flags.add(flag);
|
flags.add(flag);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withField(
|
public Builder withField(
|
||||||
Source[] sources, Flag[] fieldFlags, String fieldName, Type fieldType) {
|
final Source[] sources,
|
||||||
|
final Flag[] fieldFlags,
|
||||||
|
final String fieldName,
|
||||||
|
final Type fieldType) {
|
||||||
final Field field = new Field(sources, fieldFlags, fieldName, fieldType);
|
final Field field = new Field(sources, fieldFlags, fieldName, fieldType);
|
||||||
int existingIndex = fields.indexOf(field);
|
final int existingIndex = fields.indexOf(field);
|
||||||
if (existingIndex == -1) {
|
if (existingIndex == -1) {
|
||||||
fields.add(field);
|
fields.add(field);
|
||||||
} else {
|
} else {
|
||||||
|
@ -626,13 +643,13 @@ public class Reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withMethod(
|
public Builder withMethod(
|
||||||
Source[] sources,
|
final Source[] sources,
|
||||||
Flag[] methodFlags,
|
final Flag[] methodFlags,
|
||||||
String methodName,
|
final String methodName,
|
||||||
Type returnType,
|
final Type returnType,
|
||||||
Type... methodArgs) {
|
final Type... methodArgs) {
|
||||||
final Method method = new Method(sources, methodFlags, methodName, returnType, methodArgs);
|
final Method method = new Method(sources, methodFlags, methodName, returnType, methodArgs);
|
||||||
int existingIndex = methods.indexOf(method);
|
final int existingIndex = methods.indexOf(method);
|
||||||
if (existingIndex == -1) {
|
if (existingIndex == -1) {
|
||||||
methods.add(method);
|
methods.add(method);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import io.opentracing.noop.NoopScopeManager.NoopScope;
|
||||||
import io.opentracing.tag.Tags;
|
import io.opentracing.tag.Tags;
|
||||||
import io.opentracing.util.GlobalTracer;
|
import io.opentracing.util.GlobalTracer;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -92,12 +93,13 @@ public final class PreparedStatementInstrumentation extends Instrumenter.Default
|
||||||
{
|
{
|
||||||
if (dbInfo == null) {
|
if (dbInfo == null) {
|
||||||
try {
|
try {
|
||||||
final String url = connection.getMetaData().getURL();
|
final DatabaseMetaData metaData = connection.getMetaData();
|
||||||
|
final String url = metaData.getURL();
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
// Remove end of url to prevent passwords from leaking:
|
// Remove end of url to prevent passwords from leaking:
|
||||||
final String sanitizedURL = url.replaceAll("[?;].*", "");
|
final String sanitizedURL = url.replaceAll("[?;].*", "");
|
||||||
final String type = url.split(":", -1)[1];
|
final String type = url.split(":", -1)[1];
|
||||||
String user = connection.getMetaData().getUserName();
|
String user = metaData.getUserName();
|
||||||
if (user != null && user.trim().equals("")) {
|
if (user != null && user.trim().equals("")) {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import io.opentracing.noop.NoopScopeManager.NoopScope;
|
||||||
import io.opentracing.tag.Tags;
|
import io.opentracing.tag.Tags;
|
||||||
import io.opentracing.util.GlobalTracer;
|
import io.opentracing.util.GlobalTracer;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -93,12 +94,13 @@ public final class StatementInstrumentation extends Instrumenter.Default {
|
||||||
{
|
{
|
||||||
if (dbInfo == null) {
|
if (dbInfo == null) {
|
||||||
try {
|
try {
|
||||||
final String url = connection.getMetaData().getURL();
|
final DatabaseMetaData metaData = connection.getMetaData();
|
||||||
|
final String url = metaData.getURL();
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
// Remove end of url to prevent passwords from leaking:
|
// Remove end of url to prevent passwords from leaking:
|
||||||
final String sanitizedURL = url.replaceAll("[?;].*", "");
|
final String sanitizedURL = url.replaceAll("[?;].*", "");
|
||||||
final String type = url.split(":", -1)[1];
|
final String type = url.split(":", -1)[1];
|
||||||
String user = connection.getMetaData().getUserName();
|
String user = metaData.getUserName();
|
||||||
if (user != null && user.trim().equals("")) {
|
if (user != null && user.trim().equals("")) {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class LettuceReactiveCommandsInstrumentation extends Instrumenter.Default
|
||||||
.and(nameStartsWith("create"))
|
.and(nameStartsWith("create"))
|
||||||
.and(nameEndsWith("Flux"))
|
.and(nameEndsWith("Flux"))
|
||||||
.and(takesArgument(0, named("java.util.function.Supplier")))
|
.and(takesArgument(0, named("java.util.function.Supplier")))
|
||||||
.and(returns(named(("reactor.core.publisher.Flux")))),
|
.and(returns(named("reactor.core.publisher.Flux"))),
|
||||||
// Cannot reference class directly here because it would lead to class load failure on Java7
|
// Cannot reference class directly here because it would lead to class load failure on Java7
|
||||||
PACKAGE + ".rx.LettuceFluxCreationAdvice");
|
PACKAGE + ".rx.LettuceFluxCreationAdvice");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue