LCOV - code coverage report
Current view: top level - server/account - VersionedAccountDestinations.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 19 22 86.4 %
Date: 2022-11-19 15:00:39 Functions: 6 8 75.0 %

          Line data    Source code
       1             : // Copyright (C) 2015 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.account;
      16             : 
      17             : import com.google.common.flogger.FluentLogger;
      18             : import com.google.gerrit.entities.Account;
      19             : import com.google.gerrit.entities.RefNames;
      20             : import com.google.gerrit.server.git.meta.VersionedMetaData;
      21             : import java.io.IOException;
      22             : import org.eclipse.jgit.errors.ConfigInvalidException;
      23             : import org.eclipse.jgit.lib.CommitBuilder;
      24             : import org.eclipse.jgit.lib.FileMode;
      25             : 
      26             : /** User configured named destinations. */
      27             : public class VersionedAccountDestinations extends VersionedMetaData {
      28           4 :   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
      29             : 
      30             :   public static VersionedAccountDestinations forUser(Account.Id id) {
      31           4 :     return new VersionedAccountDestinations(RefNames.refsUsers(id));
      32             :   }
      33             : 
      34             :   private final String ref;
      35           4 :   private final DestinationList destinations = new DestinationList();
      36             : 
      37           4 :   private VersionedAccountDestinations(String ref) {
      38           4 :     this.ref = ref;
      39           4 :   }
      40             : 
      41             :   @Override
      42             :   protected String getRefName() {
      43           4 :     return ref;
      44             :   }
      45             : 
      46             :   public DestinationList getDestinationList() {
      47           4 :     return destinations;
      48             :   }
      49             : 
      50             :   @Override
      51             :   protected void onLoad() throws IOException, ConfigInvalidException {
      52           4 :     if (revision == null) {
      53           0 :       return;
      54             :     }
      55           4 :     String prefix = DestinationList.DIR_NAME + "/";
      56           4 :     for (PathInfo p : getPathInfos(true)) {
      57           4 :       if (p.fileMode == FileMode.REGULAR_FILE) {
      58           4 :         String path = p.path;
      59           4 :         if (path.startsWith(prefix)) {
      60           4 :           String label = path.substring(prefix.length());
      61           4 :           destinations.parseLabel(
      62             :               label,
      63           4 :               readUTF8(path),
      64             :               error ->
      65           0 :                   logger.atSevere().log("Error parsing file %s: %s", path, error.getMessage()));
      66             :         }
      67             :       }
      68           4 :     }
      69           4 :   }
      70             : 
      71             :   @Override
      72             :   protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
      73           0 :     throw new UnsupportedOperationException("Cannot yet save destinations");
      74             :   }
      75             : }

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