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


##########
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) {
+        return basedir.toPath().relativize(file.toPath()).toString();

Review Comment:
   Good catch, done in ce55ffc: retries with both paths made absolute and 
normalized, falls back to the absolute file path if that still fails.



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