Let muzzle plugin test same dependency in different conditions
The muzzle plugin creates a config for each of the dependencies under test with name '...-<group_id>-<artifact_id>-<version>'. The problem is that if we want to test multiple times the same configuration under different conditions, e.g. with different extra dependencies, the plugin would throw an error as it would try to create several times the same config. This commit let directives to define an optional name that defaults to a null. If a name is provided then a slug of it is used to generate the gradle configuration name.
This commit is contained in:
parent
27489afd5c
commit
1a3e5fe69a
|
@ -261,7 +261,7 @@ class MuzzlePlugin implements Plugin<Project> {
|
|||
* @return The created muzzle task.
|
||||
*/
|
||||
private static Task addMuzzleTask(MuzzleDirective muzzleDirective, Artifact versionArtifact, Project instrumentationProject, Task runAfter, Project bootstrapProject, Project toolingProject) {
|
||||
def taskName = "muzzle-Assert${muzzleDirective.assertPass ? "Pass" : "Fail"}-$versionArtifact.groupId-$versionArtifact.artifactId-$versionArtifact.version"
|
||||
def taskName = "muzzle-Assert${muzzleDirective.assertPass ? "Pass" : "Fail"}-$versionArtifact.groupId-$versionArtifact.artifactId-$versionArtifact.version${muzzleDirective.name ? "-${muzzleDirective.getNameSlug()}" : ""}"
|
||||
def config = instrumentationProject.configurations.create(taskName)
|
||||
config.dependencies.add(instrumentationProject.dependencies.create("$versionArtifact.groupId:$versionArtifact.artifactId:$versionArtifact.version") {
|
||||
transitive = true
|
||||
|
@ -342,6 +342,16 @@ class MuzzlePlugin implements Plugin<Project> {
|
|||
* A pass or fail directive for a single dependency.
|
||||
*/
|
||||
class MuzzleDirective {
|
||||
|
||||
/**
|
||||
* Name is optional and is used to further define the scope of a directive. The motivation for this is that this
|
||||
* plugin creates a config for each of the dependencies under test with name '...-<group_id>-<artifact_id>-<version>'.
|
||||
* The problem is that if we want to test multiple times the same configuration under different conditions, e.g.
|
||||
* with different extra dependencies, the plugin would throw an error as it would try to create several times the
|
||||
* same config. This property can be used to differentiate those config names for different directives.
|
||||
*/
|
||||
String name
|
||||
|
||||
String group
|
||||
String module
|
||||
String versions
|
||||
|
@ -349,9 +359,27 @@ class MuzzleDirective {
|
|||
boolean assertPass
|
||||
boolean assertInverse = false
|
||||
|
||||
/**
|
||||
* Adds extra dependencies to the current muzzle test.
|
||||
*
|
||||
* @param compileString An extra dependency in the gradle canonical form: '<group_id>:<artifact_id>:<version_id>'.
|
||||
*/
|
||||
void extraDependency(String compileString) {
|
||||
additionalDependencies.add(compileString)
|
||||
}
|
||||
|
||||
/**
|
||||
* Slug of a directive name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getNameSlug() {
|
||||
if (null == name) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return name.trim().replaceAll("[^a-zA-Z0-9]+", "-")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue