LCOV - code coverage report
Current view: top level - server/git - ProjectRunnable.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 8 11 72.7 %
Date: 2022-11-19 15:00:39 Functions: 3 6 50.0 %

          Line data    Source code
       1             : // Copyright (C) 2010 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             : package com.google.gerrit.server.git;
      15             : 
      16             : import com.google.gerrit.common.Nullable;
      17             : import com.google.gerrit.entities.Project;
      18             : import java.util.concurrent.Callable;
      19             : import java.util.concurrent.FutureTask;
      20             : 
      21             : /** Used to retrieve the project name from an operation * */
      22             : public interface ProjectRunnable extends Runnable {
      23             :   Project.NameKey getProjectNameKey();
      24             : 
      25             :   @Nullable
      26             :   String getRemoteName();
      27             : 
      28             :   boolean hasCustomizedPrint();
      29             : 
      30             :   /**
      31             :    * Wraps the callable as a {@link FutureTask} and makes it comply with the {@link ProjectRunnable}
      32             :    * interface.
      33             :    */
      34             :   static <T> FutureTask<T> fromCallable(
      35             :       Callable<T> callable,
      36             :       Project.NameKey projectName,
      37             :       String operationName,
      38             :       @Nullable String remoteHostname,
      39             :       boolean hasCustomPrint) {
      40          96 :     return new FromCallable<>(callable, projectName, operationName, remoteHostname, hasCustomPrint);
      41             :   }
      42             : 
      43             :   class FromCallable<T> extends FutureTask<T> implements ProjectRunnable {
      44             :     private final Project.NameKey project;
      45             :     private final String operationName;
      46             :     private final String remoteHostname;
      47             :     private final boolean hasCustomPrint;
      48             : 
      49             :     FromCallable(
      50             :         Callable<T> callable,
      51             :         Project.NameKey project,
      52             :         String operationName,
      53             :         @Nullable String remoteHostname,
      54             :         boolean hasCustomPrint) {
      55          96 :       super(callable);
      56          96 :       this.project = project;
      57          96 :       this.operationName = operationName;
      58          96 :       this.remoteHostname = remoteHostname;
      59          96 :       this.hasCustomPrint = hasCustomPrint;
      60          96 :     }
      61             : 
      62             :     @Override
      63             :     public Project.NameKey getProjectNameKey() {
      64           0 :       return project;
      65             :     }
      66             : 
      67             :     @Override
      68             :     public String getRemoteName() {
      69           0 :       return remoteHostname;
      70             :     }
      71             : 
      72             :     @Override
      73             :     public boolean hasCustomizedPrint() {
      74           0 :       return hasCustomPrint;
      75             :     }
      76             : 
      77             :     @Override
      78             :     public String toString() {
      79          10 :       return operationName;
      80             :     }
      81             :   }
      82             : }

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