This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git
commit c09f8b4a1620643c40018cb54730cc06176c35c2 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Feb 9 12:00:36 2021 +0000 Replace `-verbose` with `-logLevel=` to provide more control --- CHANGES.md | 1 + .../org/apache/tomcat/jakartaee/MigrationCLI.java | 103 +++++++++++---------- .../tomcat/jakartaee/LocalStrings.properties | 16 +++- 3 files changed, 70 insertions(+), 50 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index af74bb7..99d84e1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ - Include the Maven Wrapper source files in the source distribution. (markt) - Ensure that all the Manifest attributes are processed during the migration process. (markt) - Include `.properties` and `.json` files in the conversion process. (markt) +- Replace `-verbose` with `-logLevel=` to provide more control over logging level. (markt) ## 0.1.0 diff --git a/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java b/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java index 5c3bf4f..64af9b9 100644 --- a/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java +++ b/src/main/java/org/apache/tomcat/jakartaee/MigrationCLI.java @@ -20,82 +20,87 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; +import java.util.Locale; 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 LOGLEVEL_ARG = "-logLevel="; private static final String PROFILE_ARG = "-profile="; - + // Will be removed for 1.0.0 + @Deprecated + private static final String VERBOSE_ARG = "-verbose"; private static final String ZIPINMEMORY_ARG = "-zipInMemory"; - public static void main(String[] args) { - System.setProperty("java.util.logging.SimpleFormatter.format", "%5$s%n %6$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"); - } - - boolean zipInMemory = false; - if (arguments.contains(ZIPINMEMORY_ARG)) { - zipInMemory = true; - arguments.remove(ZIPINMEMORY_ARG); - } + public static void main(String[] args) throws IOException { + // Defaults + System.setProperty("java.util.logging.SimpleFormatter.format", "%5$s%n"); Migration migration = new Migration(); - migration.setZipInMemory(zipInMemory); - 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; + // Process argumnets + List<String> arguments = new ArrayList<>(Arrays.asList(args)); + + // Process the custom log level if present + // Use an iterator so we can remove the log level argument if found + Iterator<String> iter = arguments.iterator(); + while (iter.hasNext()) { + String argument = iter.next(); + if (argument.startsWith(LOGLEVEL_ARG)) { + iter.remove(); + String logLevelName = argument.substring(LOGLEVEL_ARG.length()); + Level level = null; try { - migration.setEESpecProfile(EESpecProfile.valueOf(arguments.get(0).substring(PROFILE_ARG.length()))); + level = Level.parse(logLevelName.toUpperCase(Locale.ENGLISH)); + } catch (IllegalArgumentException iae) { + invalidArguments(); + } + // Configure the explicit level + Logger.getGlobal().getParent().getHandlers()[0].setLevel(level); + Logger.getGlobal().getParent().setLevel(level); + } else if (argument.startsWith(PROFILE_ARG)) { + iter.remove(); + String profileName = argument.substring(PROFILE_ARG.length()); + try { + EESpecProfile profile = EESpecProfile.valueOf(profileName.toUpperCase(Locale.ENGLISH)); + migration.setEESpecProfile(profile); } catch (IllegalArgumentException e) { // Invalid profile value - valid = false; + invalidArguments(); + } + } else if (argument.equals(ZIPINMEMORY_ARG)) { + iter.remove(); + migration.setZipInMemory(true); + } else if (argument.equals(VERBOSE_ARG)) { + iter.remove(); + // Ignore if LOGLEVEL_ARG has set something different + if (Logger.getGlobal().getParent().getLevel().equals(Level.INFO)) { + Logger.getGlobal().getParent().getHandlers()[0].setLevel(Level.FINE); + Logger.getGlobal().getParent().setLevel(Level.FINE); } } } - if (arguments.size() == 2) { - source = arguments.get(0); - dest = arguments.get(1); - valid = true; - } - if (!valid) { - usage(); - System.exit(1); + + if (arguments.size() != 2) { + invalidArguments(); } + String source = arguments.get(0); + String dest = arguments.get(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); - } + migration.execute(); } - private static void usage() { + private static void invalidArguments() { System.out.println(sm.getString("migration.usage")); + System.exit(1); } - } diff --git a/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties b/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties index cf62ca3..d3274e4 100644 --- a/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties +++ b/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties @@ -24,5 +24,19 @@ migration.mkdirError=Error creating destination directory [{0}] migration.removeSignature=Remove cryptographic signature for [{0}] migration.skipSignatureFile=Drop cryptographic signature file [{0}] migration.stream=Migrating stream [{0}] -migration.usage=Usage: Migration [-profile=TOMCAT|-profile=EE] [-zipInMemory] [-verbose] <source> <destination> +migration.usage=Usage: Migration [options] <source> <destination>\n\ +where options includes:\n\ +\ -logLevel=<name of java.util.logging.level enum value>\n\ +\ Useful values are INFO (default), FINE or FINEST\n\ +\ -profile=<profile name>\n\ +\ TOMCAT (default) to convert Java EE APIs provided by Tomcat\n\ +\ EE to convert all Java EE APIs\n\ +\ -zipInMemory\n\ +\ By default zip format archives (.zip, jar, .war, .ear, etc.)\n\ +\ are processed in memory. This is more efficient but is not\n\ +\ compatible with some zip archive structures. If you see an\n\ +\ exception while processing a zip file, enabling this option\n\ +\ may workaround the issue. + + migration.warnSignatureRemoval=Removed cryptographic signature from JAR file --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org