Line data Source code
1 : // Copyright (C) 2021 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.entities; 16 : 17 : import com.google.auto.value.AutoValue; 18 : import com.google.gerrit.extensions.annotations.ExtensionPoint; 19 : import com.google.gson.Gson; 20 : import com.google.gson.TypeAdapter; 21 : import java.util.Optional; 22 : 23 : /** 24 : * Entity describing a requirement that should be met for a change to become submittable. 25 : * 26 : * <p>There are two ways to contribute {@link SubmitRequirement}: 27 : * 28 : * <ul> 29 : * <li>Set per-project in project.config (see {@link 30 : * com.google.gerrit.server.project.ProjectState#getSubmitRequirements()} 31 : * <li>Bind a global {@link SubmitRequirement} that will be evaluated for all projects. 32 : * </ul> 33 : */ 34 : @ExtensionPoint 35 : @AutoValue 36 104 : public abstract class SubmitRequirement { 37 : /** Requirement name. */ 38 : public abstract String name(); 39 : 40 : /** Description of what this requirement means. */ 41 : public abstract Optional<String> description(); 42 : 43 : /** 44 : * Expression of the condition that makes the requirement applicable. The expression should be 45 : * evaluated for a specific {@link Change} and if it returns false, the requirement becomes 46 : * irrelevant for the change (i.e. {@link #submittabilityExpression()} and {@link 47 : * #overrideExpression()} are not evaluated). 48 : * 49 : * <p>An empty {@link Optional} indicates that the requirement is applicable for any change. 50 : */ 51 : public abstract Optional<SubmitRequirementExpression> applicabilityExpression(); 52 : 53 : /** 54 : * Expression of the condition that allows the submission of a change. The expression should be 55 : * evaluated for a specific {@link Change} and if it returns true, the requirement becomes 56 : * fulfilled for the change. 57 : */ 58 : public abstract SubmitRequirementExpression submittabilityExpression(); 59 : 60 : /** 61 : * Expression that, if evaluated to true, causes the submit requirement to be fulfilled, 62 : * regardless of the submittability expression. This expression should be evaluated for a specific 63 : * {@link Change}. 64 : * 65 : * <p>An empty {@link Optional} indicates that the requirement is not overridable. 66 : */ 67 : public abstract Optional<SubmitRequirementExpression> overrideExpression(); 68 : 69 : /** 70 : * Boolean value indicating if the {@link SubmitRequirement} definition can be overridden in child 71 : * projects. 72 : * 73 : * <p>For globally bound {@link SubmitRequirement}, indicates if can be overridden by {@link 74 : * SubmitRequirement} in project.config. 75 : * 76 : * <p>Default is false. 77 : */ 78 : public abstract boolean allowOverrideInChildProjects(); 79 : 80 : public static SubmitRequirement.Builder builder() { 81 104 : return new AutoValue_SubmitRequirement.Builder(); 82 : } 83 : 84 : public static TypeAdapter<SubmitRequirement> typeAdapter(Gson gson) { 85 3 : return new AutoValue_SubmitRequirement.GsonTypeAdapter(gson); 86 : } 87 : 88 : @AutoValue.Builder 89 104 : public abstract static class Builder { 90 : 91 : public abstract Builder setName(String name); 92 : 93 : public abstract Builder setDescription(Optional<String> description); 94 : 95 : public abstract Builder setApplicabilityExpression( 96 : Optional<SubmitRequirementExpression> applicabilityExpression); 97 : 98 : public abstract Builder setSubmittabilityExpression( 99 : SubmitRequirementExpression submittabilityExpression); 100 : 101 : public abstract Builder setOverrideExpression( 102 : Optional<SubmitRequirementExpression> overrideExpression); 103 : 104 : public abstract Builder setAllowOverrideInChildProjects(boolean allowOverrideInChildProjects); 105 : 106 : public abstract SubmitRequirement build(); 107 : } 108 : }