You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2025/11/12 12:36:42 UTC

(tomcat-jakartaee-migration) branch main updated (f0cd44a -> 8375192)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git


    from f0cd44a  Ignore IDE config for Checkstyle
     new 73aa014  Add test cases for NO-OP conversions that should leave JARs unchanged
     new d0e548a  When src == dest, only write dest if the file has changed
     new 5079f19  Simplify code - no functional change
     new 984be4b  When converting a file in an archive, update the last modified time
     new 8375192  Avoid shade warnings for commons-codec

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGES.md                                         |  4 ++
 pom.xml                                            |  6 +++
 .../org/apache/tomcat/jakartaee/Migration.java     | 57 +++++++++++++++-------
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 51 ++++++++++++++-----
 4 files changed, 90 insertions(+), 28 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat-jakartaee-migration) 05/05: Avoid shade warnings for commons-codec

Posted by ma...@apache.org.
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 83751922f2aa58bf558ec761c05b619dc1eb22e5
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 12 12:35:02 2025 +0000

    Avoid shade warnings for commons-codec
---
 pom.xml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/pom.xml b/pom.xml
index 64cee79..1e3ed27 100644
--- a/pom.xml
+++ b/pom.xml
@@ -270,6 +270,12 @@
                     <exclude>META-INF/**</exclude>
                   </excludes>
                 </filter>
+                <filter>
+                  <artifact>commons-codec:*</artifact>
+                  <excludes>
+                    <exclude>META-INF/**</exclude>
+                  </excludes>
+                </filter>
                 <filter>
                   <artifact>commons-io:*</artifact>
                   <excludes>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat-jakartaee-migration) 02/05: When src == dest, only write dest if the file has changed

Posted by ma...@apache.org.
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 d0e548a87efb456443745011dbc5194709b1fec4
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 12 12:07:51 2025 +0000

    When src == dest, only write dest if the file has changed
    
    Based on PR #78 by Semiao Marco
---
 CHANGES.md                                         |  3 ++
 .../org/apache/tomcat/jakartaee/Migration.java     | 36 +++++++++++++++-------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 7e93e47..f9e8912 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,8 @@
 # Tomcat Migration Tool for Jakarta EE - Changelog
 
+## 1.0.10
+- When migrating files in place, don't replace the original file if no conversion has taken place. Based on PR[#78] by Semiao Marco.
+
 ## 1.0.9
 - Update the JaCoCo Maven plugin to 0.8.12. (dependabot/markt)
 - Update Commons BCEL to 6.10.0. (dependabot/markt)
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 45190a5..21b6e97 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -283,13 +283,17 @@ public class Migration {
         if (!inplace) {
             try (InputStream is = new FileInputStream(src);
                     OutputStream os = new FileOutputStream(dest)) {
-                migrateStream(src.getAbsolutePath(), is, os);
+                converted = migrateStream(src.getAbsolutePath(), is, os);
             }
         } else {
             ByteArrayOutputStream buffer = new ByteArrayOutputStream((int) (src.length() * 1.05));
 
             try (InputStream is = new FileInputStream(src)) {
-                migrateStream(src.getAbsolutePath(), is, buffer);
+                if (migrateStream(src.getAbsolutePath(), is, buffer)) {
+                    converted = true;
+                } else {
+                    return;
+                }
             }
 
             try (OutputStream os = new FileOutputStream(dest)) {
@@ -299,12 +303,14 @@ public class Migration {
     }
 
 
-    private void migrateArchiveStreaming(InputStream src, OutputStream dest) throws IOException {
+    private boolean migrateArchiveStreaming(InputStream src, OutputStream dest) throws IOException {
+        boolean convertedArchive = false;
         try (ZipArchiveInputStream srcZipStream = new ZipArchiveInputStream(CloseShieldInputStream.wrap(src));
                 ZipArchiveOutputStream destZipStream = new ZipArchiveOutputStream(CloseShieldOutputStream.wrap(dest))) {
             ZipArchiveEntry srcZipEntry;
             CRC32 crc32 = new CRC32();
             while ((srcZipEntry = srcZipStream.getNextEntry()) != null) {
+                boolean convertedStream = false;
                 String srcName = srcZipEntry.getName();
                 if (isSignatureFile(srcName)) {
                     logger.log(Level.WARNING, sm.getString("migration.skipSignatureFile", srcName));
@@ -322,7 +328,7 @@ public class Migration {
                 String destName = profile.convert(srcName);
                 if (srcZipEntry.getMethod() == ZipEntry.STORED) {
                     ByteArrayOutputStream tempBuffer = new ByteArrayOutputStream((int) (srcZipEntry.getSize() * 1.05));
-                    migrateStream(srcName, srcZipStream, tempBuffer);
+                    convertedStream = migrateStream(srcName, srcZipStream, tempBuffer);
                     crc32.update(tempBuffer.toByteArray(), 0, tempBuffer.size());
                     MigrationZipArchiveEntry destZipEntry = new MigrationZipArchiveEntry(srcZipEntry);
                     destZipEntry.setName(destName);
@@ -336,15 +342,18 @@ public class Migration {
                     MigrationZipArchiveEntry destZipEntry = new MigrationZipArchiveEntry(srcZipEntry);
                     destZipEntry.setName(destName);
                     destZipStream.putArchiveEntry(destZipEntry);
-                    migrateStream(srcName, srcZipStream, destZipStream);
+                    convertedStream = migrateStream(srcName, srcZipStream, destZipStream);
                     destZipStream.closeArchiveEntry();
                 }
+                convertedArchive = convertedArchive || convertedStream;
             }
         }
+        return convertedArchive;
     }
 
 
-    private void migrateArchiveInMemory(InputStream src, OutputStream dest) throws IOException {
+    private boolean migrateArchiveInMemory(InputStream src, OutputStream dest) throws IOException {
+        boolean convertedArchive = false;
         // Read the source into memory
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         IOUtils.copy(src, baos);
@@ -367,7 +376,8 @@ public class Migration {
                 MigrationZipArchiveEntry destZipEntry = new MigrationZipArchiveEntry(srcZipEntry);
                 destZipEntry.setName(destName);
                 destZipStream.putArchiveEntry(destZipEntry);
-                migrateStream(srcName, srcZipFile.getInputStream(srcZipEntry), destZipStream);
+                boolean convertedStream = migrateStream(srcName, srcZipFile.getInputStream(srcZipEntry), destZipStream);
+                convertedArchive = convertedArchive || convertedStream;
                 destZipStream.closeArchiveEntry();
             }
         }
@@ -375,6 +385,8 @@ public class Migration {
         // Write the destination back to the stream
         ByteArrayInputStream bais = new ByteArrayInputStream(destByteChannel.array(), 0, (int) destByteChannel.size());
         IOUtils.copy(bais, dest);
+
+        return convertedArchive;
     }
 
 
@@ -388,28 +400,30 @@ public class Migration {
     }
 
 
-    private void migrateStream(String name, InputStream src, OutputStream dest) throws IOException {
+    private boolean migrateStream(String name, InputStream src, OutputStream dest) throws IOException {
+        boolean convertedStream = false;
         if (isExcluded(name)) {
             Util.copy(src, dest);
             logger.log(Level.INFO, sm.getString("migration.skip", name));
         } else if (isArchive(name)) {
             if (zipInMemory) {
                 logger.log(Level.INFO, sm.getString("migration.archive.memory", name));
-                migrateArchiveInMemory(src, dest);
+                convertedStream = migrateArchiveInMemory(src, dest);
                 logger.log(Level.INFO, sm.getString("migration.archive.complete", name));
             } else {
                 logger.log(Level.INFO, sm.getString("migration.archive.stream", name));
-                migrateArchiveStreaming(src, dest);
+                convertedStream = migrateArchiveStreaming(src, dest);
                 logger.log(Level.INFO, sm.getString("migration.archive.complete", name));
             }
         } else {
             for (Converter converter : converters) {
                 if (converter.accepts(name)) {
-                    converted = converted | converter.convert(name, src, dest, profile);
+                    convertedStream  = converter.convert(name, src, dest, profile);
                     break;
                 }
             }
         }
+        return convertedStream;
     }
 
     private boolean isArchive(String fileName) {


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat-jakartaee-migration) 03/05: Simplify code - no functional change

Posted by ma...@apache.org.
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 5079f194c408ed65eb2a084e7268c371fd1a09ce
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 12 12:11:39 2025 +0000

    Simplify code - no functional change
---
 src/main/java/org/apache/tomcat/jakartaee/Migration.java | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 21b6e97..2242453 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -279,13 +279,7 @@ public class Migration {
     }
 
     private void migrateFile(File src, File dest) throws IOException {
-        boolean inplace = src.equals(dest);
-        if (!inplace) {
-            try (InputStream is = new FileInputStream(src);
-                    OutputStream os = new FileOutputStream(dest)) {
-                converted = migrateStream(src.getAbsolutePath(), is, os);
-            }
-        } else {
+        if (src.equals(dest)) {
             ByteArrayOutputStream buffer = new ByteArrayOutputStream((int) (src.length() * 1.05));
 
             try (InputStream is = new FileInputStream(src)) {
@@ -299,6 +293,11 @@ public class Migration {
             try (OutputStream os = new FileOutputStream(dest)) {
                 os.write(buffer.toByteArray());
             }
+        } else {
+            try (InputStream is = new FileInputStream(src);
+                    OutputStream os = new FileOutputStream(dest)) {
+                converted = migrateStream(src.getAbsolutePath(), is, os);
+            }
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat-jakartaee-migration) 01/05: Add test cases for NO-OP conversions that should leave JARs unchanged

Posted by ma...@apache.org.
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 73aa0143cb39a6dc5502f72d4541a180edd8a54e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 12 12:04:23 2025 +0000

    Add test cases for NO-OP conversions that should leave JARs unchanged
---
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 51 +++++++++++++++++-----
 1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index 6fc6a9b..5332978 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.jar.JarFile;
 
 import org.apache.commons.io.FileUtils;
@@ -233,31 +234,59 @@ public class MigrationTest {
 
     @Test
     public void testMigrateSignedJarFileRSA() throws Exception {
-        testMigrateSignedJarFile("rsa");
+        testMigrateSignedJarFile("rsa", EESpecProfiles.TOMCAT);
     }
 
     @Test
     public void testMigrateSignedJarFileDSA() throws Exception {
-        testMigrateSignedJarFile("dsa");
+        testMigrateSignedJarFile("dsa", EESpecProfiles.TOMCAT);
     }
 
     @Test
     public void testMigrateSignedJarFileEC() throws Exception {
-        testMigrateSignedJarFile("ec");
+        testMigrateSignedJarFile("ec", EESpecProfiles.TOMCAT);
     }
 
-    private void testMigrateSignedJarFile(String algorithm) throws Exception {
-        File jarFile = new File("target/test-classes/hellocgi-signed-" + algorithm + ".jar");
+    @Test
+    public void testNoopSignedJarFileRSA() throws Exception {
+        testMigrateSignedJarFile("rsa", EESpecProfiles.JEE8);
+    }
+
+    @Test
+    public void testNoopSignedJarFileDSA() throws Exception {
+        testMigrateSignedJarFile("dsa", EESpecProfiles.JEE8);
+    }
+
+    @Test
+    public void testNoopSignedJarFileEC() throws Exception {
+        testMigrateSignedJarFile("ec", EESpecProfiles.JEE8);
+    }
+
+    private void testMigrateSignedJarFile(String algorithm, EESpecProfile profile) throws Exception {
+        File jarFileSrc = new File("target/test-classes/hellocgi-signed-" + algorithm + ".jar");
+        File jarFileTmp = new File("target/test-classes/hellocgi-signed-" + algorithm + "-tmp.jar");
+        Files.copy(jarFileSrc.toPath(), jarFileTmp.toPath());
 
         Migration migration = new Migration();
-        migration.setSource(jarFile);
-        migration.setDestination(jarFile);
+        migration.setEESpecProfile(profile);
+        migration.setSource(jarFileTmp);
+        migration.setDestination(jarFileTmp);
         migration.execute();
 
-        try (JarFile jar = new JarFile(jarFile)) {
-            assertNull("Digest not removed from the manifest", jar.getManifest().getAttributes("org/apache/tomcat/jakartaee/HelloCGI.class"));
-            assertNull("Signature key not removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + "." + algorithm.toUpperCase()));
-            assertNull("Signed manifest not removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + ".SF"));
+        try (JarFile jar = new JarFile(jarFileTmp)) {
+            if (profile == EESpecProfiles.JEE8) {
+                assertNotNull("Digest removed from the manifest", jar.getManifest().getAttributes("org/apache/tomcat/jakartaee/HelloCGI.class"));
+                assertNotNull("Signature key removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + "." + algorithm.toUpperCase()));
+                assertNotNull("Signed manifest removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + ".SF"));
+                assertFalse("The JAR was converted", migration.hasConverted());
+            } else {
+                assertNull("Digest not removed from the manifest", jar.getManifest().getAttributes("org/apache/tomcat/jakartaee/HelloCGI.class"));
+                assertNull("Signature key not removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + "." + algorithm.toUpperCase()));
+                assertNull("Signed manifest not removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + ".SF"));
+                assertTrue("The JAR was not converted", migration.hasConverted());
+            }
+        } finally {
+            assertTrue("Unable to delete " + jarFileTmp.getAbsolutePath(), jarFileTmp.delete());
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat-jakartaee-migration) 04/05: When converting a file in an archive, update the last modified time

Posted by ma...@apache.org.
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 984be4b2878386d8a4f3f3111683b864f782daeb
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 12 12:14:21 2025 +0000

    When converting a file in an archive, update the last modified time
    
    Based on PR #78 by Semiao Marco
---
 CHANGES.md                                               |  1 +
 src/main/java/org/apache/tomcat/jakartaee/Migration.java | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index f9e8912..e83616e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,7 @@
 
 ## 1.0.10
 - When migrating files in place, don't replace the original file if no conversion has taken place. Based on PR[#78] by Semiao Marco.
+- When converting a file in an archive, update the last modified time for that archive entry.  Based on PR[#78] by Semiao Marco.
 
 ## 1.0.9
 - Update the JaCoCo Maven plugin to 0.8.12. (dependabot/markt)
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 2242453..00fa3eb 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -24,6 +24,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.attribute.FileTime;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashSet;
@@ -333,6 +334,9 @@ public class Migration {
                     destZipEntry.setName(destName);
                     destZipEntry.setSize(tempBuffer.size());
                     destZipEntry.setCrc(crc32.getValue());
+                    if (convertedStream) {
+                        destZipEntry.setLastModifiedTime(FileTime.fromMillis(System.currentTimeMillis()));
+                    }
                     destZipStream.putArchiveEntry(destZipEntry);
                     tempBuffer.writeTo(destZipStream);
                     destZipStream.closeArchiveEntry();
@@ -342,6 +346,9 @@ public class Migration {
                     destZipEntry.setName(destName);
                     destZipStream.putArchiveEntry(destZipEntry);
                     convertedStream = migrateStream(srcName, srcZipStream, destZipStream);
+                    if (convertedStream) {
+                        destZipEntry.setLastModifiedTime(FileTime.fromMillis(System.currentTimeMillis()));
+                    }
                     destZipStream.closeArchiveEntry();
                 }
                 convertedArchive = convertedArchive || convertedStream;
@@ -376,8 +383,11 @@ public class Migration {
                 destZipEntry.setName(destName);
                 destZipStream.putArchiveEntry(destZipEntry);
                 boolean convertedStream = migrateStream(srcName, srcZipFile.getInputStream(srcZipEntry), destZipStream);
-                convertedArchive = convertedArchive || convertedStream;
+                if (convertedStream) {
+                    destZipEntry.setLastModifiedTime(FileTime.fromMillis(System.currentTimeMillis()));
+                }
                 destZipStream.closeArchiveEntry();
+                convertedArchive = convertedArchive || convertedStream;
             }
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org