You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/09/10 10:23:26 UTC

[PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

gnodet opened a new pull request, #13094:
URL: https://github.com/apache/maven/pull/13094

   ## Problem
   
   Three major Java IDEs independently override the same internal Maven component — `PluginDependenciesResolver` — for identical reasons:
   
   | IDE | Class | Approach |
   |-----|-------|----------|
   | IntelliJ IDEA | `Maven40PluginDependenciesResolver` | implements interface directly, `@Priority(10)` |
   | Eclipse m2e | `EclipsePluginDependenciesResolver` | extends `DefaultPluginDependenciesResolver` |
   | NetBeans | `NbPluginDependenciesResolver` | extends `DefaultPluginDependenciesResolver` |
   
   The root cause: m2e's source still carries the original comment from 2009:
   
   > Plugin realms are cached and there is currently no way to purge cached realms due to MNG-4194. Workspace plugins cannot be cached, so we disable this until MNG-4194 is fixed.
   
   `DefaultPluginRealmCache` is `@Singleton`. Plugin realms cannot be purged within a session. If the IDE workspace reader resolves a plugin, the cached realm becomes stale when workspace sources change. The only available workaround is to disable the IDE workspace reader during plugin resolution — which requires overriding an internal component.
   
   This was raised in the Maven dev list: [\[DISCUSS\] No supported extension point for plugin/extension resolution (in IDEs)?](https://lists.apache.org/thread/mtt7kg632lfs2hxcx0nv9bn4omkgbvt6)
   
   ## Solution
   
   Introduce a proper SPI in `maven-api-spi`:
   
   ```java
   package org.apache.maven.api.spi;
   
   public interface WorkspaceReader extends SpiService {
       Optional<Path> findArtifact(Artifact artifact);
       List<String> findVersions(Artifact artifact);
   
       default boolean isApplicableForPluginResolution() {
           return true;
       }
   }
   ```
   
   - Uses Maven 4 API types exclusively — no `maven-resolver-api` dependency required
   - `isApplicableForPluginResolution()` lets IDE integrators opt their reader out of plugin resolution without touching any internal component
   - `SpiWorkspaceReaderAdapter` bridges SPI implementations into the resolver workspace reader chain
   - `DefaultPluginDependenciesResolver` filters out non-applicable readers when building plugin sessions
   
   ## Migration for IDE integrators
   
   Instead of extending `DefaultPluginDependenciesResolver`:
   
   ```java
   // BEFORE (internal, fragile)
   @Named @Singleton
   class MyIdePluginDependenciesResolver extends DefaultPluginDependenciesResolver {
       @Override public Artifact resolve(Plugin plugin, ...) {
           try (var d = myWorkspaceReader.disable()) {
               return super.resolve(plugin, ...);
           }
       }
   }
   
   // AFTER (SPI, stable)
   @Named
   class MyIdeWorkspaceReader implements org.apache.maven.api.spi.WorkspaceReader {
       @Override public Optional<Path> findArtifact(Artifact artifact) { ... }
       @Override public List<String> findVersions(Artifact artifact) { ... }
       @Override public boolean isApplicableForPluginResolution() { return false; }
   }
   ```
   
   ## Changes
   
   - `maven-api-spi`: new `WorkspaceReader` SPI interface
   - `maven-core`: `SpiWorkspaceReaderAdapter` bridges SPI → resolver; `DefaultMaven` injects SPI readers; `DefaultPluginDependenciesResolver` filters them per plugin session
   - IT `mng-8766`: verifies SPI reader with `isApplicableForPluginResolution()=false` is not called during plugin resolution


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4003075885


##########
impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java:
##########
@@ -348,8 +349,14 @@ private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceRea
                 workspaceReaders.add(repoWorkspaceReader);
             }
         }
-        // 3) .. n) Project-scoped workspace readers
+        // 3) .. n) Project-scoped legacy workspace readers (org.eclipse.aether)
         workspaceReaders.addAll(getProjectScopedExtensionComponents(session.getProjects(), WorkspaceReader.class));
+        // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
+        //      has loaded core extensions into the container so they are visible via lookupList.

Review Comment:
   💡 **Not addressed from previous review** — this comment still says "visible via lookupList" but the code uses `getProjectScopedExtensionComponents()`. Raised in the previous review at `8850b59ed8`.
   
   ```suggestion
           // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
           //      has loaded core extensions into the container so they are visible via getProjectScopedExtensionComponents.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "laeubi (via GitHub)" <gi...@apache.org>.
laeubi commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-5617834130

   I'm not sure this really solve the issue or is wanted. Instead one more want to be able to purge the cache (so no disabling is actually needed) isn't it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-6168324642

   Cross-referencing #13499 (updated with m2e analysis) — the `invalidate(Artifact)` pattern added to `PluginRealmCache` in this PR should be generalized across Maven's other caches.
   
   m2e overrides 5 cache components (`PluginRealmCache`, `ExtensionRealmCache`, `ProjectRealmCache`, `PluginArtifactsCache`, `MavenMetadataCache`) solely to add eviction/flushing for IDE workspace mutability. A unified cache invalidation API (or making caches session-scoped) would eliminate all 5 overrides.
   
   _Claude Code on behalf of Guillaume Nodet_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4273510507


##########
its/core-it-suite/src/test/resources/mng-8766-spi-workspace-reader/extension/src/main/java/org/apache/maven/its/extensions/TestSpiWorkspaceReader.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.its.extensions;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.spi.WorkspaceReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Named("test-ide")
+public class TestSpiWorkspaceReader implements WorkspaceReader {
+
+    private static final Logger log = LoggerFactory.getLogger(TestSpiWorkspaceReader.class);
+
+    /**
+     * GAV of the synthetic artifact served by this workspace reader.
+     * The test project declares a dependency on this artifact.
+     */
+    private static final String SYNTHETIC_GROUP = "org.apache.maven.its.mng8766";
+
+    private static final String SYNTHETIC_ARTIFACT = "virtual-dep";
+    private static final String SYNTHETIC_VERSION = "1.0";
+
+    public TestSpiWorkspaceReader() {
+        log.info("[SPI-WR] created");
+    }
+
+    @Override
+    public Optional<Path> findArtifact(Artifact artifact) {
+        log.info("[SPI-WR] findArtifact({})", artifact.key());
+        if (isSyntheticArtifact(artifact)) {
+            try {
+                // Return a minimal (empty) jar file so the resolver can satisfy the dependency
+                Path jar = Files.createTempFile("mng8766-virtual-dep", ".jar");
+                jar.toFile().deleteOnExit();
+                // Write a valid empty ZIP/jar (4 bytes: end-of-central-directory signature)
+                try (OutputStream os = Files.newOutputStream(jar)) {
+                    os.write(new byte[] {0x50, 0x4B, 0x05, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
+                }
+                log.info("[SPI-WR] findArtifact: returning synthetic jar for {}", artifact.key());
+                return Optional.of(jar);
+            } catch (IOException e) {
+                log.warn("[SPI-WR] could not create synthetic jar: {}", e.getMessage());
+            }
+        }
+        return Optional.empty();
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        log.info("[SPI-WR] findVersions({})", artifact.key());
+        if (SYNTHETIC_GROUP.equals(artifact.getGroupId()) && SYNTHETIC_ARTIFACT.equals(artifact.getArtifactId())) {

Review Comment:
   ⚠️ **Deprecated API** — `getGroupId()` and `getArtifactId()` are `@Deprecated(since = "4.1.0", forRemoval = true)`. This IT extension is the canonical example of WorkspaceReader SPI usage that implementors will copy — it should use the noun-style API.
   
   ```suggestion
           if (SYNTHETIC_GROUP.equals(artifact.groupId()) && SYNTHETIC_ARTIFACT.equals(artifact.artifactId())) {
   ```



##########
its/core-it-suite/src/test/resources/mng-8766-spi-workspace-reader/extension/src/main/java/org/apache/maven/its/extensions/TestSpiWorkspaceReader.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.its.extensions;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.spi.WorkspaceReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Named("test-ide")
+public class TestSpiWorkspaceReader implements WorkspaceReader {
+
+    private static final Logger log = LoggerFactory.getLogger(TestSpiWorkspaceReader.class);
+
+    /**
+     * GAV of the synthetic artifact served by this workspace reader.
+     * The test project declares a dependency on this artifact.
+     */
+    private static final String SYNTHETIC_GROUP = "org.apache.maven.its.mng8766";
+
+    private static final String SYNTHETIC_ARTIFACT = "virtual-dep";
+    private static final String SYNTHETIC_VERSION = "1.0";
+
+    public TestSpiWorkspaceReader() {
+        log.info("[SPI-WR] created");
+    }
+
+    @Override
+    public Optional<Path> findArtifact(Artifact artifact) {
+        log.info("[SPI-WR] findArtifact({})", artifact.key());
+        if (isSyntheticArtifact(artifact)) {
+            try {
+                // Return a minimal (empty) jar file so the resolver can satisfy the dependency
+                Path jar = Files.createTempFile("mng8766-virtual-dep", ".jar");
+                jar.toFile().deleteOnExit();
+                // Write a valid empty ZIP/jar (4 bytes: end-of-central-directory signature)
+                try (OutputStream os = Files.newOutputStream(jar)) {
+                    os.write(new byte[] {0x50, 0x4B, 0x05, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
+                }
+                log.info("[SPI-WR] findArtifact: returning synthetic jar for {}", artifact.key());
+                return Optional.of(jar);
+            } catch (IOException e) {
+                log.warn("[SPI-WR] could not create synthetic jar: {}", e.getMessage());
+            }
+        }
+        return Optional.empty();
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        log.info("[SPI-WR] findVersions({})", artifact.key());
+        if (SYNTHETIC_GROUP.equals(artifact.getGroupId()) && SYNTHETIC_ARTIFACT.equals(artifact.getArtifactId())) {
+            return Collections.singletonList(SYNTHETIC_VERSION);
+        }
+        return Collections.emptyList();
+    }
+
+    @Override
+    public Optional<Path> findModel(Artifact artifact) {
+        log.info("[SPI-WR] findModel({})", artifact.key());
+        if (isSyntheticArtifact(artifact)) {
+            try {
+                Path pom = Files.createTempFile("mng8766-virtual-dep", ".pom");
+                pom.toFile().deleteOnExit();
+                String pomContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                        + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n"
+                        + "  <modelVersion>4.0.0</modelVersion>\n"
+                        + "  <groupId>" + SYNTHETIC_GROUP + "</groupId>\n"
+                        + "  <artifactId>" + SYNTHETIC_ARTIFACT + "</artifactId>\n"
+                        + "  <version>" + SYNTHETIC_VERSION + "</version>\n"
+                        + "  <packaging>jar</packaging>\n"
+                        + "</project>\n";
+                Files.writeString(pom, pomContent);
+                log.info("[SPI-WR] findModel: returning synthetic POM for {}", artifact.key());
+                return Optional.of(pom);
+            } catch (IOException e) {
+                log.warn("[SPI-WR] could not create synthetic POM: {}", e.getMessage());
+            }
+        }
+        return Optional.empty();
+    }
+
+    private static boolean isSyntheticArtifact(Artifact artifact) {
+        return SYNTHETIC_GROUP.equals(artifact.getGroupId())
+                && SYNTHETIC_ARTIFACT.equals(artifact.getArtifactId())
+                && SYNTHETIC_VERSION.equals(artifact.getVersion().toString());

Review Comment:
   ⚠️ **Deprecated API** — same issue in `isSyntheticArtifact()`: `getGroupId()`, `getArtifactId()`, `getVersion()` are all `@Deprecated(since = "4.1.0", forRemoval = true)`.
   
   ```suggestion
           return SYNTHETIC_GROUP.equals(artifact.groupId())
                   && SYNTHETIC_ARTIFACT.equals(artifact.artifactId())
                   && SYNTHETIC_VERSION.equals(artifact.version().toString());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4009742025


##########
api/maven-api-spi/src/main/java/org/apache/maven/api/spi/WorkspaceReader.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.api.spi;
+
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.annotations.Consumer;
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.di.Named;
+
+/**
+ * SPI for IDE and tool integrators to provide workspace artifact resolution.
+ *
+ * <p>Implementations are discovered via DI and are automatically bridged into the
+ * resolver's workspace reader chain, replacing the need for the internal
+ * {@code @Named("ide")} resolver {@code WorkspaceReader} mechanism.
+ *
+ * <p>Implementations should be annotated with {@link Named} and registered as
+ * Maven core extensions (via {@code .mvn/extensions.xml}).
+ *
+ * <p>Unlike the legacy {@code org.eclipse.aether.repository.WorkspaceReader}, this SPI
+ * uses Maven 4 API types only (no maven-resolver-api dependency required).
+ *
+ * @since 4.1.0
+ */
+@Experimental
+@Consumer
+@Named
+public interface WorkspaceReader extends SpiService {
+
+    /**
+     * Finds the path on disk for the given artifact in the workspace, if present.
+     *
+     * @param artifact the artifact to look up, never {@code null}
+     * @return the path to the artifact file, or empty if not found in workspace
+     */
+    Optional<Path> findArtifact(Artifact artifact);
+
+    /**
+     * Returns the list of available versions for the given artifact in the workspace.
+     *
+     * @param artifact the artifact to look up (version is ignored), never {@code null}
+     * @return list of available versions, may be empty
+     */
+    List<String> findVersions(Artifact artifact);
+
+    /**
+     * Whether this workspace reader should participate in plugin resolution.
+     *
+     * <p>IDE workspace readers should return {@code false} here: plugin realms are cached
+     * by {@code DefaultPluginRealmCache} (which is {@code @Singleton}) and cannot be purged
+     * within a session, so resolving plugins from the workspace can lead to stale classloaders
+     * when workspace sources change.
+     *
+     * <p>Defaults to {@code true} (participates in plugin resolution).
+     *
+     * @return {@code true} if this reader should be consulted during plugin resolution
+     */
+    default boolean isApplicableForPluginResolution() {
+        return true;
+    }

Review Comment:
   The `isApplicableForPluginResolution()` method was removed entirely in [44e96719ff](https://github.com/gnodet/maven/commit/44e96719ff) based on your feedback. The current SPI has no such method — the `WorkspaceReader` interface now only exposes `findArtifact()` and `findVersions()`. The design discussion is captured in the PR thread comment above.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r3978486993


##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8766SpiWorkspaceReaderTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Path;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Integration test for the {@code WorkspaceReader} SPI in maven-api-spi.
+ *
+ * <p>Verifies that SPI workspace readers with {@code isApplicableForPluginResolution() == false}
+ * are discovered and active, but are <em>not</em> consulted during plugin resolution.
+ *
+ * @since 4.1.0
+ */
+class MavenITmng8766SpiWorkspaceReaderTest extends AbstractMavenIntegrationTestCase {
+
+    @Test
+    void testSpiWorkspaceReaderFilteredFromPluginResolution() throws Exception {
+        Path testDir = extractResources("mng-8766-spi-workspace-reader");
+
+        // First, install the extension
+        Verifier verifier = newVerifier(testDir.resolve("extension"));
+        verifier.addCliArgument("install");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        // Run the project that uses the extension — process-resources triggers plugin resolution
+        verifier = newVerifier(testDir.resolve("project"));
+        verifier.addCliArgument("process-resources");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        // Verify the SPI workspace reader was created (proves discovery works)
+        verifier.verifyTextInLog("[SPI-WR] created");
+
+        // The SPI workspace reader should be called for artifact resolution in the main session
+        // (e.g., during project dependency resolution, model building, etc.)
+        List<String> logLines = verifier.loadLogLines();

Review Comment:
   💡 The comment says the SPI reader "should be called for artifact resolution" but there's no `assertTrue` verifying it *was* called for regular dependency resolution (e.g. `findArtifact` for `junit:junit`). The test only asserts the negative case (not called for plugin resolution).
   
   Adding a positive assertion would make the test truly verify both directions of the contract and catch regressions where SPI readers are silently dropped from the main chain entirely.
   
   ```suggestion
           // The SPI workspace reader should be called for artifact resolution in the main session
           // (e.g., during project dependency resolution, model building, etc.)
           List<String> logLines = verifier.loadLogLines();
           boolean hasFindArtifactCalls =
                   logLines.stream().anyMatch(line -> line.contains("[SPI-WR] findArtifact("));
           assertTrue(
                   hasFindArtifactCalls,
                   "SPI workspace reader should be consulted during regular artifact resolution");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add WorkspaceReader SPI to maven-api-spi [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4275965407


##########
impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java:
##########
@@ -342,14 +355,30 @@ private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceRea
         // 1) Reactor workspace reader
         WorkspaceReader reactorReader = lookup.lookup(WorkspaceReader.class, ReactorReader.HINT);
         workspaceReaders.add(reactorReader);
-        // 2) Repository system session-scoped workspace reader (contains ide and exec request reader)
+        // 2) Repository system session-scoped workspace reader (contains ide, exec request reader,
+        //    and SPI readers already registered from the global container before buildGraph()).
         for (WorkspaceReader repoWorkspaceReader : chainedWorkspaceReader.getReaders()) {
             if (repoWorkspaceReader != null && repoWorkspaceReader != reactorReader) {
                 workspaceReaders.add(repoWorkspaceReader);
             }
         }
-        // 3) .. n) Project-scoped workspace readers
+        // 3) .. n) Project-scoped legacy workspace readers (org.eclipse.aether)
         workspaceReaders.addAll(getProjectScopedExtensionComponents(session.getProjects(), WorkspaceReader.class));
+        // n+1) Project-scoped SPI workspace readers not yet registered (those loaded by project-level

Review Comment:
   💡 Cosmetic — `IdentityHashMap<..., Boolean>` used as a set can be replaced with the idiomatic Java pattern:
   
   ```suggestion
           Set<org.apache.maven.api.spi.WorkspaceReader> wrappedDelegates =
                   Collections.newSetFromMap(new IdentityHashMap<>());
           workspaceReaders.stream()
                   .filter(r -> r instanceof SpiWorkspaceReaderAdapter)
                   .forEach(r -> wrappedDelegates.add(((SpiWorkspaceReaderAdapter) r).getDelegate()));
   ```
   
   Then the guard becomes `!wrappedDelegates.contains(spiReader)`. Functionally identical, but reads more clearly as a set operation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-6173224221

   **Rebase needed before merge:**
   
   The PR branch's merge base (`40c59633cb`) pre-dates the independent merge of MNG-8767 (`e018004714`) to master. After rebasing, `PluginRealmCache.java` and `DefaultPluginRealmCache.java` will disappear from the diff (they are now identical to master). However, `DefaultMavenPluginManager` will require a manual conflict resolution: master now passes `pluginDescriptor.getDependencyNode()` to the 3-arg `CacheRecord` constructor and restores the node on cache hit — the PR branch still uses the 2-arg constructor. The resolution is straightforward: adopt master's version of the supplier lambda.
   
   _This comment was generated by an AI agent, Hermès on behalf of @gnodet._
   
   <!-- reviewer: gnodet-bot -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-6172617899

   Fixed all issues raised in the latest review:
   
   - **LightweightApiArtifact noun-style accessors** — implemented `groupId()`, `artifactId()`, `version()`, `baseVersion()`, `classifier()`, `extension()` as required by the master `Artifact` API migration (commit `27814e934e`). The deprecated `getX()` shims are now inherited as defaults.
   - **`findModel()` exception logging** — parse failures are now logged at DEBUG level with the full exception, helping IDE integrators diagnose POM parse problems (commit `d0b59bba7c`).
   - **Comment indentation in `DefaultMaven.java`** — the continuation indent on the SPI workspace reader block is corrected (commit `27814e934e`).
   - **`SpiWorkspaceReaderAdapter` implements `MavenWorkspaceReader`** — `findModel()` is now reachable through the chain (commit `d0b59bba7c`).
   - **PluginRealmCache changes** — reverted in commit `4d3fa6ab43`; will be addressed separately in MNG-8767.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4274418057


##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8766SpiWorkspaceReaderTest.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Path;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Integration test for the {@code WorkspaceReader} SPI in maven-api-spi (MNG-8766).
+ *
+ * <p>Verifies that SPI workspace readers are:
+ * <ol>
+ *   <li>Discovered via DI and active during the build session</li>
+ *   <li>Consulted for regular artifact resolution (findArtifact, findVersions)</li>
+ *   <li>Consulted for model resolution via findModel() — the path wired through
+ *       {@code SpiWorkspaceReaderAdapter} implementing {@code MavenWorkspaceReader}</li>

Review Comment:
   Stale Javadoc after the `Optional<Model>` refactor — `findModel()` no longer returns a path.
   
   ```suggestion
    *   <li>Consulted for model resolution via findModel() — the pre-built {@link org.apache.maven.api.model.Model}
    *       returned by the SPI is passed directly through {@code SpiWorkspaceReaderAdapter}
    *       to the resolver, bypassing {@code ModelProcessor} entirely</li>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4009783749


##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReaderAdapter.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.ArtifactCoordinates;
+import org.apache.maven.api.Version;
+import org.apache.maven.api.annotations.Nonnull;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.WorkspaceReader;
+import org.eclipse.aether.repository.WorkspaceRepository;
+
+/**
+ * Bridge adapter that wraps an {@link org.apache.maven.api.spi.WorkspaceReader SPI WorkspaceReader}
+ * into a resolver {@link WorkspaceReader}.
+ *
+ * <p>This adapter translates between resolver {@link Artifact} and Maven API
+ * {@link org.apache.maven.api.Artifact} types, allowing SPI implementations to work
+ * with Maven 4 API types exclusively while being integrated into the resolver's
+ * workspace reader chain.
+ *
+ * @since 4.1.0
+ */
+public class SpiWorkspaceReaderAdapter implements WorkspaceReader {
+
+    private final org.apache.maven.api.spi.WorkspaceReader delegate;
+    private final WorkspaceRepository repository;
+
+    public SpiWorkspaceReaderAdapter(org.apache.maven.api.spi.WorkspaceReader delegate) {
+        this.delegate = delegate;
+        this.repository = new WorkspaceRepository("spi-" + delegate.getClass().getSimpleName());
+    }
+
+    @Override
+    public WorkspaceRepository getRepository() {
+        return repository;
+    }
+
+    @Override
+    public File findArtifact(Artifact artifact) {
+        Optional<Path> result = delegate.findArtifact(toApiArtifact(artifact));
+        return result.map(Path::toFile).orElse(null);
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        return delegate.findVersions(toApiArtifact(artifact));
+    }
+
+    /**
+     * Returns the underlying SPI workspace reader.
+     */
+    public org.apache.maven.api.spi.WorkspaceReader getDelegate() {
+        return delegate;
+    }
+
+    /**
+     * Creates a lightweight Maven API {@link org.apache.maven.api.Artifact} from a resolver artifact
+     * without requiring an active session.
+     */
+    private static org.apache.maven.api.Artifact toApiArtifact(Artifact artifact) {
+        return new LightweightApiArtifact(artifact);
+    }
+
+    /**
+     * A lightweight implementation of {@link org.apache.maven.api.Artifact} that wraps a resolver artifact
+     * for the purpose of passing artifact coordinates to SPI workspace readers.
+     */
+    private static class LightweightApiArtifact implements org.apache.maven.api.Artifact {
+        private final Artifact artifact;
+        private final String key;
+
+        LightweightApiArtifact(Artifact artifact) {
+            this.artifact = artifact;
+            this.key = getGroupId()
+                    + ':'
+                    + getArtifactId()
+                    + ':'
+                    + getExtension()
+                    + (getClassifier().isEmpty() ? "" : ":" + getClassifier())
+                    + ':'
+                    + artifact.getVersion();
+        }
+
+        @Override
+        public String key() {
+            return key;
+        }
+
+        @Nonnull
+        @Override
+        public String getGroupId() {
+            return artifact.getGroupId();
+        }
+
+        @Nonnull
+        @Override
+        public String getArtifactId() {
+            return artifact.getArtifactId();
+        }
+
+        @Nonnull
+        @Override
+        public Version getVersion() {
+            return new StringVersion(artifact.getVersion());
+        }
+
+        @Nonnull
+        @Override
+        public Version getBaseVersion() {
+            return new StringVersion(artifact.getBaseVersion());
+        }
+
+        @Nonnull
+        @Override
+        public String getExtension() {
+            return artifact.getExtension();
+        }
+
+        @Nonnull
+        @Override
+        public String getClassifier() {
+            return artifact.getClassifier();
+        }
+
+        @Override
+        public boolean isSnapshot() {
+            return artifact.isSnapshot();
+        }
+
+        @Nonnull
+        @Override
+        public ArtifactCoordinates toCoordinates() {
+            throw new UnsupportedOperationException("Lightweight artifact wrapper does not support toCoordinates(); "
+                    + "use Session.createArtifactCoordinates() instead");
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            return o instanceof org.apache.maven.api.Artifact a && key.equals(a.key());
+        }
+
+        @Override
+        public int hashCode() {
+            return key.hashCode();
+        }
+
+        @Override
+        public String toString() {
+            return key;
+        }
+    }
+
+    /**
+     * Simple {@link Version} implementation that wraps a version string.
+     */
+    private record StringVersion(String version) implements Version {
+        @Override
+        public int compareTo(Version o) {
+            return version.compareTo(o.toString());

Review Comment:
   Fixed in 4a192fef92. Added Javadoc to `StringVersion` explicitly documenting that `compareTo()` uses lexicographic string ordering and is not correct for semantic version comparison — directing callers to use `VersionParser` when ordering matters. Since this wrapper is solely used to pass artifact coordinates to SPI workspace readers (not for version sorting), using a full parser here would add unnecessary session coupling; the documentation makes the limitation explicit for any future reader implementations that might call `getVersion().compareTo()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r3978894658


##########
its/core-it-suite/src/test/resources/mng-8766-spi-workspace-reader/project/pom.xml:
##########
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
+
+  <groupId>org.apache.maven.its.mng8766</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: mng-8766</name>
+  <description>Verify that SPI WorkspaceReader is used for dependency resolution but not for plugin resolution.</description>

Review Comment:
   💡 Same stale description — the IT no longer verifies plugin resolution exclusion.
   
   ```suggestion
     <description>Verify that SPI WorkspaceReader is discovered and consulted for artifact resolution.</description>
   ```



##########
its/core-it-suite/src/test/resources/mng-8766-spi-workspace-reader/extension/pom.xml:
##########
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
+
+  <groupId>org.apache.maven.its.mng8766</groupId>
+  <artifactId>spi-workspace-reader</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: spi-workspace-reader</name>
+  <description>SPI WorkspaceReader extension that opts out of plugin resolution</description>

Review Comment:
   💡 Stale description from the previous approach — the extension no longer "opts out of plugin resolution." The SPI now provides workspace artifact resolution, and cache invalidation is handled separately via `PluginRealmCache.invalidate()`.
   
   ```suggestion
     <description>SPI WorkspaceReader extension for IDE workspace artifact resolution</description>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-5618387536

   Thanks @laeubi, you're right on both counts.
   
   The approach has been reworked in [44e96719ff](https://github.com/gnodet/maven/commit/44e96719ff):
   
   - **Removed `isApplicableForPluginResolution()`** from the `WorkspaceReader` SPI — opting out of plugin resolution was the wrong lever.
   - **Added `PluginRealmCache.invalidate(Artifact)`** (with a default no-op for backward compat) so IDE integrators can purge stale plugin realms when a workspace artifact is rebuilt. `DefaultPluginRealmCache` implements it by evicting all entries whose resolved artifacts match the given `groupId:artifactId:version` and disposing the associated `ClassRealm`.
   
   The reasoning: IDEs trust their own build — if they've rebuilt a plugin from the workspace, they want it used. The right API is cache invalidation on demand, not blanket exclusion from resolution.
   
   As for the generics of `isApplicableFor(ResolutionContext)` with an enum — agreed that would be overkill given the direction change.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add WorkspaceReader SPI to maven-api-spi [maven]

Posted by "gnodet-bot (via GitHub) via issues" <is...@maven.apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4495301488


##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8766SpiWorkspaceReaderTest.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Path;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Integration test for the {@code WorkspaceReader} SPI in maven-api-spi (MNG-8766).
+ *
+ * <p>Verifies that SPI workspace readers are:
+ * <ol>
+ *   <li>Discovered via DI and active during the build session</li>
+ *   <li>Consulted for regular artifact resolution (findArtifact, findVersions)</li>
+ *   <li>Consulted for model resolution via findModel() — the pre-built {@link org.apache.maven.api.model.Model}
+ *       returned by the SPI is passed directly through {@code SpiWorkspaceReaderAdapter}
+ *       to the resolver, bypassing {@code ModelProcessor} entirely</li>
+ * </ol>
+ *
+ * <p>The test extension ({@code TestSpiWorkspaceReader}) serves a completely synthetic artifact
+ * ({@code org.apache.maven.its.mng8766:virtual-dep:1.0}) that does not exist in any repository.
+ * The project POM declares a dependency on this artifact, so Maven must consult the workspace reader
+ * for both the artifact file ({@code findArtifact}) and the model ({@code findModel}).
+ *

Review Comment:
   🔧 **Nit:** `@since 4.1.0` is inconsistent with the rest of this PR — `WorkspaceReader.java` and `SpiWorkspaceReaderAdapter.java` both use `@since 4.2.0`. Should be:
   
   ```suggestion
    * @since 4.2.0
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-6169544908

   This PR currently covers two concerns that now have separate tracking sub-issues under #13499:
   
   1. **Workspace reader SPI** (`WorkspaceReader` in `maven-api-spi`) → tracked by #13515 (specifically the `findModel()` gap)
   2. **Plugin realm cache invalidation** (`PluginRealmCache.invalidate()`) → tracked by #13519 (generalizing invalidation across all caches)
   
   These could be split into separate PRs to allow independent review and merging, or kept together if that's simpler — just noting the tracking structure for visibility.
   
   _Claude Code on behalf of Guillaume Nodet_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4272095391


##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReaderAdapter.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.ArtifactCoordinates;
+import org.apache.maven.api.Version;
+import org.apache.maven.api.annotations.Nonnull;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.WorkspaceReader;
+import org.eclipse.aether.repository.WorkspaceRepository;
+
+/**
+ * Bridge adapter that wraps an {@link org.apache.maven.api.spi.WorkspaceReader SPI WorkspaceReader}
+ * into a resolver {@link WorkspaceReader}.
+ *
+ * <p>This adapter translates between resolver {@link Artifact} and Maven API
+ * {@link org.apache.maven.api.Artifact} types, allowing SPI implementations to work
+ * with Maven 4 API types exclusively while being integrated into the resolver's
+ * workspace reader chain.
+ *
+ * @since 4.1.0
+ */
+public class SpiWorkspaceReaderAdapter implements WorkspaceReader {

Review Comment:
   ⚠️ **`findModel()` is dead code** — the adapter must implement `MavenWorkspaceReader`
   
   `MavenChainedWorkspaceReader.findModel()` only calls readers that are `instanceof MavenWorkspaceReader`:
   
   ```java
   for (WorkspaceReader workspaceReader : readers) {
       if (workspaceReader instanceof MavenWorkspaceReader mavenWorkspaceReader) {
           model = mavenWorkspaceReader.findModel(artifact);
   ```
   
   This adapter implements `WorkspaceReader` only — so the SPI's new `findModel(Artifact)` is never invoked. IDE integrators implementing `findModel()` will silently get no effect.
   
   Fix: implement `MavenWorkspaceReader` and bridge the call. `maven-core` already depends on `maven-impl` (which defines `MavenWorkspaceReader`), so no new module dependency is needed.
   
   ```suggestion
   public class SpiWorkspaceReaderAdapter implements MavenWorkspaceReader {
   ```
   
   And add the bridge method:
   
   ```java
   @Override
   public Model findModel(Artifact artifact) {
       Optional<Path> path = delegate.findModel(toApiArtifact(artifact));
       if (path.isEmpty()) {
           return null;
       }
       try {
           return new org.apache.maven.model.v4.MavenStaxReader().read(java.nio.file.Files.newInputStream(path.get()));
       } catch (Exception e) {
           return null;
       }
   }
   ```
   
   This also requires adding `import org.apache.maven.impl.resolver.MavenWorkspaceReader;` and the `org.apache.maven.api.model.Model` import.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-6170764997

   💡 **Rebase heads-up — `LightweightApiArtifact` will need noun-style accessor migration**
   
   `LightweightApiArtifact` currently implements `getGroupId()`, `getArtifactId()`, `getClassifier()`, `getExtension()` — which are still abstract on the PR branch's base but were migrated to deprecated defaults on master (with `groupId()`, `artifactId()`, etc. now being the abstract methods).
   
   After rebasing onto current master, the class will fail to compile: `groupId()` / `artifactId()` etc. are abstract and unimplemented. The `key()` override also calls `getGroupId()` etc., which after migration will produce `AbstractMethodError` (the default `getGroupId()` delegates to `groupId()`, which is unimplemented).
   
   When rebasing, rename:
   - `getGroupId()` → `groupId()`
   - `getArtifactId()` → `artifactId()`
   - `getExtension()` → `extension()`
   - `getClassifier()` → `classifier()`
   - `getVersion()` / `getBaseVersion()` → `version()` / `baseVersion()` (return type changes to `Version` — check if that's still the case on master)
   - Update `key()` to call the noun-style methods directly
   
   _This comment was generated by an AI agent, Hermès on behalf of @gnodet._
   
   <!-- reviewer: gnodet-bot -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4273507032


##########
its/core-it-suite/src/test/resources/mng-8766-spi-workspace-reader/extension/src/main/java/org/apache/maven/its/extensions/TestSpiWorkspaceReader.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.its.extensions;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.spi.WorkspaceReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Named("test-ide")
+public class TestSpiWorkspaceReader implements WorkspaceReader {
+
+    private static final Logger log = LoggerFactory.getLogger(TestSpiWorkspaceReader.class);
+
+    /**
+     * GAV of the synthetic artifact served by this workspace reader.
+     * The test project declares a dependency on this artifact.
+     */
+    private static final String SYNTHETIC_GROUP = "org.apache.maven.its.mng8766";
+
+    private static final String SYNTHETIC_ARTIFACT = "virtual-dep";
+    private static final String SYNTHETIC_VERSION = "1.0";
+
+    public TestSpiWorkspaceReader() {
+        log.info("[SPI-WR] created");
+    }
+
+    @Override
+    public Optional<Path> findArtifact(Artifact artifact) {
+        log.info("[SPI-WR] findArtifact({})", artifact.key());
+        if (isSyntheticArtifact(artifact)) {
+            try {
+                // Return a minimal (empty) jar file so the resolver can satisfy the dependency
+                Path jar = Files.createTempFile("mng8766-virtual-dep", ".jar");
+                jar.toFile().deleteOnExit();
+                // Write a valid empty ZIP/jar (4 bytes: end-of-central-directory signature)
+                try (OutputStream os = Files.newOutputStream(jar)) {
+                    os.write(new byte[] {0x50, 0x4B, 0x05, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
+                }
+                log.info("[SPI-WR] findArtifact: returning synthetic jar for {}", artifact.key());
+                return Optional.of(jar);
+            } catch (IOException e) {
+                log.warn("[SPI-WR] could not create synthetic jar: {}", e.getMessage());
+            }
+        }
+        return Optional.empty();
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        log.info("[SPI-WR] findVersions({})", artifact.key());
+        if (SYNTHETIC_GROUP.equals(artifact.getGroupId()) && SYNTHETIC_ARTIFACT.equals(artifact.getArtifactId())) {

Review Comment:
   ⚠️ **Deprecated API** — `getGroupId()` and `getArtifactId()` are `@Deprecated(since = "4.1.0", forRemoval = true)`. This IT extension is the canonical example of WorkspaceReader SPI usage that implementors will copy — it should use the noun-style API.
   
   ```suggestion
           if (SYNTHETIC_GROUP.equals(artifact.groupId()) && SYNTHETIC_ARTIFACT.equals(artifact.artifactId())) {
   ```



##########
its/core-it-suite/src/test/resources/mng-8766-spi-workspace-reader/extension/src/main/java/org/apache/maven/its/extensions/TestSpiWorkspaceReader.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.its.extensions;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.spi.WorkspaceReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Named("test-ide")
+public class TestSpiWorkspaceReader implements WorkspaceReader {
+
+    private static final Logger log = LoggerFactory.getLogger(TestSpiWorkspaceReader.class);
+
+    /**
+     * GAV of the synthetic artifact served by this workspace reader.
+     * The test project declares a dependency on this artifact.
+     */
+    private static final String SYNTHETIC_GROUP = "org.apache.maven.its.mng8766";
+
+    private static final String SYNTHETIC_ARTIFACT = "virtual-dep";
+    private static final String SYNTHETIC_VERSION = "1.0";
+
+    public TestSpiWorkspaceReader() {
+        log.info("[SPI-WR] created");
+    }
+
+    @Override
+    public Optional<Path> findArtifact(Artifact artifact) {
+        log.info("[SPI-WR] findArtifact({})", artifact.key());
+        if (isSyntheticArtifact(artifact)) {
+            try {
+                // Return a minimal (empty) jar file so the resolver can satisfy the dependency
+                Path jar = Files.createTempFile("mng8766-virtual-dep", ".jar");
+                jar.toFile().deleteOnExit();
+                // Write a valid empty ZIP/jar (4 bytes: end-of-central-directory signature)
+                try (OutputStream os = Files.newOutputStream(jar)) {
+                    os.write(new byte[] {0x50, 0x4B, 0x05, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
+                }
+                log.info("[SPI-WR] findArtifact: returning synthetic jar for {}", artifact.key());
+                return Optional.of(jar);
+            } catch (IOException e) {
+                log.warn("[SPI-WR] could not create synthetic jar: {}", e.getMessage());
+            }
+        }
+        return Optional.empty();
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        log.info("[SPI-WR] findVersions({})", artifact.key());
+        if (SYNTHETIC_GROUP.equals(artifact.getGroupId()) && SYNTHETIC_ARTIFACT.equals(artifact.getArtifactId())) {
+            return Collections.singletonList(SYNTHETIC_VERSION);
+        }
+        return Collections.emptyList();
+    }
+
+    @Override
+    public Optional<Path> findModel(Artifact artifact) {
+        log.info("[SPI-WR] findModel({})", artifact.key());
+        if (isSyntheticArtifact(artifact)) {
+            try {
+                Path pom = Files.createTempFile("mng8766-virtual-dep", ".pom");
+                pom.toFile().deleteOnExit();
+                String pomContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                        + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n"
+                        + "  <modelVersion>4.0.0</modelVersion>\n"
+                        + "  <groupId>" + SYNTHETIC_GROUP + "</groupId>\n"
+                        + "  <artifactId>" + SYNTHETIC_ARTIFACT + "</artifactId>\n"
+                        + "  <version>" + SYNTHETIC_VERSION + "</version>\n"
+                        + "  <packaging>jar</packaging>\n"
+                        + "</project>\n";
+                Files.writeString(pom, pomContent);
+                log.info("[SPI-WR] findModel: returning synthetic POM for {}", artifact.key());
+                return Optional.of(pom);
+            } catch (IOException e) {
+                log.warn("[SPI-WR] could not create synthetic POM: {}", e.getMessage());
+            }
+        }
+        return Optional.empty();
+    }
+
+    private static boolean isSyntheticArtifact(Artifact artifact) {
+        return SYNTHETIC_GROUP.equals(artifact.getGroupId())
+                && SYNTHETIC_ARTIFACT.equals(artifact.getArtifactId())
+                && SYNTHETIC_VERSION.equals(artifact.getVersion().toString());

Review Comment:
   ⚠️ **Deprecated API** — same issue in `isSyntheticArtifact()`: `getGroupId()`, `getArtifactId()`, `getVersion()` are all `@Deprecated(since = "4.1.0", forRemoval = true)`.
   
   ```suggestion
           return SYNTHETIC_GROUP.equals(artifact.groupId())
                   && SYNTHETIC_ARTIFACT.equals(artifact.artifactId())
                   && SYNTHETIC_VERSION.equals(artifact.version().toString());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r3978601671


##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8766SpiWorkspaceReaderTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Path;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Integration test for the {@code WorkspaceReader} SPI in maven-api-spi.
+ *
+ * <p>Verifies that SPI workspace readers with {@code isApplicableForPluginResolution() == false}
+ * are discovered and active, but are <em>not</em> consulted during plugin resolution.
+ *
+ * @since 4.1.0
+ */
+class MavenITmng8766SpiWorkspaceReaderTest extends AbstractMavenIntegrationTestCase {
+
+    @Test
+    void testSpiWorkspaceReaderFilteredFromPluginResolution() throws Exception {
+        Path testDir = extractResources("mng-8766-spi-workspace-reader");
+
+        // First, install the extension
+        Verifier verifier = newVerifier(testDir.resolve("extension"));
+        verifier.addCliArgument("install");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        // Run the project that uses the extension — process-resources triggers plugin resolution
+        verifier = newVerifier(testDir.resolve("project"));
+        verifier.addCliArgument("process-resources");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        // Verify the SPI workspace reader was created (proves discovery works)
+        verifier.verifyTextInLog("[SPI-WR] created");
+
+        // The SPI workspace reader should be called for artifact resolution in the main session
+        // (e.g., during project dependency resolution, model building, etc.)
+        List<String> logLines = verifier.loadLogLines();

Review Comment:
   Fixed in d1d0447c7a. Added the positive assertion for regular artifact resolution. Also fixed the root cause of the CI failure: SPI workspace readers were injected via constructor (javax.inject), but extensions register their beans in the Maven 4 DI system. Switched to `lookup.lookupList()` which finds them through the Sisu-DI bridge.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4009781548


##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReadersHolder.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.spi.WorkspaceReader;
+
+/**
+ * Collects all {@link WorkspaceReader} SPI implementations from core extensions via the
+ * maven-di layer.
+ *
+ * <p>SPI components registered via {@link Named @Named} live in the maven-di layer, not in
+ * Plexus/SISU, so {@code container.lookupList()} cannot find them. This holder is a maven-di
+ * {@link Singleton @Singleton} that receives all named {@link WorkspaceReader} bindings injected
+ * as a {@code Map} at first instantiation — which happens in
+ * {@code DefaultMaven.setupWorkspaceReader()}, after {@code buildGraph()} has loaded core
+ * extensions and their DI bindings are visible.</p>
+ *
+ * <p>This class intentionally uses {@code @org.apache.maven.api.di} annotations (not
+ * {@code javax.inject}), so it is only discovered by the maven-di injector and bridged to
+ * Guice/SISU via {@code SisuDiBridgeModule.BridgeInjectorImpl}, making it accessible via
+ * {@code Lookup.lookup(SpiWorkspaceReadersHolder.class)}.</p>
+ *
+ * <p>The {@code Map} parameter is {@link Nullable} so that when no {@link WorkspaceReader}
+ * SPI implementation is registered (no core extension provides one), the maven-di injector
+ * injects {@code null} rather than throwing a {@code DIException}.</p>
+ *
+ * @since 4.1.0
+ */
+@Named
+@Singleton
+public class SpiWorkspaceReadersHolder {
+    private final List<WorkspaceReader> readers;
+
+    @Inject
+    public SpiWorkspaceReadersHolder(@Nullable Map<String, WorkspaceReader> readers) {
+        this.readers = readers != null ? new ArrayList<>(readers.values()) : Collections.emptyList();
+    }
+
+    public List<WorkspaceReader> getReaders() {
+        return readers;
+    }

Review Comment:
   Fixed in 4a192fef92. `getReaders()` now returns `Collections.unmodifiableList(readers)`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4003088885


##########
impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java:
##########
@@ -348,8 +349,15 @@ private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceRea
                 workspaceReaders.add(repoWorkspaceReader);
             }
         }
-        // 3) .. n) Project-scoped workspace readers
+        // 3) .. n) Project-scoped legacy workspace readers (org.eclipse.aether)
         workspaceReaders.addAll(getProjectScopedExtensionComponents(session.getProjects(), WorkspaceReader.class));
+        // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
+        //      has loaded core extensions into the container so they are visible via lookupList.

Review Comment:
   Fixed in 8bbf426e4c.



##########
impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java:
##########
@@ -348,8 +349,14 @@ private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceRea
                 workspaceReaders.add(repoWorkspaceReader);
             }
         }
-        // 3) .. n) Project-scoped workspace readers
+        // 3) .. n) Project-scoped legacy workspace readers (org.eclipse.aether)
         workspaceReaders.addAll(getProjectScopedExtensionComponents(session.getProjects(), WorkspaceReader.class));
+        // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
+        //      has loaded core extensions into the container so they are visible via lookupList.

Review Comment:
   Fixed in 8bbf426e4c.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13094:
URL: https://github.com/apache/maven/pull/13094#issuecomment-6165901382

   Cross-referencing #13499 — Tycho's analysis identified one gap in this PR's `WorkspaceReader` SPI.
   
   Tycho's `TychoWorkspaceReader` implements `MavenWorkspaceReader` which extends `WorkspaceReader` with **`findModel(Artifact)`** — used to generate synthetic POMs for P2 artifacts that have no Maven pom.xml. This method is not in the current SPI.
   
   Worth considering whether `findModel()` (or an equivalent model-provision mechanism) should be added to the v4 `WorkspaceReader` SPI for extensions that resolve non-Maven artifacts requiring synthetic model generation.
   
   _Claude Code on behalf of Guillaume Nodet_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4273028197


##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReaderAdapter.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.maven.api.ArtifactCoordinates;
+import org.apache.maven.api.Version;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.impl.resolver.MavenWorkspaceReader;
+import org.apache.maven.model.v4.MavenStaxReader;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.WorkspaceRepository;
+
+/**
+ * Bridge adapter that wraps an {@link org.apache.maven.api.spi.WorkspaceReader SPI WorkspaceReader}
+ * into a {@link MavenWorkspaceReader}.
+ *
+ * <p>This adapter translates between resolver {@link Artifact} and Maven API
+ * {@link org.apache.maven.api.Artifact} types, allowing SPI implementations to work
+ * with Maven 4 API types exclusively while being integrated into the resolver's
+ * workspace reader chain. By implementing {@link MavenWorkspaceReader}, the adapter
+ * also participates in model resolution: {@link #findModel(Artifact)} delegates to
+ * {@link org.apache.maven.api.spi.WorkspaceReader#findModel(org.apache.maven.api.Artifact)}
+ * and parses the returned POM path into a v4 {@link Model}.
+ *
+ * @since 4.1.0
+ */
+public class SpiWorkspaceReaderAdapter implements MavenWorkspaceReader {
+
+    private final org.apache.maven.api.spi.WorkspaceReader delegate;
+    private final WorkspaceRepository repository;
+
+    public SpiWorkspaceReaderAdapter(org.apache.maven.api.spi.WorkspaceReader delegate) {
+        this.delegate = delegate;
+        this.repository = new WorkspaceRepository("spi-" + delegate.getClass().getSimpleName());
+    }
+
+    @Override
+    public WorkspaceRepository getRepository() {
+        return repository;
+    }
+
+    @Override
+    public File findArtifact(Artifact artifact) {
+        Optional<Path> result = delegate.findArtifact(toApiArtifact(artifact));
+        return result.map(Path::toFile).orElse(null);
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        return delegate.findVersions(toApiArtifact(artifact));
+    }
+
+    @Override
+    public Model findModel(Artifact artifact) {
+        Optional<Path> modelPath = delegate.findModel(toApiArtifact(artifact));
+        if (modelPath.isEmpty()) {
+            return null;
+        }
+        try (InputStream is = Files.newInputStream(modelPath.get())) {
+            return new MavenStaxReader().read(is, false, null);
+        } catch (IOException | XMLStreamException e) {
+            // Return null — consistent with other MavenWorkspaceReader implementations.
+            // The caller (DefaultArtifactDescriptorReader) will fall back to normal resolution.
+            return null;

Review Comment:
   ⚠️ **Silent exception swallowing:** When `MavenStaxReader` fails to parse the POM, the exception is caught and `null` is returned without any log entry. The caller (`DefaultArtifactDescriptorReader`) will fall back to normal resolution — but the IDE implementor has no way to diagnose why their `findModel()` return value was ignored.
   
   Add at least a debug-level log:
   ```suggestion
           } catch (IOException | XMLStreamException e) {
               // Fall back to normal resolution — log at debug so integrators can diagnose.
               if (LOGGER.isDebugEnabled()) {
                   LOGGER.debug("Failed to parse model from workspace reader for {}: {}", artifact, e.getMessage());
               }
               return null;
           }
   ```
   (requires adding `private static final Logger LOGGER = LoggerFactory.getLogger(SpiWorkspaceReaderAdapter.class);`)



##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReaderAdapter.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.maven.api.ArtifactCoordinates;
+import org.apache.maven.api.Version;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.impl.resolver.MavenWorkspaceReader;
+import org.apache.maven.model.v4.MavenStaxReader;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.WorkspaceRepository;
+
+/**
+ * Bridge adapter that wraps an {@link org.apache.maven.api.spi.WorkspaceReader SPI WorkspaceReader}
+ * into a {@link MavenWorkspaceReader}.
+ *
+ * <p>This adapter translates between resolver {@link Artifact} and Maven API
+ * {@link org.apache.maven.api.Artifact} types, allowing SPI implementations to work
+ * with Maven 4 API types exclusively while being integrated into the resolver's
+ * workspace reader chain. By implementing {@link MavenWorkspaceReader}, the adapter
+ * also participates in model resolution: {@link #findModel(Artifact)} delegates to
+ * {@link org.apache.maven.api.spi.WorkspaceReader#findModel(org.apache.maven.api.Artifact)}
+ * and parses the returned POM path into a v4 {@link Model}.
+ *
+ * @since 4.1.0
+ */
+public class SpiWorkspaceReaderAdapter implements MavenWorkspaceReader {
+
+    private final org.apache.maven.api.spi.WorkspaceReader delegate;
+    private final WorkspaceRepository repository;
+
+    public SpiWorkspaceReaderAdapter(org.apache.maven.api.spi.WorkspaceReader delegate) {
+        this.delegate = delegate;
+        this.repository = new WorkspaceRepository("spi-" + delegate.getClass().getSimpleName());
+    }
+
+    @Override
+    public WorkspaceRepository getRepository() {
+        return repository;
+    }
+
+    @Override
+    public File findArtifact(Artifact artifact) {
+        Optional<Path> result = delegate.findArtifact(toApiArtifact(artifact));
+        return result.map(Path::toFile).orElse(null);
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        return delegate.findVersions(toApiArtifact(artifact));
+    }
+
+    @Override
+    public Model findModel(Artifact artifact) {
+        Optional<Path> modelPath = delegate.findModel(toApiArtifact(artifact));
+        if (modelPath.isEmpty()) {
+            return null;
+        }
+        try (InputStream is = Files.newInputStream(modelPath.get())) {
+            return new MavenStaxReader().read(is, false, null);
+        } catch (IOException | XMLStreamException e) {
+            // Return null — consistent with other MavenWorkspaceReader implementations.
+            // The caller (DefaultArtifactDescriptorReader) will fall back to normal resolution.
+            return null;
+        }
+    }
+
+    /**
+     * Returns the underlying SPI workspace reader.
+     */
+    public org.apache.maven.api.spi.WorkspaceReader getDelegate() {
+        return delegate;
+    }
+
+    /**
+     * Creates a lightweight Maven API {@link org.apache.maven.api.Artifact} from a resolver artifact
+     * without requiring an active session.
+     */
+    private static org.apache.maven.api.Artifact toApiArtifact(Artifact artifact) {
+        return new LightweightApiArtifact(artifact);
+    }
+
+    /**
+     * A lightweight implementation of {@link org.apache.maven.api.Artifact} that wraps a resolver artifact
+     * for the purpose of passing artifact coordinates to SPI workspace readers.
+     */
+    private static class LightweightApiArtifact implements org.apache.maven.api.Artifact {
+        private final Artifact artifact;
+        private final String key;
+
+        LightweightApiArtifact(Artifact artifact) {
+            this.artifact = artifact;
+            this.key = getGroupId()
+                    + ':'
+                    + getArtifactId()
+                    + ':'
+                    + getExtension()
+                    + (getClassifier().isEmpty() ? "" : ":" + getClassifier())
+                    + ':'
+                    + artifact.getVersion();
+        }

Review Comment:
   ⚠️ **Rebase hazard — missing noun-style accessors:** `master` has completed the `Artifact` API migration: `groupId()`, `artifactId()`, `version()`, `baseVersion()`, `classifier()`, and `extension()` are now the abstract contract; `getGroupId()` etc. are `default` shims that delegate to them.
   
   This class only overrides the deprecated `getX()` variants but never implements `groupId()`, `artifactId()`, etc. After rebasing onto `master`, the Java compiler will reject this class as abstract (6 unimplemented abstract methods).
   
   Fix: implement the noun-style methods and remove (or keep for backward compat) the `getX()` overrides:
   ```suggestion
           LightweightApiArtifact(Artifact artifact) {
               this.artifact = artifact;
               this.key = groupId()
                       + ':'
                       + artifactId()
                       + ':'
                       + extension()
                       + (classifier().isEmpty() ? "" : ":" + classifier())
                       + ':'
                       + artifact.getVersion();
           }
   ```



##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReaderAdapter.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.maven.api.ArtifactCoordinates;
+import org.apache.maven.api.Version;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.impl.resolver.MavenWorkspaceReader;
+import org.apache.maven.model.v4.MavenStaxReader;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.WorkspaceRepository;
+
+/**
+ * Bridge adapter that wraps an {@link org.apache.maven.api.spi.WorkspaceReader SPI WorkspaceReader}
+ * into a {@link MavenWorkspaceReader}.
+ *
+ * <p>This adapter translates between resolver {@link Artifact} and Maven API
+ * {@link org.apache.maven.api.Artifact} types, allowing SPI implementations to work
+ * with Maven 4 API types exclusively while being integrated into the resolver's
+ * workspace reader chain. By implementing {@link MavenWorkspaceReader}, the adapter
+ * also participates in model resolution: {@link #findModel(Artifact)} delegates to
+ * {@link org.apache.maven.api.spi.WorkspaceReader#findModel(org.apache.maven.api.Artifact)}
+ * and parses the returned POM path into a v4 {@link Model}.
+ *
+ * @since 4.1.0
+ */
+public class SpiWorkspaceReaderAdapter implements MavenWorkspaceReader {
+
+    private final org.apache.maven.api.spi.WorkspaceReader delegate;
+    private final WorkspaceRepository repository;
+
+    public SpiWorkspaceReaderAdapter(org.apache.maven.api.spi.WorkspaceReader delegate) {
+        this.delegate = delegate;
+        this.repository = new WorkspaceRepository("spi-" + delegate.getClass().getSimpleName());
+    }
+
+    @Override
+    public WorkspaceRepository getRepository() {
+        return repository;
+    }
+
+    @Override
+    public File findArtifact(Artifact artifact) {
+        Optional<Path> result = delegate.findArtifact(toApiArtifact(artifact));
+        return result.map(Path::toFile).orElse(null);
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        return delegate.findVersions(toApiArtifact(artifact));
+    }
+
+    @Override
+    public Model findModel(Artifact artifact) {
+        Optional<Path> modelPath = delegate.findModel(toApiArtifact(artifact));
+        if (modelPath.isEmpty()) {
+            return null;
+        }
+        try (InputStream is = Files.newInputStream(modelPath.get())) {
+            return new MavenStaxReader().read(is, false, null);
+        } catch (IOException | XMLStreamException e) {
+            // Return null — consistent with other MavenWorkspaceReader implementations.
+            // The caller (DefaultArtifactDescriptorReader) will fall back to normal resolution.
+            return null;
+        }
+    }
+
+    /**
+     * Returns the underlying SPI workspace reader.
+     */
+    public org.apache.maven.api.spi.WorkspaceReader getDelegate() {
+        return delegate;
+    }
+
+    /**
+     * Creates a lightweight Maven API {@link org.apache.maven.api.Artifact} from a resolver artifact
+     * without requiring an active session.
+     */
+    private static org.apache.maven.api.Artifact toApiArtifact(Artifact artifact) {
+        return new LightweightApiArtifact(artifact);
+    }
+
+    /**
+     * A lightweight implementation of {@link org.apache.maven.api.Artifact} that wraps a resolver artifact
+     * for the purpose of passing artifact coordinates to SPI workspace readers.
+     */
+    private static class LightweightApiArtifact implements org.apache.maven.api.Artifact {
+        private final Artifact artifact;
+        private final String key;
+
+        LightweightApiArtifact(Artifact artifact) {
+            this.artifact = artifact;
+            this.key = getGroupId()
+                    + ':'
+                    + getArtifactId()
+                    + ':'
+                    + getExtension()
+                    + (getClassifier().isEmpty() ? "" : ":" + getClassifier())
+                    + ':'
+                    + artifact.getVersion();
+        }
+
+        @Override
+        public String key() {
+            return key;
+        }
+
+        @Nonnull
+        @Override
+        public String getGroupId() {

Review Comment:
   ⚠️ **Missing noun-style accessor implementations (see rebase hazard above).**
   
   The class currently overrides the deprecated `getGroupId()` / `getArtifactId()` / `getVersion()` / `getBaseVersion()` / `getExtension()` / `getClassifier()` accessors, but `master` declares `groupId()`, `artifactId()`, `version()`, `baseVersion()`, `classifier()`, `extension()` as abstract. These 6 methods need to be implemented:
   
   ```java
   @Nonnull
   @Override
   public String groupId() {
       return artifact.getGroupId();
   }
   
   @Nonnull
   @Override
   public String artifactId() {
       return artifact.getArtifactId();
   }
   
   // … similarly for version(), baseVersion(), classifier(), extension()
   ```



##########
impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java:
##########
@@ -348,8 +349,15 @@ private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceRea
                 workspaceReaders.add(repoWorkspaceReader);
             }
         }
-        // 3) .. n) Project-scoped workspace readers
+        // 3) .. n) Project-scoped legacy workspace readers (org.eclipse.aether)
         workspaceReaders.addAll(getProjectScopedExtensionComponents(session.getProjects(), WorkspaceReader.class));
+        // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
+        //      has loaded core extensions into the container so they are visible via
+        // getProjectScopedExtensionComponents.

Review Comment:
   🔧 **Nit — comment continuation indent dropped on third line:**
   
   ```
           // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
           //      has loaded core extensions into the container so they are visible via
           // getProjectScopedExtensionComponents.   ← should be indented to align with the line above
   ```
   
   ```suggestion
           //      getProjectScopedExtensionComponents.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4009761131


##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReaderAdapter.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.ArtifactCoordinates;
+import org.apache.maven.api.Version;
+import org.apache.maven.api.annotations.Nonnull;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.WorkspaceReader;
+import org.eclipse.aether.repository.WorkspaceRepository;
+
+/**
+ * Bridge adapter that wraps an {@link org.apache.maven.api.spi.WorkspaceReader SPI WorkspaceReader}
+ * into a resolver {@link WorkspaceReader}.
+ *
+ * <p>This adapter translates between resolver {@link Artifact} and Maven API
+ * {@link org.apache.maven.api.Artifact} types, allowing SPI implementations to work
+ * with Maven 4 API types exclusively while being integrated into the resolver's
+ * workspace reader chain.
+ *
+ * @since 4.1.0
+ */
+public class SpiWorkspaceReaderAdapter implements WorkspaceReader {
+
+    private final org.apache.maven.api.spi.WorkspaceReader delegate;
+    private final WorkspaceRepository repository;
+
+    public SpiWorkspaceReaderAdapter(org.apache.maven.api.spi.WorkspaceReader delegate) {
+        this.delegate = delegate;
+        this.repository = new WorkspaceRepository("spi-" + delegate.getClass().getSimpleName());
+    }
+
+    @Override
+    public WorkspaceRepository getRepository() {
+        return repository;
+    }
+
+    @Override
+    public File findArtifact(Artifact artifact) {
+        Optional<Path> result = delegate.findArtifact(toApiArtifact(artifact));
+        return result.map(Path::toFile).orElse(null);
+    }
+
+    @Override
+    public List<String> findVersions(Artifact artifact) {
+        return delegate.findVersions(toApiArtifact(artifact));
+    }
+
+    /**
+     * Returns the underlying SPI workspace reader.
+     */
+    public org.apache.maven.api.spi.WorkspaceReader getDelegate() {
+        return delegate;
+    }
+
+    /**
+     * Creates a lightweight Maven API {@link org.apache.maven.api.Artifact} from a resolver artifact
+     * without requiring an active session.
+     */
+    private static org.apache.maven.api.Artifact toApiArtifact(Artifact artifact) {
+        return new LightweightApiArtifact(artifact);
+    }
+
+    /**
+     * A lightweight implementation of {@link org.apache.maven.api.Artifact} that wraps a resolver artifact
+     * for the purpose of passing artifact coordinates to SPI workspace readers.
+     */
+    private static class LightweightApiArtifact implements org.apache.maven.api.Artifact {
+        private final Artifact artifact;
+        private final String key;
+
+        LightweightApiArtifact(Artifact artifact) {
+            this.artifact = artifact;
+            this.key = getGroupId()
+                    + ':'
+                    + getArtifactId()
+                    + ':'
+                    + getExtension()
+                    + (getClassifier().isEmpty() ? "" : ":" + getClassifier())
+                    + ':'
+                    + artifact.getVersion();
+        }
+
+        @Override
+        public String key() {
+            return key;
+        }
+
+        @Nonnull
+        @Override
+        public String getGroupId() {
+            return artifact.getGroupId();
+        }
+
+        @Nonnull
+        @Override
+        public String getArtifactId() {
+            return artifact.getArtifactId();
+        }
+
+        @Nonnull
+        @Override
+        public Version getVersion() {
+            return new StringVersion(artifact.getVersion());
+        }
+
+        @Nonnull
+        @Override
+        public Version getBaseVersion() {
+            return new StringVersion(artifact.getBaseVersion());
+        }
+
+        @Nonnull
+        @Override
+        public String getExtension() {
+            return artifact.getExtension();
+        }
+
+        @Nonnull
+        @Override
+        public String getClassifier() {
+            return artifact.getClassifier();
+        }
+
+        @Override
+        public boolean isSnapshot() {
+            return artifact.isSnapshot();
+        }
+
+        @Nonnull
+        @Override
+        public ArtifactCoordinates toCoordinates() {
+            throw new UnsupportedOperationException("Lightweight artifact wrapper does not support toCoordinates(); "
+                    + "use Session.createArtifactCoordinates() instead");
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            return o instanceof org.apache.maven.api.Artifact a && key.equals(a.key());
+        }
+
+        @Override
+        public int hashCode() {
+            return key.hashCode();
+        }
+
+        @Override
+        public String toString() {
+            return key;
+        }
+    }
+
+    /**
+     * Simple {@link Version} implementation that wraps a version string.
+     */
+    private record StringVersion(String version) implements Version {
+        @Override
+        public int compareTo(Version o) {
+            return version.compareTo(o.toString());

Review Comment:
   ⚠️ `StringVersion.compareTo()` uses `String.compareTo()` — lexicographic ordering. This breaks for multi-digit version components: `"10".compareTo("9")` returns a negative value (`'1' < '9'`), so version `10` would sort before `9`.
   
   The contract of `org.apache.maven.api.Version` requires semantic ordering. Any SPI implementation that sorts or compares versions (e.g. to pick the highest available workspace version) will silently get wrong results.
   
   Since this is a lightweight wrapper whose `toString()` is used for equality and lookup, and Maven has a proper `VersionParser` available via the session, the safest fix is to delegate `compareTo` to a real parser — or at minimum document the limitation explicitly in the Javadoc so implementors know not to rely on it.
   
   ```suggestion
       private record StringVersion(String version) implements Version {
           @Override
           public int compareTo(Version o) {
               // NOTE: lexicographic comparison only — does not honour semantic version ordering.
               // This wrapper is intended for artifact coordinate lookup only (via toString());
               // do not use compareTo() for version range evaluation or sorting.
               return version.compareTo(o.toString());
           }
   ```



##########
impl/maven-core/src/main/java/org/apache/maven/resolver/SpiWorkspaceReadersHolder.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.spi.WorkspaceReader;
+
+/**
+ * Collects all {@link WorkspaceReader} SPI implementations from core extensions via the
+ * maven-di layer.
+ *
+ * <p>SPI components registered via {@link Named @Named} live in the maven-di layer, not in
+ * Plexus/SISU, so {@code container.lookupList()} cannot find them. This holder is a maven-di
+ * {@link Singleton @Singleton} that receives all named {@link WorkspaceReader} bindings injected
+ * as a {@code Map} at first instantiation — which happens in
+ * {@code DefaultMaven.setupWorkspaceReader()}, after {@code buildGraph()} has loaded core
+ * extensions and their DI bindings are visible.</p>
+ *
+ * <p>This class intentionally uses {@code @org.apache.maven.api.di} annotations (not
+ * {@code javax.inject}), so it is only discovered by the maven-di injector and bridged to
+ * Guice/SISU via {@code SisuDiBridgeModule.BridgeInjectorImpl}, making it accessible via
+ * {@code Lookup.lookup(SpiWorkspaceReadersHolder.class)}.</p>
+ *
+ * <p>The {@code Map} parameter is {@link Nullable} so that when no {@link WorkspaceReader}
+ * SPI implementation is registered (no core extension provides one), the maven-di injector
+ * injects {@code null} rather than throwing a {@code DIException}.</p>
+ *
+ * @since 4.1.0
+ */
+@Named
+@Singleton
+public class SpiWorkspaceReadersHolder {
+    private final List<WorkspaceReader> readers;
+
+    @Inject
+    public SpiWorkspaceReadersHolder(@Nullable Map<String, WorkspaceReader> readers) {
+        this.readers = readers != null ? new ArrayList<>(readers.values()) : Collections.emptyList();
+    }
+
+    public List<WorkspaceReader> getReaders() {
+        return readers;
+    }

Review Comment:
   💡 `getReaders()` returns the internal `ArrayList` directly. While `SpiWorkspaceReadersHolder` is a `@Singleton` and the list is never modified after construction, exposing a mutable `List` through a public method is a correctness risk — any caller can call `.add()` / `.remove()` / `.clear()` and silently corrupt the shared state for subsequent builds in the same session.
   
   Return an unmodifiable view:
   
   ```suggestion
       public List<WorkspaceReader> getReaders() {
           return Collections.unmodifiableList(readers);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "laeubi (via GitHub)" <gi...@apache.org>.
laeubi commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r3978540442


##########
api/maven-api-spi/src/main/java/org/apache/maven/api/spi/WorkspaceReader.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.api.spi;
+
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.annotations.Consumer;
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.di.Named;
+
+/**
+ * SPI for IDE and tool integrators to provide workspace artifact resolution.
+ *
+ * <p>Implementations are discovered via DI and are automatically bridged into the
+ * resolver's workspace reader chain, replacing the need for the internal
+ * {@code @Named("ide")} resolver {@code WorkspaceReader} mechanism.
+ *
+ * <p>Implementations should be annotated with {@link Named} and registered as
+ * Maven core extensions (via {@code .mvn/extensions.xml}).
+ *
+ * <p>Unlike the legacy {@code org.eclipse.aether.repository.WorkspaceReader}, this SPI
+ * uses Maven 4 API types only (no maven-resolver-api dependency required).
+ *
+ * @since 4.1.0
+ */
+@Experimental
+@Consumer
+@Named
+public interface WorkspaceReader extends SpiService {
+
+    /**
+     * Finds the path on disk for the given artifact in the workspace, if present.
+     *
+     * @param artifact the artifact to look up, never {@code null}
+     * @return the path to the artifact file, or empty if not found in workspace
+     */
+    Optional<Path> findArtifact(Artifact artifact);
+
+    /**
+     * Returns the list of available versions for the given artifact in the workspace.
+     *
+     * @param artifact the artifact to look up (version is ignored), never {@code null}
+     * @return list of available versions, may be empty
+     */
+    List<String> findVersions(Artifact artifact);
+
+    /**
+     * Whether this workspace reader should participate in plugin resolution.
+     *
+     * <p>IDE workspace readers should return {@code false} here: plugin realms are cached
+     * by {@code DefaultPluginRealmCache} (which is {@code @Singleton}) and cannot be purged
+     * within a session, so resolving plugins from the workspace can lead to stale classloaders
+     * when workspace sources change.
+     *
+     * <p>Defaults to {@code true} (participates in plugin resolution).
+     *
+     * @return {@code true} if this reader should be consulted during plugin resolution
+     */
+    default boolean isApplicableForPluginResolution() {
+        return true;
+    }

Review Comment:
   I would say such a method should be much more generic, e.g. to cover other cases of `isApplicableFor(...)` so maybe it can get an enum to tell if its a dependency, an extension, a plugin, ... or whatever are the cases. Also it seems odd to have this default implemented and saing IDE should return false. this sounds really odd from an OO/SPI point of view at least.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MNG-8766] Add WorkspaceReader SPI to maven-api-spi for IDE integration [maven]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13094:
URL: https://github.com/apache/maven/pull/13094#discussion_r4003041324


##########
impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java:
##########
@@ -348,8 +349,15 @@ private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceRea
                 workspaceReaders.add(repoWorkspaceReader);
             }
         }
-        // 3) .. n) Project-scoped workspace readers
+        // 3) .. n) Project-scoped legacy workspace readers (org.eclipse.aether)
         workspaceReaders.addAll(getProjectScopedExtensionComponents(session.getProjects(), WorkspaceReader.class));
+        // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
+        //      has loaded core extensions into the container so they are visible via lookupList.

Review Comment:
   💡 Stale comment — this code no longer uses `lookupList()` directly; it uses `getProjectScopedExtensionComponents()` which scans project realms.
   
   ```suggestion
           // n+1) SPI workspace readers (org.apache.maven.api.spi) — discovered here, after buildGraph()
           //      has loaded core extensions into the container so they are visible via getProjectScopedExtensionComponents.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add WorkspaceReader SPI to maven-api-spi [maven]

Posted by "gnodet (via GitHub) via issues" <is...@maven.apache.org>.
gnodet merged PR #13094:
URL: https://github.com/apache/maven/pull/13094


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org