LCOV - code coverage report
Current view: top level - index/project - ProjectField.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 21 22 95.5 %
Date: 2022-11-19 15:00:39 Functions: 10 11 90.9 %

          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.index.project;
      16             : 
      17             : import static com.google.common.collect.ImmutableList.toImmutableList;
      18             : import static com.google.gerrit.index.FieldDef.exact;
      19             : import static com.google.gerrit.index.FieldDef.fullText;
      20             : import static com.google.gerrit.index.FieldDef.prefix;
      21             : import static com.google.gerrit.index.FieldDef.storedOnly;
      22             : 
      23             : import com.google.gerrit.entities.Project;
      24             : import com.google.gerrit.entities.RefNames;
      25             : import com.google.gerrit.index.FieldDef;
      26             : import com.google.gerrit.index.RefState;
      27             : import com.google.gerrit.index.SchemaUtil;
      28             : 
      29             : /**
      30             :  * Index schema for projects.
      31             :  *
      32             :  * <p>Note that this class does not override {@link Object#equals(Object)}. It relies on instances
      33             :  * being singletons so that the default (i.e. reference) comparison works.
      34             :  */
      35           0 : public class ProjectField {
      36             :   private static byte[] toRefState(Project project) {
      37           7 :     return RefState.create(RefNames.REFS_CONFIG, project.getConfigRefState())
      38           7 :         .toByteArray(project.getNameKey());
      39             :   }
      40             : 
      41         153 :   public static final FieldDef<ProjectData, String> NAME =
      42         153 :       exact("name").stored().build(p -> p.getProject().getName());
      43             : 
      44         153 :   public static final FieldDef<ProjectData, String> DESCRIPTION =
      45         153 :       fullText("description").stored().build(p -> p.getProject().getDescription());
      46             : 
      47         153 :   public static final FieldDef<ProjectData, String> PARENT_NAME =
      48         153 :       exact("parent_name").build(p -> p.getProject().getParentName());
      49             : 
      50         153 :   public static final FieldDef<ProjectData, Iterable<String>> NAME_PART =
      51         153 :       prefix("name_part").buildRepeatable(p -> SchemaUtil.getNameParts(p.getProject().getName()));
      52             : 
      53         153 :   public static final FieldDef<ProjectData, String> STATE =
      54         153 :       exact("state").stored().build(p -> p.getProject().getState().name());
      55             : 
      56         153 :   public static final FieldDef<ProjectData, Iterable<String>> ANCESTOR_NAME =
      57         153 :       exact("ancestor_name").buildRepeatable(ProjectData::getParentNames);
      58             : 
      59             :   /**
      60             :    * All values of all refs that were used in the course of indexing this document. This covers
      61             :    * {@code refs/meta/config} of the current project and all of its parents.
      62             :    *
      63             :    * <p>Emitted as UTF-8 encoded strings of the form {@code project:ref/name:[hex sha]}.
      64             :    */
      65         153 :   public static final FieldDef<ProjectData, Iterable<byte[]>> REF_STATE =
      66         153 :       storedOnly("ref_state")
      67         153 :           .buildRepeatable(
      68             :               projectData ->
      69           7 :                   projectData.tree().stream()
      70           7 :                       .filter(p -> p.getProject().getConfigRefState() != null)
      71           7 :                       .map(p -> toRefState(p.getProject()))
      72           7 :                       .collect(toImmutableList()));
      73             : }

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