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

ASF GitHub Bot commented on MPH-183:
------------------------------------

hboutemy commented on code in PR #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r1546632408


##########
src/main/java/org/apache/maven/plugins/help/ImportedFromLocationFormatter.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.plugins.help;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.InputLocation;
+import org.apache.maven.model.InputSource;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Implementation of {@link InputLocation.StringFormatter}. Enhances the 
default implementation with support for
+ * following "references" (caused by e.g. dependency management imports).
+ */
+public class ImportedFromLocationFormatter extends 
InputLocation.StringFormatter {
+    private final Method getImportedFromMethod;
+    private final MavenProject project;
+
+    public ImportedFromLocationFormatter(final Method getImportedFromMethod, 
final MavenProject project) {
+        this.getImportedFromMethod = getImportedFromMethod;
+        this.project = project;
+    }
+
+    @Override
+    public String toString(InputLocation location) {
+        InputSource source = location.getSource();
+
+        String s = source.getModelId(); // by default, display modelId
+
+        if (StringUtils.isBlank(s) || s.contains("[unknown-version]")) {
+            // unless it is blank or does not provide version information
+            s = source.toString();
+        }
+
+        InputLocation importedFrom = getImportedFrom(location);
+
+        StringBuilder p = new StringBuilder();
+
+        while (importedFrom != null
+                && 
!source.toString().equals(importedFrom.getSource().toString())) {
+            p.append(" from ").append(importedFrom.getSource().getModelId());
+            importedFrom = getImportedFrom(importedFrom);
+        }
+
+        return '}' + s + ((location.getLineNumber() >= 0) ? ", line " + 
location.getLineNumber() : "") + p;
+    }
+
+    protected InputLocation getImportedFrom(final InputLocation location) {
+        try {
+            InputLocation result = (InputLocation) 
getImportedFromMethod.invoke(location);
+
+            if (result == null && project != null) {
+                for (Dependency dependency : 
project.getDependencyManagement().getDependencies()) {

Review Comment:
   MNG-7344 is not supposed to be limited to dependencyManagement import, but 
be able to work with imports done for example by Tiles Maven Plugin. Then 
iterating only on dependencyManagement is suspect
   
   notice that this opens again the question of what is the purpose of trying 
to do something if there war no importFrom in location



##########
src/main/java/org/apache/maven/plugins/help/DefaultInputLocationFormatter.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.plugins.help;
+
+import org.apache.maven.model.InputLocation;
+import org.apache.maven.model.InputSource;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Maven 3.x-based implementation of {@link InputLocation.StringFormatter}.

Review Comment:
   it's not Maven 3, it"s "without import tracking", as I hope we'll have 
import tracking for Maven 3 too



##########
src/main/java/org/apache/maven/plugins/help/ImportedFromLocationFormatter.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.plugins.help;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.InputLocation;
+import org.apache.maven.model.InputSource;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Implementation of {@link InputLocation.StringFormatter}. Enhances the 
default implementation with support for
+ * following "references" (caused by e.g. dependency management imports).
+ */
+public class ImportedFromLocationFormatter extends 
InputLocation.StringFormatter {
+    private final Method getImportedFromMethod;
+    private final MavenProject project;
+
+    public ImportedFromLocationFormatter(final Method getImportedFromMethod, 
final MavenProject project) {
+        this.getImportedFromMethod = getImportedFromMethod;
+        this.project = project;
+    }
+
+    @Override
+    public String toString(InputLocation location) {
+        InputSource source = location.getSource();
+
+        String s = source.getModelId(); // by default, display modelId
+
+        if (StringUtils.isBlank(s) || s.contains("[unknown-version]")) {
+            // unless it is blank or does not provide version information
+            s = source.toString();
+        }
+
+        InputLocation importedFrom = getImportedFrom(location);
+
+        StringBuilder p = new StringBuilder();
+
+        while (importedFrom != null
+                && 
!source.toString().equals(importedFrom.getSource().toString())) {
+            p.append(" from ").append(importedFrom.getSource().getModelId());
+            importedFrom = getImportedFrom(importedFrom);
+        }
+
+        return '}' + s + ((location.getLineNumber() >= 0) ? ", line " + 
location.getLineNumber() : "") + p;
+    }
+
+    protected InputLocation getImportedFrom(final InputLocation location) {
+        try {
+            InputLocation result = (InputLocation) 
getImportedFromMethod.invoke(location);
+
+            if (result == null && project != null) {

Review Comment:
   I don't get why we do all this: if the current location is not the result of 
an import, why are we trying to do something?





> Effective-pom + verbose should show import path to BOM dependencyManagement
> ---------------------------------------------------------------------------
>
>                 Key: MPH-183
>                 URL: https://issues.apache.org/jira/browse/MPH-183
>             Project: Maven Help Plugin
>          Issue Type: Improvement
>    Affects Versions: 3.2.0
>            Reporter: Robert Scholte
>            Assignee: Maarten Mulders
>            Priority: Major
>         Attachments: mph-183-it.zip
>
>
> The popular spring-boot makes a lot of use of BOMs. Using BOMs is a good 
> practice, but right now it is very hard to determine where 
> dependencyManagement dependencies and especially their versions are coming 
> from.
> Instead of only showing only the final location (from the BOM POM), it should 
> also show the import path from the current project to that specific pom 
> (where is the BOM POM imported?).
> This way it will be easier to figure out which dependency in which POM needs 
> to be upgraded: it's the version in the POM declaring the import of the BOM 
> POM, not the version in the imported BOM POM.



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

Reply via email to