Dissolve gerrit-server top-level directory
Change-Id: I538512dfe0f1bea774c01fdd45fa410a45634011
This commit is contained in:
committed by
Dave Borowitz
parent
472396c797
commit
376a7bbb64
@@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.group.InternalGroup;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.util.Optional;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class AccountGroupIdHandler extends OptionHandler<AccountGroup.Id> {
|
||||
private final GroupCache groupCache;
|
||||
|
||||
@Inject
|
||||
public AccountGroupIdHandler(
|
||||
final GroupCache groupCache,
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<AccountGroup.Id> setter) {
|
||||
super(parser, option, setter);
|
||||
this.groupCache = groupCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int parseArguments(Parameters params) throws CmdLineException {
|
||||
final String n = params.getParameter(0);
|
||||
Optional<InternalGroup> group = groupCache.get(new AccountGroup.NameKey(n));
|
||||
if (!group.isPresent()) {
|
||||
throw new CmdLineException(owner, "Group \"" + n + "\" does not exist");
|
||||
}
|
||||
setter.addValue(group.get().getId());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "GROUP";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.account.GroupBackend;
|
||||
import com.google.gerrit.server.account.GroupBackends;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class AccountGroupUUIDHandler extends OptionHandler<AccountGroup.UUID> {
|
||||
private final GroupBackend groupBackend;
|
||||
|
||||
@Inject
|
||||
public AccountGroupUUIDHandler(
|
||||
final GroupBackend groupBackend,
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<AccountGroup.UUID> setter) {
|
||||
super(parser, option, setter);
|
||||
this.groupBackend = groupBackend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int parseArguments(Parameters params) throws CmdLineException {
|
||||
final String n = params.getParameter(0);
|
||||
GroupReference group = GroupBackends.findExactSuggestion(groupBackend, n);
|
||||
if (group == null) {
|
||||
throw new CmdLineException(owner, "Group \"" + n + "\" does not exist");
|
||||
}
|
||||
setter.addValue(group.getUUID());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "GROUP";
|
||||
}
|
||||
}
|
||||
110
java/com/google/gerrit/server/args4j/AccountIdHandler.java
Normal file
110
java/com/google/gerrit/server/args4j/AccountIdHandler.java
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.extensions.client.AuthType;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.AccountException;
|
||||
import com.google.gerrit.server.account.AccountManager;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.account.AuthRequest;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class AccountIdHandler extends OptionHandler<Account.Id> {
|
||||
private final AccountResolver accountResolver;
|
||||
private final AccountManager accountManager;
|
||||
private final AuthType authType;
|
||||
|
||||
@Inject
|
||||
public AccountIdHandler(
|
||||
AccountResolver accountResolver,
|
||||
AccountManager accountManager,
|
||||
AuthConfig authConfig,
|
||||
@Assisted CmdLineParser parser,
|
||||
@Assisted OptionDef option,
|
||||
@Assisted Setter<Account.Id> setter) {
|
||||
super(parser, option, setter);
|
||||
this.accountResolver = accountResolver;
|
||||
this.accountManager = accountManager;
|
||||
this.authType = authConfig.getAuthType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int parseArguments(Parameters params) throws CmdLineException {
|
||||
String token = params.getParameter(0);
|
||||
Account.Id accountId;
|
||||
try {
|
||||
Account a = accountResolver.find(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 e) {
|
||||
throw new CmdLineException(owner, "database is down");
|
||||
} catch (IOException e) {
|
||||
throw new CmdLineException(owner, "Failed to load account", e);
|
||||
} catch (ConfigInvalidException e) {
|
||||
throw new CmdLineException(owner, "Invalid account config", e);
|
||||
}
|
||||
setter.addValue(accountId);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private Account.Id createAccountByLdap(String user) throws CmdLineException, IOException {
|
||||
if (!user.matches(Account.USER_NAME_PATTERN)) {
|
||||
throw new CmdLineException(owner, "user \"" + user + "\" not found");
|
||||
}
|
||||
|
||||
try {
|
||||
AuthRequest req = AuthRequest.forUser(user);
|
||||
req.setSkipAuthentication(true);
|
||||
return accountManager.authenticate(req).getAccountId();
|
||||
} catch (AccountException e) {
|
||||
throw new CmdLineException(owner, "user \"" + user + "\" not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "EMAIL";
|
||||
}
|
||||
}
|
||||
77
java/com/google/gerrit/server/args4j/ChangeIdHandler.java
Normal file
77
java/com/google/gerrit/server/args4j/ChangeIdHandler.java
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class ChangeIdHandler extends OptionHandler<Change.Id> {
|
||||
private final Provider<InternalChangeQuery> queryProvider;
|
||||
|
||||
@Inject
|
||||
public ChangeIdHandler(
|
||||
// TODO(dborowitz): Not sure whether this is injectable here.
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<Change.Id> setter) {
|
||||
super(parser, option, setter);
|
||||
this.queryProvider = queryProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int parseArguments(Parameters params) throws CmdLineException {
|
||||
final String token = params.getParameter(0);
|
||||
final String[] tokens = token.split(",");
|
||||
if (tokens.length != 3) {
|
||||
throw new CmdLineException(
|
||||
owner, "change should be specified as <project>,<branch>,<change-id>");
|
||||
}
|
||||
|
||||
try {
|
||||
final Change.Key key = Change.Key.parse(tokens[2]);
|
||||
final Project.NameKey project = new Project.NameKey(tokens[0]);
|
||||
final Branch.NameKey branch = new Branch.NameKey(project, tokens[1]);
|
||||
for (ChangeData cd : queryProvider.get().byBranchKey(branch, key)) {
|
||||
setter.addValue(cd.getId());
|
||||
return 1;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CmdLineException(owner, "Change-Id is not valid");
|
||||
} catch (OrmException e) {
|
||||
throw new CmdLineException(owner, "Database error: " + e.getMessage());
|
||||
}
|
||||
|
||||
throw new CmdLineException(owner, "\"" + token + "\": change not found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "CHANGE";
|
||||
}
|
||||
}
|
||||
48
java/com/google/gerrit/server/args4j/ObjectIdHandler.java
Normal file
48
java/com/google/gerrit/server/args4j/ObjectIdHandler.java
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class ObjectIdHandler extends OptionHandler<ObjectId> {
|
||||
|
||||
@Inject
|
||||
public ObjectIdHandler(
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<ObjectId> setter) {
|
||||
super(parser, option, setter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int parseArguments(Parameters params) throws CmdLineException {
|
||||
final String n = params.getParameter(0);
|
||||
setter.addValue(ObjectId.fromString(n));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultMetaVariable() {
|
||||
return "COMMIT";
|
||||
}
|
||||
}
|
||||
55
java/com/google/gerrit/server/args4j/PatchSetIdHandler.java
Normal file
55
java/com/google/gerrit/server/args4j/PatchSetIdHandler.java
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class PatchSetIdHandler extends OptionHandler<PatchSet.Id> {
|
||||
|
||||
@Inject
|
||||
public PatchSetIdHandler(
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<PatchSet.Id> setter) {
|
||||
super(parser, option, setter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int parseArguments(Parameters params) throws CmdLineException {
|
||||
final String token = params.getParameter(0);
|
||||
final PatchSet.Id id;
|
||||
try {
|
||||
id = PatchSet.Id.parse(token);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CmdLineException(owner, "\"" + token + "\" is not a valid patch set");
|
||||
}
|
||||
|
||||
setter.addValue(id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "CHANGE,PATCHSET";
|
||||
}
|
||||
}
|
||||
103
java/com/google/gerrit/server/args4j/ProjectHandler.java
Normal file
103
java/com/google/gerrit/server/args4j/ProjectHandler.java
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.common.ProjectUtil;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.permissions.ProjectPermission;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ProjectHandler extends OptionHandler<ProjectState> {
|
||||
private static final Logger log = LoggerFactory.getLogger(ProjectHandler.class);
|
||||
|
||||
private final ProjectCache projectCache;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final Provider<CurrentUser> user;
|
||||
|
||||
@Inject
|
||||
public ProjectHandler(
|
||||
ProjectCache projectCache,
|
||||
PermissionBackend permissionBackend,
|
||||
Provider<CurrentUser> user,
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<ProjectState> setter) {
|
||||
super(parser, option, setter);
|
||||
this.projectCache = projectCache;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int parseArguments(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);
|
||||
|
||||
ProjectState state;
|
||||
try {
|
||||
state = projectCache.checkedGet(nameKey);
|
||||
if (state == null) {
|
||||
throw new CmdLineException(owner, String.format("project %s not found", nameWithoutSuffix));
|
||||
}
|
||||
permissionBackend.user(user).project(nameKey).check(ProjectPermission.ACCESS);
|
||||
} catch (AuthException e) {
|
||||
throw new CmdLineException(owner, new NoSuchProjectException(nameKey).getMessage());
|
||||
} catch (PermissionBackendException | IOException e) {
|
||||
log.warn("Cannot load project " + nameWithoutSuffix, e);
|
||||
throw new CmdLineException(owner, new NoSuchProjectException(nameKey).getMessage());
|
||||
}
|
||||
|
||||
setter.addValue(state);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "PROJECT";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.server.util.SocketUtil;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.net.SocketAddress;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class SocketAddressHandler extends OptionHandler<SocketAddress> {
|
||||
|
||||
@Inject
|
||||
public SocketAddressHandler(
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<SocketAddress> setter) {
|
||||
super(parser, option, setter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int parseArguments(Parameters params) throws CmdLineException {
|
||||
final String token = params.getParameter(0);
|
||||
try {
|
||||
setter.addValue(SocketUtil.parse(token, 0));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CmdLineException(owner, e.getMessage());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "HOST:PORT";
|
||||
}
|
||||
}
|
||||
47
java/com/google/gerrit/server/args4j/SubcommandHandler.java
Normal file
47
java/com/google/gerrit/server/args4j/SubcommandHandler.java
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class SubcommandHandler extends OptionHandler<String> {
|
||||
|
||||
@Inject
|
||||
public SubcommandHandler(
|
||||
@Assisted final CmdLineParser parser,
|
||||
@Assisted final OptionDef option,
|
||||
@Assisted final Setter<String> setter) {
|
||||
super(parser, option, setter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int parseArguments(Parameters params) throws CmdLineException {
|
||||
setter.addValue(params.getParameter(0));
|
||||
owner.stopOptionParsing();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDefaultMetaVariable() {
|
||||
return "COMMAND";
|
||||
}
|
||||
}
|
||||
62
java/com/google/gerrit/server/args4j/TimestampHandler.java
Normal file
62
java/com/google/gerrit/server/args4j/TimestampHandler.java
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.TimeZone;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.OptionDef;
|
||||
import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class TimestampHandler extends OptionHandler<Timestamp> {
|
||||
public static final String TIMESTAMP_FORMAT = "yyyyMMdd_HHmm";
|
||||
|
||||
@Inject
|
||||
public TimestampHandler(
|
||||
@Assisted CmdLineParser parser,
|
||||
@Assisted OptionDef option,
|
||||
@Assisted Setter<Timestamp> setter) {
|
||||
super(parser, option, setter);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultMetaVariable() {
|
||||
return "TIMESTAMP";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user