Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ApplicationInsightsAppenderClassFileTransformer implements ClassFil
UnshadedSdkPackageName.get() + "/log4j/v2/ApplicationInsightsAppender";
private static final String UNSHADED_CLASS_NAME_LOG_4_JV_1_2 =
UnshadedSdkPackageName.get() + "/log4j/v1_2/ApplicationInsightsAppender";
private static final String UNSHADED_CLASS_NAME_LOGBACK_LOGGING_EVENT =
UnshadedSdkPackageName.getLogbackPrefix() + "logback/classic/spi/ILoggingEvent";

@Override
@Nullable
Expand Down Expand Up @@ -73,7 +75,7 @@ public MethodVisitor visitMethod(
@Nullable String[] exceptions) {
MethodVisitor mv = cw.visitMethod(access, name, descriptor, signature, exceptions);
if (name.equals("append")
&& (descriptor.equals("(Lch/qos/logback/classic/spi/ILoggingEvent;)V")
&& (descriptor.equals("(L" + UNSHADED_CLASS_NAME_LOGBACK_LOGGING_EVENT + ";)V")
|| descriptor.equals("(Lorg/apache/log4j/spi/LoggingEvent;)V")
|| descriptor.equals("(Lorg/apache/logging/log4j/core/LogEvent;)V"))) {
// no-op the append() method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@

public class UnshadedSdkPackageName {

// using constant here so that it will NOT get shaded
// IMPORTANT FOR THIS NOT TO BE FINAL (or private)
// OTHERWISE COMPILER COULD THEORETICALLY INLINE IT BELOW AND APPLY .substring(1)
// and then it WOULD be shaded
// using package-prefix constants here so that they will NOT get shaded
// IMPORTANT FOR THESE NOT TO BE FINAL (or private)
// OTHERWISE COMPILER COULD THEORETICALLY INLINE THEM BELOW AND APPLY .substring(1)
// and then they WOULD be shaded
@SuppressWarnings("ConstantField") // field value intentionally mutable for specific use case
static String ALMOST_PREFIX = "!com/microsoft/applicationinsights";

@SuppressWarnings("ConstantField") // field value intentionally mutable for specific use case
static String ALMOST_LOGBACK_PREFIX = "!ch/qos/";

public static String get() {
return ALMOST_PREFIX.substring(1);
}

public static String getLogbackPrefix() {
return ALMOST_LOGBACK_PREFIX.substring(1);
}

private UnshadedSdkPackageName() {}
}
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ dependencies {
// When updating, update above in plugins too
implementation("com.diffplug.spotless:spotless-plugin-gradle:8.2.1")
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:6.4.8")
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.9")
implementation("com.gradleup.shadow:shadow-gradle-plugin:9.3.2")

implementation("org.owasp:dependency-check-gradle:12.2.0")

implementation("io.opentelemetry.instrumentation:gradle-plugins:2.19.0-alpha")
implementation("io.opentelemetry.instrumentation:gradle-plugins:2.26.1-alpha")

implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.3.0")
implementation("net.ltgt.gradle:gradle-nullaway-plugin:3.0.0")
Expand Down
23 changes: 20 additions & 3 deletions buildSrc/src/main/kotlin/ai.shadow-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@ plugins {
}

tasks.withType<ShadowJar>().configureEach {
mergeServiceFiles {
include("inst/META-INF/services/*")
}
mergeServiceFiles()
mergeServiceFiles("inst/META-INF/services")

exclude("**/module-info.class")
exclude("META-INF/*.SF")
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
exclude("META-INF/maven/**")
exclude("META-INF/INDEX.LIST")

// Keep service loaders merged while deduplicating non-functional META-INF metadata.
eachFile {
if (path.startsWith("META-INF/") && !path.startsWith("META-INF/services/")) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
filesMatching("META-INF/services/**") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
filesMatching("inst/META-INF/services/**") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

// Prevents conflict with other SLF4J instances. Important for premain.
relocate("org.slf4j", "io.opentelemetry.javaagent.slf4j")
Expand Down
8 changes: 6 additions & 2 deletions buildSrc/src/main/kotlin/ai.smoke-test-jar.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ val aiSmokeTest = extensions.getByType(AiSmokeTestExtension::class)
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("")
mergeServiceFiles()


filesMatching("META-INF/spring.factories") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

// Properly merge spring.factories files from all dependencies
// This is required for Spring Boot auto-configuration to work
// Use PropertiesFileTransformer to merge duplicate keys instead of simple append
transform(PropertiesFileTransformer::class.java) {
paths = listOf("META-INF/spring.factories")
mergeStrategy = "append"
mergeStrategy = PropertiesFileTransformer.MergeStrategy.Append
}

// Set main class - can be overridden by individual projects via mainClassName property
Expand Down