This is an automated email from the ASF dual-hosted git repository. remm 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 97d7652 Report non fatal errors using the main boolean result 97d7652 is described below commit 97d765260b19a1a3b132602d18b3c244da5204af Author: remm <r...@apache.org> AuthorDate: Tue Jan 21 10:11:41 2020 +0100 Report non fatal errors using the main boolean result Some cleanups as well. --- .../org/apache/tomcat/jakartaee/Migration.java | 45 ++++++++++++++-------- .../tomcat/jakartaee/LocalStrings.properties | 2 +- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java index 044e0a1..64f68d5 100644 --- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java +++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java @@ -72,55 +72,63 @@ public class Migration { public boolean execute() throws IOException { logger.log(Level.INFO, sm.getString("migration.execute", source.getAbsolutePath(), destination.getAbsolutePath())); + boolean result = true; long t1 = System.nanoTime(); if (source.isDirectory()) { if (destination.mkdirs()) { - migrateDirectory(source, destination); + result = result && migrateDirectory(source, destination); } else { - logger.log(Level.SEVERE, sm.getString("migration.mkdirError", destination.getAbsolutePath())); + logger.log(Level.WARNING, sm.getString("migration.mkdirError", destination.getAbsolutePath())); + result = false; } } else { // Single file File parentDestination = destination.getParentFile(); if (parentDestination.exists() || parentDestination.mkdirs()) { - migrateFile(source, destination); + result = result && migrateFile(source, destination); } else { - logger.log(Level.SEVERE, sm.getString("migration.mkdirError", parentDestination.getAbsolutePath())); + logger.log(Level.WARNING, sm.getString("migration.mkdirError", parentDestination.getAbsolutePath())); + result = false; } } - logger.log(Level.INFO, sm.getString("migration.done"), - Long.valueOf(TimeUnit.MILLISECONDS.convert(System.nanoTime() - t1, TimeUnit.NANOSECONDS))); - return true; + logger.log(Level.INFO, sm.getString("migration.done", + Long.valueOf(TimeUnit.MILLISECONDS.convert(System.nanoTime() - t1, TimeUnit.NANOSECONDS)), + Boolean.valueOf(result))); + return result; } - private void migrateDirectory(File src, File dest) throws IOException { + private boolean migrateDirectory(File src, File dest) throws IOException { + boolean result = true; String[] files = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); if (srcFile.isDirectory()) { if (destFile.mkdir()) { - migrateDirectory(srcFile, destFile); + result = result && migrateDirectory(srcFile, destFile); } else { - logger.log(Level.SEVERE, sm.getString("migration.mkdirError", destFile.getAbsolutePath())); + logger.log(Level.WARNING, sm.getString("migration.mkdirError", destFile.getAbsolutePath())); + result = false; } } else { - migrateFile(srcFile, destFile); + result = result && migrateFile(srcFile, destFile); } } + return result; } - private void migrateFile(File src, File dest) throws IOException { + private boolean migrateFile(File src, File dest) throws IOException { try (InputStream is = new FileInputStream(src); OutputStream os = new FileOutputStream(dest)) { - migrateStream(src.getName(), is, os); + return migrateStream(src.getName(), is, os); } } - private void migrateArchive(InputStream src, OutputStream dest) throws IOException { + private boolean migrateArchive(InputStream src, OutputStream dest) throws IOException { + boolean result = true; try (JarInputStream jarIs = new JarInputStream(new NonClosingInputStream(src)); JarOutputStream jarOs = new JarOutputStream(new NonClosingOutputStream(dest))) { Manifest manifest = jarIs.getManifest(); @@ -137,16 +145,17 @@ public class Migration { String destName = Util.convert(sourceName); JarEntry destEntry = new JarEntry(destName); jarOs.putNextEntry(destEntry); - migrateStream(destEntry.getName(), jarIs, jarOs); + result = result && migrateStream(destEntry.getName(), jarIs, jarOs); } } + return result; } - private void migrateStream(String name, InputStream src, OutputStream dest) throws IOException { + private boolean migrateStream(String name, InputStream src, OutputStream dest) throws IOException { if (isArchive(name)) { logger.log(Level.INFO, sm.getString("migration.archive", name)); - migrateArchive(src, dest); + return migrateArchive(src, dest); } else { logger.log(Level.FINE, sm.getString("migration.stream", name)); for (Converter converter : converters) { @@ -155,6 +164,7 @@ public class Migration { break; } } + return true; } } @@ -188,6 +198,7 @@ public class Migration { result = migration.execute(); } catch (IOException e) { logger.log(Level.SEVERE, sm.getString("migration.error"), e); + result = false; } // Signal caller that migration failed diff --git a/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties b/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties index 9310641..fdfe379 100644 --- a/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties +++ b/src/main/resources/org/apache/tomcat/jakartaee/LocalStrings.properties @@ -15,7 +15,7 @@ migration.archive=Migrating archive [{0}] migration.cannotReadSource=Cannot read source location [{0}] -migration.done=Migration completed in [{0}] milliseconds +migration.done=Migration completed successfully [{1}] in [{0}] milliseconds migration.entry=Migrating Jar entry [{0}] migration.error=Error performing migration migration.execute=Performing migration from source [{0}] to destination [{1}] --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org