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/07 00:56:12 UTC

[tomcat-jakartaee-migration] branch master updated (397ff8a -> c4e5c18)

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

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


    from 397ff8a  Travis integration
     new c8afe9b  One line log messages when running from the command line
     new 07b9ad1  Test with an alternative profile
     new 703262f  Moved EESpecProfile to the top level
     new e58d4c5  Renamed getEESpecLevel() to getEESpecProfile()
     new 39ada70  Turned the migration profile into an instance field of the Migration class
     new ec70314  Added a -verbose option
     new 3618367  Renamed NoOpConverter to PassThroughConverter
     new f69a7d9  Support inplace file migration
     new 884aa46  Moved common stream operation methods to the Util class
     new c4e5c18  Test invalid options

The 10 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:
 .../apache/tomcat/jakartaee/ClassConverter.java    |  4 +-
 .../org/apache/tomcat/jakartaee/Converter.java     |  2 +-
 .../org/apache/tomcat/jakartaee/EESpecProfile.java | 50 +++++++++++++
 .../org/apache/tomcat/jakartaee/Migration.java     | 84 +++++++++++++++++-----
 ...oOpConverter.java => PassThroughConverter.java} | 10 +--
 .../org/apache/tomcat/jakartaee/TextConverter.java | 24 ++-----
 .../java/org/apache/tomcat/jakartaee/Util.java     | 66 +++++------------
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 52 ++++++++++++++
 .../tomcat/jakartaee/NoExitSecurityManager.java}   | 64 +++++++++--------
 9 files changed, 234 insertions(+), 122 deletions(-)
 create mode 100644 src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
 rename src/main/java/org/apache/tomcat/jakartaee/{NoOpConverter.java => PassThroughConverter.java} (79%)
 copy src/{main/java/org/apache/tomcat/jakartaee/Converter.java => test/java/org/apache/tomcat/jakartaee/NoExitSecurityManager.java} (67%)


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


[tomcat-jakartaee-migration] 04/10: Renamed getEESpecLevel() to getEESpecProfile()

Posted by eb...@apache.org.
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

commit e58d4c5f5f13cfa7221cea762e046ee9df7c4936
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 23:16:29 2020 +0200

    Renamed getEESpecLevel() to getEESpecProfile()
---
 src/main/java/org/apache/tomcat/jakartaee/Migration.java | 2 +-
 src/main/java/org/apache/tomcat/jakartaee/Util.java      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index e671b98..dcaec1e 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -76,7 +76,7 @@ public class Migration {
 
     public boolean execute() throws IOException {
         logger.log(Level.INFO, sm.getString("migration.execute", source.getAbsolutePath(),
-                destination.getAbsolutePath(), Util.getEESpecLevel().toString()));
+                destination.getAbsolutePath(), Util.getEESpecProfile().toString()));
         boolean result = true;
         long t1 = System.nanoTime();
         if (source.isDirectory()) {
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Util.java b/src/main/java/org/apache/tomcat/jakartaee/Util.java
index b879e92..af0bb12 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Util.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Util.java
@@ -44,7 +44,7 @@ public class Util {
      * Get the Jakarta EE profile being used.
      * @return the profile
      */
-    public static EESpecProfile getEESpecLevel() {
+    public static EESpecProfile getEESpecProfile() {
         return profile;
     }
 


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


[tomcat-jakartaee-migration] 10/10: Test invalid options

Posted by eb...@apache.org.
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

commit c4e5c1840652d44523b38b49c3057187bfef0efb
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Tue Apr 7 02:52:51 2020 +0200

    Test invalid options
---
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 25 +++++++++++++++
 .../tomcat/jakartaee/NoExitSecurityManager.java    | 36 ++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index 80e595d..8ed7f81 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -20,12 +20,24 @@ package org.apache.tomcat.jakartaee;
 import java.io.File;
 
 import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
 
 public class MigrationTest {
 
+    @Before
+    public void setUp() {
+        System.setSecurityManager(new NoExitSecurityManager());
+    }
+
+    @After
+    public void tearDown() {
+        System.setSecurityManager(null);
+    }
+
     @Test
     public void testMigrateSingleSourceFile() throws Exception {
         File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
@@ -64,4 +76,17 @@ public class MigrationTest {
         assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet"));
         assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet"));
     }
+
+    @Test
+    public void testInvalidOption() throws Exception {
+        File sourceFile = new File("target/test-classes/HelloServlet.java");
+        File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
+
+        try {
+            Migration.main(new String[] {"-invalid", sourceFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
+            fail("No error code returned");
+        } catch (SecurityException e) {
+            assertEquals("error code", "1", e.getMessage());
+        }
+    }
 }
diff --git a/src/test/java/org/apache/tomcat/jakartaee/NoExitSecurityManager.java b/src/test/java/org/apache/tomcat/jakartaee/NoExitSecurityManager.java
new file mode 100644
index 0000000..446e96c
--- /dev/null
+++ b/src/test/java/org/apache/tomcat/jakartaee/NoExitSecurityManager.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.jakartaee;
+
+import java.security.Permission;
+
+public class NoExitSecurityManager extends SecurityManager {
+
+    @Override
+    public void checkPermission(Permission perm) {
+    }
+
+    @Override
+    public void checkPermission(Permission perm, Object context) {
+    }
+    
+    @Override
+    public void checkExit(int status) {
+        throw new SecurityException("" + status);
+    }
+}


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


[tomcat-jakartaee-migration] 06/10: Added a -verbose option

Posted by eb...@apache.org.
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

commit ec703144edb902b1db9f7298165684fd912e45f8
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 23:47:43 2020 +0200

    Added a -verbose option
---
 .../org/apache/tomcat/jakartaee/Migration.java     | 24 ++++++++++++++--------
 .../org/apache/tomcat/jakartaee/MigrationTest.java |  2 +-
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 5c8d41b..75d3007 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -256,27 +257,34 @@ public class Migration {
     public static void main(String[] args) {
         System.setProperty("java.util.logging.SimpleFormatter.format", "%5$s%n");
 
+        List<String> arguments = new ArrayList<>(Arrays.asList(args));
+        if (arguments.contains("-verbose")) {
+            Logger.getGlobal().getParent().getHandlers()[0].setLevel(Level.FINE);
+            Logger.getGlobal().getParent().setLevel(Level.FINE);
+            arguments.remove("-verbose");
+        }
+
         Migration migration = new Migration();
 
         boolean valid = false;
         String source = null;
         String dest = null;
-        if (args.length == 3) {
-            if (args[0].startsWith(PROFILE_ARG)) {
-                source = args[1];
-                dest = args[2];
+        if (arguments.size() == 3) {
+            if (arguments.get(0).startsWith(PROFILE_ARG)) {
+                source = arguments.get(1);
+                dest = arguments.get(2);
                 valid = true;
                 try {
-                    migration.setEESpecProfile(EESpecProfile.valueOf(args[0].substring(PROFILE_ARG.length())));
+                    migration.setEESpecProfile(EESpecProfile.valueOf(arguments.get(0).substring(PROFILE_ARG.length())));
                 } catch (IllegalArgumentException e) {
                     // Invalid profile value
                     valid = false;
                 }
             }
         }
-        if (args.length == 2) {
-            source = args[0];
-            dest = args[1];
+        if (arguments.size() == 2) {
+            source = arguments.get(0);
+            dest = arguments.get(1);
             valid = true;
         }
         if (!valid) {
diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index fa0fa74..5ddda03 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -41,7 +41,7 @@ public class MigrationTest {
     @Test
     public void testMigrateSingleSourceFileWithProfile() throws Exception {
         File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
-        Migration.main(new String[] {"-profile=EE", "target/test-classes/HelloServlet.java", migratedFile.getAbsolutePath()});
+        Migration.main(new String[] {"-verbose", "-profile=EE", "target/test-classes/HelloServlet.java", migratedFile.getAbsolutePath()});
 
         assertTrue("Migrated file not found", migratedFile.exists());
 


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


Re: [tomcat-jakartaee-migration] branch master updated (397ff8a -> c4e5c18)

Posted by Emmanuel Bourg <eb...@apache.org>.
Le 07/04/2020 à 12:24, Mark Thomas a écrit :

> +1 to all of the above.

Thank you for the review.


>>      new 3618367  Renamed NoOpConverter to PassThroughConverter
> 
> What problem does this commit address and/or what new feature does it
> add? It looks more like a personal preference for a different name to me.

I've found "NoOp" to be confusing, at first glance based on the name I
thought it was an empty implementation of the Converter interface, and I
was wrong since it actually copies the source unmodified. I think the
term "pass-through" better describes the behavior of the converter.


> I think there is less likelihood of conflict if there is a technical
> justification for a change, and, if the justification is not / might not
> be obvious then mention it in the commit message.

Ok, I tend to write concise commit messages but I'll try to elaborate in
this kind of situation.


> This tests creates a file but doesn't remove it afterwards. Tests that
> create files should remove those files on completion. It might be worth
> considering creating such files in a temporary location rather than in
> the source tree.

I agree this can be improved.


> Generally, the code was clean (no IDE warnings) and the aim is to keep
> it this way as it enables errors to be spotted more easily. This is no
> longer the case after the above changes. The unused charset parameter is
> flagged as a warning.

Sorry, for some reason my IDE was misconfigured and no longer
highlighted unused code. I'll fix that.

Emmanuel Bourg

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


Re: [tomcat-jakartaee-migration] branch master updated (397ff8a -> c4e5c18)

Posted by Mark Thomas <ma...@apache.org>.
On 07/04/2020 01:56, ebourg@apache.org wrote:
> This is an automated email from the ASF dual-hosted git repository.
> 
> ebourg pushed a change to branch master
> in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git.
> 
> 
>     from 397ff8a  Travis integration
>      new c8afe9b  One line log messages when running from the command line
>      new 07b9ad1  Test with an alternative profile
>      new 703262f  Moved EESpecProfile to the top level
>      new e58d4c5  Renamed getEESpecLevel() to getEESpecProfile()
>      new 39ada70  Turned the migration profile into an instance field of the Migration class
>      new ec70314  Added a -verbose option

+1 to all of the above.

>      new 3618367  Renamed NoOpConverter to PassThroughConverter

What problem does this commit address and/or what new feature does it
add? It looks more like a personal preference for a different name to me.

My main concern here is if two (or more) committers feel strongly about
an issue of personal preference the situation can escalate.

I think there is less likelihood of conflict if there is a technical
justification for a change, and, if the justification is not / might not
be obvious then mention it in the commit message.

>      new f69a7d9  Support inplace file migration

This tests creates a file but doesn't remove it afterwards. Tests that
create files should remove those files on completion. It might be worth
considering creating such files in a temporary location rather than in
the source tree.

>      new 884aa46  Moved common stream operation methods to the Util class

The charset parameter on Util.toString() appears to be unused.

>      new c4e5c18  Test invalid options

Generally, the code was clean (no IDE warnings) and the aim is to keep
it this way as it enables errors to be spotted more easily. This is no
longer the case after the above changes. The unused charset parameter is
flagged as a warning.

Mark

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


[tomcat-jakartaee-migration] 08/10: Support inplace file migration

Posted by eb...@apache.org.
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

commit f69a7d986c0105d392ac3b33f2717a6a6263ce5d
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Tue Apr 7 01:16:49 2020 +0200

    Support inplace file migration
---
 .../org/apache/tomcat/jakartaee/Migration.java     | 26 +++++++++++++++++++---
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 15 +++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 422e723..4ba79bd 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -16,6 +16,7 @@
  */
 package org.apache.tomcat.jakartaee;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -144,10 +145,29 @@ public class Migration {
 
 
     private boolean migrateFile(File src, File dest) throws IOException {
-        try (InputStream is = new FileInputStream(src);
-                OutputStream os = new FileOutputStream(dest)) {
-            return migrateStream(src.getName(), is, os);
+        boolean result = false;
+
+        boolean inplace = src.equals(dest);
+        if (!inplace) {
+            try (InputStream is = new FileInputStream(src);
+                 OutputStream os = new FileOutputStream(dest)) {
+                result = migrateStream(src.getName(), is, os);
+            }
+        } else {
+            File tmp = new File(dest.getParentFile(), dest.getName() + ".tmp");
+
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream((int) (src.length() * 1.05));
+
+            try (InputStream is = new FileInputStream(src)) {
+                result = migrateStream(src.getName(), is, buffer);
+            }
+
+            try (OutputStream os = new FileOutputStream(dest)) {
+                os.write(buffer.toByteArray());
+            }
         }
+
+        return result;
     }
 
 
diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index 5ddda03..80e595d 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -49,4 +49,19 @@ public class MigrationTest {
         assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet"));
         assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet"));
     }
+
+    @Test
+    public void testMigrateSingleSourceFileInPlace() throws Exception {
+        File sourceFile = new File("target/test-classes/HelloServlet.java");
+        File migratedFile = new File("target/test-classes/HelloServlet.inplace.java");
+        FileUtils.copyFile(sourceFile, migratedFile);
+
+        Migration.main(new String[] {"-profile=EE", migratedFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
+
+        assertTrue("Migrated file not found", migratedFile.exists());
+
+        String migratedSource = FileUtils.readFileToString(migratedFile);
+        assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet"));
+        assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet"));
+    }
 }


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


[tomcat-jakartaee-migration] 01/10: One line log messages when running from the command line

Posted by eb...@apache.org.
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

commit c8afe9b579d312d8dc7f1be97e158e304c1230b4
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 22:45:12 2020 +0200

    One line log messages when running from the command line
---
 src/main/java/org/apache/tomcat/jakartaee/Migration.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 5d8fdf1..e671b98 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -236,6 +236,8 @@ public class Migration {
     private static final String PROFILE_ARG = "-profile=";
 
     public static void main(String[] args) {
+        System.setProperty("java.util.logging.SimpleFormatter.format", "%5$s%n");
+
         boolean valid = false;
         String source = null;
         String dest = null;


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


[tomcat-jakartaee-migration] 07/10: Renamed NoOpConverter to PassThroughConverter

Posted by eb...@apache.org.
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

commit 3618367bef264a5f34ff7eb046843dee1397a91e
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 23:51:32 2020 +0200

    Renamed NoOpConverter to PassThroughConverter
---
 src/main/java/org/apache/tomcat/jakartaee/Migration.java              | 4 ++--
 .../jakartaee/{NoOpConverter.java => PassThroughConverter.java}       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 75d3007..422e723 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -57,8 +57,8 @@ public class Migration {
         converters.add(new TextConverter());
         converters.add(new ClassConverter());
 
-        // Final converter is the NoOpConverter
-        converters.add(new NoOpConverter());
+        // Final converter is the pass-through converter
+        converters.add(new PassThroughConverter());
     }
 
     /**
diff --git a/src/main/java/org/apache/tomcat/jakartaee/NoOpConverter.java b/src/main/java/org/apache/tomcat/jakartaee/PassThroughConverter.java
similarity index 96%
rename from src/main/java/org/apache/tomcat/jakartaee/NoOpConverter.java
rename to src/main/java/org/apache/tomcat/jakartaee/PassThroughConverter.java
index aeedb00..9b44ca5 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/NoOpConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/PassThroughConverter.java
@@ -20,7 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
-public class NoOpConverter implements Converter {
+public class PassThroughConverter implements Converter {
 
     @Override
     public boolean accepts(String filename) {


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


[tomcat-jakartaee-migration] 02/10: Test with an alternative profile

Posted by eb...@apache.org.
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

commit 07b9ad1bb056706922985b9f6eb3a13bc11b98cd
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 23:01:41 2020 +0200

    Test with an alternative profile
---
 src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index a531d1d..fa0fa74 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -37,4 +37,16 @@ public class MigrationTest {
         assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet"));
         assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet"));
     }
+
+    @Test
+    public void testMigrateSingleSourceFileWithProfile() throws Exception {
+        File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
+        Migration.main(new String[] {"-profile=EE", "target/test-classes/HelloServlet.java", migratedFile.getAbsolutePath()});
+
+        assertTrue("Migrated file not found", migratedFile.exists());
+
+        String migratedSource = FileUtils.readFileToString(migratedFile);
+        assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet"));
+        assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet"));
+    }
 }


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


[tomcat-jakartaee-migration] 03/10: Moved EESpecProfile to the top level

Posted by eb...@apache.org.
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

commit 703262fce1cf10af87715696e38d3e6328594f0d
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 23:13:00 2020 +0200

    Moved EESpecProfile to the top level
---
 .../org/apache/tomcat/jakartaee/EESpecProfile.java | 44 ++++++++++++++++++++++
 .../java/org/apache/tomcat/jakartaee/Util.java     | 18 +--------
 2 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java b/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
new file mode 100644
index 0000000..3d77867
--- /dev/null
+++ b/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.jakartaee;
+
+import java.util.regex.Pattern;
+
+/**
+ * Specification profile defining the replacements performed.
+ */
+public enum EESpecProfile {
+
+    TOMCAT("javax([/\\.](annotation|ejb|el|mail|persistence|security[/\\.]auth[/\\.]message|servlet|transaction|websocket))"),
+
+    EE("javax([/\\.](activation|annotation|decorator|ejb|el|enterprise|json|interceptor|inject|mail|persistence|"
+                + "security[/\\.]auth[/\\.]message|servlet|transaction|validation|websocket|ws[/\\.]rs|"
+                + "xml[/\\.](bind|namespace|rpc|soap|stream|ws|XMLConstants)))");
+
+    private Pattern pattern;
+
+    EESpecProfile(String pattern) {
+        this.pattern = Pattern.compile(pattern);
+    }
+
+    /**
+     * Return the replacement pattern for this profile.
+     */
+    public Pattern getPattern() {
+        return pattern;
+    }
+}
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Util.java b/src/main/java/org/apache/tomcat/jakartaee/Util.java
index 2a2ae81..b879e92 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Util.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Util.java
@@ -22,18 +22,7 @@ import java.util.regex.Pattern;
 
 public class Util {
 
-    public enum EESpecProfile { TOMCAT, EE };
-
-    private static final Pattern TOMCAT_PATTERN = Pattern.compile(
-            "javax([/\\.](annotation|ejb|el|mail|persistence|security[/\\.]auth[/\\.]message|servlet|transaction|websocket))");
-
-    private static final Pattern EE_PATTERN = Pattern.compile(
-            "javax([/\\.](activation|annotation|decorator|ejb|el|enterprise|json|interceptor|inject|mail|persistence|"
-            + "security[/\\.]auth[/\\.]message|servlet|transaction|validation|websocket|ws[/\\.]rs|"
-            + "xml[/\\.](bind|namespace|rpc|soap|stream|ws|XMLConstants)))");
-
     private static EESpecProfile profile = EESpecProfile.TOMCAT;
-    private static Pattern pattern = TOMCAT_PATTERN;
 
     /**
      * Set the Jakarta EE specifications that should be used.
@@ -49,11 +38,6 @@ public class Util {
      */
     public static void setEESpecProfile(EESpecProfile profile) {
         Util.profile = profile;
-        if (profile == EESpecProfile.TOMCAT) {
-            pattern = TOMCAT_PATTERN;
-        } else if (profile == EESpecProfile.EE) {
-            pattern = EE_PATTERN;
-        }
     }
 
     /**
@@ -82,7 +66,7 @@ public class Util {
 
 
     public static String convert(String name) {
-        Matcher m = pattern.matcher(name);
+        Matcher m = profile.getPattern().matcher(name);
         return m.replaceAll("jakarta$1");
     }
 


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


[tomcat-jakartaee-migration] 09/10: Moved common stream operation methods to the Util class

Posted by eb...@apache.org.
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

commit 884aa46156a8d12634737e4bf1d73c3afc8cd51c
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Tue Apr 7 02:37:29 2020 +0200

    Moved common stream operation methods to the Util class
---
 .../tomcat/jakartaee/PassThroughConverter.java     |  6 +-----
 .../org/apache/tomcat/jakartaee/TextConverter.java | 22 ++++------------------
 .../java/org/apache/tomcat/jakartaee/Util.java     | 21 +++++++++++++++++++++
 3 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/PassThroughConverter.java b/src/main/java/org/apache/tomcat/jakartaee/PassThroughConverter.java
index 9b44ca5..24c01f9 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/PassThroughConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/PassThroughConverter.java
@@ -31,10 +31,6 @@ public class PassThroughConverter implements Converter {
     @Override
     public void convert(InputStream src, OutputStream dest, EESpecProfile profile) throws IOException {
         // This simply copies the source to the destination
-        byte[] buf = new byte[8192];
-        int numRead;
-        while ((numRead = src.read(buf)) >= 0) {
-            dest.write(buf, 0, numRead);
-        }
+        Util.copy(src, dest);
     }
 }
diff --git a/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java b/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java
index e0fdc2f..5ad1b0b 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java
@@ -17,7 +17,6 @@
 package org.apache.tomcat.jakartaee;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -60,25 +59,12 @@ public class TextConverter implements Converter {
      */
     @Override
     public void convert(InputStream src, OutputStream dest, EESpecProfile profile) throws IOException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        flow(src, baos);
-
-        String srcString = new String(baos.toByteArray(), StandardCharsets.ISO_8859_1);
-
+        String srcString = Util.toString(src, StandardCharsets.ISO_8859_1);
         String destString = profile.convert(srcString);
 
-        ByteArrayInputStream bais = new ByteArrayInputStream(destString.getBytes(StandardCharsets.ISO_8859_1));
-        flow (bais, dest);
-    }
-
+        dest.write(destString.getBytes());
 
-    private static void flow(InputStream is, OutputStream os) throws IOException {
-        byte[] buf = new byte[8192];
-        int numRead;
-        while ( (numRead = is.read(buf) ) >= 0) {
-            if (os != null) {
-                os.write(buf, 0, numRead);
-            }
-        }
+        ByteArrayInputStream bais = new ByteArrayInputStream(destString.getBytes(StandardCharsets.ISO_8859_1));
+        Util.copy(bais, dest);
     }
 }
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Util.java b/src/main/java/org/apache/tomcat/jakartaee/Util.java
index edd7203..7189d8a 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Util.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Util.java
@@ -16,6 +16,12 @@
  */
 package org.apache.tomcat.jakartaee;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.Locale;
 
 public class Util {
@@ -36,6 +42,21 @@ public class Util {
         return filename.substring(lastPeriod + 1).toLowerCase(Locale.ENGLISH);
     }
 
+    public static void copy(InputStream is, OutputStream os) throws IOException {
+        byte[] buf = new byte[8192];
+        int numRead;
+        while ( (numRead = is.read(buf) ) >= 0) {
+            os.write(buf, 0, numRead);
+        }
+    }
+
+    public static String toString(InputStream is, Charset charset) throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        Util.copy(is, baos);
+
+        return new String(baos.toByteArray(), StandardCharsets.ISO_8859_1);
+    }
+
     private Util() {
         // Hide default constructor. Utility class.
     }


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


[tomcat-jakartaee-migration] 05/10: Turned the migration profile into an instance field of the Migration class

Posted by eb...@apache.org.
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

commit 39ada7099918e7f571e4119b200e79f242cf72a2
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 23:28:39 2020 +0200

    Turned the migration profile into an instance field of the Migration class
---
 .../apache/tomcat/jakartaee/ClassConverter.java    |  4 +--
 .../org/apache/tomcat/jakartaee/Converter.java     |  2 +-
 .../org/apache/tomcat/jakartaee/EESpecProfile.java |  6 ++++
 .../org/apache/tomcat/jakartaee/Migration.java     | 30 +++++++++++++++----
 .../org/apache/tomcat/jakartaee/NoOpConverter.java |  2 +-
 .../org/apache/tomcat/jakartaee/TextConverter.java |  4 +--
 .../java/org/apache/tomcat/jakartaee/Util.java     | 35 ----------------------
 7 files changed, 37 insertions(+), 46 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java b/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
index 4b7777b..9d398d7 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
@@ -35,7 +35,7 @@ public class ClassConverter implements Converter {
 
 
     @Override
-    public void convert(InputStream src, OutputStream dest) throws IOException {
+    public void convert(InputStream src, OutputStream dest, EESpecProfile profile) throws IOException {
 
         ClassParser parser = new ClassParser(src, "unknown");
         JavaClass javaClass = parser.parse();
@@ -46,7 +46,7 @@ public class ClassConverter implements Converter {
             if (constantPool[i] instanceof ConstantUtf8) {
                 ConstantUtf8 c = (ConstantUtf8) constantPool[i];
                 String str = c.getBytes();
-                c = new ConstantUtf8(Util.convert(str));
+                c = new ConstantUtf8(profile.convert(str));
                 constantPool[i] = c;
             }
         }
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Converter.java b/src/main/java/org/apache/tomcat/jakartaee/Converter.java
index f3d62ec..92ef1dd 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Converter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Converter.java
@@ -24,5 +24,5 @@ public interface Converter {
 
     boolean accepts(String filename);
 
-    void convert(InputStream src, OutputStream dest) throws IOException;
+    void convert(InputStream src, OutputStream dest, EESpecProfile profile) throws IOException;
 }
diff --git a/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java b/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
index 3d77867..45aed81 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
@@ -16,6 +16,7 @@
  */
 package org.apache.tomcat.jakartaee;
 
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
@@ -41,4 +42,9 @@ public enum EESpecProfile {
     public Pattern getPattern() {
         return pattern;
     }
+
+    public String convert(String name) {
+        Matcher m = pattern.matcher(name);
+        return m.replaceAll("jakarta$1");
+    }
 }
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index dcaec1e..5c8d41b 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -44,6 +44,7 @@ public class Migration {
     private static final Logger logger = Logger.getLogger(Migration.class.getCanonicalName());
     private static final StringManager sm = StringManager.getManager(Migration.class);
 
+    private EESpecProfile profile = EESpecProfile.TOMCAT;
     private File source;
     private File destination;
     private final List<Converter> converters;
@@ -59,6 +60,23 @@ public class Migration {
         converters.add(new NoOpConverter());
     }
 
+    /**
+     * Set the Jakarta EE specifications that should be used.
+     *
+     * @param profile the Jakarta EE specification profile
+     */
+    public void setEESpecProfile(EESpecProfile profile) {
+        this.profile = profile;
+    }
+
+    /**
+     * Get the Jakarta EE profile being used.
+     *
+     * @return the profile
+     */
+    public EESpecProfile getEESpecProfile() {
+        return profile;
+    }
 
     public void setSource(File source) {
         if (!source.canRead()) {
@@ -76,7 +94,7 @@ public class Migration {
 
     public boolean execute() throws IOException {
         logger.log(Level.INFO, sm.getString("migration.execute", source.getAbsolutePath(),
-                destination.getAbsolutePath(), Util.getEESpecProfile().toString()));
+                destination.getAbsolutePath(), profile.toString()));
         boolean result = true;
         long t1 = System.nanoTime();
         if (source.isDirectory()) {
@@ -157,7 +175,7 @@ public class Migration {
                     logger.log(Level.FINE, sm.getString("migration.skipSignatureFile", sourceName));
                     continue;
                 }
-                String destName = Util.convert(sourceName);
+                String destName = profile.convert(sourceName);
                 JarEntry destEntry = new JarEntry(destName);
                 jarOs.putNextEntry(destEntry);
                 result = result && migrateStream(destEntry.getName(), jarIs, jarOs);
@@ -181,7 +199,7 @@ public class Migration {
             logger.log(Level.FINE, sm.getString("migration.stream", name));
             for (Converter converter : converters) {
                 if (converter.accepts(name)) {
-                    converter.convert(src, dest);
+                    converter.convert(src, dest, profile);
                     break;
                 }
             }
@@ -238,6 +256,8 @@ public class Migration {
     public static void main(String[] args) {
         System.setProperty("java.util.logging.SimpleFormatter.format", "%5$s%n");
 
+        Migration migration = new Migration();
+
         boolean valid = false;
         String source = null;
         String dest = null;
@@ -247,7 +267,7 @@ public class Migration {
                 dest = args[2];
                 valid = true;
                 try {
-                    Util.setEESpecProfile(args[0].substring(PROFILE_ARG.length()));
+                    migration.setEESpecProfile(EESpecProfile.valueOf(args[0].substring(PROFILE_ARG.length())));
                 } catch (IllegalArgumentException e) {
                     // Invalid profile value
                     valid = false;
@@ -263,7 +283,7 @@ public class Migration {
             usage();
             System.exit(1);
         }
-        Migration migration = new Migration();
+
         migration.setSource(new File(source));
         migration.setDestination(new File(dest));
         boolean result = false;
diff --git a/src/main/java/org/apache/tomcat/jakartaee/NoOpConverter.java b/src/main/java/org/apache/tomcat/jakartaee/NoOpConverter.java
index cd1152a..aeedb00 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/NoOpConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/NoOpConverter.java
@@ -29,7 +29,7 @@ public class NoOpConverter implements Converter {
     }
 
     @Override
-    public void convert(InputStream src, OutputStream dest) throws IOException {
+    public void convert(InputStream src, OutputStream dest, EESpecProfile profile) throws IOException {
         // This simply copies the source to the destination
         byte[] buf = new byte[8192];
         int numRead;
diff --git a/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java b/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java
index d0a0db2..e0fdc2f 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/TextConverter.java
@@ -59,13 +59,13 @@ public class TextConverter implements Converter {
      * execution.
      */
     @Override
-    public void convert(InputStream src, OutputStream dest) throws IOException {
+    public void convert(InputStream src, OutputStream dest, EESpecProfile profile) throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         flow(src, baos);
 
         String srcString = new String(baos.toByteArray(), StandardCharsets.ISO_8859_1);
 
-        String destString = Util.convert(srcString);
+        String destString = profile.convert(srcString);
 
         ByteArrayInputStream bais = new ByteArrayInputStream(destString.getBytes(StandardCharsets.ISO_8859_1));
         flow (bais, dest);
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Util.java b/src/main/java/org/apache/tomcat/jakartaee/Util.java
index af0bb12..edd7203 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Util.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Util.java
@@ -17,37 +17,9 @@
 package org.apache.tomcat.jakartaee;
 
 import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 public class Util {
 
-    private static EESpecProfile profile = EESpecProfile.TOMCAT;
-
-    /**
-     * Set the Jakarta EE specifications that should be used.
-     * @param profile the Jakarta EE specification profile
-     */
-    public static void setEESpecProfile(String profile) {
-        setEESpecProfile(EESpecProfile.valueOf(profile));
-    }
-
-    /**
-     * Set the Jakarta EE specifications that should be used.
-     * @param profile the Jakarta EE specification profile
-     */
-    public static void setEESpecProfile(EESpecProfile profile) {
-        Util.profile = profile;
-    }
-
-    /**
-     * Get the Jakarta EE profile being used.
-     * @return the profile
-     */
-    public static EESpecProfile getEESpecProfile() {
-        return profile;
-    }
-
     /**
      * Get the extension of a filename
      * <p>
@@ -64,13 +36,6 @@ public class Util {
         return filename.substring(lastPeriod + 1).toLowerCase(Locale.ENGLISH);
     }
 
-
-    public static String convert(String name) {
-        Matcher m = profile.getPattern().matcher(name);
-        return m.replaceAll("jakarta$1");
-    }
-
-
     private Util() {
         // Hide default constructor. Utility class.
     }


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