Copilot commented on code in PR #640:
URL: https://github.com/apache/maven-war-plugin/pull/640#discussion_r3653245655
##########
src/main/java/org/apache/maven/plugins/war/WarMojo.java:
##########
@@ -386,12 +388,53 @@ public void setWarName(String warName) {
public WarArchiver getWarArchiver() {
try {
- return (WarArchiver) getArchiverManager().getArchiver("war");
+ if (isCompressLibs()) {
+ return (WarArchiver) getArchiverManager().getArchiver("war");
+ } else {
+ return new UncompressedLibsWarArchiver();
+ }
Review Comment:
When compressLibs=false, getWarArchiver() bypasses ArchiverManager and
instantiates WarArchiver directly (new UncompressedLibsWarArchiver()). In this
plugin, archivers are normally obtained from ArchiverManager (e.g.
AbstractWarMojo looks up the JarArchiver via
archiverManager.getArchiver("jar")), which ensures the container-configured
archiver instance (logger, Plexus/Sisu component setup, defaults) is used.
Creating the archiver with `new` risks missing that setup and behaving
differently from the standard WAR archiver.
##########
src/main/java/org/apache/maven/plugins/war/WarMojo.java:
##########
@@ -386,12 +388,53 @@ public void setWarName(String warName) {
public WarArchiver getWarArchiver() {
try {
- return (WarArchiver) getArchiverManager().getArchiver("war");
+ if (isCompressLibs()) {
+ return (WarArchiver) getArchiverManager().getArchiver("war");
+ } else {
+ return new UncompressedLibsWarArchiver();
+ }
} catch (NoSuchArchiverException e) {
throw new IllegalStateException("Cannot find war archiver", e);
}
}
+ /**
+ * A {@link WarArchiver} subclass that stores dependency library JARs
({@code WEB-INF/lib/*.jar})
+ * in STORED mode (uncompressed) instead of DEFLATED mode, while still
compressing all other entries.
+ * This improves servlet container startup time since the
already-compressed JARs are not
+ * decompressed and recompressed during WAR creation and extraction.
+ */
+ private static class UncompressedLibsWarArchiver extends WarArchiver {
+
+ UncompressedLibsWarArchiver() {
+ super();
+ }
+
+ @Override
+ protected void zipFile(
+ InputStreamSupplier in,
+ ConcurrentJarCreator zOut,
+ String vPath,
+ long lastModified,
+ File fromArchive,
+ int mode,
+ String symlinkDestination,
+ boolean addInParallel)
+ throws IOException, ArchiverException {
+ if (vPath.startsWith("WEB-INF/lib/") && !vPath.endsWith("/")) {
Review Comment:
The override disables compression for *any* non-directory entry under
WEB-INF/lib/, but the parameter/Javadoc describe affecting dependency JARs
(WEB-INF/lib/*.jar). As written, additional resources placed under WEB-INF/lib/
(e.g., native libraries or metadata files) would also be forced to STORED,
which is a behavior change beyond the documented scope.
--
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]