[Git][java-team/tomcat-jakartaee-migration][upstream] New upstream version 1.0.7

Emmanuel Bourg (@ebourg) gitlab at salsa.debian.org
Tue Oct 10 18:28:25 BST 2023



Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / tomcat-jakartaee-migration


Commits:
9c5b0b44 by Emmanuel Bourg at 2023-10-10T19:00:55+02:00
New upstream version 1.0.7
- - - - -


9 changed files:

- CHANGES.md
- pom.xml
- src/main/java/org/apache/tomcat/jakartaee/ManifestConverter.java
- src/main/java/org/apache/tomcat/jakartaee/Migration.java
- src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
- src/main/java/org/apache/tomcat/jakartaee/MigrationTask.java
- src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties
- src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
- + src/test/resources/javax.enterprise.inject.spi.Extension


Changes:

=====================================
CHANGES.md
=====================================
@@ -1,5 +1,15 @@
 # Tomcat Migration Tool for Jakarta EE - Changelog
 
+## 1.0.7
+
+- When converting directories, rename files according to the chosen profile. (fschumacher)
+- Add configuration option, `matchExcludesAgainstPathName` that can be used to configure exclusions base don path name rather than just file name.  PR[#38](https://github.com/apache/tomcat-jakartaee-migration/pull/38) provided by Réda Housni Alaoui. (markt)
+- Update OSGI servlet specification versions if present in manifest file. PR[#42](https://github.com/apache/tomcat-jakartaee-migration/pull/42) provided by Ivan Furnadjiev. (markt)
+- Update Commons BCEL to 6.7.0. (markt)
+- Update Commons Compress to 1.23.0. (markt)
+- Provided workaround for the known JDK bug identified as the cause of migration failures in issue [#46](https://github.com/apache/tomcat-jakartaee-migration/issues/46). (markt/ebourg)
+
+
 ## 1.0.6
 
 - Fix handling of javax.annotation package in 1.0.5. PR [#40](https://github.com/apache/tomcat-jakartaee-migration/pull/40) provided by Danny Thomas (remm)


=====================================
pom.xml
=====================================
@@ -26,7 +26,7 @@
 
   <groupId>org.apache.tomcat</groupId>
   <artifactId>jakartaee-migration</artifactId>
-  <version>1.0.6</version>
+  <version>1.0.7</version>
   <name>Apache Tomcat Migration Tool for Jakarta EE</name>
 
   <description>The aim of the tool is to take a web application written for Java EE 8 that
@@ -62,7 +62,7 @@
   <scm>
     <connection>scm:git:https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git</connection>
     <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git</developerConnection>
-    <tag>1.0.6</tag>
+    <tag>1.0.7</tag>
     <url>https://gitbox.apache.org/repos/asf?p=tomcat-jakartaee-migration.git</url>
   </scm>
 
@@ -77,12 +77,12 @@
     <dependency>
       <groupId>org.apache.bcel</groupId>
       <artifactId>bcel</artifactId>
-      <version>6.6.0</version>
+      <version>6.7.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-compress</artifactId>
-      <version>1.22</version>
+      <version>1.23.0</version>
     </dependency>
     <dependency>
       <groupId>commons-io</groupId>


=====================================
src/main/java/org/apache/tomcat/jakartaee/ManifestConverter.java
=====================================
@@ -29,6 +29,8 @@ import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.commons.io.IOUtils;
 
@@ -128,6 +130,7 @@ public class ManifestConverter implements Converter {
         // Update package names in values
         for (Entry<Object,Object> entry : attributes.entrySet()) {
             String newValue = profile.convert((String) entry.getValue());
+            newValue = replaceVersion(newValue);
             // Object comparison is deliberate
             if (newValue != entry.getValue()) {
                 entry.setValue(newValue);
@@ -136,4 +139,17 @@ public class ManifestConverter implements Converter {
         }
         return converted;
     }
+
+    private String replaceVersion(String entryValue) {
+        if (entryValue.contains("jakarta.servlet")) {
+            StringBuffer builder = new StringBuffer();
+            Matcher matcher = Pattern.compile("jakarta.servlet([^,]*);version=\"(.*?)\"").matcher(entryValue);
+            while (matcher.find()) {
+                matcher.appendReplacement(builder, "jakarta.servlet$1;version=\"[5.0.0,7.0.0)\"");
+            }
+            matcher.appendTail(builder);
+            return builder.toString();
+        }
+        return entryValue;
+    }
 }


=====================================
src/main/java/org/apache/tomcat/jakartaee/Migration.java
=====================================
@@ -40,6 +40,7 @@ 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.archivers.zip.ZipShort;
 import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.input.CloseShieldInputStream;
@@ -55,6 +56,9 @@ public class Migration {
 
     private static final Set<String> DEFAULT_EXCLUDES = new HashSet<>();
 
+    private static final ZipShort EXTRA_FIELD_ZIP64 = new ZipShort(1);
+    private static final long ZIP64_THRESHOLD_LENGTH = 0xFFFFFFFFL;
+
     static {
         // Apache Commons
         DEFAULT_EXCLUDES.add("commons-codec-*.jar");
@@ -94,6 +98,7 @@ public class Migration {
     private EESpecProfile profile = EESpecProfiles.TOMCAT;
 
     private boolean enableDefaultExcludes = true;
+    private boolean matchExcludesAgainstPathName;
     private boolean zipInMemory;
     private boolean converted;
     private State state = State.NOT_STARTED;
@@ -161,6 +166,14 @@ public class Migration {
         this.enableDefaultExcludes = enableDefaultExcludes;
     }
 
+    /**
+     * Enable exclude matching against the path name.
+     * @param matchExcludesAgainstPathName true to match excludes against the path name instead of the file name
+     */
+    public void setMatchExcludesAgainstPathName(boolean matchExcludesAgainstPathName) {
+        this.matchExcludesAgainstPathName = matchExcludesAgainstPathName;
+    }
+
     /**
      * Buffer all conversion operations for compressed archives in memory.
      * @param zipInMemory true to buffer in memory
@@ -252,7 +265,7 @@ public class Migration {
         String[] files = src.list();
         for (String file : files) {
             File srcFile = new File(src, file);
-            File destFile = new File(dest, file);
+            File destFile = new File(dest, profile.convert(file));
             if (srcFile.isDirectory()) {
                 if ((destFile.exists() && destFile.isDirectory()) || destFile.mkdir()) {
                     migrateDirectory(srcFile, destFile);
@@ -265,7 +278,6 @@ public class Migration {
         }
     }
 
-
     private void migrateFile(File src, File dest) throws IOException {
         boolean inplace = src.equals(dest);
         if (!inplace) {
@@ -298,6 +310,15 @@ public class Migration {
                     logger.log(Level.WARNING, sm.getString("migration.skipSignatureFile", srcName));
                     continue;
                 }
+                if (srcZipEntry.getSize() > ZIP64_THRESHOLD_LENGTH ||
+                        srcZipEntry.getCompressedSize() > ZIP64_THRESHOLD_LENGTH) {
+                    logger.log(Level.WARNING, sm.getString("migration.jdk8303866", srcName));
+                } else {
+                    // Avoid JDK bug - https://bugs.openjdk.org/browse/JDK-8303866
+                    if (srcZipEntry.getExtraField(EXTRA_FIELD_ZIP64) != null) {
+                        srcZipEntry.removeExtraField(EXTRA_FIELD_ZIP64);
+                    }
+                }
                 String destName = profile.convert(srcName);
                 if (srcZipEntry.getMethod() == ZipEntry.STORED) {
                     ByteArrayOutputStream tempBuffer = new ByteArrayOutputStream((int) (srcZipEntry.getSize() * 1.05));
@@ -404,7 +425,10 @@ public class Migration {
             return true;
         }
 
-        if (GlobMatcher.matchName(excludes, filename, true)) {
+        if (!matchExcludesAgainstPathName && GlobMatcher.matchName(excludes, filename, true)) {
+            return true;
+        }
+        if (matchExcludesAgainstPathName && GlobMatcher.matchName(excludes, name, true)) {
             return true;
         }
 


=====================================
src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
=====================================
@@ -37,6 +37,7 @@ public class MigrationCLI {
     private static final String LOGLEVEL_ARG = "-logLevel=";
     private static final String PROFILE_ARG = "-profile=";
     private static final String ZIPINMEMORY_ARG = "-zipInMemory";
+    private static final String MATCHEXCLUDESPATH_ARG ="-matchExcludesAgainstPathName";
 
     /**
      * Build the migration tool CLI instance.
@@ -91,6 +92,9 @@ public class MigrationCLI {
             } else if (argument.equals(ZIPINMEMORY_ARG)) {
                 iter.remove();
                 migration.setZipInMemory(true);
+            } else if (argument.equals(MATCHEXCLUDESPATH_ARG)) {
+                iter.remove();
+                migration.setMatchExcludesAgainstPathName(true);
             }
         }
 


=====================================
src/main/java/org/apache/tomcat/jakartaee/MigrationTask.java
=====================================
@@ -39,6 +39,7 @@ public class MigrationTask extends Task {
     private String profile = EESpecProfiles.TOMCAT.toString();
     private boolean zipInMemory = false;
     private String excludes;
+    private boolean matchExcludesAgainstPathName;
 
     /**
      * Set the source file.
@@ -82,6 +83,14 @@ public class MigrationTask extends Task {
         this.excludes = excludes;
     }
 
+    /**
+     * Enable exclude matching against the path name.
+     * @param matchExcludesAgainstPathName true to match excludes against the path name instead of the file name
+     */
+    public void setMatchExcludesAgainstPathName(boolean matchExcludesAgainstPathName) {
+        this.matchExcludesAgainstPathName = matchExcludesAgainstPathName;
+    }
+
     @Override
     public void execute() throws BuildException {
         // redirect the log messages to Ant
@@ -105,6 +114,7 @@ public class MigrationTask extends Task {
         migration.setDestination(dest);
         migration.setEESpecProfile(profile);
         migration.setZipInMemory(zipInMemory);
+        migration.setMatchExcludesAgainstPathName(matchExcludesAgainstPathName);
         if (this.excludes != null) {
             String[] excludes= this.excludes.split(",");
             for (String exclude : excludes) {


=====================================
src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties
=====================================
@@ -26,6 +26,7 @@ migration.alreadyRunning=Migration is already running
 migration.done=Migration completed successfully in [{0}] milliseconds
 migration.error=Error performing migration
 migration.execute=Performing migration from source [{0}] to destination [{1}] with Jakarta EE specification profile [{2}]
+migration.jdk8303866=Due to size of [{0}], migrated JAR will fail if used in a JDK without the fix for https://bugs.openjdk.org/browse/JDK-8303866 - Using an in memory migration rather than a streaming migration may work-around the issue.
 migration.mkdirError=Error creating destination directory [{0}]a
 migration.skip=Migration skipped for archive [{0}] because it is excluded (the archive was copied unchanged)
 migration.skipSignatureFile=Drop cryptographic signature file [{0}]
@@ -49,7 +50,12 @@ where options includes:\n\
 \                exception while processing a zip file, enabling this option\n\
 \                may workaround the issue by processing the archive in memory.\n\
 \                This requires more memory than a streaming approach but is\n\
-\                able to handle a wider range of zip archive structures.
+\                able to handle a wider range of zip archive structures.\n\
+\    -matchExcludesAgainstPathName\n\
+\                By default, exclusions are matched against file name. If this\n\
+\                option is enabled, exclusions will be matched against the full\n\
+\                path.
+
 migration.warnSignatureRemoval=Removed cryptographic signature from JAR file
 
 passThroughConverter.noConversion=No conversion necessary for [{0}]


=====================================
src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
=====================================
@@ -139,6 +139,39 @@ public class MigrationTest {
         String migratedSource = FileUtils.readFileToString(migratedFile, StandardCharsets.UTF_8);
         assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet"));
         assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet"));
+
+        File migratedSpiFile = new File("target/test-classes/migration/javax.enterprise.inject.spi.Extension");
+        assertTrue("SPI file has not been migrated by renaming", migratedSpiFile.exists());
+
+        String migratedSpiSource = FileUtils.readFileToString(migratedSpiFile, StandardCharsets.UTF_8);
+        assertTrue("SPI file not copied with content", migratedSpiSource.contains("some.class.Reference"));
+    }
+
+    @Test
+    public void testMigrateDirectoryWithEeProfile() throws Exception {
+        File sourceDirectory = new File("src/test/resources");
+        File destinationDirectory = new File("target/test-classes/migration-ee");
+
+        Migration migration = new Migration();
+        migration.setEESpecProfile(EESpecProfiles.EE);
+        migration.setSource(sourceDirectory);
+        migration.setDestination(destinationDirectory);
+        migration.execute();
+
+        assertTrue("Destination directory not found", destinationDirectory.exists());
+
+        File migratedFile = new File(destinationDirectory, "HelloServlet.java");
+        assertTrue("Migrated file not found", migratedFile.exists());
+
+        String migratedSource = FileUtils.readFileToString(migratedFile, StandardCharsets.UTF_8);
+        assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet"));
+        assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet"));
+
+        File migratedSpiFile = new File(destinationDirectory, "jakarta.enterprise.inject.spi.Extension");
+        assertTrue("SPI file not migrated by renaming", migratedSpiFile.exists());
+
+        String migratedSpiSource = FileUtils.readFileToString(migratedSpiFile, StandardCharsets.UTF_8);
+        assertTrue("SPI file not copied with content", migratedSpiSource.contains("some.class.Reference"));
     }
 
     @Test


=====================================
src/test/resources/javax.enterprise.inject.spi.Extension
=====================================
@@ -0,0 +1 @@
+some.class.Reference
\ No newline at end of file



View it on GitLab: https://salsa.debian.org/java-team/tomcat-jakartaee-migration/-/commit/9c5b0b44176a46183dbbfbc2d4dfa6c1de688ff3

-- 
View it on GitLab: https://salsa.debian.org/java-team/tomcat-jakartaee-migration/-/commit/9c5b0b44176a46183dbbfbc2d4dfa6c1de688ff3
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20231010/04fdc070/attachment.htm>


More information about the pkg-java-commits mailing list