[ 
https://issues.apache.org/jira/browse/MNG-7038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17714179#comment-17714179
 ] 

ASF GitHub Bot commented on MNG-7038:
-------------------------------------

gnodet commented on code in PR #1061:
URL: https://github.com/apache/maven/pull/1061#discussion_r1171526547


##########
maven-model-builder/src/main/java/org/apache/maven/model/root/DefaultRootLocator.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.root;
+
+import javax.inject.Named;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.codehaus.plexus.util.xml.pull.MXParser;
+
+@Named
+public class DefaultRootLocator implements RootLocator {
+
+    public boolean isRootDirectory(Path dir) {
+        if (Files.isDirectory(dir.resolve(".mvn"))) {
+            return true;
+        }
+        // we're too early to use the modelProcessor ...
+        Path pom = dir.resolve("pom.xml");
+        try (InputStream is = Files.newInputStream(pom)) {
+            MXParser parser = new MXParser();
+            parser.setInput(is, null);
+            if (parser.nextTag() == MXParser.START_TAG && 
parser.getName().equals("project")) {
+                for (int i = 0; i < parser.getAttributeCount(); i++) {
+                    if ("root".equals(parser.getAttributeName(i))) {
+                        return 
Boolean.parseBoolean(parser.getAttributeValue(i));
+                    }
+                }
+            }
+        } catch (Exception e) {
+            // Ignore

Review Comment:
   Not sure how to handle that.  If there's really `pom.xml` file which is not 
readable / parseable, the build should fail a bit later with a cleaner 
exception that we can display here.
   That's why I decided to go this way.  The problem is that doing it in a 
cleaner way will involve differentiating what can be ignored and what errors 
should be displayed to the user, and how to display them, and whether this 
should fail the build or not.  Also, even the check is minimalist as we don't 
check the namespace.
   What would you suggest ?





> Introduce public property to point to a root directory of (multi-module) 
> project
> --------------------------------------------------------------------------------
>
>                 Key: MNG-7038
>                 URL: https://issues.apache.org/jira/browse/MNG-7038
>             Project: Maven
>          Issue Type: Improvement
>            Reporter: Envious Guest
>            Assignee: Guillaume Nodet
>            Priority: Major
>             Fix For: 4.0.0-alpha-6
>
>
> This is a request to expose a property *maven.multiModuleProjectDirectory* 
> which is currently internal (or introduce a brand new one with analogous 
> functionality).
>  * For a single-module project, its value should be same as *project.basedir*
>  * For multi-module project, its value should point to a project.basedir of a 
> root module
> Example:
> multi-module // located at /home/me/sources
>  +- module-a
>  +- module B
> Sample multi-module/pom.xml: 
> {{<project>}}
>  {{    <parent>}}
>  {{        <groupId>com.acme</groupId>}}
>  {{        <artifactId>corp-parent</artifactId>}}
>  {{        <version>1.0.0-RELEASE</version>}}
>  {{    </parent>}}
>  {{    <groupId>com.acme</groupId>}}
>  {{        <artifactId>multi-module</artifactId>}}
>  {{        <version>0.5.2-SNAPSHOT</version>}}
>  {{    <modules>}}
>  {{        <module>module-a</module>}}
>  {{        <module>module-b</module>}}
>  {{    </modules>}}
>  {{</project>}}
> The property requested should return /home/me/sources/multi-module, 
> regardless of whether it's referenced in any of the child modules (module-a, 
> module-b) or in multi-module.
> Note that multi-module itself has parent (e.g. installed in a local 
> repository), so the new property should be smart enough to detect it and 
> still point to /home/me/sources/multi-module instead of the local repository 
> where the corp-parent is installed.
> The use-case for such a property could be to have a directory for combined 
> report of static analysis tools. Typical example - jacoco combined coverage 
> reports.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to