Skip to content
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
3 changes: 3 additions & 0 deletions maven-extension/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ dependencies {
implementation("io.opentelemetry.semconv:opentelemetry-semconv")
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")

annotationProcessor("com.google.auto.service:auto-service")
annotationProcessor("com.google.auto.value:auto-value")
compileOnly("com.google.auto.service:auto-service")
compileOnly("com.google.auto.value:auto-value-annotations")

compileOnly("org.apache.maven:maven-core:3.5.0") // do not auto-update, support older mvn versions
Expand All @@ -36,6 +38,7 @@ dependencies {
testImplementation("io.opentelemetry:opentelemetry-api-incubator")
testImplementation("org.apache.maven:maven-core:3.5.0")
testImplementation("org.slf4j:slf4j-simple")
testImplementation("com.google.auto.service:auto-service")
}

// The jar dependencies bundled in the uber-jar by the shadow plugin are wrongly added as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.maven.handler;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.maven.MavenGoal;
Expand All @@ -21,7 +22,8 @@
import org.slf4j.LoggerFactory;

/** See https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin */
final class GoogleJibBuildHandler implements MojoGoalExecutionHandler {
@AutoService(MojoGoalExecutionHandler.class)
public final class GoogleJibBuildHandler implements MojoGoalExecutionHandler {
private static final Logger logger = LoggerFactory.getLogger(GoogleJibBuildHandler.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.maven.handler;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.maven.MavenGoal;
Expand All @@ -26,7 +27,8 @@
* achieve this instrumenting the <a
* href="https://projects.eclipse.org/projects/technology.aether">Aether library</a>
*/
final class MavenDeployHandler implements MojoGoalExecutionHandler {
@AutoService(MojoGoalExecutionHandler.class)
public final class MavenDeployHandler implements MojoGoalExecutionHandler {
private static final Logger logger = LoggerFactory.getLogger(MavenDeployHandler.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ public static Map<MavenGoal, MojoGoalExecutionHandler> loadMojoGoalExecutionHand
ClassLoader classLoader) {

// built-in handlers
List<MojoGoalExecutionHandler> builtInHandlers =
Arrays.asList(
new GoogleJibBuildHandler(),
new MavenDeployHandler(),
new SnykMonitorHandler(),
new SnykTestHandler(),
new SpringBootBuildImageHandler());
List<MojoGoalExecutionHandler> builtInHandlers = Arrays.asList();

List<MojoGoalExecutionHandler> spiHandlers = new ArrayList<>();
// Must use the classloader of the class rather the default ThreadContextClassloader to prevent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.maven.handler;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.maven.MavenGoal;
Expand All @@ -16,7 +17,8 @@
import org.apache.maven.execution.ExecutionEvent;

/** See https://github.com/snyk/snyk-maven-plugin */
final class SnykMonitorHandler implements MojoGoalExecutionHandler {
@AutoService(MojoGoalExecutionHandler.class)
public final class SnykMonitorHandler implements MojoGoalExecutionHandler {
Comment on lines -19 to +21
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot why this change

Copy link
Author

Choose a reason for hiding this comment

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

The changes on lines 19-21 implement the style guide requirements for SPI registration:

  1. Line 8: Added import com.google.auto.service.AutoService;
  2. Line 20: Added @AutoService(MojoGoalExecutionHandler.class) to automatically generate the META-INF/services file, eliminating manual service file maintenance
  3. Line 21: Changed from final class to public final class because ServiceLoader requires implementation classes to be public for instantiation

This follows the same pattern applied to all other MojoGoalExecutionHandler implementations and modernizes the SPI registration approach as outlined in the style guide.


/**
* Snyk command "reversed engineered" invoking the Snyk CLI on a Maven project with the `-d` debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.maven.handler;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.maven.MavenGoal;
Expand All @@ -16,7 +17,8 @@
import org.apache.maven.execution.ExecutionEvent;

/** See https://github.com/snyk/snyk-maven-plugin */
final class SnykTestHandler implements MojoGoalExecutionHandler {
@AutoService(MojoGoalExecutionHandler.class)
public final class SnykTestHandler implements MojoGoalExecutionHandler {
Comment on lines -19 to +21
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot why this change?

Copy link
Author

Choose a reason for hiding this comment

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

The changes on lines 19-21 implement the style guide requirements for SPI registration:

  1. Line 8: Added import com.google.auto.service.AutoService;
  2. Line 20: Added @AutoService(MojoGoalExecutionHandler.class) to automatically generate the META-INF/services file, eliminating manual service file maintenance
  3. Line 21: Changed from final class to public final class because ServiceLoader requires implementation classes to be public for instantiation

This follows the same pattern applied to all other MojoGoalExecutionHandler implementations and modernizes the SPI registration approach as outlined in the style guide.


/**
* Snyk command "reversed engineered" invoking the Snyk CLI on a Maven project with the `-d` debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.maven.handler;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.maven.MavenGoal;
Expand Down Expand Up @@ -32,7 +33,8 @@
* : spring-boot/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/</a>
* </ul>
*/
final class SpringBootBuildImageHandler implements MojoGoalExecutionHandler {
@AutoService(MojoGoalExecutionHandler.class)
public final class SpringBootBuildImageHandler implements MojoGoalExecutionHandler {
Comment on lines +36 to +37
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot why this change?

Copy link
Author

Choose a reason for hiding this comment

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

The changes on lines 36-37 implement the style guide requirements for SPI registration:

  1. Line 36: Added @AutoService(MojoGoalExecutionHandler.class) to automatically generate the META-INF/services file, eliminating manual service file maintenance
  2. Line 37: Changed from final class to public final class because ServiceLoader requires implementation classes to be public for instantiation

This follows the established pattern used throughout the OpenTelemetry Java Contrib codebase and modernizes the SPI registration approach as outlined in the style guide.

private static final Logger logger = LoggerFactory.getLogger(SpringBootBuildImageHandler.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

package io.opentelemetry.maven.resources;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.resources.Resource;

@SuppressWarnings("rawtypes")
@AutoService(ComponentProvider.class)
public class MavenResourceDetector implements ComponentProvider<Resource> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.maven.resources;

import com.google.auto.service.AutoService;
import io.opentelemetry.maven.semconv.MavenOtelSemanticAttributes;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
Expand All @@ -17,6 +18,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@AutoService(ResourceProvider.class)
public class MavenResourceProvider implements ResourceProvider {

private static final Logger logger = LoggerFactory.getLogger(MavenResourceProvider.class);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import org.junit.jupiter.api.Test;

public class MavenUtilsTests {
class MavenUtilsTests {

@Test
public void getPluginArtifactIdShortName_builtinPluginName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* Note: if otel-java-contrib bumps to Java 11+, we could use junit-pioneer's
* {@code @SetSystemProperty} and {@code @ClearSystemProperty} but no bump is planned for now.
*/
public class OpenTelemetrySdkServiceTest {
class OpenTelemetrySdkServiceTest {

/** Verify default config */
@Test
public void testDefaultConfiguration() {
void testDefaultConfiguration() {
System.clearProperty("otel.exporter.otlp.endpoint");
System.clearProperty("otel.service.name");
System.clearProperty("otel.resource.attributes");
Expand All @@ -40,7 +40,7 @@ public void testDefaultConfiguration() {

/** Verify overwritten `service.name`,`key1` and `key2` */
@Test
public void testOverwrittenResourceAttributes() {
void testOverwrittenResourceAttributes() {
System.setProperty("otel.service.name", "my-maven");
System.setProperty("otel.resource.attributes", "key1=val1,key2=val2");

Expand All @@ -59,7 +59,7 @@ public void testOverwrittenResourceAttributes() {

/** Verify defining `otel.exporter.otlp.endpoint` works */
@Test
public void testOverwrittenExporterConfiguration_1() {
void testOverwrittenExporterConfiguration_1() {
System.setProperty("otel.exporter.otlp.endpoint", "https://example.com:4317");

try (OpenTelemetrySdkService openTelemetrySdkService = new OpenTelemetrySdkService()) {
Expand All @@ -78,7 +78,7 @@ public void testOverwrittenExporterConfiguration_1() {

/** Verify defining `otel.exporter.otlp.traces.endpoint` works */
@Test
public void testOverwrittenExporterConfiguration_2() {
void testOverwrittenExporterConfiguration_2() {
System.clearProperty("otel.exporter.otlp.endpoint");
System.clearProperty("otel.traces.exporter");
System.setProperty("otel.exporter.otlp.traces.endpoint", "https://example.com:4317/");
Expand All @@ -102,7 +102,7 @@ public void testOverwrittenExporterConfiguration_2() {

/** Verify defining `otel.exporter.otlp.traces.endpoint` and `otel.traces.exporter` works */
@Test
public void testOverwrittenExporterConfiguration_3() {
void testOverwrittenExporterConfiguration_3() {
System.clearProperty("otel.exporter.otlp.endpoint");
System.setProperty("otel.traces.exporter", "otlp");
System.setProperty("otel.exporter.otlp.traces.endpoint", "https://example.com:4317/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import io.opentelemetry.api.trace.Tracer;
import org.junit.jupiter.api.Test;

public class SpanRegistryTest {
class SpanRegistryTest {

/** MVND reuses the same Maven process and thus the Span Registry is reused. */
@Test
public void testSpanRegistryReuseWhenUsingMvnDaemon() {
void testSpanRegistryReuseWhenUsingMvnDaemon() {
SpanRegistry spanRegistry = new SpanRegistry();

Tracer tracer = OpenTelemetry.noop().getTracer("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Map;
import org.junit.jupiter.api.Test;

public class MojoGoalExecutionHandlerConfigurationTest {
class MojoGoalExecutionHandlerConfigurationTest {

@Test
public void mojoGoalExecutionHandlers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
* https://github.com/takari/takari-lifecycle/blob/master/takari-lifecycle-plugin/src/test/java/io/takari/maven/plugins/plugin/PluginDescriptorMojoTest.java
*/
@SuppressWarnings({"DeduplicateConstants", "deprecation"})
public class MojoGoalExecutionHandlerTest {
class MojoGoalExecutionHandlerTest {

@Test
public void testMavenDeploy() throws Exception {
void testMavenDeploy() throws Exception {

String pomXmlPath = "projects/jar/pom.xml";
String mojoGroupId = "org.apache.maven.plugins";
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testMavenDeploy() throws Exception {
}

@Test
public void testSpringBootBuildImage_springboot_1() throws Exception {
void testSpringBootBuildImage_springboot_1() throws Exception {

String pomXmlPath = "projects/springboot_1/pom.xml";
String mojoGroupId = "org.springframework.boot";
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testSpringBootBuildImage_springboot_1() throws Exception {
}

@Test
public void testSpringBootBuildImage_springboot_2() throws Exception {
void testSpringBootBuildImage_springboot_2() throws Exception {

String pomXmlPath = "projects/springboot_2/pom.xml";
String mojoGroupId = "org.springframework.boot";
Expand Down Expand Up @@ -180,7 +180,7 @@ public void testSpringBootBuildImage_springboot_2() throws Exception {
}

@Test
public void testGoogleJibBuild_jib_1() throws Exception {
void testGoogleJibBuild_jib_1() throws Exception {

String pomXmlPath = "projects/jib_1/pom.xml";
String mojoGroupId = "com.google.cloud.tools";
Expand Down Expand Up @@ -221,7 +221,7 @@ public void testGoogleJibBuild_jib_1() throws Exception {
}

@Test
public void testGoogleJibBuild_jib_2() throws Exception {
void testGoogleJibBuild_jib_2() throws Exception {

String pomXmlPath = "projects/jib_2/pom.xml";
String mojoGroupId = "com.google.cloud.tools";
Expand Down Expand Up @@ -262,7 +262,7 @@ public void testGoogleJibBuild_jib_2() throws Exception {
}

@Test
public void testSnykTest_snyk_1() throws Exception {
void testSnykTest_snyk_1() throws Exception {

String pomXmlPath = "projects/snyk_1/pom.xml";
String mojoGroupId = "io.snyk";
Expand Down Expand Up @@ -298,7 +298,7 @@ public void testSnykTest_snyk_1() throws Exception {
}

@Test
public void testSnykMonitor_snyk_1() throws Exception {
void testSnykMonitor_snyk_1() throws Exception {

String pomXmlPath = "projects/snyk_1/pom.xml";
String mojoGroupId = "io.snyk";
Expand Down