-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Gradle instrumentation to support v8.10 (#7443)
- Loading branch information
1 parent
cb14799
commit fcd4bc4
Showing
4 changed files
with
162 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...y/datadog/trace/instrumentation/gradle/GradleBuildScopeServices_8_10_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package datadog.trace.instrumentation.gradle; | ||
|
||
import static datadog.trace.agent.tooling.bytebuddy.matcher.ClassLoaderMatchers.hasClassNamed; | ||
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.agent.tooling.InstrumenterModule; | ||
import datadog.trace.api.Config; | ||
import java.util.Set; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.gradle.internal.service.DefaultServiceRegistry; | ||
import org.gradle.internal.service.ServiceRegistry; | ||
import org.gradle.internal.service.scopes.Scope; | ||
|
||
@AutoService(InstrumenterModule.class) | ||
public class GradleBuildScopeServices_8_10_Instrumentation extends InstrumenterModule.CiVisibility | ||
implements Instrumenter.ForSingleType { | ||
|
||
public GradleBuildScopeServices_8_10_Instrumentation() { | ||
super("gradle", "gradle-build-scope-services"); | ||
} | ||
|
||
@Override | ||
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
// Instrument Gradle [8.10 ... ) | ||
return hasClassNamed("org.gradle.internal.classpath.transforms.AdhocInterceptors"); | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.gradle.internal.service.ScopedServiceRegistry"; | ||
} | ||
|
||
@Override | ||
public String[] helperClassNames() { | ||
return new String[] { | ||
packageName + ".CiVisibilityGradleListenerInjector", | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(Set<TargetSystem> enabledSystems) { | ||
return super.isApplicable(enabledSystems) | ||
&& Config.get().isCiVisibilityBuildInstrumentationEnabled(); | ||
} | ||
|
||
@Override | ||
public void methodAdvice(MethodTransformer transformer) { | ||
transformer.applyAdvice( | ||
isConstructor() | ||
.and(takesArgument(0, Class.class)) | ||
.and(takesArgument(1, boolean.class)) | ||
.and(takesArgument(3, named("org.gradle.internal.service.ServiceRegistry[]"))), | ||
getClass().getName() + "$Construct"); | ||
} | ||
|
||
public static class Construct { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void afterConstructor( | ||
@Advice.This final DefaultServiceRegistry buildScopeServices, | ||
@Advice.Argument(0) final Class<? extends Scope> scope, | ||
@Advice.Argument(3) final ServiceRegistry[] parentServices) { | ||
if (scope.getSimpleName().equals("Build")) { | ||
CiVisibilityGradleListenerInjector.injectCiVisibilityGradleListener( | ||
buildScopeServices, parentServices); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String muzzleDirective() { | ||
return "skipMuzzle"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters