Copilot commented on code in PR #639:
URL: https://github.com/apache/maven-war-plugin/pull/639#discussion_r3665665260
##########
src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java:
##########
@@ -127,4 +142,136 @@ protected File
getOverlayTempDirectory(WarPackagingContext context, Overlay over
}
return result;
}
+
+ /**
+ * Identifies jars from the overlay's {@code WEB-INF/lib} whose
groupId:artifactId matches a
+ * non-optional runtime-scope dependency resolved by the project. When the
overlay jar contains
+ * {@code META-INF/maven/**\/pom.properties}, the groupId is read from
that metadata for a precise
+ * match. Otherwise, matching falls back to artifactId only.
+ *
+ * <p>The overlay's cached unpack directory is <em>not</em> mutated; the
returned set is used
+ * as additional excludes during the copy step.
+ *
+ * @param context the packaging context
+ * @param overlayDir the unpacked overlay directory
+ * @return set of paths (relative to the overlay dir) to exclude from the
overlay copy
+ */
+ private Set<String> computeConflictingJars(WarPackagingContext context,
File overlayDir) {
+ File libDir = new File(overlayDir, "WEB-INF/lib");
+ if (!libDir.isDirectory()) {
+ return Collections.emptySet();
+ }
+
+ ScopeArtifactFilter filter = new
ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+ Set<String> projectArtifactKeys = new HashSet<>();
+ Set<String> projectFallbackIds = new HashSet<>();
+ for (Artifact artifact : context.getProject().getArtifacts()) {
+ if (!artifact.isOptional() && filter.include(artifact) &&
"jar".equals(artifact.getType())) {
+ projectArtifactKeys.add(artifact.getGroupId() + ":" +
artifact.getArtifactId());
+ projectFallbackIds.add(artifact.getArtifactId());
+ }
+ }
+
+ if (projectArtifactKeys.isEmpty()) {
+ return Collections.emptySet();
+ }
+
+ File[] overlayJars = libDir.listFiles((dir, name) ->
name.endsWith(".jar"));
+ if (overlayJars == null) {
+ return Collections.emptySet();
+ }
+
+ Set<String> conflicting = new HashSet<>();
+ for (File overlayJar : overlayJars) {
+ String jarName = overlayJar.getName();
+ String artifactId = extractArtifactId(jarName);
+ if (artifactId == null) {
+ continue;
+ }
+
+ String groupId = getJarGroupId(overlayJar);
+ String key = (groupId != null) ? groupId + ":" + artifactId :
artifactId;
+ if ((groupId != null && projectArtifactKeys.contains(key))
+ || (groupId == null &&
projectFallbackIds.contains(artifactId))) {
+ context.getLog()
+ .debug("Excluding dependency [" + jarName + "] from
overlay [" + overlay.getId()
+ + "]; project runtime dependencies already
include a version");
+ conflicting.add("WEB-INF/lib/" + jarName);
+ }
Review Comment:
`computeConflictingJars(...)` references `overlay.getId()` but `overlay` is
not in scope in this method, so this will not compile. Pass the `Overlay
overlay` into `computeConflictingJars(...)` (and update the call site), or
remove the overlay id from the log message and rely on other available context.
##########
src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java:
##########
@@ -127,4 +142,136 @@ protected File
getOverlayTempDirectory(WarPackagingContext context, Overlay over
}
return result;
}
+
+ /**
+ * Identifies jars from the overlay's {@code WEB-INF/lib} whose
groupId:artifactId matches a
+ * non-optional runtime-scope dependency resolved by the project. When the
overlay jar contains
+ * {@code META-INF/maven/**\/pom.properties}, the groupId is read from
that metadata for a precise
+ * match. Otherwise, matching falls back to artifactId only.
+ *
+ * <p>The overlay's cached unpack directory is <em>not</em> mutated; the
returned set is used
+ * as additional excludes during the copy step.
+ *
+ * @param context the packaging context
+ * @param overlayDir the unpacked overlay directory
+ * @return set of paths (relative to the overlay dir) to exclude from the
overlay copy
+ */
+ private Set<String> computeConflictingJars(WarPackagingContext context,
File overlayDir) {
+ File libDir = new File(overlayDir, "WEB-INF/lib");
+ if (!libDir.isDirectory()) {
+ return Collections.emptySet();
+ }
Review Comment:
`computeConflictingJars(...)` references `overlay.getId()` but `overlay` is
not in scope in this method, so this will not compile. Pass the `Overlay
overlay` into `computeConflictingJars(...)` (and update the call site), or
remove the overlay id from the log message and rely on other available context.
--
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]