1
- import static MuzzleAction.createClassLoader
2
-
3
1
import org.apache.maven.repository.internal.MavenRepositorySystemUtils
4
2
import org.eclipse.aether.DefaultRepositorySystemSession
5
3
import org.eclipse.aether.RepositorySystem
@@ -20,6 +18,7 @@ import org.eclipse.aether.version.Version
20
18
import org.gradle.api.Action
21
19
import org.gradle.api.DefaultTask
22
20
import org.gradle.api.GradleException
21
+ import org.gradle.api.NamedDomainObjectProvider
23
22
import org.gradle.api.Plugin
24
23
import org.gradle.api.Project
25
24
import org.gradle.api.Task
@@ -30,6 +29,7 @@ import org.gradle.api.invocation.BuildInvocationDetails
30
29
import org.gradle.api.model.ObjectFactory
31
30
import org.gradle.api.provider.Property
32
31
import org.gradle.api.tasks.SourceSet
32
+ import org.gradle.api.tasks.TaskProvider
33
33
import org.gradle.jvm.toolchain.JavaLanguageVersion
34
34
import org.gradle.jvm.toolchain.JavaToolchainService
35
35
import org.gradle.workers.WorkAction
@@ -93,36 +93,31 @@ class MuzzlePlugin implements Plugin<Project> {
93
93
def toolingProject = childProjects. get(' agent-tooling' )
94
94
project. extensions. create(" muzzle" , MuzzleExtension , project. objects)
95
95
96
- def muzzleBootstrap = project. configurations. create (' muzzleBootstrap' , {
96
+ def muzzleBootstrap = project. configurations. register (' muzzleBootstrap' , {
97
97
canBeConsumed : false
98
98
canBeResolved : true
99
99
})
100
- def muzzleTooling = project. configurations. create (' muzzleTooling' , {
100
+ def muzzleTooling = project. configurations. register (' muzzleTooling' , {
101
101
canBeConsumed : false
102
102
canBeResolved : true
103
103
})
104
- project. dependencies. add(' muzzleBootstrap' , bootstrapProject)
105
- project. dependencies. add(' muzzleTooling' , toolingProject)
104
+
105
+ project. dependencies. add(muzzleBootstrap. name, bootstrapProject)
106
+ project. dependencies. add(muzzleTooling. name, toolingProject)
106
107
107
108
project. evaluationDependsOn ' :dd-java-agent:agent-bootstrap'
108
109
project. evaluationDependsOn ' :dd-java-agent:agent-tooling'
109
110
110
111
// compileMuzzle compiles all projects required to run muzzle validation.
111
112
// Not adding group and description to keep this task from showing in `gradle tasks`.
112
- def compileMuzzle = project. task(' compileMuzzle' )
113
- compileMuzzle. dependsOn(toolingProject. tasks. named(" compileJava" ))
114
- project. afterEvaluate {
115
- project. tasks. matching {
116
- it. name =~ / \A instrument(Main)?(_.+)?(Java|Scala|Kotlin)/
117
- }. all {
118
- compileMuzzle. dependsOn(it)
119
- }
113
+ TaskProvider<Task > compileMuzzle = project. tasks. register(' compileMuzzle' ) {
114
+ it. dependsOn(project. tasks. withType(InstrumentTask ))
115
+ it. dependsOn bootstrapProject. tasks. named(" compileJava" )
116
+ it. dependsOn bootstrapProject. tasks. named(" compileMain_java11Java" )
117
+ it. dependsOn toolingProject. tasks. named(" compileJava" )
120
118
}
121
- compileMuzzle. dependsOn bootstrapProject. tasks. compileJava
122
- compileMuzzle. dependsOn bootstrapProject. tasks. compileMain_java11Java
123
- compileMuzzle. dependsOn toolingProject. tasks. compileJava
124
119
125
- project. task([ ' type ' : MuzzleTask ], ' muzzle ' ) {
120
+ def muzzleTask = project. tasks . register( ' muzzle ' , MuzzleTask ) {
126
121
description = " Run instrumentation muzzle on compile time dependencies"
127
122
doLast {
128
123
if (! project. muzzle. directives. any { it. assertPass }) {
@@ -133,23 +128,23 @@ class MuzzlePlugin implements Plugin<Project> {
133
128
dependsOn compileMuzzle
134
129
}
135
130
136
- project. task([ ' type ' : MuzzleTask ], ' printReferences ' ) {
131
+ project. tasks . register( ' printReferences ' , MuzzleTask ) {
137
132
description = " Print references created by instrumentation muzzle"
138
133
doLast {
139
134
printMuzzle(project)
140
135
}
141
136
dependsOn compileMuzzle
142
137
}
143
- project. task([' type' : MuzzleTask ], ' generateMuzzleReport' ) {
138
+
139
+ project. tasks. register(' generateMuzzleReport' , MuzzleTask ) {
144
140
description = " Print instrumentation version report"
145
141
doLast {
146
142
dumpVersionRanges(project)
147
143
}
148
144
dependsOn compileMuzzle
149
145
}
150
146
151
-
152
- project. task([' type' : MuzzleTask ], ' mergeMuzzleReports' ) {
147
+ project. tasks. register(' mergeMuzzleReports' , MuzzleTask ) {
153
148
description = " Merge generated version reports in one unique csv"
154
149
doLast {
155
150
mergeReports(project)
@@ -174,35 +169,37 @@ class MuzzlePlugin implements Plugin<Project> {
174
169
final RepositorySystemSession session = newRepositorySystemSession(system)
175
170
project. afterEvaluate {
176
171
// use runAfter to set up task finalizers in version order
177
- Task runAfter = project. tasks. muzzle
178
- // runLast is the last task to finish, so we can time the execution
179
- Task runLast = runAfter
172
+ TaskProvider<Task > runAfter = muzzleTask
180
173
for (MuzzleDirective muzzleDirective : project. muzzle. directives) {
181
174
project. getLogger(). info(" configured $muzzleDirective " )
182
175
183
176
if (muzzleDirective. coreJdk) {
184
- runLast = runAfter = addMuzzleTask(muzzleDirective, null , project, runAfter, muzzleBootstrap, muzzleTooling)
177
+ runAfter = addMuzzleTask(muzzleDirective, null , project, runAfter, muzzleBootstrap, muzzleTooling)
185
178
} else {
186
179
def range = resolveVersionRange(muzzleDirective, system, session)
187
- runLast = muzzleDirectiveToArtifacts(muzzleDirective, range). inject(runLast ) { last , Artifact singleVersion ->
180
+ for ( Artifact singleVersion : muzzleDirectiveToArtifacts(muzzleDirective, range)) {
188
181
runAfter = addMuzzleTask(muzzleDirective, singleVersion, project, runAfter, muzzleBootstrap, muzzleTooling)
189
182
}
190
183
if (muzzleDirective. assertInverse) {
191
- runLast = inverseOf(muzzleDirective, system, session). inject(runLast) { last1 , MuzzleDirective inverseDirective ->
192
- muzzleDirectiveToArtifacts(inverseDirective, resolveVersionRange(inverseDirective, system, session)). inject(last1) { last2 , Artifact singleVersion ->
184
+ for (MuzzleDirective inverseDirective : inverseOf(muzzleDirective, system, session)) {
185
+ def inverseRange = resolveVersionRange(inverseDirective, system, session)
186
+ for (Artifact singleVersion : (muzzleDirectiveToArtifacts(inverseDirective, inverseRange))) {
193
187
runAfter = addMuzzleTask(inverseDirective, singleVersion, project, runAfter, muzzleBootstrap, muzzleTooling)
194
188
}
195
189
}
196
190
}
197
191
}
198
192
}
199
- def timingTask = project. task (" muzzle-end" ) {
193
+ def timingTask = project. tasks . register (" muzzle-end" ) {
200
194
doLast {
201
195
long endTime = System . currentTimeMillis()
202
196
generateResultsXML(project, endTime - startTime)
203
197
}
204
198
}
205
- runLast. finalizedBy(timingTask)
199
+ // last muzzle task to run
200
+ runAfter. configure {
201
+ finalizedBy(timingTask)
202
+ }
206
203
}
207
204
}
208
205
@@ -236,7 +233,7 @@ class MuzzlePlugin implements Plugin<Project> {
236
233
Map<String , TestedArtifact > map = new TreeMap<> ()
237
234
def versionScheme = new GenericVersionScheme ()
238
235
dir. eachFileMatch(~/ .*\. csv/ ) { file ->
239
- file. eachLine { line , nb ->
236
+ file. eachLine { line , nb ->
240
237
if (nb == 1 ) {
241
238
// skip header
242
239
return
@@ -255,7 +252,6 @@ class MuzzlePlugin implements Plugin<Project> {
255
252
dumpVersionsToCsv(project, map)
256
253
}
257
254
258
-
259
255
private static void dumpVersionRanges (Project project ) {
260
256
final RepositorySystem system = newRepositorySystem()
261
257
final RepositorySystemSession session = newRepositorySystemSession(system)
@@ -318,9 +314,9 @@ class MuzzlePlugin implements Plugin<Project> {
318
314
FileCollection cp = project. files()
319
315
project. getLogger(). info(" Creating muzzle classpath for $muzzleTaskName " )
320
316
if (' muzzle' == muzzleTaskName) {
321
- cp + = project. configurations. compileClasspath
317
+ cp + = project. configurations. named( " compileClasspath" ) . get()
322
318
} else {
323
- cp + = project. configurations. getByName (muzzleTaskName)
319
+ cp + = project. configurations. named (muzzleTaskName) . get( )
324
320
}
325
321
if (project. getLogger(). isInfoEnabled()) {
326
322
cp. forEach { project. getLogger(). info(" -- $it " ) }
@@ -431,52 +427,61 @@ class MuzzlePlugin implements Plugin<Project> {
431
427
*
432
428
* @return The created muzzle task.
433
429
*/
434
- private static Task addMuzzleTask (MuzzleDirective muzzleDirective , Artifact versionArtifact , Project instrumentationProject , Task runAfter , Configuration muzzleBootstrap , Configuration muzzleTooling ) {
435
- def taskName
430
+ private static TaskProvider<Task > addMuzzleTask (
431
+ MuzzleDirective muzzleDirective ,
432
+ Artifact versionArtifact ,
433
+ Project instrumentationProject ,
434
+ TaskProvider<Task > runAfter ,
435
+ NamedDomainObjectProvider<Configuration > muzzleBootstrap ,
436
+ NamedDomainObjectProvider<Configuration > muzzleTooling
437
+ ) {
438
+ def muzzleTaskName
436
439
if (muzzleDirective. coreJdk) {
437
- taskName = " muzzle-Assert$muzzleDirective "
440
+ muzzleTaskName = " muzzle-Assert$muzzleDirective "
438
441
} else {
439
- taskName = " muzzle-Assert${ muzzleDirective.assertPass ? "Pass" : "Fail"} -$versionArtifact . groupId -$versionArtifact . artifactId -$versionArtifact . version ${ muzzleDirective.name ? "-${muzzleDirective.getNameSlug()}" : ""} "
442
+ muzzleTaskName = " muzzle-Assert${ muzzleDirective.assertPass ? "Pass" : "Fail"} -$versionArtifact . groupId -$versionArtifact . artifactId -$versionArtifact . version ${ muzzleDirective.name ? "-${muzzleDirective.getNameSlug()}" : ""} "
440
443
}
441
- def config = instrumentationProject. configurations. create(taskName)
442
-
443
- if (! muzzleDirective. coreJdk) {
444
- def depId = " $versionArtifact . groupId :$versionArtifact . artifactId :$versionArtifact . version "
445
- if (versionArtifact. classifier) {
446
- depId + = " :" + versionArtifact. classifier
447
- }
448
- def dep = instrumentationProject. dependencies. create(depId) {
449
- transitive = true
450
- }
451
- // The following optional transitive dependencies are brought in by some legacy module such as log4j 1.x but are no
452
- // longer bundled with the JVM and have to be excluded for the muzzle tests to be able to run.
453
- dep. exclude group : ' com.sun.jdmk' , module : ' jmxtools'
454
- dep. exclude group : ' com.sun.jmx' , module : ' jmxri'
455
- // Also exclude specifically excluded dependencies
456
- for (String excluded : muzzleDirective. excludedDependencies) {
457
- String [] parts = excluded. split(' :' )
458
- dep. exclude group : parts[0 ], module : parts[1 ]
459
- }
460
-
461
- config. dependencies. add(dep)
462
- }
463
- for (String additionalDependency : muzzleDirective. additionalDependencies) {
464
- config. dependencies. add(instrumentationProject. dependencies. create(additionalDependency) { dep ->
444
+ instrumentationProject. configurations. register(muzzleTaskName) { Configuration taskConfig ->
445
+ if (! muzzleDirective. coreJdk) {
446
+ def depId = " $versionArtifact . groupId :$versionArtifact . artifactId :$versionArtifact . version "
447
+ if (versionArtifact. classifier) {
448
+ depId + = " :" + versionArtifact. classifier
449
+ }
450
+ def dep = instrumentationProject. dependencies. create(depId) {
451
+ transitive = true
452
+ }
453
+ // The following optional transitive dependencies are brought in by some legacy module such as log4j 1.x but are no
454
+ // longer bundled with the JVM and have to be excluded for the muzzle tests to be able to run.
455
+ dep. exclude group : ' com.sun.jdmk' , module : ' jmxtools'
456
+ dep. exclude group : ' com.sun.jmx' , module : ' jmxri'
457
+ // Also exclude specifically excluded dependencies
465
458
for (String excluded : muzzleDirective. excludedDependencies) {
466
459
String [] parts = excluded. split(' :' )
467
460
dep. exclude group : parts[0 ], module : parts[1 ]
468
461
}
469
- dep. transitive = true
470
- })
462
+
463
+ taskConfig. dependencies. add(dep)
464
+ }
465
+ for (String additionalDependency : muzzleDirective. additionalDependencies) {
466
+ taskConfig. dependencies. add(instrumentationProject. dependencies. create(additionalDependency) { dep ->
467
+ for (String excluded : muzzleDirective. excludedDependencies) {
468
+ String [] parts = excluded. split(' :' )
469
+ dep. exclude group : parts[0 ], module : parts[1 ]
470
+ }
471
+ dep. transitive = true
472
+ })
473
+ }
471
474
}
472
475
473
- def muzzleTask = instrumentationProject. task([ ' type ' : MuzzleTask ], taskName ) {
476
+ def muzzleTask = instrumentationProject. tasks . register(muzzleTaskName, MuzzleTask ) {
474
477
doLast {
475
478
assertMuzzle(muzzleBootstrap, muzzleTooling, instrumentationProject, muzzleDirective)
476
479
}
477
480
}
478
481
479
- runAfter. finalizedBy(muzzleTask)
482
+ runAfter. configure {
483
+ finalizedBy(muzzleTask)
484
+ }
480
485
muzzleTask
481
486
}
482
487
@@ -710,10 +715,12 @@ abstract class MuzzleTask extends DefaultTask {
710
715
@javax.inject.Inject
711
716
abstract WorkerExecutor getWorkerExecutor ()
712
717
713
- void assertMuzzle (Configuration muzzleBootstrap ,
714
- Configuration muzzleTooling ,
715
- Project instrumentationProject ,
716
- MuzzleDirective muzzleDirective = null ) {
718
+ public void assertMuzzle (
719
+ NamedDomainObjectProvider<Configuration > muzzleBootstrap ,
720
+ NamedDomainObjectProvider<Configuration > muzzleTooling ,
721
+ Project instrumentationProject ,
722
+ MuzzleDirective muzzleDirective = null
723
+ ) {
717
724
def workQueue
718
725
String javaVersion = muzzleDirective?. javaVersion
719
726
if (javaVersion) {
@@ -730,8 +737,8 @@ abstract class MuzzleTask extends DefaultTask {
730
737
}
731
738
workQueue. submit(MuzzleAction . class, parameters -> {
732
739
parameters. buildStartedTime. set(invocationDetails. buildStartedTime)
733
- parameters. bootstrapClassPath. setFrom(muzzleBootstrap)
734
- parameters. toolingClassPath. setFrom(muzzleTooling)
740
+ parameters. bootstrapClassPath. setFrom(muzzleBootstrap. get() )
741
+ parameters. toolingClassPath. setFrom(muzzleTooling. get() )
735
742
parameters. instrumentationClassPath. setFrom(MuzzlePlugin . createAgentClassPath(instrumentationProject))
736
743
parameters. testApplicationClassPath. setFrom(MuzzlePlugin . createMuzzleClassPath(instrumentationProject, name))
737
744
if (muzzleDirective) {
@@ -743,7 +750,7 @@ abstract class MuzzleTask extends DefaultTask {
743
750
})
744
751
}
745
752
746
- void printMuzzle (Project instrumentationProject ) {
753
+ public void printMuzzle (Project instrumentationProject ) {
747
754
FileCollection cp = instrumentationProject. sourceSets. main. runtimeClasspath
748
755
ClassLoader cl = new URLClassLoader (cp* . toURI()* . toURL() as URL [], null as ClassLoader )
749
756
Method printMethod = cl. loadClass(' datadog.trace.agent.tooling.muzzle.MuzzleVersionScanPlugin' )
0 commit comments