Don't use deprecated constructors of CmdLineException
Change-Id: If01fa896537209821d6a7a262ee978572195a397 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
62718a9cbc
commit
d1e821ec3f
|
@ -57,6 +57,7 @@
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
import org.eclipse.jgit.pgm.internal.CLIText;
|
import org.eclipse.jgit.pgm.internal.CLIText;
|
||||||
|
import org.eclipse.jgit.pgm.opt.CmdLineParser;
|
||||||
|
|
||||||
@Command(usage = "usage_RevParse")
|
@Command(usage = "usage_RevParse")
|
||||||
class RevParse extends TextBuiltin {
|
class RevParse extends TextBuiltin {
|
||||||
|
@ -78,7 +79,8 @@ protected void run() throws Exception {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (verify && commits.size() > 1) {
|
if (verify && commits.size() > 1) {
|
||||||
throw new CmdLineException(CLIText.get().needSingleRevision);
|
final CmdLineParser clp = new CmdLineParser(this);
|
||||||
|
throw new CmdLineException(clp, CLIText.get().needSingleRevision);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final ObjectId o : commits) {
|
for (final ObjectId o : commits) {
|
||||||
|
|
|
@ -109,7 +109,7 @@ public int parseArguments(final Parameters params) throws CmdLineException {
|
||||||
try {
|
try {
|
||||||
dirc = DirCache.read(new File(name), FS.DETECTED);
|
dirc = DirCache.read(new File(name), FS.DETECTED);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notAnIndexFile, name), e);
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notAnIndexFile, name), e);
|
||||||
}
|
}
|
||||||
setter.addValue(new DirCacheIterator(dirc));
|
setter.addValue(new DirCacheIterator(dirc));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -119,20 +119,20 @@ 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(e.getMessage());
|
throw new CmdLineException(clp, e.getMessage());
|
||||||
}
|
}
|
||||||
if (id == null)
|
if (id == null)
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
|
throw new CmdLineException(clp, MessageFormat.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(MessageFormat.format(CLIText.get().notATree, name));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
|
||||||
} catch (IncorrectObjectTypeException e) {
|
} catch (IncorrectObjectTypeException e) {
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
setter.addValue(p);
|
setter.addValue(p);
|
||||||
|
|
|
@ -86,14 +86,14 @@ 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(e.getMessage());
|
throw new CmdLineException(clp, e.getMessage());
|
||||||
}
|
}
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
setter.addValue(id);
|
setter.addValue(id);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notAnObject, name));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notAnObject, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -96,8 +96,10 @@ public int parseArguments(final Parameters params) throws CmdLineException {
|
||||||
final int dot2 = name.indexOf(".."); //$NON-NLS-1$
|
final int dot2 = name.indexOf(".."); //$NON-NLS-1$
|
||||||
if (dot2 != -1) {
|
if (dot2 != -1) {
|
||||||
if (!option.isMultiValued())
|
if (!option.isMultiValued())
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().onlyOneMetaVarExpectedIn
|
throw new CmdLineException(clp,
|
||||||
, option.metaVar(), name));
|
MessageFormat.format(
|
||||||
|
CLIText.get().onlyOneMetaVarExpectedIn,
|
||||||
|
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);
|
||||||
|
@ -116,20 +118,20 @@ 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(e.getMessage());
|
throw new CmdLineException(clp, e.getMessage());
|
||||||
}
|
}
|
||||||
if (id == null)
|
if (id == null)
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name));
|
throw new CmdLineException(clp, MessageFormat.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(MessageFormat.format(CLIText.get().notACommit, name));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name));
|
||||||
} catch (IncorrectObjectTypeException e) {
|
} catch (IncorrectObjectTypeException e) {
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interesting)
|
if (interesting)
|
||||||
|
|
|
@ -89,20 +89,20 @@ 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(e.getMessage());
|
throw new CmdLineException(clp, e.getMessage());
|
||||||
}
|
}
|
||||||
if (id == null)
|
if (id == null)
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
|
throw new CmdLineException(clp, MessageFormat.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(MessageFormat.format(CLIText.get().notATree, name));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
|
||||||
} catch (IncorrectObjectTypeException e) {
|
} catch (IncorrectObjectTypeException e) {
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
|
throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
|
||||||
}
|
}
|
||||||
setter.addValue(c);
|
setter.addValue(c);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -63,6 +63,8 @@
|
||||||
* we can execute at runtime with the remaining arguments of the parser.
|
* we can execute at runtime with the remaining arguments of the parser.
|
||||||
*/
|
*/
|
||||||
public class SubcommandHandler extends OptionHandler<TextBuiltin> {
|
public class SubcommandHandler extends OptionHandler<TextBuiltin> {
|
||||||
|
private final org.eclipse.jgit.pgm.opt.CmdLineParser clp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new handler for the command name.
|
* Create a new handler for the command name.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -75,6 +77,7 @@ public class SubcommandHandler extends OptionHandler<TextBuiltin> {
|
||||||
public SubcommandHandler(final CmdLineParser parser,
|
public SubcommandHandler(final CmdLineParser parser,
|
||||||
final OptionDef option, final Setter<? super TextBuiltin> setter) {
|
final OptionDef option, final Setter<? super TextBuiltin> setter) {
|
||||||
super(parser, option, setter);
|
super(parser, option, setter);
|
||||||
|
clp = (org.eclipse.jgit.pgm.opt.CmdLineParser) parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,7 +85,7 @@ 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(MessageFormat.format(
|
throw new CmdLineException(clp, MessageFormat.format(
|
||||||
CLIText.get().notAJgitCommand, name));
|
CLIText.get().notAJgitCommand, name));
|
||||||
|
|
||||||
// Force option parsing to stop. Everything after us should
|
// Force option parsing to stop. Everything after us should
|
||||||
|
|
Loading…
Reference in New Issue