Stop using deprecated CmdLineException constructors
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>
This commit is contained in:
parent
e7c2ae052b
commit
72b3587d42
|
@ -86,7 +86,8 @@ protected void run() throws Exception {
|
||||||
} else {
|
} else {
|
||||||
if (verify && commits.size() > 1) {
|
if (verify && commits.size() > 1) {
|
||||||
final CmdLineParser clp = new CmdLineParser(this);
|
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) {
|
for (final ObjectId o : commits) {
|
||||||
|
|
|
@ -45,14 +45,47 @@
|
||||||
package org.eclipse.jgit.pgm.internal;
|
package org.eclipse.jgit.pgm.internal;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.eclipse.jgit.nls.NLS;
|
import org.eclipse.jgit.nls.NLS;
|
||||||
import org.eclipse.jgit.nls.TranslationBundle;
|
import org.eclipse.jgit.nls.TranslationBundle;
|
||||||
|
import org.kohsuke.args4j.Localizable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translation bundle for JGit command line interface
|
* Translation bundle for JGit command line interface
|
||||||
*/
|
*/
|
||||||
public class CLIText extends TranslationBundle {
|
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
|
* @return an instance of this translation bundle
|
||||||
|
|
|
@ -119,20 +119,25 @@ public int parseArguments(final Parameters params) throws CmdLineException {
|
||||||
try {
|
try {
|
||||||
id = clp.getRepository().resolve(name);
|
id = clp.getRepository().resolve(name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(clp, e.getMessage());
|
throw new CmdLineException(clp, CLIText.format(e.getMessage()));
|
||||||
}
|
}
|
||||||
if (id == null)
|
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();
|
final CanonicalTreeParser p = new CanonicalTreeParser();
|
||||||
try (ObjectReader curs = clp.getRepository().newObjectReader()) {
|
try (ObjectReader curs = clp.getRepository().newObjectReader()) {
|
||||||
p.reset(curs, clp.getRevWalk().parseTree(id));
|
p.reset(curs, clp.getRevWalk().parseTree(id));
|
||||||
} catch (MissingObjectException e) {
|
} 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) {
|
} 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) {
|
} 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);
|
setter.addValue(p);
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
package org.eclipse.jgit.pgm.opt;
|
package org.eclipse.jgit.pgm.opt;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.pgm.internal.CLIText;
|
import org.eclipse.jgit.pgm.internal.CLIText;
|
||||||
|
@ -86,14 +85,15 @@ public int parseArguments(final Parameters params) throws CmdLineException {
|
||||||
try {
|
try {
|
||||||
id = clp.getRepository().resolve(name);
|
id = clp.getRepository().resolve(name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(clp, e.getMessage());
|
throw new CmdLineException(clp, CLIText.format(e.getMessage()));
|
||||||
}
|
}
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
setter.addValue(id);
|
setter.addValue(id);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notAnObject, name));
|
throw new CmdLineException(clp,
|
||||||
|
CLIText.format(CLIText.get().notAnObject), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
package org.eclipse.jgit.pgm.opt;
|
package org.eclipse.jgit.pgm.opt;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
|
@ -97,9 +96,8 @@ public int parseArguments(final Parameters params) throws CmdLineException {
|
||||||
if (dot2 != -1) {
|
if (dot2 != -1) {
|
||||||
if (!option.isMultiValued())
|
if (!option.isMultiValued())
|
||||||
throw new CmdLineException(clp,
|
throw new CmdLineException(clp,
|
||||||
MessageFormat.format(
|
CLIText.format(CLIText.get().onlyOneMetaVarExpectedIn),
|
||||||
CLIText.get().onlyOneMetaVarExpectedIn,
|
option.metaVar(), name);
|
||||||
option.metaVar(), name));
|
|
||||||
|
|
||||||
final String left = name.substring(0, dot2);
|
final String left = name.substring(0, dot2);
|
||||||
final String right = name.substring(dot2 + 2);
|
final String right = name.substring(dot2 + 2);
|
||||||
|
@ -118,20 +116,25 @@ private void addOne(final String name, final boolean interesting)
|
||||||
try {
|
try {
|
||||||
id = clp.getRepository().resolve(name);
|
id = clp.getRepository().resolve(name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(clp, e.getMessage());
|
throw new CmdLineException(clp, CLIText.format(e.getMessage()));
|
||||||
}
|
}
|
||||||
if (id == null)
|
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;
|
final RevCommit c;
|
||||||
try {
|
try {
|
||||||
c = clp.getRevWalk().parseCommit(id);
|
c = clp.getRevWalk().parseCommit(id);
|
||||||
} catch (MissingObjectException e) {
|
} 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) {
|
} 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) {
|
} 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)
|
if (interesting)
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
package org.eclipse.jgit.pgm.opt;
|
package org.eclipse.jgit.pgm.opt;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
|
@ -89,20 +88,25 @@ public int parseArguments(final Parameters params) throws CmdLineException {
|
||||||
try {
|
try {
|
||||||
id = clp.getRepository().resolve(name);
|
id = clp.getRepository().resolve(name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(clp, e.getMessage());
|
throw new CmdLineException(clp, CLIText.format(e.getMessage()));
|
||||||
}
|
}
|
||||||
if (id == null)
|
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;
|
final RevTree c;
|
||||||
try {
|
try {
|
||||||
c = clp.getRevWalk().parseTree(id);
|
c = clp.getRevWalk().parseTree(id);
|
||||||
} catch (MissingObjectException e) {
|
} 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) {
|
} 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) {
|
} 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);
|
setter.addValue(c);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -43,8 +43,6 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.pgm.opt;
|
package org.eclipse.jgit.pgm.opt;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.pgm.CommandCatalog;
|
import org.eclipse.jgit.pgm.CommandCatalog;
|
||||||
import org.eclipse.jgit.pgm.CommandRef;
|
import org.eclipse.jgit.pgm.CommandRef;
|
||||||
import org.eclipse.jgit.pgm.TextBuiltin;
|
import org.eclipse.jgit.pgm.TextBuiltin;
|
||||||
|
@ -85,8 +83,8 @@ public int parseArguments(final Parameters params) throws CmdLineException {
|
||||||
final String name = params.getParameter(0);
|
final String name = params.getParameter(0);
|
||||||
final CommandRef cr = CommandCatalog.get(name);
|
final CommandRef cr = CommandCatalog.get(name);
|
||||||
if (cr == null)
|
if (cr == null)
|
||||||
throw new CmdLineException(clp, MessageFormat.format(
|
throw new CmdLineException(clp,
|
||||||
CLIText.get().notAJgitCommand, name));
|
CLIText.format(CLIText.get().notAJgitCommand), name);
|
||||||
|
|
||||||
// Force option parsing to stop. Everything after us should
|
// Force option parsing to stop. Everything after us should
|
||||||
// be arguments known only to this command and must not be
|
// be arguments known only to this command and must not be
|
||||||
|
|
|
@ -42,8 +42,6 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.jgit.pgm.opt;
|
package org.eclipse.jgit.pgm.opt;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.pgm.internal.CLIText;
|
import org.eclipse.jgit.pgm.internal.CLIText;
|
||||||
import org.kohsuke.args4j.CmdLineException;
|
import org.kohsuke.args4j.CmdLineException;
|
||||||
import org.kohsuke.args4j.CmdLineParser;
|
import org.kohsuke.args4j.CmdLineParser;
|
||||||
|
@ -105,8 +103,9 @@ public int parseArguments(Parameters params) throws CmdLineException {
|
||||||
if ("no".equals(mode) || "all".equals(mode)) { //$NON-NLS-1$ //$NON-NLS-2$
|
if ("no".equals(mode) || "all".equals(mode)) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
setter.addValue(mode);
|
setter.addValue(mode);
|
||||||
} else {
|
} else {
|
||||||
throw new CmdLineException(owner, MessageFormat
|
throw new CmdLineException(owner,
|
||||||
.format(CLIText.get().invalidUntrackedFilesMode, mode));
|
CLIText.format(CLIText.get().invalidUntrackedFilesMode),
|
||||||
|
mode);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue