// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.plugins.codeowners.backend.proto;

import com.google.gerrit.plugins.codeowners.backend.AbstractFileBasedCodeOwnerBackend;
import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfig;
import com.google.gerrit.plugins.codeowners.backend.PathExpressionMatcher;
import com.google.gerrit.plugins.codeowners.backend.SimplePathExpressionMatcher;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.meta.MetaDataUpdate;
import com.google.gerrit.server.update.RetryHelper;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Optional;
import org.eclipse.jgit.lib.PersonIdent;

/** Backend that supports a proto syntax for storing {@link CodeOwnerConfig}s. */
@Singleton
public class ProtoBackend extends AbstractFileBasedCodeOwnerBackend {
  /** The ID of this code owner backend. */
  public static final String ID = "proto";

  /** The name of the files in which {@link CodeOwnerConfig}s are stored. */
  static final String CODE_OWNER_CONFIG_FILE_NAME = "OWNERS_METADATA";

  @Inject
  ProtoBackend(
      GitRepositoryManager repoManager,
      @GerritPersonIdent PersonIdent serverIdent,
      MetaDataUpdate.InternalFactory metaDataUpdateInternalFactory,
      RetryHelper retryHelper,
      ProtoCodeOwnerConfigParser codeOwnerConfigParser) {
    super(
        repoManager,
        serverIdent,
        metaDataUpdateInternalFactory,
        retryHelper,
        CODE_OWNER_CONFIG_FILE_NAME,
        codeOwnerConfigParser);
  }

  @Override
  public Optional<PathExpressionMatcher> getPathExpressionMatcher() {
    return Optional.of(SimplePathExpressionMatcher.INSTANCE);
  }
}

@@ -1334,16 +1334,19 @@
 nt;%0A%0A/**
+%0A *
  Backend
@@ -1412,16 +1412,388 @@
 onfig%7Ds.
+%0A *%0A * %3Cp%3E%3Cstrong%3ENote:%3C/strong%3E This backend is currently only experimental and should not be used in%0A * production. The reason for this is that the proto syntax is not finalized yet and backwards%0A * incompatible changes to it are likely to happen. Instead it's recommended to use the %7B@link%0A * com.google.gerrit.plugins.codeowners.backend.findowners.FindOwnersBackend%7D.%0A
  */%0A@Sin

Mark the ProtoBackend as experimental