Support muzzle testInverse = true
This commit is contained in:
parent
f94f22bcba
commit
c369fafe8c
|
@ -16,7 +16,8 @@ muzzle {
|
|||
pass {
|
||||
group = "org.hibernate"
|
||||
module = "hibernate-core"
|
||||
versions = "[3.5.0-Final,4.0.0.Final)"
|
||||
versions = "[3.3.2.GA,4.0.0.Final)"
|
||||
assertInverse = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +32,7 @@ testSets {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly group: 'org.hibernate', name: 'hibernate-core', version: '3.5.0-Final'
|
||||
compileOnly group: 'org.hibernate', name: 'hibernate-core', version: '3.3.2.GA'
|
||||
|
||||
compile project(':dd-java-agent:agent-tooling')
|
||||
compile project(':dd-java-agent:instrumentation:hibernate')
|
||||
|
@ -44,7 +45,7 @@ dependencies {
|
|||
testCompile project(':dd-java-agent:testing')
|
||||
testCompile project(':dd-java-agent:instrumentation:jdbc')
|
||||
|
||||
testCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.5.0-Final'
|
||||
testCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.3.2.GA'
|
||||
testCompile group: 'org.hibernate', name: 'hibernate-annotations', version: '+'
|
||||
testCompile group: 'javassist', name: 'javassist', version: '+'
|
||||
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package datadog.trace.instrumentation.hibernate.core.v3_5;
|
||||
|
||||
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.classic.Validatable;
|
||||
|
||||
public abstract class AbstractHibernateInstrumentation extends Instrumenter.Default {
|
||||
|
||||
|
@ -22,12 +20,23 @@ public abstract class AbstractHibernateInstrumentation extends Instrumenter.Defa
|
|||
"datadog.trace.agent.decorator.DatabaseClientDecorator",
|
||||
"datadog.trace.agent.decorator.OrmClientDecorator",
|
||||
"datadog.trace.instrumentation.hibernate.HibernateDecorator",
|
||||
packageName + ".AbstractHibernateInstrumentation$V3Advice",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
return not(classLoaderHasClasses("org.hibernate.SharedSessionContract"))
|
||||
.and(classLoaderHasClasses("org.hibernate.EntityNameResolver"));
|
||||
public abstract static class V3Advice {
|
||||
|
||||
/**
|
||||
* Some cases of instrumentation will match more broadly than others, so this unused method
|
||||
* allows all instrumentation to uniformly match versions of Hibernate between 3.5 and 4.
|
||||
*/
|
||||
public static void muzzleCheck(
|
||||
// Not in 4.0
|
||||
final Validatable validatable,
|
||||
// Not before 3.2.0.GA (Can't find anything not before 3.5)
|
||||
final EntityNameResolver resolver) {
|
||||
validatable.validate();
|
||||
resolver.resolveEntityName(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CriteriaInstrumentation extends AbstractHibernateInstrumentation {
|
|||
CriteriaMethodAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class CriteriaMethodAdvice {
|
||||
public static class CriteriaMethodAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startMethod(
|
||||
|
|
|
@ -48,7 +48,7 @@ public class QueryInstrumentation extends AbstractHibernateInstrumentation {
|
|||
QueryMethodAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class QueryMethodAdvice {
|
||||
public static class QueryMethodAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startMethod(
|
||||
|
|
|
@ -57,7 +57,7 @@ public class SessionFactoryInstrumentation extends AbstractHibernateInstrumentat
|
|||
SessionFactoryAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class SessionFactoryAdvice {
|
||||
public static class SessionFactoryAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void openSession(@Advice.Return final Object session) {
|
||||
|
|
|
@ -107,7 +107,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
return transformers;
|
||||
}
|
||||
|
||||
public static class SessionCloseAdvice {
|
||||
public static class SessionCloseAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void closeSession(
|
||||
|
@ -138,7 +138,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class SessionMethodAdvice {
|
||||
public static class SessionMethodAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startMethod(
|
||||
|
@ -171,7 +171,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class GetQueryAdvice {
|
||||
public static class GetQueryAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getQuery(
|
||||
|
@ -193,7 +193,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class GetTransactionAdvice {
|
||||
public static class GetTransactionAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getTransaction(
|
||||
|
@ -216,7 +216,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class GetCriteriaAdvice {
|
||||
public static class GetCriteriaAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getCriteria(
|
||||
|
|
|
@ -41,7 +41,7 @@ public class TransactionInstrumentation extends AbstractHibernateInstrumentation
|
|||
TransactionCommitAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class TransactionCommitAdvice {
|
||||
public static class TransactionCommitAdvice extends V3Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startCommit(@Advice.This final Transaction transaction) {
|
||||
|
|
|
@ -10,6 +10,7 @@ muzzle {
|
|||
group = "org.hibernate"
|
||||
module = "hibernate-core"
|
||||
versions = "[4.0.0.Final,)"
|
||||
assertInverse = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package datadog.trace.instrumentation.hibernate.core.v4_0;
|
||||
|
||||
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
|
||||
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.hibernate.SharedSessionContract;
|
||||
|
||||
public abstract class AbstractHibernateInstrumentation extends Instrumenter.Default {
|
||||
|
||||
|
@ -21,11 +19,18 @@ public abstract class AbstractHibernateInstrumentation extends Instrumenter.Defa
|
|||
"datadog.trace.agent.decorator.DatabaseClientDecorator",
|
||||
"datadog.trace.agent.decorator.OrmClientDecorator",
|
||||
"datadog.trace.instrumentation.hibernate.HibernateDecorator",
|
||||
packageName + ".AbstractHibernateInstrumentation$V4Advice",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
return classLoaderHasClasses("org.hibernate.SharedSessionContract");
|
||||
public abstract static class V4Advice {
|
||||
|
||||
/**
|
||||
* Some cases of instrumentation will match more broadly than others, so this unused method
|
||||
* allows all instrumentation to uniformly match versions of Hibernate starting at 4.0.
|
||||
*/
|
||||
public static void muzzleCheck(final SharedSessionContract contract) {
|
||||
contract.createCriteria("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CriteriaInstrumentation extends AbstractHibernateInstrumentation {
|
|||
CriteriaMethodAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class CriteriaMethodAdvice {
|
||||
public static class CriteriaMethodAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startMethod(
|
||||
|
|
|
@ -48,7 +48,7 @@ public class QueryInstrumentation extends AbstractHibernateInstrumentation {
|
|||
QueryMethodAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class QueryMethodAdvice {
|
||||
public static class QueryMethodAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startMethod(
|
||||
|
|
|
@ -49,7 +49,7 @@ public class SessionFactoryInstrumentation extends AbstractHibernateInstrumentat
|
|||
SessionFactoryAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class SessionFactoryAdvice {
|
||||
public static class SessionFactoryAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void openSession(@Advice.Return final SharedSessionContract session) {
|
||||
|
|
|
@ -102,7 +102,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
return transformers;
|
||||
}
|
||||
|
||||
public static class SessionCloseAdvice {
|
||||
public static class SessionCloseAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void closeSession(
|
||||
|
@ -126,7 +126,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class SessionMethodAdvice {
|
||||
public static class SessionMethodAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startMethod(
|
||||
|
@ -152,7 +152,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class GetQueryAdvice {
|
||||
public static class GetQueryAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getQuery(
|
||||
|
@ -168,7 +168,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class GetTransactionAdvice {
|
||||
public static class GetTransactionAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getTransaction(
|
||||
|
@ -185,7 +185,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
public static class GetCriteriaAdvice {
|
||||
public static class GetCriteriaAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getCriteria(
|
||||
|
|
|
@ -41,7 +41,7 @@ public class TransactionInstrumentation extends AbstractHibernateInstrumentation
|
|||
TransactionCommitAdvice.class.getName());
|
||||
}
|
||||
|
||||
public static class TransactionCommitAdvice {
|
||||
public static class TransactionCommitAdvice extends V4Advice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static SessionState startCommit(@Advice.This final Transaction transaction) {
|
||||
|
|
Loading…
Reference in New Issue