diff options
author | Andrey Loskutov <loskutov@gmx.de> | 2016-01-03 15:27:01 +0100 |
---|---|---|
committer | Andrey Loskutov <loskutov@gmx.de> | 2016-01-06 17:26:43 -0500 |
commit | 24468f09e3fb991ea5a6af293f84c7fe37e78b95 (patch) | |
tree | 629aafff1313f73acc7ae34b93e7818e2129ff3c /org.eclipse.jgit.pgm | |
parent | 24cd8e170d377cef87166d43ca25bfa2340755c6 (diff) | |
download | jgit-24468f09e3fb991ea5a6af293f84c7fe37e78b95.tar.gz jgit-24468f09e3fb991ea5a6af293f84c7fe37e78b95.zip |
Added CLIText.fatalError(String) API for tests
In different places (Main, TextBuiltin, CLIGitCommand) we report fatal
errors and at same time want to check for fatal errors in the tests.
Using common API simplifies the error testing and helps to navigate to
the actual error check implementation.
Change-Id: Iecde79beb33ea595171f168f46b0b10ab2f339bb
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit.pgm')
3 files changed, 18 insertions, 5 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index d04cef0c7f..e31306b214 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -128,7 +128,7 @@ public class Main { } catch (Die err) { if (err.isAborted()) System.exit(1); - System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); + System.err.println(CLIText.fatalError(err.getMessage())); if (showStackTrace) err.printStackTrace(); System.exit(128); @@ -147,10 +147,10 @@ public class Main { } if (!showStackTrace && err.getCause() != null && err instanceof TransportException) - System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getCause().getMessage())); + System.err.println(CLIText.fatalError(err.getCause().getMessage())); if (err.getClass().getName().startsWith("org.eclipse.jgit.errors.")) { //$NON-NLS-1$ - System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); + System.err.println(CLIText.fatalError(err.getMessage())); if (showStackTrace) err.printStackTrace(); System.exit(128); @@ -176,7 +176,7 @@ public class Main { clp.parseArgument(argv); } catch (CmdLineException err) { if (argv.length > 0 && !help && !version) { - writer.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); + writer.println(CLIText.fatalError(err.getMessage())); writer.flush(); System.exit(1); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java index 95938326fd..c4c5d64a0e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java @@ -216,7 +216,7 @@ public abstract class TextBuiltin { try { clp.parseArgument(args); } catch (CmdLineException err) { - this.errw.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); + this.errw.println(CLIText.fatalError(err.getMessage())); if (help) { printUsage("", clp); //$NON-NLS-1$ } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java index fd86ddf2b7..2812137266 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java @@ -74,6 +74,19 @@ public class CLIText extends TranslationBundle { return MessageFormat.format(get().lineFormat, line); } + /** + * Format the given argument as fatal error using the format defined by + * {@link #fatalError} ("fatal: " by default). + * + * @param message + * the message to format + * @return the formatted line + * @since 4.2 + */ + public static String fatalError(String message) { + return MessageFormat.format(get().fatalError, message); + } + // @formatter:off /***/ public String alreadyOnBranch; /***/ public String alreadyUpToDate; |