Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No more gradle warnings #2103

Merged
merged 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines -76 to +77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost rid of the bootstrap and tooling project dependencies #1225 (comment) 🎉

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