use of org.kohsuke.args4j.CmdLineException in project gerrit by GerritCodeReview.
the class ParameterParser method parse.
<T> boolean parse(T param, ListMultimap<String, String> in, HttpServletRequest req, HttpServletResponse res) throws IOException {
CmdLineParser clp = parserFactory.create(param);
DynamicOptions pluginOptions = new DynamicOptions(param, injector, dynamicBeans);
pluginOptions.parseDynamicBeans(clp);
pluginOptions.setDynamicBeans();
pluginOptions.onBeanParseStart();
try {
clp.parseOptionMap(in);
} catch (CmdLineException | NumberFormatException e) {
if (!clp.wasHelpRequestedByOption()) {
replyError(req, res, SC_BAD_REQUEST, e.getMessage(), e);
return false;
}
}
if (clp.wasHelpRequestedByOption()) {
StringWriter msg = new StringWriter();
clp.printQueryStringUsage(req.getRequestURI(), msg);
msg.write('\n');
msg.write('\n');
clp.printUsage(msg, null);
msg.write('\n');
CacheHeaders.setNotCacheable(res);
replyBinaryResult(req, res, BinaryResult.create(msg.toString()).setContentType("text/plain"));
return false;
}
pluginOptions.onBeanParseEnd();
return true;
}
use of org.kohsuke.args4j.CmdLineException in project gerrit by GerritCodeReview.
the class ProjectControlHandler method parseArguments.
@Override
public final int parseArguments(final Parameters params) throws CmdLineException {
String projectName = params.getParameter(0);
while (projectName.endsWith("/")) {
projectName = projectName.substring(0, projectName.length() - 1);
}
while (projectName.startsWith("/")) {
// Be nice and drop the leading "/" if supplied by an absolute path.
// We don't have a file system hierarchy, just a flat namespace in
// the database's Project entities. We never encode these with a
// leading '/' but users might accidentally include them in Git URLs.
//
projectName = projectName.substring(1);
}
String nameWithoutSuffix = ProjectUtil.stripGitSuffix(projectName);
Project.NameKey nameKey = new Project.NameKey(nameWithoutSuffix);
ProjectControl control;
try {
control = projectControlFactory.controlFor(nameKey, user.get());
permissionBackend.user(user).project(nameKey).check(ProjectPermission.ACCESS);
} catch (AuthException e) {
throw new CmdLineException(owner, new NoSuchProjectException(nameKey).getMessage());
} catch (NoSuchProjectException e) {
throw new CmdLineException(owner, e.getMessage());
} catch (PermissionBackendException | IOException e) {
log.warn("Cannot load project " + nameWithoutSuffix, e);
throw new CmdLineException(owner, new NoSuchProjectException(nameKey).getMessage());
}
setter.addValue(control);
return 1;
}
use of org.kohsuke.args4j.CmdLineException in project gerrit by GerritCodeReview.
the class TimestampHandler method parseArguments.
@Override
public int parseArguments(Parameters params) throws CmdLineException {
String timestamp = params.getParameter(0);
try {
DateFormat fmt = new SimpleDateFormat(TIMESTAMP_FORMAT);
fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
setter.addValue(new Timestamp(fmt.parse(timestamp).getTime()));
return 1;
} catch (ParseException e) {
throw new CmdLineException(owner, String.format("Invalid timestamp: %s; expected format: %s", timestamp, TIMESTAMP_FORMAT), e);
}
}
use of org.kohsuke.args4j.CmdLineException in project gerrit by GerritCodeReview.
the class AccountGroupIdHandler method parseArguments.
@Override
public final int parseArguments(final Parameters params) throws CmdLineException {
final String n = params.getParameter(0);
final AccountGroup group = groupCache.get(new AccountGroup.NameKey(n));
if (group == null) {
throw new CmdLineException(owner, "Group \"" + n + "\" does not exist");
}
setter.addValue(group.getId());
return 1;
}
use of org.kohsuke.args4j.CmdLineException in project gerrit by GerritCodeReview.
the class AccountIdHandler method parseArguments.
@Override
public int parseArguments(Parameters params) throws CmdLineException {
String token = params.getParameter(0);
Account.Id accountId;
try {
Account a = accountResolver.find(db.get(), token);
if (a != null) {
accountId = a.getId();
} else {
switch(authType) {
case HTTP_LDAP:
case CLIENT_SSL_CERT_LDAP:
case LDAP:
accountId = createAccountByLdap(token);
break;
case CUSTOM_EXTENSION:
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
case HTTP:
case LDAP_BIND:
case OAUTH:
case OPENID:
case OPENID_SSO:
default:
throw new CmdLineException(owner, "user \"" + token + "\" not found");
}
}
} catch (OrmException | IOException e) {
throw new CmdLineException(owner, "database is down");
}
setter.addValue(accountId);
return 1;
}
Aggregations