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

[Maven Extension] Migrate from Plexus to JSR 330 dependency injection APIs #1320

Merged
merged 6 commits into from
May 28, 2024

Conversation

cyrille-leclerc
Copy link
Member

@cyrille-leclerc cyrille-leclerc commented May 21, 2024

Description:

Maven is migrating its Dependency Injection framework from Plexus to JSR-330 and Eclipse Sisu as documented in https://maven.apache.org/maven-jsr330.html .

This PR migrates the OTel Maven Extension from Plexus to JSR-330.

The OpenTelemetry Maven Extension primarily relies on the AbstractExecutionListener API which is unfortunately not supported by Maven's JSR-330 / Sisu APIs as it was by Maven's Plexus APIs.
This PR works around this limitation hooking the OtelExecutionListener using the AbstractMavenLifecycleParticipant#afterProjectsRead API that is well supported by Maven's JSR-330/Sisu APIs.

Details on MAven JSR-330 / Sisu APIs behavior

See test Maven extensions https://github.com/cyrille-leclerc/maven-extension-test

Maven Extension APIMaven EventExtension loading mechanism
${maven.home}/lib/extmvn -Dmaven.ext.class.path=pom.xml's <extensions>.mvn/extensions.xml
JSR330AbstractExecutionListener 🔴 🔴 🔴 🔴
JSR330AbstractMavenLifecycleParticipant#afterSessionStart 🟢 🟢 🔴 🟢
JSR330AbstractMavenLifecycleParticipant#afterProjectsRead 🟢 🟢 🟢 🟢
JSR330AbstractMavenLifecycleParticipant#afterSessionEnd 🟢 🟢 🟢 🟢
JSR330AbstractEventSpy#init 🟢 🟢 🔴 🟢
JSR330AbstractEventSpy#onEvent 🟢 🟢 🔴 🟢
JSR330AbstractEventSpy#close 🟢 🟢 🔴 🟢

Existing Issue(s):

Testing:

Unfortunately, there is no testing framework for Maven extensions.
I've done manual tests including tests of a Jenkins + Maven pipeline.

Documentation:

No change for the users

Outstanding items:

None

@cyrille-leclerc
Copy link
Member Author

cyrille-leclerc commented May 21, 2024

works building with a pom.xml but not yet with the Gradle build.

pom.xml to build the Maven Extension
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.opentelemetry.contrib</groupId>
  <artifactId>opentelemetry-maven-extension</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <properties>
    <java.version>17</java.version>
    <auto-value.version>1.10.4</auto-value.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <version>1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-api</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk-trace</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk-extension-autoconfigure-spi</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry.semconv</groupId>
      <artifactId>opentelemetry-semconv</artifactId>
      <version>1.25.0-alpha</version>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry.semconv</groupId>
      <artifactId>opentelemetry-semconv-incubating</artifactId>
      <version>1.25.0-alpha</version>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-exporter-otlp</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.auto.value</groupId>
      <artifactId>auto-value-annotations</artifactId>
      <version>${auto-value.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.36</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <version>3.0.2</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
      <version>3.5.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.36</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.10.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>3.25.3</version>
      <scope>test</scope>
    </dependency>

  </dependencies>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-bom</artifactId>
        <version>1.37.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-bom-alpha</artifactId>
        <version>1.37.0-alpha</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <annotationProcessorPaths>
            <path>
              <groupId>com.google.auto.value</groupId>
              <artifactId>auto-value</artifactId>
              <version>${auto-value.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.eclipse.sisu</groupId>
        <artifactId>sisu-maven-plugin</artifactId>
        <version>0.9.0.M2</version>
        <executions>
          <execution>
            <id>generate-index</id>
            <goals>
              <goal>main-index</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.5.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

@cyrille-leclerc
Copy link
Member Author

The Gradle build of the Maven Extension now produces a valid Maven extension. I'm doing more tests.

@cyrille-leclerc cyrille-leclerc changed the title [Maven Extension] JSR 330 support [Maven Extension] Migrate from Plexus to JSR 330 dependency injection APIs May 22, 2024
@cyrille-leclerc cyrille-leclerc marked this pull request as ready for review May 22, 2024 09:11
@cyrille-leclerc cyrille-leclerc requested review from a team and kenfinnigan May 22, 2024 09:11
@laurit laurit added this to the v1.36.0 milestone May 28, 2024
@trask trask merged commit 516aed9 into open-telemetry:main May 28, 2024
14 checks passed
@cyrille-leclerc cyrille-leclerc deleted the jsr-330 branch August 13, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants