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/08 21:32:36 UTC

[tomcat-jakartaee-migration] branch master updated (54c1fe1 -> 70a9455)

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 54c1fe1  Avoid deprecation warning
     new 0a52c66  Split the CLI handling from the main migration class
     new 44521e8  Ant task for the migration tool
     new 75de6b5  Test with an invalid profile
     new 70a9455  Wrap the lines in the README file

The 4 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:
 README.md                                          | 17 ++--
 pom.xml                                            | 14 +++-
 .../org/apache/tomcat/jakartaee/AntHandler.java    | 67 ++++++++++++++++
 .../org/apache/tomcat/jakartaee/Migration.java     | 63 ---------------
 .../org/apache/tomcat/jakartaee/MigrationCLI.java  | 92 ++++++++++++++++++++++
 .../org/apache/tomcat/jakartaee/MigrationTask.java | 82 +++++++++++++++++++
 .../org/apache/tomcat/jakartaee/antlib.xml         |  4 +
 src/main/scripts/migrate.sh                        |  2 +-
 .../apache/tomcat/jakartaee/MigrationTaskTest.java | 81 +++++++++++++++++++
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 21 ++++-
 src/test/resources/testbuild.xml                   | 13 +++
 11 files changed, 382 insertions(+), 74 deletions(-)
 create mode 100644 src/main/java/org/apache/tomcat/jakartaee/AntHandler.java
 create mode 100644 src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
 create mode 100644 src/main/java/org/apache/tomcat/jakartaee/MigrationTask.java
 create mode 100644 src/main/resources/org/apache/tomcat/jakartaee/antlib.xml
 create mode 100644 src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java
 create mode 100644 src/test/resources/testbuild.xml


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


[tomcat-jakartaee-migration] 01/04: Split the CLI handling from the main 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 0a52c66b751e3245fad11faf85f7dbfa4343bac9
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Wed Apr 8 18:55:17 2020 +0200

    Split the CLI handling from the main migration class
---
 pom.xml                                            |  2 +-
 .../org/apache/tomcat/jakartaee/Migration.java     | 63 ---------------
 .../org/apache/tomcat/jakartaee/MigrationCLI.java  | 92 ++++++++++++++++++++++
 src/main/scripts/migrate.sh                        |  2 +-
 .../org/apache/tomcat/jakartaee/MigrationTest.java |  8 +-
 5 files changed, 98 insertions(+), 69 deletions(-)

diff --git a/pom.xml b/pom.xml
index 2d4ddd8..f6bd9d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,7 +100,7 @@
           <archive>
             <manifest>
               <addClasspath>true</addClasspath>
-              <mainClass>org.apache.tomcat.jakartaee.Migration</mainClass>
+              <mainClass>org.apache.tomcat.jakartaee.MigrationCLI</mainClass>
             </manifest>
           </archive>
         </configuration>
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 68a8fc2..44efc5a 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -24,7 +24,6 @@ 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;
@@ -270,68 +269,6 @@ 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");
-
-        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 (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(arguments.get(0).substring(PROFILE_ARG.length())));
-                } catch (IllegalArgumentException e) {
-                    // Invalid profile value
-                    valid = false;
-                }
-            }
-        }
-        if (arguments.size() == 2) {
-            source = arguments.get(0);
-            dest = arguments.get(1);
-            valid = true;
-        }
-        if (!valid) {
-            usage();
-            System.exit(1);
-        }
-
-        migration.setSource(new File(source));
-        migration.setDestination(new File(dest));
-        boolean result = false;
-        try {
-            result = migration.execute();
-        } catch (IOException e) {
-            logger.log(Level.SEVERE, sm.getString("migration.error"), e);
-            result = false;
-        }
-
-        // Signal caller that migration failed
-        if (!result) {
-            System.exit(1);
-        }
-    }
-
-
-    private static void usage() {
-        System.out.println(sm.getString("migration.usage"));
-    }
-
-
     private static boolean isArchive(String fileName) {
         return fileName.endsWith(".jar") || fileName.endsWith(".war") || fileName.endsWith(".zip");
     }
diff --git a/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java b/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
new file mode 100644
index 0000000..1b6dc80
--- /dev/null
+++ b/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
@@ -0,0 +1,92 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class MigrationCLI {
+
+    private static final Logger logger = Logger.getLogger(MigrationCLI.class.getCanonicalName());
+    private static final StringManager sm = StringManager.getManager(MigrationCLI.class);
+
+    private static final String PROFILE_ARG = "-profile=";
+
+    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 (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(arguments.get(0).substring(PROFILE_ARG.length())));
+                } catch (IllegalArgumentException e) {
+                    // Invalid profile value
+                    valid = false;
+                }
+            }
+        }
+        if (arguments.size() == 2) {
+            source = arguments.get(0);
+            dest = arguments.get(1);
+            valid = true;
+        }
+        if (!valid) {
+            usage();
+            System.exit(1);
+        }
+
+        migration.setSource(new File(source));
+        migration.setDestination(new File(dest));
+        boolean result = false;
+        try {
+            result = migration.execute();
+        } catch (IOException e) {
+            logger.log(Level.SEVERE, sm.getString("migration.error"), e);
+            result = false;
+        }
+
+        // Signal caller that migration failed
+        if (!result) {
+            System.exit(1);
+        }
+    }
+
+    private static void usage() {
+        System.out.println(sm.getString("migration.usage"));
+    }
+    
+}
diff --git a/src/main/scripts/migrate.sh b/src/main/scripts/migrate.sh
index 4f8826b..c2b941c 100644
--- a/src/main/scripts/migrate.sh
+++ b/src/main/scripts/migrate.sh
@@ -1,4 +1,4 @@
 #!/bin/sh
 
 # Assumes java is on the path
-java -cp "../lib/*" org.apache.tomcat.jakartaee.Migration "$@"
+java -cp "../lib/*" org.apache.tomcat.jakartaee.MigrationCLI "$@"
diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index c41a735..e77925f 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -42,7 +42,7 @@ public class MigrationTest {
     @Test
     public void testMigrateSingleSourceFile() throws Exception {
         File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
-        Migration.main(new String[] {"target/test-classes/HelloServlet.java", migratedFile.getAbsolutePath()});
+        MigrationCLI.main(new String[] {"target/test-classes/HelloServlet.java", migratedFile.getAbsolutePath()});
 
         assertTrue("Migrated file not found", migratedFile.exists());
 
@@ -54,7 +54,7 @@ public class MigrationTest {
     @Test
     public void testMigrateSingleSourceFileWithProfile() throws Exception {
         File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
-        Migration.main(new String[] {"-verbose", "-profile=EE", "target/test-classes/HelloServlet.java", migratedFile.getAbsolutePath()});
+        MigrationCLI.main(new String[] {"-verbose", "-profile=EE", "target/test-classes/HelloServlet.java", migratedFile.getAbsolutePath()});
 
         assertTrue("Migrated file not found", migratedFile.exists());
 
@@ -69,7 +69,7 @@ public class MigrationTest {
         File migratedFile = new File("target/test-classes/HelloServlet.inplace.java");
         FileUtils.copyFile(sourceFile, migratedFile);
 
-        Migration.main(new String[] {"-profile=EE", migratedFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
+        MigrationCLI.main(new String[] {"-profile=EE", migratedFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
 
         assertTrue("Migrated file not found", migratedFile.exists());
 
@@ -84,7 +84,7 @@ public class MigrationTest {
         File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
 
         try {
-            Migration.main(new String[] {"-invalid", sourceFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
+            MigrationCLI.main(new String[] {"-invalid", sourceFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
             fail("No error code returned");
         } catch (SecurityException e) {
             assertEquals("error code", "1", e.getMessage());


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


[tomcat-jakartaee-migration] 03/04: Test with an invalid 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 75de6b5d61afac8e13621cffe63df892e602df26
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Wed Apr 8 23:18:23 2020 +0200

    Test with an invalid profile
---
 .../java/org/apache/tomcat/jakartaee/MigrationTest.java     | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index e77925f..813ca55 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -90,4 +90,17 @@ public class MigrationTest {
             assertEquals("error code", "1", e.getMessage());
         }
     }
+
+    @Test
+    public void testInvalidProfile() throws Exception {
+        File sourceFile = new File("target/test-classes/HelloServlet.java");
+        File migratedFile = new File("target/test-classes/HelloServlet.migrated.java");
+
+        try {
+            MigrationCLI.main(new String[] {"-profile=JSERV", sourceFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
+            fail("No error code returned");
+        } catch (SecurityException e) {
+            assertEquals("error code", "1", e.getMessage());
+        }
+    }
 }


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


[tomcat-jakartaee-migration] 02/04: Ant task for the migration tool

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 44521e8f1f4beb84ce1e7780481eb3ee19e7e2bd
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Wed Apr 8 22:46:02 2020 +0200

    Ant task for the migration tool
---
 pom.xml                                            | 12 ++++
 .../org/apache/tomcat/jakartaee/AntHandler.java    | 67 ++++++++++++++++++
 .../org/apache/tomcat/jakartaee/MigrationTask.java | 82 ++++++++++++++++++++++
 .../org/apache/tomcat/jakartaee/antlib.xml         |  4 ++
 .../apache/tomcat/jakartaee/MigrationTaskTest.java | 81 +++++++++++++++++++++
 src/test/resources/testbuild.xml                   | 13 ++++
 6 files changed, 259 insertions(+)

diff --git a/pom.xml b/pom.xml
index f6bd9d3..c094b75 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,12 @@
       <artifactId>commons-io</artifactId>
       <version>2.6</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.ant</groupId>
+      <artifactId>ant</artifactId>
+      <version>1.10.7</version>
+      <scope>provided</scope>
+    </dependency>
 
     <!-- Test dependencies -->
     <dependency>
@@ -95,6 +101,12 @@
     </resources>   
     <plugins>
       <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <reuseForks>false</reuseForks>
+        </configuration>
+      </plugin>
+      <plugin>
         <artifactId>maven-jar-plugin</artifactId>
         <configuration>
           <archive>
diff --git a/src/main/java/org/apache/tomcat/jakartaee/AntHandler.java b/src/main/java/org/apache/tomcat/jakartaee/AntHandler.java
new file mode 100644
index 0000000..e7747b7
--- /dev/null
+++ b/src/main/java/org/apache/tomcat/jakartaee/AntHandler.java
@@ -0,0 +1,67 @@
+/*
+ * 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.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+/**
+ * JUL log handler redirecting the messages logged to Ant.
+ */
+ class AntHandler extends Handler {
+
+    private final Task task;
+
+    public AntHandler(Task task) {
+        this.task = task;
+    }
+
+    @Override
+    public void publish(LogRecord record) {
+        task.log(record.getMessage(), record.getThrown(), toAntLevel(record.getLevel()));
+    }
+
+    @Override
+    public void flush() {
+    }
+
+    @Override
+    public void close() throws SecurityException {
+    }
+
+    /**
+     * Convert the JUL level to the equivalent Ant one.
+     */
+    private int toAntLevel(Level level) {
+        if (level.intValue() >= Level.SEVERE.intValue()) {
+            return Project.MSG_ERR;
+        } else if (level.intValue() >= Level.WARNING.intValue()) {
+            return Project.MSG_WARN;
+        } else if (level.intValue() >= Level.INFO.intValue()) {
+            return Project.MSG_INFO;
+        } else if (level.intValue() >= Level.FINE.intValue()) {
+            return Project.MSG_VERBOSE;
+        } else {
+            return Project.MSG_DEBUG;
+        }
+    }
+}
diff --git a/src/main/java/org/apache/tomcat/jakartaee/MigrationTask.java b/src/main/java/org/apache/tomcat/jakartaee/MigrationTask.java
new file mode 100644
index 0000000..4d7d967
--- /dev/null
+++ b/src/main/java/org/apache/tomcat/jakartaee/MigrationTask.java
@@ -0,0 +1,82 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.util.logging.Handler;
+import java.util.logging.Logger;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * Ant task for the Jakarta EE migration tool.
+ */
+public class MigrationTask extends Task {
+
+    private File src;
+    private File dest;
+    private String profile = EESpecProfile.TOMCAT.toString();
+
+    public void setSrc(File src) {
+        this.src = src;
+    }
+
+    public void setDest(File dest) {
+        this.dest = dest;
+    }
+
+    public void setProfile(String profile) {
+        this.profile = profile;
+    }
+
+    @Override
+    public void execute() throws BuildException {
+        // redirect the log messages to Ant
+        Logger logger = Logger.getLogger(Migration.class.getCanonicalName());
+        logger.setUseParentHandlers(false);
+        for (Handler handler : logger.getHandlers()) {
+            logger.removeHandler(handler);
+        }
+        logger.addHandler(new AntHandler(this));
+
+        // check the parameters
+        EESpecProfile profile = null;
+        try {
+            profile = EESpecProfile.valueOf(this.profile.toUpperCase());
+        } catch (IllegalArgumentException e) {
+            throw new BuildException("Invalid profile specified: " + this.profile, getLocation()); // todo i18n
+        }
+
+        Migration migration = new Migration();
+        migration.setSource(src);
+        migration.setDestination(dest);
+        migration.setEESpecProfile(profile);
+
+        boolean success = false;
+        try {
+            success = migration.execute();
+        } catch (IOException e) {
+            throw new BuildException(e, getLocation());
+        }
+
+        if (!success) {
+            throw new BuildException("Migration failed", getLocation());
+        }
+    }
+}
diff --git a/src/main/resources/org/apache/tomcat/jakartaee/antlib.xml b/src/main/resources/org/apache/tomcat/jakartaee/antlib.xml
new file mode 100644
index 0000000..daedd05
--- /dev/null
+++ b/src/main/resources/org/apache/tomcat/jakartaee/antlib.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<antlib>
+  <taskdef name="javax2jakarta" classname="org.apache.tomcat.jakartaee.MigrationTask"/>
+</antlib>
diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java
new file mode 100644
index 0000000..1baa1d7
--- /dev/null
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.io.File;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class MigrationTaskTest {
+
+    private Project project;
+
+    @Before
+    public void setUp() throws Exception {
+        project = new Project();
+        project.setCoreLoader(getClass().getClassLoader());
+        project.init();
+
+        File buildFile = new File("target/test-classes/testbuild.xml");
+        project.setBaseDir(buildFile.getParentFile());
+
+        final ProjectHelper helper = ProjectHelper.getProjectHelper();
+        helper.parse(project, buildFile);
+
+        redirectOutput(System.out);
+    }
+
+    /**
+     * Redirects the Ant output to the specified stream.
+     */
+    private void redirectOutput(OutputStream out) {
+        DefaultLogger logger = new DefaultLogger();
+        logger.setOutputPrintStream(new PrintStream(out));
+        logger.setMessageOutputLevel(Project.MSG_INFO);
+        project.addBuildListener(logger);
+    }
+
+    @Test(expected = BuildException.class)
+    public void testUnsupportedKeyStoreType() {
+        project.executeTarget("invalid-profile");
+    }
+
+    @Test
+    public void testMigrateSingleSourceFile() throws Exception {
+        project.executeTarget("migrate-single-source-file");
+
+        File migratedFile = new File("target/test-classes/HelloServlet.migrated-by-ant.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"));
+    }
+}
diff --git a/src/test/resources/testbuild.xml b/src/test/resources/testbuild.xml
new file mode 100644
index 0000000..3b64b59
--- /dev/null
+++ b/src/test/resources/testbuild.xml
@@ -0,0 +1,13 @@
+<project name="Jsign Ant tests">
+
+  <taskdef name="javax2jakarta" classname="org.apache.tomcat.jakartaee.MigrationTask"/>
+
+  <target name="migrate-single-source-file">
+    <javax2jakarta src="HelloServlet.java" dest="HelloServlet.migrated-by-ant.java" profile="tomcat"/>
+  </target>
+
+  <target name="invalid-profile">
+    <javax2jakarta src="foo" dest="bar" profile="tOmCaT"/>
+  </target>
+
+</project>


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


[tomcat-jakartaee-migration] 04/04: Wrap the lines in the README file

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 70a94559e5a288d30f0794210c100e21d950d40b
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Wed Apr 8 23:22:45 2020 +0200

    Wrap the lines in the README file
---
 README.md | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 6ae92c4..2890a27 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,9 @@
 
 This tool is a work in progress.
 
-The aim of the tool is to take a web application written for Java EE 8 that runs on Apache Tomcat 9 and convert it automatically so it runs on Apache Tomcat 10 which implements Jakarta EE 9.
+The aim of the tool is to take a web application written for Java EE 8 that
+runs on Apache Tomcat 9 and convert it automatically so it runs on Apache
+Tomcat 10 which implements Jakarta EE 9.
 
 ## Usage
 
@@ -20,16 +22,20 @@ Migrate your Servlet application with:
 
     java -jar target/jakartaee-migration-*-shaded.jar <source> <destination>
 
-The source should be a path to a compressed archive, a folder or an individual file. The destination will be created at the specified path as a resource of the same type as the source.
+The source should be a path to a compressed archive, a folder or an individual
+file. The destination will be created at the specified path as a resource of
+the same type as the source.
 
 > **INFO**
-> This tool will remove cryptographic signatures from JAR files contained in the *source*, as the changed resources would not match them anymore.
+> This tool will remove cryptographic signatures from JAR files contained
+> in the *source*, as the changed resources would not match them anymore.
 >
 > A warning will be logged for each JAR file where the signature has been removed.
 
 ## Differences between Java EE 8 and Jakarta EE 9
 
-Jakarta EE 9 is still under development and there are some details that remain to be worked out.
+Jakarta EE 9 is still under development and there are some details that remain
+to be worked out.
 
 The differences currently supported by this tool are:
 
@@ -39,6 +45,7 @@ The differences yet to be implemented by this tool are:
 
 * Remaining issues once resolved
 
-The issues still to be resolved by the Jakarta EE projects that will impact this tool are:
+The issues still to be resolved by the Jakarta EE projects that will impact
+this tool are:
 
 * XML schemas


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