Remove scala from dependency management
Will close after this is merged and that PR is rebased.
I tested and it does bring a few more scala versions into Intellij
without this, but scala is an odd case.
MODIFY
conventions/src/main/kotlin/otel.scala-conventions.gradle.kts
conventions/src/main/kotlin/otel.scala-conventions.gradle.kts
@@ -5,7 +5,7 @@ plugins {
}
dependencies {
- testImplementation("org.scala-lang:scala-library")
+ testCompileOnly("org.scala-lang:scala-library:2.11.12")
}
tasks {

MODIFY
dependencyManagement/build.gradle.kts
dependencyManagement/build.gradle.kts
@@ -100,7 +100,6 @@ val DEPENDENCIES = listOf(
"org.codehaus.mojo:animal-sniffer-annotations:1.22",
"org.junit-pioneer:junit-pioneer:1.9.0",
"org.objenesis:objenesis:3.3",
- "org.scala-lang:scala-library:2.11.12",
// Note that this is only referenced as "org.springframework.boot" in build files, not the artifact name.
"org.springframework.boot:spring-boot-dependencies:2.7.5",
"javax.validation:validation-api:2.0.1.Final",

MODIFY
instrumentation/executors/javaagent/build.gradle.kts
instrumentation/executors/javaagent/build.gradle.kts
plugins {
id("otel.javaagent-instrumentation")
+ id("otel.scala-conventions")
}
muzzle {
@@ -12,6 +13,8 @@ dependencies {
bootstrap(project(":instrumentation:executors:bootstrap"))
testImplementation(project(":instrumentation:executors:testing"))
+
+ testImplementation("org.scala-lang:scala-library:2.11.12")
}
testing {

RENAME
instrumentation/scala-fork-join-2.8/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/scalaexecutors/ScalaInstrumentationTest.scala
instrumentation/executors/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/scalaexecutors/ScalaInstrumentationTest.scala
MODIFY
instrumentation/jdbc/javaagent/build.gradle.kts
instrumentation/jdbc/javaagent/build.gradle.kts
plugins {
id("otel.javaagent-instrumentation")
+ id("otel.scala-conventions")
}
muzzle {
@@ -34,6 +35,11 @@ dependencies {
latestDepTestLibrary("org.apache.derby:derby:10.14.+")
testImplementation(project(":instrumentation:jdbc:testing"))
+
+ // these dependencies are for SlickTest
+ testImplementation("org.scala-lang:scala-library:2.11.12")
+ testImplementation("com.typesafe.slick:slick_2.11:3.2.0")
+ testImplementation("com.h2database:h2:1.4.197")
}
sourceSets {
@@ -46,6 +52,22 @@ sourceSets {
}
}
-tasks.withType<Test>().configureEach {
+tasks {
+ val testSlick by registering(Test::class) {
+ filter {
+ includeTestsMatching("SlickTest")
+ }
+ include("**/SlickTest.*")
+ }
+
+ test {
+ filter {
+ excludeTestsMatching("SlickTest")
+ }
jvmArgs("-Dotel.instrumentation.jdbc-datasource.enabled=true")
}
+
+ check {
+ dependsOn(testSlick)
+ }
+}

RENAME
instrumentation/scala-fork-join-2.8/javaagent/src/slickTest/scala/io/opentelemetry/javaagent/instrumentation/scalaexecutors/SlickTest.scala
instrumentation/jdbc/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/scalaexecutors/SlickTest.scala
MODIFY
instrumentation/scala-fork-join-2.8/javaagent/build.gradle.kts
instrumentation/scala-fork-join-2.8/javaagent/build.gradle.kts
plugins {
id("otel.javaagent-instrumentation")
id("otel.scala-conventions")
- id("org.unbroken-dome.test-sets")
}
muzzle {
@@ -13,10 +12,6 @@ muzzle {
}
}
-testSets {
- create("slickTest")
-}
-
dependencies {
bootstrap(project(":instrumentation:executors:bootstrap"))
@@ -24,21 +19,5 @@ dependencies {
latestDepTestLibrary("org.scala-lang:scala-library:2.11.+")
- testInstrumentation(project(":instrumentation:jdbc:javaagent"))
-
testImplementation(project(":instrumentation:executors:testing"))
-
- add("slickTestImplementation", project(":testing-common"))
- add("slickTestImplementation", "org.scala-lang:scala-library")
- add("slickTestImplementation", "com.typesafe.slick:slick_2.11:3.2.0")
- add("slickTestImplementation", "com.h2database:h2:1.4.197")
-}
-
-// Run Slick library tests along with the rest of tests
-tasks {
- val slickTest by existing
-
- check {
- dependsOn(slickTest)
- }
}

MODIFY
instrumentation/scala-fork-join-2.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/scalaexecutors/ScalaForkJoinPoolInstrumentation.java
instrumentation/scala-fork-join-2.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/scalaexecutors/ScalaForkJoinPoolInstrumentation.java
package io.opentelemetry.javaagent.instrumentation.scalaexecutors;
import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.context.Context;
@@ -24,22 +25,14 @@ public class ScalaForkJoinPoolInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
- // This might need to be an extendsClass matcher...
return named("scala.concurrent.forkjoin.ForkJoinPool");
}
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
- named("execute")
- .and(takesArgument(0, named(ScalaForkJoinTaskInstrumentation.TASK_CLASS_NAME))),
- ScalaForkJoinPoolInstrumentation.class.getName() + "$SetScalaForkJoinStateAdvice");
- transformer.applyAdviceToMethod(
- named("submit")
- .and(takesArgument(0, named(ScalaForkJoinTaskInstrumentation.TASK_CLASS_NAME))),
- ScalaForkJoinPoolInstrumentation.class.getName() + "$SetScalaForkJoinStateAdvice");
- transformer.applyAdviceToMethod(
- named("invoke")
+ // doSubmit is internal method prior to 2.11, and externalPush is the internal method after
+ namedOneOf("doSubmit", "externalPush")
.and(takesArgument(0, named(ScalaForkJoinTaskInstrumentation.TASK_CLASS_NAME))),
ScalaForkJoinPoolInstrumentation.class.getName() + "$SetScalaForkJoinStateAdvice");
}

ADD
instrumentation/scala-fork-join-2.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/scalaexecutors/ForkJoinPoolBridge.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.scalaexecutors;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.jetbrains.annotations.NotNull;
+import scala.concurrent.forkjoin.ForkJoinPool;
+import scala.concurrent.forkjoin.ForkJoinTask;
+
+public class ForkJoinPoolBridge implements ExecutorService {
+
+ private final ForkJoinPool delegate;
+
+ public ForkJoinPoolBridge(ForkJoinPool delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void shutdown() {
+ delegate.shutdown();
+ }
+
+ @NotNull
+ @Override
+ public List<Runnable> shutdownNow() {
+ return delegate.shutdownNow();
+ }
+
+ @Override
+ public boolean isShutdown() {
+ return delegate.isShutdown();
+ }
+
+ @Override
+ public boolean isTerminated() {
+ return delegate.isTerminated();
+ }
+
+ @Override
+ public boolean awaitTermination(long timeout, @NotNull TimeUnit unit)
+ throws InterruptedException {
+ return delegate.awaitTermination(timeout, unit);
+ }
+
+ @NotNull
+ @Override
+ public <T> Future<T> submit(@NotNull Callable<T> task) {
+ return delegate.submit(task);
+ }
+
+ @NotNull
+ @Override
+ public <T> Future<T> submit(@NotNull Runnable task, T result) {
+ return delegate.submit(task, result);
+ }
+
+ @NotNull
+ @Override
+ public Future<?> submit(@NotNull Runnable task) {
+ return delegate.submit(task);
+ }
+
+ @NotNull
+ @Override
+ public <T> List<Future<T>> invokeAll(@NotNull Collection<? extends Callable<T>> tasks) {
+ return delegate.invokeAll(tasks);
+ }
+
+ @NotNull
+ @Override
+ public <T> List<Future<T>> invokeAll(
+ @NotNull Collection<? extends Callable<T>> tasks, long timeout, @NotNull TimeUnit unit) {
+ // Scala 2.8's ForkJoinPool doesn't have corresponding method
+ return delegate.invokeAll(tasks);
+ }
+
+ @NotNull
+ @Override
+ public <T> T invokeAny(@NotNull Collection<? extends Callable<T>> tasks)
+ throws InterruptedException, ExecutionException {
+ // Scala 2.8's ForkJoinPool doesn't have corresponding method
+ return delegate.submit(tasks.iterator().next()).get();
+ }
+
+ @Override
+ public <T> T invokeAny(
+ @NotNull Collection<? extends Callable<T>> tasks, long timeout, @NotNull TimeUnit unit)
+ throws InterruptedException, ExecutionException {
+ // Scala 2.8's ForkJoinPool doesn't have corresponding method
+ return delegate.submit(tasks.iterator().next()).get();
+ }
+
+ public <T> T invoke(ForkJoinTask<T> task) {
+ return delegate.invoke(task);
+ }
+
+ @Override
+ public void execute(@NotNull Runnable command) {
+ delegate.execute(command);
+ }
+
+ public <T> void execute(ForkJoinTask<T> task) {
+ delegate.execute(task);
+ }
+}

MODIFY
instrumentation/scala-fork-join-2.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/scalaexecutors/ScalaExecutorInstrumentationTest.java
instrumentation/scala-fork-join-2.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/scalaexecutors/ScalaExecutorInstrumentationTest.java
@@ -14,13 +14,13 @@ import scala.concurrent.forkjoin.ForkJoinPool;
import scala.concurrent.forkjoin.ForkJoinTask;
class ScalaExecutorInstrumentationTest
- extends AbstractExecutorServiceTest<ForkJoinPool, ScalaAsyncChild> {
+ extends AbstractExecutorServiceTest<ForkJoinPoolBridge, ScalaAsyncChild> {
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
ScalaExecutorInstrumentationTest() {
- super(new ForkJoinPool(), testing);
+ super(new ForkJoinPoolBridge(new ForkJoinPool()), testing);
}
@Override
@@ -34,7 +34,7 @@ class ScalaExecutorInstrumentationTest
}
@Test
- void submitForkJoinTask() {
- executeTwoTasks(task -> executor().submit((ForkJoinTask<?>) task));
+ void executeForkJoinTask() {
+ executeTwoTasks(task -> executor().execute((ForkJoinTask<?>) task));
}
}

Remove scala from dependency management (#7296)

Will close #7216 after this is merged and that PR is rebased.

I tested and it does bring a few more scala versions into Intellij
without this, but scala is an odd case.