]> source.dussan.org Git - jgit.git/commitdiff
Stop using deprecated CmdLineException constructors 45/104345/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 5 Sep 2017 11:27:32 +0000 (20:27 +0900)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 5 Sep 2017 22:28:47 +0000 (00:28 +0200)
Instead of taking a String, the constructors now take a Localizable
and a variable list of format arguments.

Introduce a new Format helper class in CLIText, which implements the
Localizable interface, and use it in place of raw Strings.

Change-Id: I241eda16e242293ceb17b3c85ae5df85bd37c658
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/ObjectIdHandler.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/SubcommandHandler.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/UntrackedFilesHandler.java

index a66b7fa63928f52662002099d0ac4374b0e2bdef..fa9f64de4fdbf0588f97840ef99243112927ae20 100644 (file)
@@ -86,7 +86,8 @@ class RevParse extends TextBuiltin {
                } else {
                        if (verify && commits.size() > 1) {
                                final CmdLineParser clp = new CmdLineParser(this);
-                               throw new CmdLineException(clp, CLIText.get().needSingleRevision);
+                               throw new CmdLineException(clp,
+                                               CLIText.format(CLIText.get().needSingleRevision));
                        }
 
                        for (final ObjectId o : commits) {
index 7d304bc1c18759087551b9f4f5241c6f27bd4ee1..dfb489d826525d4daf0981e35dd48dc03d94c6ad 100644 (file)
 package org.eclipse.jgit.pgm.internal;
 
 import java.text.MessageFormat;
+import java.util.Locale;
 
 import org.eclipse.jgit.nls.NLS;
 import org.eclipse.jgit.nls.TranslationBundle;
+import org.kohsuke.args4j.Localizable;
 
 /**
  * Translation bundle for JGit command line interface
  */
 public class CLIText extends TranslationBundle {
+       /**
+        * Formats text strings using {@code Localizable}.
+        *
+        */
+       public static class Format implements Localizable {
+               final String text;
+
+               Format(String text) {
+                       this.text = text;
+               }
+
+               @Override
+               public String formatWithLocale(Locale locale, Object... args) {
+                       // we don't care about Locale for now
+                       return format(args);
+               }
+
+               @Override
+               public String format(Object... args) {
+                       return MessageFormat.format(text, args);
+               }
+       }
+
+       /**
+        * @param text
+        *            the text to format.
+        * @return a new Format instance.
+        */
+       public static Format format(String text) {
+               return new Format(text);
+       }
 
        /**
         * @return an instance of this translation bundle
index 8f56bda5f083cbf8e51993bbe47b652cc7dd1c06..587f98ca5302297f3a107fb5022c8731d1ff7974 100644 (file)
@@ -119,20 +119,25 @@ public class AbstractTreeIteratorHandler extends
                try {
                        id = clp.getRepository().resolve(name);
                } catch (IOException e) {
-                       throw new CmdLineException(clp, e.getMessage());
+                       throw new CmdLineException(clp, CLIText.format(e.getMessage()));
                }
                if (id == null)
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notATree), name);
 
                final CanonicalTreeParser p = new CanonicalTreeParser();
                try (ObjectReader curs = clp.getRepository().newObjectReader()) {
                        p.reset(curs, clp.getRevWalk().parseTree(id));
                } catch (MissingObjectException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notATree), name);
                } catch (IncorrectObjectTypeException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notATree), name);
                } catch (IOException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().cannotReadBecause), name,
+                                       e.getMessage());
                }
 
                setter.addValue(p);
index 75ca554efb44a856fd78602f95db41ae6704b8dd..74bab2d2ede1fa3154923d6f7e5f31250705412d 100644 (file)
@@ -45,7 +45,6 @@
 package org.eclipse.jgit.pgm.opt;
 
 import java.io.IOException;
-import java.text.MessageFormat;
 
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.pgm.internal.CLIText;
@@ -86,14 +85,15 @@ public class ObjectIdHandler extends OptionHandler<ObjectId> {
                try {
                        id = clp.getRepository().resolve(name);
                } catch (IOException e) {
-                       throw new CmdLineException(clp, e.getMessage());
+                       throw new CmdLineException(clp, CLIText.format(e.getMessage()));
                }
                if (id != null) {
                        setter.addValue(id);
                        return 1;
                }
 
-               throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notAnObject, name));
+               throw new CmdLineException(clp,
+                               CLIText.format(CLIText.get().notAnObject), name);
        }
 
        @Override
index 7661774f5d486e109fbf10b6d0233628753bae83..27555e3442d856446218ec7d643767a8683af3a7 100644 (file)
@@ -45,7 +45,6 @@
 package org.eclipse.jgit.pgm.opt;
 
 import java.io.IOException;
-import java.text.MessageFormat;
 
 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
 import org.eclipse.jgit.errors.MissingObjectException;
@@ -97,9 +96,8 @@ public class RevCommitHandler extends OptionHandler<RevCommit> {
                if (dot2 != -1) {
                        if (!option.isMultiValued())
                                throw new CmdLineException(clp,
-                                               MessageFormat.format(
-                                                               CLIText.get().onlyOneMetaVarExpectedIn,
-                                                               option.metaVar(), name));
+                                               CLIText.format(CLIText.get().onlyOneMetaVarExpectedIn),
+                                               option.metaVar(), name);
 
                        final String left = name.substring(0, dot2);
                        final String right = name.substring(dot2 + 2);
@@ -118,20 +116,25 @@ public class RevCommitHandler extends OptionHandler<RevCommit> {
                try {
                        id = clp.getRepository().resolve(name);
                } catch (IOException e) {
-                       throw new CmdLineException(clp, e.getMessage());
+                       throw new CmdLineException(clp, CLIText.format(e.getMessage()));
                }
                if (id == null)
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notACommit), name);
 
                final RevCommit c;
                try {
                        c = clp.getRevWalk().parseCommit(id);
                } catch (MissingObjectException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notACommit), name);
                } catch (IncorrectObjectTypeException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notACommit), name);
                } catch (IOException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().cannotReadBecause), name,
+                                       e.getMessage());
                }
 
                if (interesting)
index 9f1d21ec4beadd34a71a5a84604bc77d2c33efbf..15ed5890e92992996de42fb0ab726be303ca4310 100644 (file)
@@ -45,7 +45,6 @@
 package org.eclipse.jgit.pgm.opt;
 
 import java.io.IOException;
-import java.text.MessageFormat;
 
 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
 import org.eclipse.jgit.errors.MissingObjectException;
@@ -89,20 +88,25 @@ public class RevTreeHandler extends OptionHandler<RevTree> {
                try {
                        id = clp.getRepository().resolve(name);
                } catch (IOException e) {
-                       throw new CmdLineException(clp, e.getMessage());
+                       throw new CmdLineException(clp, CLIText.format(e.getMessage()));
                }
                if (id == null)
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notATree), name);
 
                final RevTree c;
                try {
                        c = clp.getRevWalk().parseTree(id);
                } catch (MissingObjectException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notATree), name);
                } catch (IncorrectObjectTypeException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notATree), name);
                } catch (IOException e) {
-                       throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().cannotReadBecause), name,
+                                       e.getMessage());
                }
                setter.addValue(c);
                return 1;
index 311597e6bb4b18e9f41aca3dc0ea1b843857fe2d..ae5263fba7cba64a6ceee4644bd3c0a687072013 100644 (file)
@@ -43,8 +43,6 @@
 
 package org.eclipse.jgit.pgm.opt;
 
-import java.text.MessageFormat;
-
 import org.eclipse.jgit.pgm.CommandCatalog;
 import org.eclipse.jgit.pgm.CommandRef;
 import org.eclipse.jgit.pgm.TextBuiltin;
@@ -85,8 +83,8 @@ public class SubcommandHandler extends OptionHandler<TextBuiltin> {
                final String name = params.getParameter(0);
                final CommandRef cr = CommandCatalog.get(name);
                if (cr == null)
-                       throw new CmdLineException(clp, MessageFormat.format(
-                                       CLIText.get().notAJgitCommand, name));
+                       throw new CmdLineException(clp,
+                                       CLIText.format(CLIText.get().notAJgitCommand), name);
 
                // Force option parsing to stop. Everything after us should
                // be arguments known only to this command and must not be
index 3edd0ddbe0e5c67911bb112dad3c45f7b6154ead..e22b2e49b1f6045dee16354951d13b94efb245be 100644 (file)
@@ -42,8 +42,6 @@
  */
 package org.eclipse.jgit.pgm.opt;
 
-import java.text.MessageFormat;
-
 import org.eclipse.jgit.pgm.internal.CLIText;
 import org.kohsuke.args4j.CmdLineException;
 import org.kohsuke.args4j.CmdLineParser;
@@ -105,8 +103,9 @@ public class UntrackedFilesHandler extends StringOptionHandler {
                        if ("no".equals(mode) || "all".equals(mode)) { //$NON-NLS-1$ //$NON-NLS-2$
                                setter.addValue(mode);
                        } else {
-                               throw new CmdLineException(owner, MessageFormat
-                                               .format(CLIText.get().invalidUntrackedFilesMode, mode));
+                               throw new CmdLineException(owner,
+                                               CLIText.format(CLIText.get().invalidUntrackedFilesMode),
+                                               mode);
                        }
                        return 1;
                } else {