LCOV - code coverage report
Current view: top level - extensions/api/access - PluginPermission.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 7 17 41.2 %
Date: 2022-11-19 15:00:39 Functions: 3 9 33.3 %

          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.extensions.api.access;
      16             : 
      17             : import static java.util.Objects.requireNonNull;
      18             : 
      19             : import java.util.Objects;
      20             : 
      21             : /** A global capability type permission used by a plugin. */
      22             : public class PluginPermission implements GlobalOrPluginPermission {
      23             :   private final String pluginName;
      24             :   private final String capability;
      25             :   private final boolean fallBackToAdmin;
      26             : 
      27             :   public PluginPermission(String pluginName, String capability) {
      28           0 :     this(pluginName, capability, true);
      29           0 :   }
      30             : 
      31           1 :   public PluginPermission(String pluginName, String capability, boolean fallBackToAdmin) {
      32           1 :     this.pluginName = requireNonNull(pluginName, "pluginName");
      33           1 :     this.capability = requireNonNull(capability, "capability");
      34           1 :     this.fallBackToAdmin = fallBackToAdmin;
      35           1 :   }
      36             : 
      37             :   public String pluginName() {
      38           1 :     return pluginName;
      39             :   }
      40             : 
      41             :   public String capability() {
      42           1 :     return capability;
      43             :   }
      44             : 
      45             :   public boolean fallBackToAdmin() {
      46           0 :     return fallBackToAdmin;
      47             :   }
      48             : 
      49             :   @Override
      50             :   public String describeForException() {
      51           0 :     return capability + " for plugin " + pluginName;
      52             :   }
      53             : 
      54             :   @Override
      55             :   public int hashCode() {
      56           0 :     return Objects.hash(pluginName, capability);
      57             :   }
      58             : 
      59             :   @Override
      60             :   public boolean equals(Object other) {
      61           0 :     if (other instanceof PluginPermission) {
      62           0 :       PluginPermission b = (PluginPermission) other;
      63           0 :       return pluginName.equals(b.pluginName) && capability.equals(b.capability);
      64             :     }
      65           0 :     return false;
      66             :   }
      67             : 
      68             :   @Override
      69             :   public String toString() {
      70           0 :     return "PluginPermission[plugin=" + pluginName + ", capability=" + capability + ']';
      71             :   }
      72             : }

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