Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/it/MWAR-446/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>MWAR-446</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<compressLibs>false</compressLibs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>@plexusUtilVersion@</version>
</dependency>
</dependencies>
</project>
23 changes: 23 additions & 0 deletions src/it/MWAR-446/src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->
<html>
<body>Hello World</body>
</html>
48 changes: 48 additions & 0 deletions src/it/MWAR-446/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.util.zip.ZipEntry
import java.util.zip.ZipFile

def warFile = new File(basedir, 'target/MWAR-446-0.0.1-SNAPSHOT.war')
assert warFile.exists() : "WAR file should exist"

def zipFile = new ZipFile(warFile)
try {
def foundStoredJar = false
def foundDeflatedEntry = false

zipFile.entries().each { ZipEntry entry ->
if (entry.name.startsWith('WEB-INF/lib/') && entry.name.endsWith('.jar')) {
assert entry.method == ZipEntry.STORED :
"JAR entry ${entry.name} should be STORED (method=0) but was method=${entry.method}"
foundStoredJar = true
}
if (entry.name == 'index.html') {
assert entry.method == ZipEntry.DEFLATED :
"index.html should be DEFLATED (method=8) but was method=${entry.method}"
foundDeflatedEntry = true
}
}

assert foundStoredJar : "Should have found at least one JAR in WEB-INF/lib/"
assert foundDeflatedEntry : "Should have found index.html"
} finally {
zipFile.close()
}
20 changes: 20 additions & 0 deletions src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ public abstract class AbstractWarMojo extends AbstractMojo {
@Parameter(defaultValue = "true")
private boolean recompressZippedFiles;

/**
* Whether dependency libraries (i.e. JAR files in {@code WEB-INF/lib/}) should be compressed (DEFLATED) when

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove i.e.,

* added to the WAR archive. Setting this to {@code false} will store the library JARs without compression
* (STORED mode), which can improve servlet container startup time since the JARs do not need to be decompressed.
* Note that since JAR files are already compressed, storing them without additional compression typically has
* negligible impact on the overall WAR file size.
*
* @since 3.5.2
*/
@Parameter(defaultValue = "true")
private boolean compressLibs;

/**
* @since 2.4
*/
Expand Down Expand Up @@ -1052,6 +1064,14 @@ protected boolean isRecompressZippedFiles() {
return recompressZippedFiles;
}

/**
* @return {@link #compressLibs}
* @since 3.5.2
*/
protected boolean isCompressLibs() {
return compressLibs;
}

/**
* @return {@link #includeEmptyDirectories}
*/
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/org/apache/maven/plugins/war/WarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.shared.filtering.MavenFileFilter;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
import org.codehaus.plexus.archiver.ArchiveEntry;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
import org.codehaus.plexus.archiver.war.WarArchiver;
import org.codehaus.plexus.archiver.zip.ConcurrentJarCreator;
import org.codehaus.plexus.util.FileUtils;

/**
Expand Down Expand Up @@ -200,12 +202,12 @@
archiver.setOutputFile(warFile);

// configure for Reproducible Builds based on outputTimestamp value
archiver.configureReproducible(outputTimestamp);

Check warning on line 205 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

configureReproducible(java.lang.String) in org.apache.maven.archiver.MavenArchiver has been deprecated

Check warning on line 205 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

configureReproducible(java.lang.String) in org.apache.maven.archiver.MavenArchiver has been deprecated

Check warning on line 205 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

configureReproducible(java.lang.String) in org.apache.maven.archiver.MavenArchiver has been deprecated

Check warning on line 205 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

configureReproducible(java.lang.String) in org.apache.maven.archiver.MavenArchiver has been deprecated

Check warning on line 205 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

configureReproducible(java.lang.String) in org.apache.maven.archiver.MavenArchiver has been deprecated

Check warning on line 205 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

configureReproducible(java.lang.String) in org.apache.maven.archiver.MavenArchiver has been deprecated

Check warning on line 205 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

configureReproducible(java.lang.String) in org.apache.maven.archiver.MavenArchiver has been deprecated

getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated webapp archive.");
getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated webapp archive.");

warArchiver.addDirectory(getWebappDirectory(), getPackagingIncludes(), getPackagingExcludes());

Check warning on line 210 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

addDirectory(java.io.File,java.lang.String[],java.lang.String[]) in org.codehaus.plexus.archiver.AbstractArchiver has been deprecated

Check warning on line 210 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

addDirectory(java.io.File,java.lang.String[],java.lang.String[]) in org.codehaus.plexus.archiver.AbstractArchiver has been deprecated

Check warning on line 210 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

addDirectory(java.io.File,java.lang.String[],java.lang.String[]) in org.codehaus.plexus.archiver.AbstractArchiver has been deprecated

Check warning on line 210 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

addDirectory(java.io.File,java.lang.String[],java.lang.String[]) in org.codehaus.plexus.archiver.AbstractArchiver has been deprecated

Check warning on line 210 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

addDirectory(java.io.File,java.lang.String[],java.lang.String[]) in org.codehaus.plexus.archiver.AbstractArchiver has been deprecated

Check warning on line 210 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

addDirectory(java.io.File,java.lang.String[],java.lang.String[]) in org.codehaus.plexus.archiver.AbstractArchiver has been deprecated

Check warning on line 210 in src/main/java/org/apache/maven/plugins/war/WarMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

addDirectory(java.io.File,java.lang.String[],java.lang.String[]) in org.codehaus.plexus.archiver.AbstractArchiver has been deprecated

final File webXmlFile = new File(getWebappDirectory(), "WEB-INF/web.xml");
if (webXmlFile.exists()) {
Expand Down Expand Up @@ -386,12 +388,45 @@

public WarArchiver getWarArchiver() {
try {
return (WarArchiver) getArchiverManager().getArchiver("war");
if (isCompressLibs()) {
return (WarArchiver) getArchiverManager().getArchiver("war");
} else {
return new UncompressedLibsWarArchiver();
}
Comment on lines 389 to +395
} 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(ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath)
throws IOException, ArchiverException {
if (vPath.startsWith("WEB-INF/lib/") && !vPath.endsWith("/")) {
boolean original = isCompress();
setCompress(false);
try {
super.zipFile(entry, zOut, vPath);
} finally {
setCompress(original);
}
} else {
super.zipFile(entry, zOut, vPath);
}
}
}

/**
* @return {@link #projectHelper}
*/
Expand Down
Loading