LCOV - code coverage report
Current view: top level - server/api/plugins - PluginApiImpl.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 15 19 78.9 %
Date: 2022-11-19 15:00:39 Functions: 4 5 80.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.server.api.plugins;
      16             : 
      17             : import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
      18             : 
      19             : import com.google.gerrit.extensions.api.plugins.PluginApi;
      20             : import com.google.gerrit.extensions.common.Input;
      21             : import com.google.gerrit.extensions.common.PluginInfo;
      22             : import com.google.gerrit.extensions.restapi.RestApiException;
      23             : import com.google.gerrit.server.plugins.DisablePlugin;
      24             : import com.google.gerrit.server.plugins.EnablePlugin;
      25             : import com.google.gerrit.server.plugins.GetStatus;
      26             : import com.google.gerrit.server.plugins.PluginResource;
      27             : import com.google.gerrit.server.plugins.ReloadPlugin;
      28             : import com.google.inject.Inject;
      29             : import com.google.inject.assistedinject.Assisted;
      30             : 
      31             : public class PluginApiImpl implements PluginApi {
      32             :   public interface Factory {
      33             :     PluginApiImpl create(PluginResource resource);
      34             :   }
      35             : 
      36             :   private final GetStatus getStatus;
      37             :   private final EnablePlugin enable;
      38             :   private final DisablePlugin disable;
      39             :   private final ReloadPlugin reload;
      40             :   private final PluginResource resource;
      41             : 
      42             :   @Inject
      43             :   PluginApiImpl(
      44             :       GetStatus getStatus,
      45             :       EnablePlugin enable,
      46             :       DisablePlugin disable,
      47             :       ReloadPlugin reload,
      48           3 :       @Assisted PluginResource resource) {
      49           3 :     this.getStatus = getStatus;
      50           3 :     this.enable = enable;
      51           3 :     this.disable = disable;
      52           3 :     this.reload = reload;
      53           3 :     this.resource = resource;
      54           3 :   }
      55             : 
      56             :   @Override
      57             :   public PluginInfo get() throws RestApiException {
      58             :     try {
      59           1 :       return getStatus.apply(resource).value();
      60           0 :     } catch (Exception e) {
      61           0 :       throw asRestApiException("Cannot get status", e);
      62             :     }
      63             :   }
      64             : 
      65             :   @Override
      66             :   public void enable() throws RestApiException {
      67           1 :     enable.apply(resource, new Input());
      68           1 :   }
      69             : 
      70             :   @Override
      71             :   public void disable() throws RestApiException {
      72             :     try {
      73           1 :       disable.apply(resource, new Input());
      74           1 :     } catch (Exception e) {
      75           1 :       throw asRestApiException("Cannot disable plugin", e);
      76           1 :     }
      77           1 :   }
      78             : 
      79             :   @Override
      80             :   public void reload() throws RestApiException {
      81           0 :     reload.apply(resource, new Input());
      82           0 :   }
      83             : }

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