erik-meuwese-topicus commented on code in PR #416:
URL:
https://github.com/apache/maven-build-cache-extension/pull/416#discussion_r2596338993
##########
src/main/java/org/apache/maven/buildcache/xml/DtoUtils.java:
##########
@@ -173,4 +175,56 @@ public static Artifact copy(Artifact artifact) {
copy.setFileSize(artifact.getFileSize());
return copy;
}
+
+ public static String normalizeValue(Object value, Path baseDirPath) {
+ final String currentValue;
+ if (value instanceof File) {
+ Path path = ((File) value).toPath();
+ currentValue = normalizedPath(path, baseDirPath);
+ } else if (value instanceof Path) {
+ currentValue = normalizedPath(((Path) value), baseDirPath);
+ } else if (value != null && value.getClass().isArray()) {
+ currentValue = ArrayUtils.toString(value);
+ } else {
+ currentValue = String.valueOf(value);
+ }
+ return currentValue;
+ }
+
+ /**
+ * Best effort to normalize paths from Mojo fields.
+ * - all absolute paths under project root to be relativized for
portability
+ * - redundant '..' and '.' to be removed to have consistent views on all
paths
+ * - all relative paths are considered portable and should not be touched
+ * - absolute paths outside of project directory could not be
deterministically
+ * relativized and not touched
+ */
+ private static String normalizedPath(Path path, Path baseDirPath) {
+ boolean isProjectSubdir = path.isAbsolute() &&
path.startsWith(baseDirPath);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(
+ "normalizedPath isProjectSubdir {} path '{}' - baseDirPath
'{}', path.isAbsolute() {}, path.startsWith(baseDirPath) {}",
Review Comment:
```suggestion
"normalizedPath isProjectSubdir {} path '{}' -
baseDirPath '{}', path.isAbsolute() {},"
+ " path.startsWith(baseDirPath) {}",
```
The code formatter will put it on 2 lines because it's to long. Apply the
code style formatter to minimize diffs
https://maven.apache.org/developers/conventions/code.html
--
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]