Skip to content

Commit 83aa2a4

Browse files
committed
chore: Renames plugin to BuildTimeInstrumentationPlugin
1 parent 324abc2 commit 83aa2a4

File tree

14 files changed

+93
-41
lines changed

14 files changed

+93
-41
lines changed

buildSrc/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ java {
1515
gradlePlugin {
1616
plugins {
1717
create("instrument-plugin") {
18-
id = "dd-trace-java.instrument"
19-
implementationClass = "datadog.gradle.plugin.instrument.InstrumentPlugin"
18+
id = "dd-trace-java.build-time-instrumentation"
19+
implementationClass = "datadog.gradle.plugin.instrument.BuildTimeInstrumentationPlugin"
2020
}
2121

2222
create("muzzle-plugin") {

buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/InstrumentExtension.groovy renamed to buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/BuildTimeInstrumentationExtension.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package datadog.gradle.plugin.instrument
33
import org.gradle.api.file.DirectoryProperty
44
import org.gradle.api.provider.ListProperty
55

6-
abstract class InstrumentExtension {
6+
abstract class BuildTimeInstrumentationExtension {
77
abstract ListProperty<String> getPlugins()
88
abstract ListProperty<DirectoryProperty> getAdditionalClasspath()
99
}

buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/InstrumentPlugin.groovy renamed to buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/BuildTimeInstrumentationPlugin.groovy

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,59 @@ import org.gradle.api.tasks.compile.AbstractCompile
1313
import java.util.regex.Matcher
1414

1515
/**
16-
* instrument<Language> task plugin which performs build-time instrumentation of classes.
16+
* Gradle plugin that applies ByteBuddy plugins to perform build-time bytecode instrumentation.
17+
*
18+
* <p>This plugin appends a post-processing action to existing <strong>main</strong> compilation
19+
* tasks. This plugin allows to apply one or more ByteBuddy {@link net.bytebuddy.build.Plugin}
20+
* implementations.
21+
*
22+
* <h3>Configuration:</h3>
23+
* There are two main configuration points:
24+
* <ul>
25+
* <li>The {@code buildTimeInstrumentation} extension, which allows to specify:
26+
* <ul>
27+
* <li>The list of ByteBuddy plugin class names to apply</li>
28+
* <li>Additional classpath entries required to load the plugins</li>
29+
* </ul>
30+
* </li>
31+
* <li>The {@code buildTimeInstrumentationPlugin} configuration, which allows to specify
32+
* dependencies containing the ByteBuddy plugin implementations</li>
33+
* </ul>
34+
* <p>Example configuration:
35+
*
36+
* <pre>
37+
* buildTimeInstrumentation {
38+
* plugins = ['com.example.MyByteBuddyPlugin', 'com.example.AnotherPlugin']
39+
* additionalClasspath = [file('path/to/additional/classes')]
40+
* }
41+
*
42+
* dependencies {
43+
* buildTimeInstrumentationPlugin 'com.example:my-bytebuddy-plugin:1.0.0'
44+
* buildTimeInstrumentationPlugin project(path: ':some:project', configuration: 'buildTimeInstrumentationPlugin')
45+
* }
46+
* </pre>
47+
*
48+
* <h3>Requirements for ByteBuddy plugins:</h3>
49+
* <ul>
50+
* <li>Must implement {@link net.bytebuddy.build.Plugin}</li>
51+
* <li>Must have a constructor accepting a {@link File} parameter (the target directory)</li>
52+
* <li>Plugin classes must be available on the {@code buildTimeInstrumentationPlugin} configuration</li>
53+
* </ul>
54+
*
55+
* @see BuildTimeInstrumentationExtension
56+
* @see InstrumentPostProcessingAction
57+
* @see ByteBuddyInstrumenter
1758
*/
1859
@SuppressWarnings('unused')
19-
class InstrumentPlugin implements Plugin<Project> {
60+
class BuildTimeInstrumentationPlugin implements Plugin<Project> {
2061
public static final String DEFAULT_JAVA_VERSION = 'default'
21-
public static final String INSTRUMENT_PLUGIN_CLASSPATH_CONFIGURATION = 'instrumentPluginClasspath'
22-
private final Logger logger = Logging.getLogger(InstrumentPlugin)
62+
public static final String BUILD_TIME_INSTRUMENTATION_PLUGIN_CONFIGURATION = 'buildTimeInstrumentationPlugin'
63+
private final Logger logger = Logging.getLogger(BuildTimeInstrumentationPlugin)
2364

2465
@Override
2566
void apply(Project project) {
26-
InstrumentExtension extension = project.extensions.create('instrument', InstrumentExtension)
27-
project.configurations.register(INSTRUMENT_PLUGIN_CLASSPATH_CONFIGURATION)
67+
BuildTimeInstrumentationExtension extension = project.extensions.create('buildTimeInstrumentation', BuildTimeInstrumentationExtension)
68+
project.configurations.register(BUILD_TIME_INSTRUMENTATION_PLUGIN_CONFIGURATION)
2869

2970

3071
['java', 'kotlin', 'scala', 'groovy'].each { langPluginId ->
@@ -34,22 +75,22 @@ class InstrumentPlugin implements Plugin<Project> {
3475
}
3576
}
3677

37-
private void configurePostCompilationInstrumentation(String language, Project project, InstrumentExtension extension) {
78+
private void configurePostCompilationInstrumentation(String language, Project project, BuildTimeInstrumentationExtension extension) {
3879
project.extensions.configure(SourceSetContainer) { SourceSetContainer sourceSets ->
3980
// For any "main" source-set configure its compile task
4081
sourceSets.configureEach { SourceSet sourceSet ->
4182
def sourceSetName = sourceSet.name
42-
logger.info("[InstrumentPlugin] source-set: $sourceSetName, language: $language")
83+
logger.info("[BuildTimeInstrumentationPlugin] source-set: $sourceSetName, language: $language")
4384

4485
if (!sourceSetName.startsWith(SourceSet.MAIN_SOURCE_SET_NAME)) {
45-
logger.debug("[InstrumentPlugin] Skipping non-main source set {} for language {}", sourceSetName, language)
86+
logger.debug("[BuildTimeInstrumentationPlugin] Skipping non-main source set {} for language {}", sourceSetName, language)
4687
return
4788
}
4889

4990
def compileTaskName = sourceSet.getCompileTaskName(language)
50-
logger.info("[InstrumentPlugin] compile task name: " + compileTaskName)
91+
logger.info("[BuildTimeInstrumentationPlugin] compile task name: " + compileTaskName)
5192

52-
// For each compile task, append an instrumenting post-processing step
93+
// For each _main_ compile task, append an instrumenting post-processing step
5394
// Examples of compile tasks:
5495
// - compileJava,
5596
// - compileMain_java17Java,
@@ -61,11 +102,11 @@ class InstrumentPlugin implements Plugin<Project> {
61102
project.tasks.withType(AbstractCompile).matching {
62103
it.name == compileTaskName && !it.source.isEmpty()
63104
}.configureEach {
64-
logger.info('[InstrumentPlugin] Applying instrumentPluginClasspath configuration as compile task input')
65-
it.inputs.files(project.configurations.named(INSTRUMENT_PLUGIN_CLASSPATH_CONFIGURATION))
105+
logger.info('[BuildTimeInstrumentationPlugin] Applying buildTimeInstrumentationPlugin configuration as compile task input')
106+
it.inputs.files(project.configurations.named(BUILD_TIME_INSTRUMENTATION_PLUGIN_CONFIGURATION))
66107

67108
if (it.source.isEmpty()) {
68-
logger.debug("[InstrumentPlugin] Skipping $compileTaskName for source set $sourceSetName as it has no source files")
109+
logger.debug("[BuildTimeInstrumentationPlugin] Skipping $compileTaskName for source set $sourceSetName as it has no source files")
69110
return
70111
}
71112

@@ -111,7 +152,7 @@ class InstrumentPlugin implements Plugin<Project> {
111152
tmpUninstrumentedClasses
112153
)
113154
)
114-
logger.info("[InstrumentPlugin] Configured post-compile instrumentation for $compileTaskName for source-set $sourceSetName")
155+
logger.info("[BuildTimeInstrumentationPlugin] Configured post-compile instrumentation for $compileTaskName for source-set $sourceSetName")
115156
}
116157
}
117158
}

buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/ByteBuddyInstrumenter.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import org.slf4j.Logger
1111
import org.slf4j.LoggerFactory
1212

1313
/**
14-
* Performs build-time instrumentation of classes, called indirectly from InstrumentPlugin.
15-
* (This is the byte-buddy side of the task; InstrumentPlugin contains the Gradle pieces.)
14+
* Performs build-time instrumentation of classes, called indirectly from BuildTimeInstrumentationPlugin.
15+
* (This is the byte-buddy side of the task; BuildTimeInstrumentationPlugin contains the Gradle pieces.)
1616
*/
1717
class ByteBuddyInstrumenter {
1818
static final Logger log = LoggerFactory.getLogger(ByteBuddyInstrumenter.class)

buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/InstrumentPostProcessingAction.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ abstract class InstrumentPostProcessingAction implements Action<AbstractCompile>
4444
DirectoryProperty compilerOutputDirectory,
4545
DirectoryProperty tmpDirectory
4646
) {
47-
this.javaVersion = javaVersion == InstrumentPlugin.DEFAULT_JAVA_VERSION ? JavaLanguageVersion.current() : JavaLanguageVersion.of(javaVersion)
47+
this.javaVersion = javaVersion == BuildTimeInstrumentationPlugin.DEFAULT_JAVA_VERSION ? JavaLanguageVersion.current() : JavaLanguageVersion.of(javaVersion)
4848
this.plugins = plugins
4949
this.instrumentingClassPath = instrumentingClassPath
5050
this.compilerOutputDirectory = compilerOutputDirectory
@@ -64,7 +64,7 @@ abstract class InstrumentPostProcessingAction implements Action<AbstractCompile>
6464
workQueue().submit(InstrumentAction.class, parameters -> {
6565
parameters.buildStartedTime.set(invocationDetails.buildStartedTime)
6666
parameters.pluginClassPath.from(
67-
project.configurations.named(InstrumentPlugin.INSTRUMENT_PLUGIN_CLASSPATH_CONFIGURATION)
67+
project.configurations.named(BuildTimeInstrumentationPlugin.BUILD_TIME_INSTRUMENTATION_PLUGIN_CONFIGURATION)
6868
)
6969
parameters.plugins.set(postCompileAction.plugins)
7070
parameters.instrumentingClassPath.setFrom(postCompileAction.instrumentingClassPath)

buildSrc/src/test/kotlin/datadog/gradle/plugin/instrument/InstrumentPluginTest.kt renamed to buildSrc/src/test/kotlin/datadog/gradle/plugin/instrument/BuildTimeInstrumentationPluginTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import org.objectweb.asm.FieldVisitor
1111
import java.io.File
1212
import java.io.FileInputStream
1313

14-
class InstrumentPluginTest {
14+
class BuildTimeInstrumentationPluginTest {
1515

1616
private val buildGradle = """
1717
plugins {
1818
id 'java'
19-
id 'dd-trace-java.instrument'
19+
id 'dd-trace-java.build-time-instrumentation'
2020
}
21-
21+
2222
sourceCompatibility = JavaVersion.VERSION_1_8
2323
targetCompatibility = JavaVersion.VERSION_1_8
2424
@@ -30,7 +30,7 @@ class InstrumentPluginTest {
3030
compileOnly group: 'net.bytebuddy', name: 'byte-buddy', version: '1.18.3' // just to build TestPlugin
3131
}
3232
33-
instrument.plugins = [
33+
buildTimeInstrumentation.plugins = [
3434
'TestPlugin'
3535
]
3636
""".trimIndent()

dd-java-agent/agent-otel/otel-bootstrap/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def otelApiVersion = '1.38.0'
88
def otelInstrumentationApiVersion = '2.4.0'
99

1010
apply from: "$rootDir/gradle/java.gradle"
11-
apply plugin: 'dd-trace-java.instrument'
11+
apply plugin: 'dd-trace-java.build-time-instrumentation'
1212

1313
configurations {
1414
def ec = register('embeddedClasspath') {
@@ -19,14 +19,14 @@ configurations {
1919
named('compileClasspath') {
2020
compileClasspath.extendsFrom(ec.get())
2121
}
22-
instrumentPluginClasspath {
22+
named('buildTimeInstrumentationPlugin') {
2323
visible = false
2424
canBeConsumed = false
2525
canBeResolved = true
2626
}
2727
}
2828

29-
instrument.plugins = ['datadog.opentelemetry.tooling.shim.OtelShimGradlePlugin']
29+
buildTimeInstrumentation.plugins = ['datadog.opentelemetry.tooling.shim.OtelShimGradlePlugin']
3030

3131
minimumInstructionCoverage = 0.0
3232
minimumBranchCoverage = 0.0
@@ -53,7 +53,7 @@ dependencies {
5353
compileOnly project(':dd-java-agent:agent-bootstrap')
5454
implementation project(':dd-java-agent:agent-otel:otel-shim')
5555

56-
instrumentPluginClasspath project(path: ':dd-java-agent:agent-otel:otel-tooling', configuration: 'instrumentPluginClasspath')
56+
buildTimeInstrumentationPlugin project(path: ':dd-java-agent:agent-otel:otel-tooling', configuration: 'buildTimeInstrumentationPlugin')
5757
}
5858

5959
// unpack embeddedClasspath to same path as compiled classes so it can get instrumented

dd-java-agent/agent-otel/otel-tooling/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ minimumInstructionCoverage = 0.0
44
minimumBranchCoverage = 0.0
55

66
configurations {
7-
instrumentPluginClasspath {
7+
buildTimeInstrumentationPlugin {
88
canBeConsumed = true
99
canBeResolved = false
1010
extendsFrom runtimeElements

dd-java-agent/agent-otel/otel-tooling/src/main/java/datadog/opentelemetry/tooling/shim/OtelShimGradlePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Bytebuddy gradle plugin which injects our OpenTelemetry shim into the target API.
1515
*
16-
* @see "buildSrc/src/main/groovy/InstrumentPlugin.groovy"
16+
* @see datadog.gradle.plugin.instrument.BuildTimeInstrumentationPlugin
1717
*/
1818
public class OtelShimGradlePlugin extends Plugin.ForElementMatcher {
1919
private final File targetDir;

dd-java-agent/agent-tooling/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sourceSets {
2828
}
2929

3030
configurations {
31-
register("instrumentPluginClasspath") {
31+
register("buildTimeInstrumentationPlugin") {
3232
canBeConsumed = true
3333
canBeResolved = false
3434
extendsFrom runtimeElements

0 commit comments

Comments
 (0)