This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git
commit 105e5b97c6aa274b95332697338a7c535415ad77 Author: remm <r...@apache.org> AuthorDate: Wed May 19 15:50:05 2021 +0200 Use commons-compression for the default code path 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). --- CHANGES.md | 2 ++ .../org/apache/tomcat/jakartaee/Migration.java | 34 +++++++++------------- .../tomcat/jakartaee/LocalStrings.properties | 1 - 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 98be94f..c7c1c95 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java index 59d4600..097c04e 100644 --- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java +++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java @@ -30,21 +30,16 @@ import java.util.HashSet; 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 { @@ -214,23 +209,22 @@ public class Migration { 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; } } diff --git a/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties b/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties index 54fa2fe..4aecca9 100644 --- a/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties +++ b/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties @@ -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 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org