You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/11/01 19:52:37 UTC

[GitHub] [maven-help-plugin] jjkester opened a new pull request #37: Mph 183 effective pom path to source

jjkester opened a new pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37


   The goal of [MPH-183](https://issues.apache.org/jira/browse/MPH-183) is to print via which BOM(s) a dependency got in the effective POM.
   
   Related PR that introduces the necessary changes in the model: https://github.com/apache/maven/pull/603
   
   Method for retrieving the hierarchical data from the `InputSource` is loaded with reflection. This way there is no behavior change for Maven versions below 4.0.0-alpha-1 with the new version of the plugin.
   
   ---
   
   Following this checklist to help us incorporate your 
   contribution quickly and easily:
   
    - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MPH) filed 
          for the change (usually before you start working on it).  Trivial changes like typos do not 
          require a JIRA issue.  Your pull request should address just this issue, without 
          pulling in other changes.
    - [ ] Each commit in the pull request should have a meaningful subject line and body.
    - [ ] Format the pull request title like `[MPH-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `MPH-XXX` with the appropriate JIRA issue. Best practice
          is to use the JIRA issue title in the pull request title and in the first line of the 
          commit message.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [ ] You have run the integration tests successfully (`mvn -Prun-its clean verify`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under 
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   


-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741280761



##########
File path: src/it/projects/effective-pom-with-bom/test.properties
##########
@@ -0,0 +1,19 @@
+# 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.
+
+output = result.txt

Review comment:
       There are some Windows line feeds from the test files I got in the ticket. I will convert them from CRLF to LF.




-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741280647



##########
File path: src/it/projects/effective-pom-with-bom/invoker.properties
##########
@@ -0,0 +1,20 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom

Review comment:
       There are some Windows line feeds from the test files I got in the ticket. I will convert them from CRLF to LF.

##########
File path: src/it/projects/effective-pom-with-bom/test.properties
##########
@@ -0,0 +1,19 @@
+# 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.
+
+output = result.txt

Review comment:
       There are some Windows line feeds from the test files I got in the ticket. I will convert them from CRLF to LF.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       I basically took the same approach as the other code in this class. I'll have a quick look around what the consequences are.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Will do.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       I am unable to throw a `MojoExecutionException` because this is a checked exception, and the `InputLocationStringFormatter` does not allow me to throw it.
   
   I can however create a custom `RuntimeException` and catch it in the `execute()` method. However, it is not likely that any exception will be thrown from the reflectively invoked method, so rethrowing the target exception may be the most appropriate (it does reflect the behavior of a normal non-reflective method call).

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       This is actually just the case for the `NoSuchMethodException`. The other exceptions should never be thrown and reflect other issues. I would designate these "unexpected".




-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741280647



##########
File path: src/it/projects/effective-pom-with-bom/invoker.properties
##########
@@ -0,0 +1,20 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom

Review comment:
       There are some Windows line feeds from the test files I got in the ticket. I will convert them from CRLF to LF.




-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741280647



##########
File path: src/it/projects/effective-pom-with-bom/invoker.properties
##########
@@ -0,0 +1,20 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom

Review comment:
       There are some Windows line feeds from the test files I got in the ticket. I will convert them from CRLF to LF.

##########
File path: src/it/projects/effective-pom-with-bom/test.properties
##########
@@ -0,0 +1,19 @@
+# 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.
+
+output = result.txt

Review comment:
       There are some Windows line feeds from the test files I got in the ticket. I will convert them from CRLF to LF.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       I basically took the same approach as the other code in this class. I'll have a quick look around what the consequences are.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Will do.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       I am unable to throw a `MojoExecutionException` because this is a checked exception, and the `InputLocationStringFormatter` does not allow me to throw it.
   
   I can however create a custom `RuntimeException` and catch it in the `execute()` method. However, it is not likely that any exception will be thrown from the reflectively invoked method, so rethrowing the target exception may be the most appropriate (it does reflect the behavior of a normal non-reflective method call).

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       This is actually just the case for the `NoSuchMethodException`. The other exceptions should never be thrown and reflect other issues. I would designate these "unexpected".




-- 
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-help-plugin] mthmulders commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r740810029



##########
File path: src/it/projects/effective-pom-with-bom/test.properties
##########
@@ -0,0 +1,19 @@
+# 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.
+
+output = result.txt

Review comment:
       I'm afraid there's something wrong with the line endings here.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       Wouldn't a `MojoException` be more appropriate in this case?

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Please add a debug log statement explaining that we will not show "imported by" because we're probably running Maven pre-4.

##########
File path: src/it/projects/effective-pom-with-bom/invoker.properties
##########
@@ -0,0 +1,20 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom

Review comment:
       I'm afraid there's something wrong with the line endings here.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       If a `MojoExecutionException` doesn't fit, and the existing code follows this approach already, then don't bother...

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Agreed.




-- 
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-help-plugin] mthmulders commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741366773



##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       If a `MojoExecutionException` doesn't fit, and the existing code follows this approach already, then don't bother...




-- 
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-help-plugin] mthmulders commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r740810029



##########
File path: src/it/projects/effective-pom-with-bom/test.properties
##########
@@ -0,0 +1,19 @@
+# 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.
+
+output = result.txt

Review comment:
       I'm afraid there's something wrong with the line endings here.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       Wouldn't a `MojoException` be more appropriate in this case?

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Please add a debug log statement explaining that we will not show "imported by" because we're probably running Maven pre-4.

##########
File path: src/it/projects/effective-pom-with-bom/invoker.properties
##########
@@ -0,0 +1,20 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom

Review comment:
       I'm afraid there's something wrong with the line endings here.




-- 
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-help-plugin] mthmulders commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r740810029



##########
File path: src/it/projects/effective-pom-with-bom/test.properties
##########
@@ -0,0 +1,19 @@
+# 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.
+
+output = result.txt

Review comment:
       I'm afraid there's something wrong with the line endings here.

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       Wouldn't a `MojoException` be more appropriate in this case?

##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Please add a debug log statement explaining that we will not show "imported by" because we're probably running Maven pre-4.

##########
File path: src/it/projects/effective-pom-with-bom/invoker.properties
##########
@@ -0,0 +1,20 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom

Review comment:
       I'm afraid there's something wrong with the line endings here.




-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741300890



##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       This is actually just the case for the `NoSuchMethodException`. The other exceptions should never be thrown and reflect other issues. I would designate these "unexpected".




-- 
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-help-plugin] mthmulders commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741367110



##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Agreed.




-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741281426



##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       I basically took the same approach as the other code in this class. I'll have a quick look around what the consequences are.




-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741297138



##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();

Review comment:
       I am unable to throw a `MojoExecutionException` because this is a checked exception, and the `InputLocationStringFormatter` does not allow me to throw it.
   
   I can however create a custom `RuntimeException` and catch it in the `execute()` method. However, it is not likely that any exception will be thrown from the reflectively invoked method, so rethrowing the target exception may be the most appropriate (it does reflect the behavior of a normal non-reflective method call).




-- 
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-help-plugin] jjkester commented on a change in pull request #37: [MPH-183] Effective POM path to source

Posted by GitBox <gi...@apache.org>.
jjkester commented on a change in pull request #37:
URL: https://github.com/apache/maven-help-plugin/pull/37#discussion_r741286196



##########
File path: src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
##########
@@ -298,8 +300,49 @@ else if ( e.getTargetException() instanceof RuntimeException )
 
     private static String toString( InputLocation location )
     {
-        InputSource source = location.getSource();
+        String source = toString( location.getSource() );
+        String hierarchy = toHierarchyString( location.getSource() );
+
+        return '}' + source + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" )
+                + hierarchy + ' ';
+    }
+
+    private static String toHierarchyString( InputSource source )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        try
+        {
+            // InputSource#getImportedBy() added in maven-model 4.0.0-alpha-1
+            Method getImportedBy = InputSource.class.getDeclaredMethod( "getImportedBy" );
+            InputSource importedBy = (InputSource) getImportedBy.invoke( source );
+
+            while ( importedBy != null )
+            {
+                sb.append( " via " ).append( toString( importedBy ) );
+                importedBy = (InputSource) getImportedBy.invoke( importedBy );
+            }
 
+            return sb.toString();
+        }
+        catch ( NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
+                | ClassCastException e )
+        {
+            // Just continue without hierarchy

Review comment:
       Will do.




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