Line data Source code
1 : // Copyright (C) 2018 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.change; 16 : 17 : import com.google.gerrit.extensions.common.FetchInfo; 18 : import com.google.gerrit.extensions.config.DownloadCommand; 19 : import com.google.gerrit.extensions.config.DownloadScheme; 20 : import com.google.gerrit.extensions.registration.DynamicMap; 21 : import com.google.gerrit.extensions.registration.Extension; 22 : import java.util.TreeMap; 23 : 24 : /** Populates the {@link FetchInfo} which is serialized to JSON afterwards. */ 25 : public class DownloadCommandsJson { 26 : 27 : private DownloadCommandsJson() {} 28 : 29 : /** 30 : * Populates the provided {@link FetchInfo} by calling all {@link DownloadCommand} extensions. 31 : * Will mutate {@link FetchInfo#commands}. 32 : */ 33 : public static void populateFetchMap( 34 : DownloadScheme scheme, 35 : DynamicMap<DownloadCommand> commands, 36 : String projectName, 37 : String refName, 38 : FetchInfo fetchInfo) { 39 0 : for (Extension<DownloadCommand> ext : commands) { 40 0 : String commandName = ext.getExportName(); 41 0 : DownloadCommand command = ext.getProvider().get(); 42 0 : String c = command.getCommand(scheme, projectName, refName); 43 0 : if (c != null) { 44 0 : if (fetchInfo.commands == null) { 45 0 : fetchInfo.commands = new TreeMap<>(); 46 : } 47 0 : fetchInfo.commands.put(commandName, c); 48 : } 49 0 : } 50 0 : } 51 : }