@@ -48,7 +48,7 @@ class MuzzlePlugin implements Plugin<Project> {
4848 group = ' Muzzle'
4949 description = " Run instrumentation muzzle on compile time dependencies"
5050 doLast {
51- if (project. muzzle. passDirectives . size() == 0 ) {
51+ if (! project. muzzle. directives . any { it . assertPass } ) {
5252 project. getLogger(). info(' No muzzle pass directives configured. Asserting pass against instrumentation compile-time dependencies' )
5353 final ClassLoader userCL = createCompileDepsClassLoader(project, bootstrapProject)
5454 final ClassLoader agentCL = createDDClassloader(project, toolingProject)
@@ -72,14 +72,10 @@ class MuzzlePlugin implements Plugin<Project> {
7272 project. tasks. compileMuzzle. dependsOn(toolingProject. tasks. compileJava)
7373 project. afterEvaluate {
7474 project. tasks. compileMuzzle. dependsOn(project. tasks. compileJava)
75- if (project. tasks. getNames(). contains(" compileScala" )) {
75+ if (project. tasks. getNames(). contains(' compileScala' )) {
7676 project. tasks. compileMuzzle. dependsOn(project. tasks. compileScala)
7777 }
7878 }
79- // TODO: consider:
80- // project.tasks.withType(ScalaCompile) { Task scalaTask ->
81- // project.tasks.compileMuzzle.dependsOn(scalaTask)
82- // }
8379 project. tasks. muzzle. dependsOn(project. tasks. compileMuzzle)
8480 project. tasks. printReferences. dependsOn(project. tasks. compileMuzzle)
8581
@@ -101,18 +97,11 @@ class MuzzlePlugin implements Plugin<Project> {
10197 // use runAfter to set up task finalizers in version order
10298 Task runAfter = project. tasks. muzzle
10399
104- for (MuzzleDirective pass : project. muzzle. passDirectives ) {
105- project. getLogger(). info(" configured pass directive: ${ pass .group} :${ pass .module} :${ pass .versions} " )
100+ for (MuzzleDirective muzzleDirective : project. muzzle. directives ) {
101+ project. getLogger(). info(" configured ${ muzzleDirective.assertPass ? ' pass' : 'fail' } directive: ${ muzzleDirective .group} :${ muzzleDirective .module} :${ muzzleDirective .versions} " )
106102
107- muzzleDirectiveToArtifacts(pass, system, session). collect() { Artifact singleVersion ->
108- runAfter = addMuzzleTask(pass, true , singleVersion, project, runAfter, bootstrapProject, toolingProject)
109- }
110- }
111- for (MuzzleDirective fail : project. muzzle. failDirectives) {
112- project. getLogger(). info(" configured fail directive: ${ fail.group} :${ fail.module} :${ fail.versions} " )
113-
114- muzzleDirectiveToArtifacts(fail , system, session). collect() { Artifact singleVersion ->
115- runAfter = addMuzzleTask(fail , false , singleVersion, project, runAfter, bootstrapProject, toolingProject)
103+ muzzleDirectiveToArtifacts(muzzleDirective, system, session). collect() { Artifact singleVersion ->
104+ runAfter = addMuzzleTask(muzzleDirective, singleVersion, project, runAfter, bootstrapProject, toolingProject)
116105 }
117106 }
118107 }
@@ -202,13 +191,13 @@ class MuzzlePlugin implements Plugin<Project> {
202191 *
203192 * @return The created muzzle task.
204193 */
205- private static Task addMuzzleTask (MuzzleDirective directive , boolean assertPass , Artifact versionArtifact , Project instrumentationProject , Task runAfter , Project bootstrapProject , Project toolingProject ) {
206- def taskName = " muzzle-Assert${ assertPass ? "Pass" : "Fail"} -$versionArtifact . groupId -$versionArtifact . artifactId -$versionArtifact . version "
194+ private static Task addMuzzleTask (MuzzleDirective muzzleDirective , Artifact versionArtifact , Project instrumentationProject , Task runAfter , Project bootstrapProject , Project toolingProject ) {
195+ def taskName = " muzzle-Assert${ muzzleDirective. assertPass ? "Pass" : "Fail"} -$versionArtifact . groupId -$versionArtifact . artifactId -$versionArtifact . version "
207196 def config = instrumentationProject. configurations. create(taskName)
208197 config. dependencies. add(instrumentationProject. dependencies. create(" $versionArtifact . groupId :$versionArtifact . artifactId :$versionArtifact . version " ) {
209198 transitive = true
210199 })
211- for (String additionalDependency : directive . additionalDependencies) {
200+ for (String additionalDependency : muzzleDirective . additionalDependencies) {
212201 config. dependencies. add(instrumentationProject. dependencies. create(additionalDependency) {
213202 transitive = true
214203 })
@@ -221,7 +210,7 @@ class MuzzlePlugin implements Plugin<Project> {
221210 // find all instrumenters, get muzzle, and assert
222211 Method assertionMethod = agentCL. loadClass(' datadog.trace.agent.tooling.muzzle.MuzzleVersionScanPlugin' )
223212 .getMethod(' assertInstrumentationMuzzled' , ClassLoader . class, boolean . class)
224- assertionMethod. invoke(null , userCL, assertPass)
213+ assertionMethod. invoke(null , userCL, muzzleDirective . assertPass)
225214 }
226215 }
227216 runAfter. finalizedBy(muzzleTask)
@@ -282,6 +271,7 @@ class MuzzleDirective {
282271 String module
283272 String versions
284273 List<String > additionalDependencies = new ArrayList<> ()
274+ boolean assertPass
285275 void extraDependency (String compileString ) {
286276 additionalDependencies. add(compileString)
287277 }
@@ -291,27 +281,25 @@ class MuzzleDirective {
291281 * Muzzle extension containing all pass and fail directives.
292282 */
293283class MuzzleExtension {
294- // TODO: merge pass and fail directives into single collection
295- final List<MuzzleDirective > passDirectives
296- final List<MuzzleDirective > failDirectives
284+ final List<MuzzleDirective > directives = new ArrayList<> ()
297285 private final ObjectFactory objectFactory
298286
299287 @javax.inject.Inject
300288 MuzzleExtension (final ObjectFactory objectFactory ) {
301289 this . objectFactory = objectFactory
302- passDirectives = new ArrayList<> ()
303- failDirectives = new ArrayList<> ()
304290 }
305291
306292 void pass (Action<? super MuzzleDirective > action ) {
307293 final MuzzleDirective pass = objectFactory. newInstance(MuzzleDirective )
308294 action. execute(pass)
309- passDirectives. add(pass)
295+ pass. assertPass = true
296+ directives. add(pass)
310297 }
311298
312299 void fail (Action<? super MuzzleDirective > action ) {
313300 final MuzzleDirective fail = objectFactory. newInstance(MuzzleDirective )
314301 action. execute(fail )
315- failDirectives. add(fail )
302+ fail . assertPass = false
303+ directives. add(fail )
316304 }
317305}
0 commit comments