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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to