[ https://issues.apache.org/jira/browse/MNG-7862?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17757976#comment-17757976 ]
ASF GitHub Bot commented on MNG-7862: ------------------------------------- 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? > The ModelLocator should always be used when locating pom.xml > ------------------------------------------------------------ > > Key: MNG-7862 > URL: https://issues.apache.org/jira/browse/MNG-7862 > Project: Maven > Issue Type: Improvement > Affects Versions: 4.0.0-alpha-7 > Reporter: Guillaume Nodet > Assignee: Guillaume Nodet > Priority: Major > Fix For: 4.0.0-alpha-8 > > > There are a few places where the pom.xml location is hardcoded. There's a > known interface to locate those, so those references should be cleaned. -- This message was sent by Atlassian Jira (v8.20.10#820010)