arturobernalg commented on code in PR #282:
URL: 
https://github.com/apache/maven-artifact-plugin/pull/282#discussion_r4480296296


##########
src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java:
##########
@@ -451,8 +451,15 @@ private Toolchain getToolchain() {
 
     protected String relative(File file) {
         File basedir = session.getTopLevelProject().getBasedir();
-        int length = basedir.getPath().length();
-        String path = file.getPath();
-        return path.substring(length + 1);
+        return relative(basedir, file);
+    }
+
+    /**
+     * Computes the path of {@code file} relative to {@code basedir}, 
correctly handling a {@code file} that
+     * is not actually below {@code basedir} (for example a build artifact 
copied outside the reactor), instead
+     * of assuming {@code basedir}'s path is always a literal prefix of {@code 
file}'s path.
+     */
+    static String relative(File basedir, File file) {

Review Comment:
   Agreed, inlined it in deeb052. Also dropped 
AbstractBuildinfoMojoRelativeTest since it was only testing Path.relativize 
itself, not any logic of ours.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to