This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git
The following commit(s) were added to refs/heads/main by this push:
new 24ff33e Minor improvements from code review
24ff33e is described below
commit 24ff33edc8cd8894a9462a93b40e652f57cdc713
Author: remm <remm@meteor>
AuthorDate: Fri Sep 4 15:08:17 2026 +0200
Minor improvements from code review
---
.../apache/tomcat/jakartaee/ClassConverter.java | 17 ++++++++++++--
.../org/apache/tomcat/jakartaee/EESpecProfile.java | 27 ++++++++++++++--------
.../org/apache/tomcat/jakartaee/MigrationCLI.java | 22 ++++++++++--------
3 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
b/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
index 8267dbc..ad6b45e 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
@@ -27,6 +27,7 @@ import java.security.ProtectionDomain;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.bcel.classfile.ClassFormatException;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.classfile.ConstantUtf8;
@@ -108,13 +109,20 @@ public class ClassConverter implements Converter,
ClassFileTransformer {
* @param profile the specification profile to use
* @param loader the class loader
* @return true if conversion occurred
- * @throws IOException rethrow on byte read or write
+ * @throws IOException on byte read or write, or if the class file is
malformed
*/
protected boolean convertInternal(String path, InputStream src,
OutputStream dest, EESpecProfile profile, ClassLoader loader)
throws IOException {
byte[] classBytes = IOUtils.toByteArray(src);
ClassParser parser = new ClassParser(new
ByteArrayInputStream(classBytes), "unknown");
- JavaClass javaClass = parser.parse();
+ JavaClass javaClass;
+ try {
+ javaClass = parser.parse();
+ } catch (ClassFormatException e) {
+ // BCEL reports malformed class files with an unchecked exception.
+ // Wrap it so callers only deal with the documented IOException.
+ throw new IOException(sm.getString("classConverter.invalidClass",
path), e);
+ }
boolean converted = false;
@@ -164,6 +172,11 @@ public class ClassConverter implements Converter,
ClassFileTransformer {
result.append(convertedFragment);
}
newString = result.toString();
+ if (newString.equals(str)) {
+ // All converted fragments were reverted because
the
+ // target classes do not exist in the container.
+ continue;
+ }
}
c = new ConstantUtf8(newString);
constantPool[i] = c;
diff --git a/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
b/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
index 34ba3a2..e877081 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/EESpecProfile.java
@@ -24,16 +24,6 @@ import java.util.regex.Pattern;
* Used to represent a specification profile.
*/
public interface EESpecProfile {
- /**
- * Convert the specified name to the target namespace.
- * @param name the name to convert
- * @return the converted name
- */
- default String convert(String name) {
- Matcher m = getPattern().matcher(name);
- return m.replaceAll(getTarget() + "$1");
- }
-
/**
* The source namespace.
* @return the source namespace
@@ -51,5 +41,22 @@ public interface EESpecProfile {
* @return the pattern
*/
Pattern getPattern();
+
+ /**
+ * Convert the specified name to the target namespace.
+ * <p>
+ * The pattern returned by {@link #getPattern()} must contain at least one
+ * capture group. Group 1 is the part of the name that follows the source
+ * namespace and is preserved in the converted result.
+ * <p>
+ * Names that do not match the pattern are returned unchanged.
+ *
+ * @param name the name to convert
+ * @return the converted name
+ */
+ default String convert(String name) {
+ Matcher m = getPattern().matcher(name);
+ return m.replaceAll(Matcher.quoteReplacement(getTarget()) + "$1");
+ }
}
diff --git a/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
b/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
index 33a0ef8..af8625d 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java
@@ -50,9 +50,8 @@ public class MigrationCLI {
/**
* Main method for the CLI tool.
* @param args the command line arguments
- * @throws IOException when an exception occurs
*/
- public static void main(String[] args) throws IOException {
+ public static void main(String[] args) {
// Defaults
System.setProperty("java.util.logging.SimpleFormatter.format",
"%5$s%n");
@@ -138,15 +137,20 @@ public class MigrationCLI {
String source = arguments.get(0);
String dest = arguments.get(1);
- migration.setSource(new File(source));
- migration.setDestination(new File(dest));
+ try {
+ migration.setSource(new File(source));
+ migration.setDestination(new File(dest));
- if (enableCache) {
- MigrationCache migrationCache = new MigrationCache(cacheDir,
cacheRetentionDays);
- migration.setCache(migrationCache);
- }
+ if (enableCache) {
+ MigrationCache migrationCache = new MigrationCache(cacheDir,
cacheRetentionDays);
+ migration.setCache(migrationCache);
+ }
- migration.execute();
+ migration.execute();
+ } catch (IOException | IllegalArgumentException e) {
+ System.err.println(sm.getString("migration.error") + ": " +
e.getMessage());
+ System.exit(1);
+ }
}
private static void invalidArguments() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]