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.extensions.api.plugins; 16 : 17 : import com.google.gerrit.extensions.common.PluginInfo; 18 : import com.google.gerrit.extensions.restapi.NotImplementedException; 19 : import com.google.gerrit.extensions.restapi.RestApiException; 20 : import java.util.ArrayList; 21 : import java.util.List; 22 : import java.util.Map; 23 : import java.util.SortedMap; 24 : 25 : public interface Plugins { 26 : 27 : ListRequest list() throws RestApiException; 28 : 29 : PluginApi name(String name) throws RestApiException; 30 : 31 : @Deprecated 32 : PluginApi install(String name, com.google.gerrit.extensions.common.InstallPluginInput input) 33 : throws RestApiException; 34 : 35 : PluginApi install(String name, InstallPluginInput input) throws RestApiException; 36 : 37 1 : abstract class ListRequest { 38 : private boolean all; 39 : private int limit; 40 : private int start; 41 : private String substring; 42 : private String prefix; 43 : private String regex; 44 : 45 : public List<PluginInfo> get() throws RestApiException { 46 1 : Map<String, PluginInfo> map = getAsMap(); 47 1 : List<PluginInfo> result = new ArrayList<>(map.size()); 48 1 : for (Map.Entry<String, PluginInfo> e : map.entrySet()) { 49 1 : result.add(e.getValue()); 50 1 : } 51 1 : return result; 52 : } 53 : 54 : public abstract SortedMap<String, PluginInfo> getAsMap() throws RestApiException; 55 : 56 : public ListRequest all() { 57 1 : this.all = true; 58 1 : return this; 59 : } 60 : 61 : public boolean getAll() { 62 1 : return all; 63 : } 64 : 65 : public ListRequest limit(int limit) { 66 1 : this.limit = limit; 67 1 : return this; 68 : } 69 : 70 : public int getLimit() { 71 1 : return limit; 72 : } 73 : 74 : public ListRequest start(int start) { 75 1 : this.start = start; 76 1 : return this; 77 : } 78 : 79 : public int getStart() { 80 1 : return start; 81 : } 82 : 83 : public ListRequest substring(String substring) { 84 1 : this.substring = substring; 85 1 : return this; 86 : } 87 : 88 : public String getSubstring() { 89 1 : return substring; 90 : } 91 : 92 : public ListRequest prefix(String prefix) { 93 1 : this.prefix = prefix; 94 1 : return this; 95 : } 96 : 97 : public String getPrefix() { 98 1 : return prefix; 99 : } 100 : 101 : public ListRequest regex(String regex) { 102 1 : this.regex = regex; 103 1 : return this; 104 : } 105 : 106 : public String getRegex() { 107 1 : return regex; 108 : } 109 : } 110 : 111 : /** 112 : * A default implementation which allows source compatibility when adding new methods to the 113 : * interface. 114 : */ 115 0 : class NotImplemented implements Plugins { 116 : @Override 117 : public ListRequest list() { 118 0 : throw new NotImplementedException(); 119 : } 120 : 121 : @Override 122 : public PluginApi name(String name) { 123 0 : throw new NotImplementedException(); 124 : } 125 : 126 : @Override 127 : @Deprecated 128 : public PluginApi install( 129 : String name, com.google.gerrit.extensions.common.InstallPluginInput input) 130 : throws RestApiException { 131 0 : throw new NotImplementedException(); 132 : } 133 : 134 : @Override 135 : public PluginApi install(String name, InstallPluginInput input) { 136 0 : throw new NotImplementedException(); 137 : } 138 : } 139 : }