LCOV - code coverage report
Current view: top level - sshd/commands - IndexChangesInProjectCommand.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 9 13 69.2 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2017 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.sshd.commands;
      16             : 
      17             : import static com.google.gerrit.common.data.GlobalCapability.MAINTAIN_SERVER;
      18             : 
      19             : import com.google.gerrit.extensions.annotations.RequiresAnyCapability;
      20             : import com.google.gerrit.server.project.ProjectResource;
      21             : import com.google.gerrit.server.project.ProjectState;
      22             : import com.google.gerrit.server.restapi.project.IndexChanges;
      23             : import com.google.gerrit.sshd.CommandMetaData;
      24             : import com.google.gerrit.sshd.SshCommand;
      25             : import com.google.inject.Inject;
      26             : import java.util.ArrayList;
      27             : import java.util.List;
      28             : import org.kohsuke.args4j.Argument;
      29             : 
      30             : @RequiresAnyCapability({MAINTAIN_SERVER})
      31             : @CommandMetaData(name = "changes-in-project", description = "Index changes of a project")
      32           1 : final class IndexChangesInProjectCommand extends SshCommand {
      33             : 
      34             :   @Inject private IndexChanges index;
      35             : 
      36           1 :   @Argument(
      37             :       index = 0,
      38             :       required = true,
      39             :       multiValued = true,
      40             :       metaVar = "PROJECT",
      41             :       usage = "projects for which the changes should be indexed")
      42             :   private List<ProjectState> projects = new ArrayList<>();
      43             : 
      44             :   @Override
      45             :   protected void run() throws UnloggedFailure, Failure, Exception {
      46           1 :     enableGracefulStop();
      47           1 :     if (projects.isEmpty()) {
      48           0 :       throw die("needs at least one project as command arguments");
      49             :     }
      50           1 :     projects.stream().forEach(this::index);
      51           1 :   }
      52             : 
      53             :   private void index(ProjectState projectState) {
      54             :     try {
      55           1 :       index.apply(new ProjectResource(projectState, user), null);
      56           0 :     } catch (Exception e) {
      57           0 :       writeError(
      58           0 :           "error", String.format("Unable to index %s: %s", projectState.getName(), e.getMessage()));
      59           1 :     }
      60           1 :   }
      61             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750