-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start migrating Muzzle plugin to Java (#2996)
- Loading branch information
Anuraag Agrawal
authored
May 15, 2021
1 parent
fe41885
commit 95c16c4
Showing
21 changed files
with
181 additions
and
141 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
99 changes: 99 additions & 0 deletions
99
buildSrc/src/main/java/io/opentelemetry/instrumentation/gradle/muzzle/MuzzleDirective.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,99 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.gradle.muzzle; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import org.gradle.api.provider.ListProperty; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.provider.SetProperty; | ||
|
||
public abstract class MuzzleDirective { | ||
|
||
private static final Pattern NORMALIZE_NAME_SLUG = Pattern.compile("[^a-zA-Z0-9]+"); | ||
|
||
public MuzzleDirective() { | ||
getName().convention(""); | ||
getSkipVersions().convention(Collections.emptySet()); | ||
getAdditionalDependencies().convention(Collections.emptyList()); | ||
getAssertPass().convention(false); | ||
getAssertInverse().convention(false); | ||
getCoreJdk().convention(false); | ||
} | ||
|
||
public abstract Property<String> getName(); | ||
|
||
public abstract Property<String> getGroup(); | ||
|
||
public abstract Property<String> getModule(); | ||
|
||
public abstract Property<String> getVersions(); | ||
|
||
public abstract SetProperty<String> getSkipVersions(); | ||
|
||
public abstract ListProperty<String> getAdditionalDependencies(); | ||
|
||
public abstract Property<Boolean> getAssertPass(); | ||
|
||
public abstract Property<Boolean> getAssertInverse(); | ||
|
||
public abstract Property<Boolean> getCoreJdk(); | ||
|
||
public void coreJdk() { | ||
getCoreJdk().set(true); | ||
} | ||
|
||
/** | ||
* Adds extra dependencies to the current muzzle test. | ||
* | ||
* @param compileString An extra dependency in the gradle canonical form: | ||
* '<group_id>:<artifact_id>:<version_id>'. | ||
*/ | ||
public void extraDependency(String compileString) { | ||
getAdditionalDependencies().add(compileString); | ||
} | ||
|
||
public void skip(String... version) { | ||
getSkipVersions().addAll(version); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
if (getCoreJdk().getOrElse(false)) { | ||
if (getAssertPass().getOrElse(false)) { | ||
sb.append("Pass"); | ||
} else { | ||
sb.append("Fail"); | ||
} | ||
sb.append("-core-jdk"); | ||
} else { | ||
if (getAssertPass().getOrElse(false)) { | ||
sb.append("pass"); | ||
} else { | ||
sb.append("fail"); | ||
} | ||
sb.append(getGroup().get()) | ||
.append(':') | ||
.append(getModule().get()) | ||
.append(':') | ||
.append(getVersions().get()); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
String getNameSlug() { | ||
return NORMALIZE_NAME_SLUG.matcher(getName().get().trim()).replaceAll("-"); | ||
} | ||
|
||
Set<String> getNormalizedSkipVersions() { | ||
return getSkipVersions().getOrElse(Collections.emptySet()).stream() | ||
.map(String::toLowerCase) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
buildSrc/src/main/java/io/opentelemetry/instrumentation/gradle/muzzle/MuzzleExtension.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,37 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.gradle.muzzle; | ||
|
||
import javax.inject.Inject; | ||
import org.gradle.api.Action; | ||
import org.gradle.api.model.ObjectFactory; | ||
import org.gradle.api.provider.ListProperty; | ||
|
||
public abstract class MuzzleExtension { | ||
|
||
private final ObjectFactory objectFactory; | ||
|
||
@Inject | ||
public MuzzleExtension(ObjectFactory objectFactory) { | ||
this.objectFactory = objectFactory; | ||
} | ||
|
||
public abstract ListProperty<MuzzleDirective> getDirectives(); | ||
|
||
public void pass(Action<? super MuzzleDirective> action) { | ||
MuzzleDirective pass = objectFactory.newInstance(MuzzleDirective.class); | ||
action.execute(pass); | ||
pass.getAssertPass().set(true); | ||
getDirectives().add(pass); | ||
} | ||
|
||
public void fail(Action<? super MuzzleDirective> action) { | ||
MuzzleDirective fail = objectFactory.newInstance(MuzzleDirective.class); | ||
action.execute(fail); | ||
fail.getAssertPass().set(false); | ||
getDirectives().add(fail); | ||
} | ||
} |
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
Oops, something went wrong.