Skip to content

Commit

Permalink
Use commons-compression for the default code path
Browse files Browse the repository at this point in the history
The JVM code has too much exception throwing and hardcoded behavior
given what the migration tool does, as seen in issue #20. The
commons-compression code does not seem to have the same check in that
case, as seen when using -zipInMemory (it does not do anything special
yet does not complain about duplicate entries since there's no check for
that in the code).
In some cases, this seems faster. In others not so much. This needs more
investigation to verify there's no regression in that area (or anywhere
else).
  • Loading branch information
rmaucher committed May 19, 2021
1 parent ecca93a commit 105e5b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.0.1 (in progress)

- Fix [#20] by using commons-compression instead of the Java zip code (remm)

## 1.0.0

- Fix [#14](https://github.com/apache/tomcat-jakartaee-migration/issues/14). Do not migrate `javax.xml.(registry|rpc)` namespaces. (mgrigorov)
Expand Down
34 changes: 14 additions & 20 deletions src/main/java/org/apache/tomcat/jakartaee/Migration.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.CloseShieldInputStream;
import org.apache.commons.io.output.CloseShieldOutputStream;

public class Migration {

Expand Down Expand Up @@ -214,23 +209,22 @@ private void migrateFile(File src, File dest) throws IOException {


private void migrateArchiveStreaming(String name, InputStream src, OutputStream dest) throws IOException {
try (ZipInputStream zipIs = new ZipInputStream(new CloseShieldInputStream(src));
ZipOutputStream zipOs = new ZipOutputStream(new CloseShieldOutputStream(dest))) {
ZipEntry zipEntry;
while ((zipEntry = zipIs.getNextEntry()) != null) {
String sourceName = zipEntry.getName();
if (isSignatureFile(sourceName)) {
logger.log(Level.WARNING, sm.getString("migration.skipSignatureFile", sourceName));
try (ZipArchiveInputStream srcZipStream = new ZipArchiveInputStream(src);
ZipArchiveOutputStream destZipStream = new ZipArchiveOutputStream(dest)) {
ZipArchiveEntry srcZipEntry;
while ((srcZipEntry = srcZipStream.getNextZipEntry()) != null) {
String srcName = srcZipEntry.getName();
if (isSignatureFile(srcName)) {
logger.log(Level.WARNING, sm.getString("migration.skipSignatureFile", srcName));
continue;
}
String destName = profile.convert(sourceName);
JarEntry destEntry = new JarEntry(destName);
zipOs.putNextEntry(destEntry);
migrateStream(sourceName, zipIs, zipOs);
String destName = profile.convert(srcName);
RenamableZipArchiveEntry destZipEntry = new RenamableZipArchiveEntry(srcZipEntry);
destZipEntry.setName(destName);
destZipStream.putArchiveEntry(destZipEntry);
migrateStream(srcName, srcZipStream, destZipStream);
destZipStream.closeArchiveEntry();
}
} catch (ZipException ze) {
logger.log(Level.SEVERE, sm.getString("migration.archiveFailed", name), ze);
throw ze;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ migration.archive.complete=Migration finished for archive [{0}]
migration.archive.memory=Migration starting for archive [{0}] using in memory copy
migration.skip=Migration skipped for archive [{0}] because it is excluded (the archive was copied unchanged)
migration.archive.stream=Migration starting for archive [{0}] using streaming
migration.archiveFailed=Failed to migrate archive [{0}]. Using the "-zipInMemory" option may help.
migration.cannotReadSource=Cannot read source location [{0}]
migration.done=Migration completed successfully in [{0}] milliseconds
migration.error=Error performing migration
Expand Down

0 comments on commit 105e5b9

Please sign in to comment.