No more gradle warnings (#2103)

This commit is contained in:
Nikita Salnikov-Tarnovski 2021-01-26 08:24:18 +02:00 committed by GitHub
parent df801dc2c3
commit 2d683d4289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 24 deletions

View File

@ -73,8 +73,8 @@ class MuzzlePlugin implements Plugin<Project> {
doLast {
if (!project.muzzle.directives.any { it.assertPass }) {
project.getLogger().info('No muzzle pass directives configured. Asserting pass against instrumentation compile-time dependencies')
ClassLoader userCL = createCompileDepsClassLoader(project, bootstrapProject)
ClassLoader instrumentationCL = createInstrumentationClassloader(project, toolingProject)
ClassLoader userCL = createCompileDepsClassLoader(project)
ClassLoader instrumentationCL = createInstrumentationClassloader(project)
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil')
.getMethod('assertInstrumentationMuzzled', ClassLoader.class, ClassLoader.class, boolean.class)
assertionMethod.invoke(null, instrumentationCL, userCL, true)
@ -86,7 +86,7 @@ class MuzzlePlugin implements Plugin<Project> {
group = 'Muzzle'
description = "Print references created by instrumentation muzzle"
doLast {
ClassLoader instrumentationCL = createInstrumentationClassloader(project, toolingProject)
ClassLoader instrumentationCL = createInstrumentationClassloader(project)
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil')
.getMethod('printMuzzleReferences', ClassLoader.class)
assertionMethod.invoke(null, instrumentationCL)
@ -125,15 +125,15 @@ class MuzzlePlugin implements Plugin<Project> {
project.getLogger().info("configured $muzzleDirective")
if (muzzleDirective.coreJdk) {
runAfter = addMuzzleTask(muzzleDirective, null, project, runAfter, bootstrapProject, toolingProject)
runAfter = addMuzzleTask(muzzleDirective, null, project, runAfter)
} else {
muzzleDirectiveToArtifacts(muzzleDirective, system, session).collect() { Artifact singleVersion ->
runAfter = addMuzzleTask(muzzleDirective, singleVersion, project, runAfter, bootstrapProject, toolingProject)
runAfter = addMuzzleTask(muzzleDirective, singleVersion, project, runAfter)
}
if (muzzleDirective.assertInverse) {
inverseOf(muzzleDirective, system, session).collect() { MuzzleDirective inverseDirective ->
muzzleDirectiveToArtifacts(inverseDirective, system, session).collect() { Artifact singleVersion ->
runAfter = addMuzzleTask(inverseDirective, singleVersion, project, runAfter, bootstrapProject, toolingProject)
runAfter = addMuzzleTask(inverseDirective, singleVersion, project, runAfter)
}
}
}
@ -142,14 +142,14 @@ class MuzzlePlugin implements Plugin<Project> {
}
}
private static ClassLoader getOrCreateToolingLoader(Project toolingProject) {
private static ClassLoader getOrCreateToolingLoader(Project project) {
synchronized (TOOLING_LOADER) {
ClassLoader toolingLoader = TOOLING_LOADER.get()
if (toolingLoader == null) {
Set<URL> urls = new HashSet<>()
toolingProject.getLogger().info('creating classpath for auto-tooling')
for (File f : toolingProject.sourceSets.main.runtimeClasspath.getFiles()) {
toolingProject.getLogger().info('--' + f)
project.getLogger().info('creating classpath for auto-tooling')
for (File f : project.configurations.toolingRuntime.getFiles()) {
project.getLogger().info('--' + f)
urls.add(f.toURI().toURL())
}
def loader = new URLClassLoader(urls.toArray(new URL[0]), ClassLoader.platformClassLoader)
@ -164,7 +164,7 @@ class MuzzlePlugin implements Plugin<Project> {
/**
* Create a classloader with core agent classes and project instrumentation on the classpath.
*/
private static ClassLoader createInstrumentationClassloader(Project project, Project toolingProject) {
private static ClassLoader createInstrumentationClassloader(Project project) {
project.getLogger().info("Creating instrumentation classpath for: " + project.getName())
Set<URL> urls = new HashSet<>()
for (File f : project.sourceSets.main.runtimeClasspath.getFiles()) {
@ -172,20 +172,20 @@ class MuzzlePlugin implements Plugin<Project> {
urls.add(f.toURI().toURL())
}
return new URLClassLoader(urls.toArray(new URL[0]), getOrCreateToolingLoader(toolingProject))
return new URLClassLoader(urls.toArray(new URL[0]), getOrCreateToolingLoader(project))
}
/**
* Create a classloader with all compile-time dependencies on the classpath
*/
private static ClassLoader createCompileDepsClassLoader(Project project, Project bootstrapProject) {
private static ClassLoader createCompileDepsClassLoader(Project project) {
List<URL> userUrls = new ArrayList<>()
project.getLogger().info("Creating compile-time classpath for: " + project.getName())
for (File f : project.configurations.compileOnly.getFiles()) {
for (File f : project.configurations.compileClasspath.getFiles()) {
project.getLogger().info('--' + f)
userUrls.add(f.toURI().toURL())
}
for (File f : bootstrapProject.sourceSets.main.runtimeClasspath.getFiles()) {
for (File f : project.configurations.bootstrapRuntime.getFiles()) {
project.getLogger().info('--' + f)
userUrls.add(f.toURI().toURL())
}
@ -195,7 +195,7 @@ class MuzzlePlugin implements Plugin<Project> {
/**
* Create a classloader with dependencies for a single muzzle task.
*/
private static ClassLoader createClassLoaderForTask(Project project, Project bootstrapProject, String muzzleTaskName) {
private static ClassLoader createClassLoaderForTask(Project project, String muzzleTaskName) {
List<URL> userUrls = new ArrayList<>()
project.getLogger().info("Creating task classpath")
@ -204,7 +204,7 @@ class MuzzlePlugin implements Plugin<Project> {
userUrls.add(jarFile.toURI().toURL())
}
for (File f : bootstrapProject.sourceSets.main.runtimeClasspath.getFiles()) {
for (File f : project.configurations.bootstrapRuntime.getFiles()) {
project.getLogger().info("-- Added to instrumentation bootstrap classpath: $f")
userUrls.add(f.toURI().toURL())
}
@ -334,12 +334,10 @@ class MuzzlePlugin implements Plugin<Project> {
* @param versionArtifact version to assert against.
* @param instrumentationProject instrumentation being asserted against.
* @param runAfter Task which runs before the new muzzle task.
* @param bootstrapProject Agent bootstrap project.
* @param toolingProject Agent tooling project.
*
* @return The created muzzle task.
*/
private static Task addMuzzleTask(MuzzleDirective muzzleDirective, Artifact versionArtifact, Project instrumentationProject, Task runAfter, Project bootstrapProject, Project toolingProject) {
private static Task addMuzzleTask(MuzzleDirective muzzleDirective, Artifact versionArtifact, Project instrumentationProject, Task runAfter) {
def taskName
if (muzzleDirective.coreJdk) {
taskName = "muzzle-Assert$muzzleDirective"
@ -368,7 +366,7 @@ class MuzzlePlugin implements Plugin<Project> {
def muzzleTask = instrumentationProject.task(taskName) {
dependsOn(instrumentationProject.configurations.named("runtimeClasspath"))
doLast {
ClassLoader instrumentationCL = createInstrumentationClassloader(instrumentationProject, toolingProject)
ClassLoader instrumentationCL = createInstrumentationClassloader(instrumentationProject)
def ccl = Thread.currentThread().contextClassLoader
def bogusLoader = new SecureClassLoader() {
@Override
@ -378,7 +376,7 @@ class MuzzlePlugin implements Plugin<Project> {
}
Thread.currentThread().contextClassLoader = bogusLoader
ClassLoader userCL = createClassLoaderForTask(instrumentationProject, bootstrapProject, taskName)
ClassLoader userCL = createClassLoaderForTask(instrumentationProject, taskName)
try {
// find all instrumenters, get muzzle, and assert
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil')

View File

@ -1 +0,0 @@
implementation-class=MuzzlePlugin

View File

@ -5,3 +5,5 @@ org.gradle.priority=low
# Gradle default is 256m which causes issues with our build - https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
org.gradle.warning.mode=fail

View File

@ -23,6 +23,18 @@ if (projectDir.name == 'javaagent') {
archivesBaseName = projectDir.parentFile.name
}
configurations {
toolingRuntime {
canBeConsumed = false
canBeResolved = true
}
bootstrapRuntime {
canBeConsumed = false
canBeResolved = true
}
}
afterEvaluate {
dependencies {
compileOnly project(':instrumentation-api')
@ -46,11 +58,15 @@ afterEvaluate {
testImplementation project(':utils:test-utils')
testImplementation deps.testcontainers
toolingRuntime(project(path: ":javaagent-tooling", configuration: 'instrumentationMuzzle'))
bootstrapRuntime(project(path: ":javaagent-bootstrap", configuration: 'instrumentationMuzzle'))
}
def pluginName = 'io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin'
new ByteBuddyPluginConfigurator(project, sourceSets.main, pluginName,
project(':javaagent-tooling').configurations.instrumentationMuzzle + configurations.runtimeClasspath
configurations.toolingRuntime + configurations.runtimeClasspath
).configure()
}

View File

@ -35,3 +35,11 @@ dependencies {
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.6.0'
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.18.1'
}
sourcesJar {
/*
We have two javacc config above. They both generate some overlapping files, e.g. ParseException.java.
As they both add generated files to sources, this results in duplicating files.
*/
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

View File

@ -7,6 +7,15 @@ apply from: "$rootDir/gradle/publish.gradle"
minimumBranchCoverage = 0.0
minimumInstructionCoverage = 0.0
configurations {
// classpath used by the instrumentation muzzle plugin
instrumentationMuzzle {
canBeConsumed = true
canBeResolved = false
extendsFrom implementation
}
}
dependencies {
api deps.opentelemetryApi
api deps.opentelemetryApiMetrics

View File

@ -10,6 +10,8 @@ minimumInstructionCoverage = 0
configurations {
// classpath used by the instrumentation muzzle plugin
instrumentationMuzzle {
canBeConsumed = true
canBeResolved = false
extendsFrom implementation
}
}