Skip to content

Commit

Permalink
No more gradle warnings (#2103)
Browse files Browse the repository at this point in the history
  • Loading branch information
iNikem committed Jan 26, 2021
1 parent df801dc commit 2d683d4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 24 deletions.
42 changes: 20 additions & 22 deletions buildSrc/src/main/groovy/MuzzlePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -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)
Expand All @@ -164,28 +164,28 @@ 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()) {
project.getLogger().info('--' + f)
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())
}
Expand All @@ -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")
Expand All @@ -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())
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 17 additions & 1 deletion gradle/instrumentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
}

Expand Down
8 changes: 8 additions & 0 deletions javaagent-api/javaagent-api.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 9 additions & 0 deletions javaagent-bootstrap/javaagent-bootstrap.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions javaagent-tooling/javaagent-tooling.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ minimumInstructionCoverage = 0
configurations {
// classpath used by the instrumentation muzzle plugin
instrumentationMuzzle {
canBeConsumed = true
canBeResolved = false
extendsFrom implementation
}
}
Expand Down

0 comments on commit 2d683d4

Please sign in to comment.