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 2023/08/21 13:36:13 UTC

[GitHub] [maven] gnodet opened a new pull request, #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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

   JIRA issue: https://issues.apache.org/jira/browse/MNG-7862
   
   


-- 
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


[GitHub] [maven] elharo commented on pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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

   Probably unrelated but why in the CI output do I see :"Sending email to: rishi@ca.ibm.com"?


-- 
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


[GitHub] [maven] gnodet commented on pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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

   > Probably unrelated but why in the CI output do I see :"Sending email to: [rishi@ca.ibm.com](mailto:rishi@ca.ibm.com)"?
   
   Not sure, I've disabled the s390x pipeline as it does not take into account the fact that a given branch should be tested with the maven-integration-testing branch with the same name if it exists.


-- 
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


[GitHub] [maven] gnodet commented on pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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

   > Is this for v4 only? Some of the API changes look incompatible.
   
   Yes, I did not really envision to backport it.  I think most of the changed methods are new in 4.0.  The exceptions are the default value in the model and the new `ModelSource3` which I introduced to avoid adding a method to an interface that could be possibly implemented by plugins / extensions.  I may have missed a possible incompatible change if a plugin/extension actually implements `ModelSource2` (as I should provide the previous behaviour in such a case).


-- 
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


[GitHub] [maven] elharo commented on pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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

   Filed https://issues.apache.org/jira/browse/MNG-7863?filter=-2


-- 
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


[GitHub] [maven] elharo commented on a diff in pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * be able to accept <code>relPath</code> parameter values that

Review Comment:
   delete "be able to"



##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * be able to accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory, in the latter case the provided {@code ModelLocator} will be used

Review Comment:
   run-on sentence. Break up



##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * be able to accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory, in the latter case the provided {@code ModelLocator} will be used
+     * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be used by the
+     * requested model source.</li>
+     * </ul>
+     *
+     * @param relPath is the path of the requested model source relative to this model source POM.

Review Comment:
   delete "is the"



-- 
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


[GitHub] [maven] gnodet commented on a diff in pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory</li>
+     * </ul>
+     * If the given path points at a directory, the provided {@code ModelLocator} will be used
+     * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be
+     * used by the requested model source.
+     *
+     * @param locator locator used to actually locate the pom file.
+     * @param relPath path of the requested model source relative to this model source POM.
+     * @return related model source or <code>null</code> if no such model source.
+     */
+    ModelSource3 getRelatedSource(ModelLocator locator, String relPath);
+
+    /**
+     * When using a ModelSource3, the method with a {@code ModelLocator} argument should
+     * be used instead.
+     *
+     * @deprecated use {@link #getRelatedSource(ModelLocator, String)} instead

Review Comment:
   Such a change looks a bit risky, as some code may just expect to find `ModelSource2` as they are kept in the `ModelCache`.  I'd rather leave it that way.



-- 
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


[GitHub] [maven] gnodet commented on a diff in pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -1349,23 +1349,20 @@ private File determinePom(final CommandLine commandLine, final String workingDir
             alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
         }
 
+        File current = baseDirectory;
         if (alternatePomFile != null) {
-            File pom = resolveFile(new File(alternatePomFile), workingDirectory);
-            if (pom.isDirectory()) {
-                if (modelProcessor != null) {
-                    pom = modelProcessor.locatePom(pom);
-                } else {
-                    pom = new File(pom, "pom.xml");
-                }
-            }
+            current = resolveFile(new File(alternatePomFile), workingDirectory);
+        }
 
-            return pom;
-        } else if (modelProcessor != null) {
-            File pom = modelProcessor.locatePom(baseDirectory);
+        File pom;
+        if (current.isDirectory() && modelProcessor != null) {
+            pom = modelProcessor.locatePom(current);
+        } else {
+            pom = current;
+        }
 
-            if (pom.isFile()) {
-                return pom;
-            }
+        if (pom.isFile()) {

Review Comment:
   I tried, but the logic is expected downstream, mostly when you run Maven inside a directory with no `pom.xml`.  In such cases, a `null` value is expected.  Also, the `modelLocator` is required to always return a value, but can point to a non existent file, hence the check.



-- 
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


[GitHub] [maven] gnodet commented on a diff in pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -1349,23 +1349,20 @@ private File determinePom(final CommandLine commandLine, final String workingDir
             alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
         }
 
+        File current = baseDirectory;
         if (alternatePomFile != null) {
-            File pom = resolveFile(new File(alternatePomFile), workingDirectory);
-            if (pom.isDirectory()) {
-                if (modelProcessor != null) {
-                    pom = modelProcessor.locatePom(pom);
-                } else {
-                    pom = new File(pom, "pom.xml");
-                }
-            }
+            current = resolveFile(new File(alternatePomFile), workingDirectory);
+        }
 
-            return pom;
-        } else if (modelProcessor != null) {
-            File pom = modelProcessor.locatePom(baseDirectory);
+        File pom;
+        if (current.isDirectory() && modelProcessor != null) {
+            pom = modelProcessor.locatePom(current);
+        } else {
+            pom = current;
+        }
 
-            if (pom.isFile()) {
-                return pom;
-            }
+        if (pom.isFile()) {

Review Comment:
   This method is called twice, a first time when discovering extensions, in which case, the `modelLocator` is not set up yet, and second time to create the actual maven request that will be processed.  So while the `modelLocator` should never return a directory, the `determinePom` method may return `null` during extension discovery.  I'll change the code to only call `determinePom` when `modelLocator` is set up correctly.



-- 
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


[GitHub] [maven] elharo commented on pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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

   OK, looks good overall. Is it possible to retrigger the full CI so we can see that S390 is no longer included?


-- 
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


[GitHub] [maven] gnodet commented on a diff in pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory</li>
+     * </ul>
+     * If the given path points at a directory, the provided {@code ModelLocator} will be used
+     * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be
+     * used by the requested model source.
+     *
+     * @param locator locator used to actually locate the pom file.
+     * @param relPath path of the requested model source relative to this model source POM.
+     * @return related model source or <code>null</code> if no such model source.
+     */
+    ModelSource3 getRelatedSource(ModelLocator locator, String relPath);
+
+    /**
+     * When using a ModelSource3, the method with a {@code ModelLocator} argument should
+     * be used instead.
+     *
+     * @deprecated use {@link #getRelatedSource(ModelLocator, String)} instead

Review Comment:
   Or should I deprecate ModelSource2 in favour of ModelSource3, in which case, I could simply to make `ModelSource3` extends `ModelSource2`, that would be more clear imho.



-- 
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


[GitHub] [maven] gnodet commented on pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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

   @elharo could you have another look ?


-- 
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


[GitHub] [maven] gnodet merged pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


-- 
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


[GitHub] [maven] elharo commented on a diff in pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


##########
maven-core/src/test/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformerTest.java:
##########
@@ -81,5 +81,10 @@ public Model getRawModel(String groupId, String artifactId) throws IllegalStateE
         public Model getRawModel(Path p) {
             return null;
         }
+
+        @Override
+        public Path locate(Path path) {
+            return null;

Review Comment:
   If this is just a stub in a test that isn't called, I'd prefer `throw new UnsupportedOperationException()`



##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory</li>
+     * </ul>
+     * If the given path points at a directory, the provided {@code ModelLocator} will be used
+     * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be
+     * used by the requested model source.
+     *
+     * @param locator locator used to actually locate the pom file.
+     * @param relPath path of the requested model source relative to this model source POM.
+     * @return related model source or <code>null</code> if no such model source.

Review Comment:
   no period



##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -1349,23 +1349,20 @@ private File determinePom(final CommandLine commandLine, final String workingDir
             alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
         }
 
+        File current = baseDirectory;
         if (alternatePomFile != null) {
-            File pom = resolveFile(new File(alternatePomFile), workingDirectory);
-            if (pom.isDirectory()) {
-                if (modelProcessor != null) {
-                    pom = modelProcessor.locatePom(pom);
-                } else {
-                    pom = new File(pom, "pom.xml");
-                }
-            }
+            current = resolveFile(new File(alternatePomFile), workingDirectory);
+        }
 
-            return pom;
-        } else if (modelProcessor != null) {
-            File pom = modelProcessor.locatePom(baseDirectory);
+        File pom;
+        if (current.isDirectory() && modelProcessor != null) {
+            pom = modelProcessor.locatePom(current);
+        } else {
+            pom = current;
+        }
 
-            if (pom.isFile()) {
-                return pom;
-            }
+        if (pom.isFile()) {

Review Comment:
   If the pom locates a directory, would that be a bug that should throw an exception rather than returning null?



##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory</li>
+     * </ul>
+     * If the given path points at a directory, the provided {@code ModelLocator} will be used
+     * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be
+     * used by the requested model source.
+     *
+     * @param locator locator used to actually locate the pom file.

Review Comment:
   delete actually
   delete period



##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory</li>
+     * </ul>
+     * If the given path points at a directory, the provided {@code ModelLocator} will be used
+     * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be
+     * used by the requested model source.
+     *
+     * @param locator locator used to actually locate the pom file.
+     * @param relPath path of the requested model source relative to this model source POM.
+     * @return related model source or <code>null</code> if no such model source.
+     */
+    ModelSource3 getRelatedSource(ModelLocator locator, String relPath);
+
+    /**
+     * When using a ModelSource3, the method with a {@code ModelLocator} argument should
+     * be used instead.
+     *
+     * @deprecated use {@link #getRelatedSource(ModelLocator, String)} instead

Review Comment:
   what about when not using a ModelSource3?



-- 
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


[GitHub] [maven] gnodet commented on a diff in pull request #1217: [MNG-7862] The ModelLocator should always be used when locating pom.xml

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


##########
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.model.building;
+
+import org.apache.maven.model.locator.ModelLocator;
+
+/**
+ * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
+ * when pointing to a directory.
+ */
+public interface ModelSource3 extends ModelSource2 {
+    /**
+     * Returns model source identified by a path relative to this model source POM. Implementation <strong>MUST</strong>
+     * accept <code>relPath</code> parameter values that
+     * <ul>
+     * <li>use either / or \ file path separator</li>
+     * <li>have .. parent directory references</li>
+     * <li>point either at file or directory</li>
+     * </ul>
+     * If the given path points at a directory, the provided {@code ModelLocator} will be used
+     * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be
+     * used by the requested model source.
+     *
+     * @param locator locator used to actually locate the pom file.
+     * @param relPath path of the requested model source relative to this model source POM.
+     * @return related model source or <code>null</code> if no such model source.
+     */
+    ModelSource3 getRelatedSource(ModelLocator locator, String relPath);
+
+    /**
+     * When using a ModelSource3, the method with a {@code ModelLocator} argument should
+     * be used instead.
+     *
+     * @deprecated use {@link #getRelatedSource(ModelLocator, String)} instead

Review Comment:
   This method overrides the `ModelSource2` method.  If the source does not implement `ModelSource3`, then the `ModelSource2.getRelatedSource(String)` will be called, see https://github.com/apache/maven/pull/1217/files#diff-f590407a614fe5e60543bf824d2de0b5df48fddfcbe7c42e64ac1f6606533347R1497 .



-- 
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