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

Apply spotless to groovy #12147

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ spotless {
toggleOffOn()
target("src/**/*.java")
}
plugins.withId("groovy") {
groovy {
licenseHeaderFile(
rootProject.file("buildscripts/spotless.license.java"),
"(package|import|(?:abstract )?class)"
)
endWithNewline()
}
groovy {
greclipse()
licenseHeaderFile(
rootProject.file("buildscripts/spotless.license.java"),
"(package|import|(?:abstract )?class)"
)
target("src/**/*.groovy")
endWithNewline()
}
plugins.withId("scala") {
scala {
Expand Down Expand Up @@ -108,6 +108,9 @@ if (project == rootProject) {
java {
googleJavaFormat()
}
groovy {
greclipse()
}
scala {
scalafmt()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.couchbase.mock.Bucket
import com.couchbase.mock.BucketConfiguration
import com.couchbase.mock.CouchbaseMock
import com.couchbase.mock.http.query.QueryServer
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.utils.PortUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,75 @@ import java.util.concurrent.Phaser

class AgentClassLoaderTest extends Specification {

def "agent classloader does not lock classloading around instance"() {
setup:
def className1 = 'some/class/Name1'
def className2 = 'some/class/Name2'
// any jar would do, use opentelemety sdk
URL testJarLocation = JavaVersionSpecific.getProtectionDomain().getCodeSource().getLocation()
AgentClassLoader loader = new AgentClassLoader(new File(testJarLocation.toURI()))
Phaser threadHoldLockPhase = new Phaser(2)
Phaser acquireLockFromMainThreadPhase = new Phaser(2)
def "agent classloader does not lock classloading around instance"() {
setup:
def className1 = 'some/class/Name1'
def className2 = 'some/class/Name2'
// any jar would do, use opentelemety sdk
URL testJarLocation = JavaVersionSpecific.getProtectionDomain().getCodeSource().getLocation()
AgentClassLoader loader = new AgentClassLoader(new File(testJarLocation.toURI()))
Phaser threadHoldLockPhase = new Phaser(2)
Phaser acquireLockFromMainThreadPhase = new Phaser(2)

when:
Thread thread1 = new Thread() {
@Override
void run() {
synchronized (loader.getClassLoadingLock(className1)) {
threadHoldLockPhase.arrive()
acquireLockFromMainThreadPhase.arriveAndAwaitAdvance()
}
}
}
thread1.start()
when:
Thread thread1 = new Thread() {
@Override
void run() {
synchronized (loader.getClassLoadingLock(className1)) {
threadHoldLockPhase.arrive()
acquireLockFromMainThreadPhase.arriveAndAwaitAdvance()
}
}
}
thread1.start()

Thread thread2 = new Thread() {
@Override
void run() {
threadHoldLockPhase.arriveAndAwaitAdvance()
synchronized (loader.getClassLoadingLock(className2)) {
acquireLockFromMainThreadPhase.arrive()
}
}
}
thread2.start()
thread1.join()
thread2.join()
boolean applicationDidNotDeadlock = true
Thread thread2 = new Thread() {
@Override
void run() {
threadHoldLockPhase.arriveAndAwaitAdvance()
synchronized (loader.getClassLoadingLock(className2)) {
acquireLockFromMainThreadPhase.arrive()
}
}
}
thread2.start()
thread1.join()
thread2.join()
boolean applicationDidNotDeadlock = true

then:
applicationDidNotDeadlock
}
then:
applicationDidNotDeadlock
}

def "multi release jar"() {
setup:
boolean jdk8 = "1.8" == System.getProperty("java.specification.version")
// sdk is a multi release jar
URL multiReleaseJar = JavaVersionSpecific.getProtectionDomain().getCodeSource().getLocation()
AgentClassLoader loader = new AgentClassLoader(new File(multiReleaseJar.toURI())) {
@Override
protected String getClassSuffix() {
return ""
}
}
def "multi release jar"() {
setup:
boolean jdk8 = "1.8" == System.getProperty("java.specification.version")
// sdk is a multi release jar
URL multiReleaseJar = JavaVersionSpecific.getProtectionDomain().getCodeSource().getLocation()
AgentClassLoader loader = new AgentClassLoader(new File(multiReleaseJar.toURI())) {
@Override
protected String getClassSuffix() {
return ""
}
}

when:
URL url = loader.findResource("io/opentelemetry/sdk/internal/CurrentJavaVersionSpecific.class")
when:
URL url = loader.findResource("io/opentelemetry/sdk/internal/CurrentJavaVersionSpecific.class")

then:
url != null
// versioned resource is found when not running on jdk 8
jdk8 != url.toString().contains("META-INF/versions/9/")
then:
url != null
// versioned resource is found when not running on jdk 8
jdk8 != url.toString().contains("META-INF/versions/9/")

and:
Class<?> clazz = loader.loadClass(JavaVersionSpecific.getName())
// class was loaded by agent loader used in this test
clazz.getClassLoader() == loader
// extract value of private static field that gets a different class depending on java version
Field field = clazz.getDeclaredField("CURRENT")
field.setAccessible(true)
Object javaVersionSpecific = field.get(null)
// expect a versioned class on java 9+
jdk8 != javaVersionSpecific.getClass().getName().endsWith("Java9VersionSpecific")
}
and:
Class<?> clazz = loader.loadClass(JavaVersionSpecific.getName())
// class was loaded by agent loader used in this test
clazz.getClassLoader() == loader
// extract value of private static field that gets a different class depending on java version
Field field = clazz.getDeclaredField("CURRENT")
field.setAccessible(true)
Object javaVersionSpecific = field.get(null)
// expect a versioned class on java 9+
jdk8 != javaVersionSpecific.getClass().getName().endsWith("Java9VersionSpecific")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@ import spock.lang.Specification

class AgentLoadedIntoBootstrapTest extends Specification {

def "Agent loads in when separate jvm is launched"() {
expect:
IntegrationTestUtils.runOnSeparateJvm(AgentLoadedChecker.getName()
, "" as String[]
, "" as String[]
, [:]
, true) == 0
}
def "Agent loads in when separate jvm is launched"() {
expect:
IntegrationTestUtils.runOnSeparateJvm(AgentLoadedChecker.getName()
, "" as String[]
, "" as String[]
, [:]
, true) == 0
}

// this tests the case where someone adds the contents of opentelemetry-javaagent.jar by mistake
// to their application's "uber.jar"
//
// the reason this can cause issues is because we locate the agent jar based on the CodeSource of
// the OpenTelemetryAgent class, and then we add that jar file to the bootstrap class path
//
// but if we find the OpenTelemetryAgent class in an uber jar file, and we add that (whole) uber
// jar file to the bootstrap class loader, that can cause some applications to break, as there's a
// lot of application and library code that doesn't handle getClassLoader() returning null
// (e.g. https://github.com/qos-ch/logback/pull/291)
def "application uber jar should not be added to the bootstrap class loader"() {
setup:
def mainClassName = MyClassLoaderIsNotBootstrap.getName()
def pathToJar = IntegrationTestUtils.createJarWithClasses(mainClassName,
MyClassLoaderIsNotBootstrap,
OpenTelemetryAgent).getPath()
// this tests the case where someone adds the contents of opentelemetry-javaagent.jar by mistake
// to their application's "uber.jar"
//
// the reason this can cause issues is because we locate the agent jar based on the CodeSource of
// the OpenTelemetryAgent class, and then we add that jar file to the bootstrap class path
//
// but if we find the OpenTelemetryAgent class in an uber jar file, and we add that (whole) uber
// jar file to the bootstrap class loader, that can cause some applications to break, as there's a
// lot of application and library code that doesn't handle getClassLoader() returning null
// (e.g. https://github.com/qos-ch/logback/pull/291)
def "application uber jar should not be added to the bootstrap class loader"() {
setup:
def mainClassName = MyClassLoaderIsNotBootstrap.getName()
def pathToJar = IntegrationTestUtils.createJarWithClasses(mainClassName,
MyClassLoaderIsNotBootstrap,
OpenTelemetryAgent).getPath()

expect:
IntegrationTestUtils.runOnSeparateJvm(mainClassName
, "" as String[]
, "" as String[]
, [:]
, pathToJar as String
, true) == 0
expect:
IntegrationTestUtils.runOnSeparateJvm(mainClassName
, "" as String[]
, "" as String[]
, [:]
, pathToJar as String
, true) == 0

cleanup:
new File(pathToJar).delete()
}
cleanup:
new File(pathToJar).delete()
}
}
Loading
Loading