LCOV - code coverage report
Current view: top level - server/plugins - ReloadPlugin.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 7 16 43.8 %
Date: 2022-11-19 15:00:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2012 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.plugins;
      16             : 
      17             : import com.google.common.collect.ImmutableList;
      18             : import com.google.gerrit.common.data.GlobalCapability;
      19             : import com.google.gerrit.extensions.annotations.RequiresCapability;
      20             : import com.google.gerrit.extensions.common.Input;
      21             : import com.google.gerrit.extensions.common.PluginInfo;
      22             : import com.google.gerrit.extensions.restapi.ResourceConflictException;
      23             : import com.google.gerrit.extensions.restapi.Response;
      24             : import com.google.gerrit.extensions.restapi.RestModifyView;
      25             : import com.google.inject.Inject;
      26             : import com.google.inject.Singleton;
      27             : import java.io.PrintWriter;
      28             : import java.io.StringWriter;
      29             : 
      30             : @RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
      31             : @Singleton
      32             : public class ReloadPlugin implements RestModifyView<PluginResource, Input> {
      33             : 
      34             :   private final PluginLoader loader;
      35             : 
      36             :   @Inject
      37         138 :   ReloadPlugin(PluginLoader loader) {
      38         138 :     this.loader = loader;
      39         138 :   }
      40             : 
      41             :   @Override
      42             :   public Response<PluginInfo> apply(PluginResource resource, Input input)
      43             :       throws ResourceConflictException {
      44           1 :     String name = resource.getName();
      45             :     try {
      46           1 :       loader.reload(ImmutableList.of(name));
      47           0 :     } catch (InvalidPluginException e) {
      48           0 :       throw new ResourceConflictException(e.getMessage());
      49           0 :     } catch (PluginInstallException e) {
      50           0 :       StringWriter buf = new StringWriter();
      51           0 :       buf.write(String.format("cannot reload %s\n", name));
      52           0 :       PrintWriter pw = new PrintWriter(buf);
      53           0 :       e.printStackTrace(pw);
      54           0 :       pw.flush();
      55           0 :       throw new ResourceConflictException(buf.toString());
      56           1 :     }
      57           1 :     return Response.ok(ListPlugins.toPluginInfo(loader.get(name)));
      58             :   }
      59             : }

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