Line data Source code
1 : // Copyright (C) 2013 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.pgm.init; 16 : 17 : import static com.google.gerrit.entities.LabelFunction.MAX_WITH_BLOCK; 18 : 19 : import com.google.gerrit.pgm.init.api.AllProjectsConfig; 20 : import com.google.gerrit.pgm.init.api.ConsoleUI; 21 : import com.google.gerrit.pgm.init.api.InitStep; 22 : import com.google.inject.Inject; 23 : import com.google.inject.Singleton; 24 : import java.util.Arrays; 25 : import org.eclipse.jgit.lib.Config; 26 : 27 : @Singleton 28 : public class InitLabels implements InitStep { 29 : private static final String KEY_COPY_CONDITION = "copyCondition"; 30 : private static final String KEY_LABEL = "label"; 31 : private static final String KEY_FUNCTION = "function"; 32 : private static final String KEY_VALUE = "value"; 33 : private static final String LABEL_VERIFIED = "Verified"; 34 : 35 : private final ConsoleUI ui; 36 : private final AllProjectsConfig allProjectsConfig; 37 : 38 : private boolean installVerified; 39 : 40 : @Inject 41 15 : InitLabels(ConsoleUI ui, AllProjectsConfig allProjectsConfig) { 42 15 : this.ui = ui; 43 15 : this.allProjectsConfig = allProjectsConfig; 44 15 : } 45 : 46 : @Override 47 : public void run() throws Exception { 48 15 : Config cfg = allProjectsConfig.load().getConfig(); 49 15 : if (cfg == null || !cfg.getSubsections(KEY_LABEL).contains(LABEL_VERIFIED)) { 50 15 : ui.header("Review Labels"); 51 15 : installVerified = ui.yesno(false, "Install Verified label"); 52 : } 53 15 : } 54 : 55 : @Override 56 : public void postRun() throws Exception { 57 15 : Config cfg = allProjectsConfig.load().getConfig(); 58 15 : if (installVerified) { 59 0 : cfg.setString(KEY_LABEL, LABEL_VERIFIED, KEY_FUNCTION, MAX_WITH_BLOCK.getFunctionName()); 60 0 : cfg.setStringList( 61 : KEY_LABEL, 62 : LABEL_VERIFIED, 63 : KEY_VALUE, 64 0 : Arrays.asList("-1 Fails", "0 No score", "+1 Verified")); 65 0 : cfg.setString( 66 : KEY_LABEL, 67 : LABEL_VERIFIED, 68 : KEY_COPY_CONDITION, 69 : "changekind:NO_CHANGE OR changekind:NO_CODE_CHANGE"); 70 0 : allProjectsConfig.save("Configure 'Verified' label"); 71 : } 72 15 : } 73 : }