arturobernalg commented on code in PR #282:
URL:
https://github.com/apache/maven-artifact-plugin/pull/282#discussion_r4480353918
##########
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:
Added AbstractBuildinfoMojoRelativizeTest in ce55ffc, covering the
absolute-vs-relative case (confirmed it fails without the fix). Left the
different-roots case untested since it's Windows-only and this environment
can't exercise it.
--
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]