1.1 --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java Mon Nov 17 21:59:20 2014 +0100
1.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java Mon Nov 17 23:08:26 2014 +0100
1.3 @@ -35,17 +35,38 @@
1.4
1.5 private static final Logger log = Logger.getLogger(CLIStarter.class.getName());
1.6
1.7 + // help:exit-codes
1.8 + public static final int EXIT_SUCCESS = 0; // doc:success
1.9 + public static final int EXIT_UNEXPECTED_ERROR = 1; // doc:unexpected error (probably bug)
1.10 + // 2 is reserved: http://www.tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF
1.11 + //public static final int EXIT_SQL_ERROR = 3; // ___:SQL error
1.12 + public static final int EXIT_CLI_PARSE_ERROR = 4; // doc:CLI options parse error
1.13 + public static final int EXIT_CLI_VALIDATE_ERROR = 5; // doc:CLI options validation error
1.14 + //public static final int EXIT_CONFIGURATION_ERROR = 6; // ___:configuration error
1.15 + public static final int EXIT_IMAGE_ERROR = 7; // doc:image error
1.16 + public static final int EXIT_RECURSIVE_ERROR = 8; // doc:recursive error
1.17 +
1.18 public static void main(String[] args) {
1.19
1.20 + int exitCode;
1.21 +
1.22 try {
1.23 CLIParser parser = new CLIParser();
1.24 RecursiveOptions options = parser.parseOptions(args);
1.25 options.validate();
1.26 RecursiveImageResizer resizer = new RecursiveImageResizer(options);
1.27 Counters counters = resizer.resize();
1.28 - log.log(Level.INFO, "Recursive copy/resize finished. {0}", counters);
1.29 +
1.30 + if (options.getErrorMode() == RecursiveOptions.ERROR_MODE.SILENT_SKIP || counters.get(Counters.COUNTER_TYPE.SKIPPED_ERROR) == 0) {
1.31 + log.log(Level.INFO, "Recursive copy/resize succesfully finished. {0}", counters);
1.32 + exitCode = EXIT_SUCCESS;
1.33 + } else {
1.34 + log.log(Level.SEVERE, "Recursive copy/resize finished with errors. {0}", counters);
1.35 + exitCode = EXIT_IMAGE_ERROR;
1.36 + }
1.37 } catch (CLIParserException e) {
1.38 log.log(Level.SEVERE, "Unable to parse CLI options", e);
1.39 + exitCode = EXIT_CLI_PARSE_ERROR;
1.40 } catch (InvalidOptionsException e) {
1.41 log.log(Level.SEVERE, "Invalid CLI options", e);
1.42 for (InvalidOptionsException.OptionProblem p : e.getProblems()) {
1.43 @@ -54,11 +75,16 @@
1.44 r.setParameters(new Object[]{p.getDescription()});
1.45 log.log(r);
1.46 }
1.47 + exitCode = EXIT_CLI_VALIDATE_ERROR;
1.48 } catch (RecursiveException e) {
1.49 log.log(Level.SEVERE, "Error while processing filesystem hierarchy", e);
1.50 + exitCode = EXIT_RECURSIVE_ERROR;
1.51 } catch (ResizeException e) {
1.52 log.log(Level.SEVERE, "Error while resizing image", e);
1.53 + exitCode = EXIT_IMAGE_ERROR;
1.54 }
1.55 +
1.56 + System.exit(exitCode);
1.57 }
1.58
1.59 }