You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by eb...@apache.org on 2020/04/19 00:08:10 UTC

[tomcat-jakartaee-migration] branch master updated: Test the migration of a jar file

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

ebourg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e3267b  Test the migration of a jar file
3e3267b is described below

commit 3e3267b72726287ca4620916893afa9fb84b0cf5
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Sun Apr 19 02:06:43 2020 +0200

    Test the migration of a jar file
---
 pom.xml                                            | 23 +++++++++++++++++++
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 26 ++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/pom.xml b/pom.xml
index eb2a753..b66f833 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,6 +119,29 @@
 
     <plugins>
       <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>3.0.0</version>
+        <executions>
+          <execution>
+            <id>create-test-jars</id>
+            <phase>process-test-classes</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <target>
+                <jar destfile="target/test-classes/cgi-api.jar" basedir="target/test-classes" includes="**/CommonGatewayInterface*"/>
+                <jar destfile="target/test-classes/hellocgi.jar" basedir="target/test-classes" includes="**/HelloCGI*">
+                  <manifest>
+                    <attribute name="Implementation-Version" value="1.2.3"/>
+                  </manifest>
+                </jar>
+              </target>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <reuseForks>false</reuseForks>
diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index 8ed4310..9ba59b0 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -18,7 +18,10 @@
 package org.apache.tomcat.jakartaee;
 
 import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.nio.charset.StandardCharsets;
+import java.util.jar.JarFile;
 
 import org.apache.commons.io.FileUtils;
 import org.junit.After;
@@ -137,4 +140,27 @@ public class MigrationTest {
         Class<?> cls = Class.forName("org.apache.tomcat.jakartaee.HelloCGI");
         assertEquals("jakarta.servlet.CommonGatewayInterface", cls.getSuperclass().getName());
     }
+
+    @Test
+    public void testMigrateJarFile() throws Exception {
+        File jarFile = new File("target/test-classes/hellocgi.jar");
+
+        Migration migration = new Migration();
+        migration.setSource(jarFile);
+        migration.setDestination(jarFile);
+        migration.execute();
+
+        File cgiapiFile = new File("target/test-classes/cgi-api.jar");
+        URLClassLoader classloader = new URLClassLoader(new URL[]{jarFile.toURI().toURL(), cgiapiFile.toURI().toURL()},ClassLoader.getSystemClassLoader().getParent());
+
+        Class<?> cls = Class.forName("org.apache.tomcat.jakartaee.HelloCGI", true, classloader);
+        assertEquals("jakarta.servlet.CommonGatewayInterface", cls.getSuperclass().getName());
+
+        // check the modification of the Implementation-Version manifest attribute
+        JarFile jar = new JarFile(jarFile);
+        String implementationVersion = jar.getManifest().getMainAttributes().getValue("Implementation-Version");
+        assertNotNull("Missing Implementation-Version manifest attribute", implementationVersion);
+        assertNotEquals("Implementation-Version manifest attribute not changed", "1.2.3", implementationVersion);
+        assertTrue("Implementation-Version manifest attribute doesn't match the expected pattern", implementationVersion.matches("1\\.2\\.3-migrated-[\\d\\.]+.*"));
+    }
 }


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