|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.commons.release.plugin.slsa.v1_2; |
| 18 | + |
| 19 | +import java.util.HashMap; |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | +import java.util.Objects; |
| 23 | + |
| 24 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 25 | + |
| 26 | +/** |
| 27 | + * Inputs that define the build: the build type, external and internal parameters, and resolved dependencies. |
| 28 | + * |
| 29 | + * <p>Specifies everything that influenced the build output. Together with {@link RunDetails}, it forms the complete |
| 30 | + * {@link Provenance} record.</p> |
| 31 | + * |
| 32 | + * @see <a href="https://slsa.dev/spec/v1.2">SLSA v1.2 Specification</a> |
| 33 | + */ |
| 34 | +public class BuildDefinition { |
| 35 | + |
| 36 | + /** |
| 37 | + * URI indicating what type of build was performed. |
| 38 | + */ |
| 39 | + @JsonProperty("buildType") |
| 40 | + private String buildType = "https://commons.apache.org/proper/commons-release-plugin/slsa/v0.1.0"; |
| 41 | + |
| 42 | + /** |
| 43 | + * Inputs passed to the build. |
| 44 | + */ |
| 45 | + @JsonProperty("externalParameters") |
| 46 | + private Map<String, Object> externalParameters = new HashMap<>(); |
| 47 | + |
| 48 | + /** |
| 49 | + * Parameters set by the build platform. |
| 50 | + */ |
| 51 | + @JsonProperty("internalParameters") |
| 52 | + private Map<String, Object> internalParameters = new HashMap<>(); |
| 53 | + |
| 54 | + /** |
| 55 | + * Artifacts the build depends on, specified by URI and digest. |
| 56 | + */ |
| 57 | + @JsonProperty("resolvedDependencies") |
| 58 | + private List<ResourceDescriptor> resolvedDependencies; |
| 59 | + |
| 60 | + /** |
| 61 | + * Creates a new BuildDefinition instance with the default build type. |
| 62 | + */ |
| 63 | + public BuildDefinition() { |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Creates a new BuildDefinition with the given build type and external parameters. |
| 68 | + * |
| 69 | + * @param buildType URI indicating what type of build was performed |
| 70 | + * @param externalParameters inputs passed to the build |
| 71 | + */ |
| 72 | + public BuildDefinition(String buildType, Map<String, Object> externalParameters) { |
| 73 | + this.buildType = buildType; |
| 74 | + this.externalParameters = externalParameters; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public boolean equals(Object o) { |
| 79 | + if (this == o) { |
| 80 | + return true; |
| 81 | + } |
| 82 | + if (o == null || getClass() != o.getClass()) { |
| 83 | + return false; |
| 84 | + } |
| 85 | + BuildDefinition that = (BuildDefinition) o; |
| 86 | + return Objects.equals(buildType, that.buildType) && Objects.equals(externalParameters, that.externalParameters) && Objects.equals(internalParameters, |
| 87 | + that.internalParameters) && Objects.equals(resolvedDependencies, that.resolvedDependencies); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Gets the URI indicating what type of build was performed. |
| 92 | + * |
| 93 | + * <p>Determines the meaning of {@code externalParameters} and {@code internalParameters}.</p> |
| 94 | + * |
| 95 | + * @return the build type URI |
| 96 | + */ |
| 97 | + public String getBuildType() { |
| 98 | + return buildType; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Gets the inputs passed to the build, such as command-line arguments or environment variables. |
| 103 | + * |
| 104 | + * @return the external parameters map, or {@code null} if not set |
| 105 | + */ |
| 106 | + public Map<String, Object> getExternalParameters() { |
| 107 | + return externalParameters; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Gets the artifacts the build depends on, such as sources, dependencies, build tools, and base images, |
| 112 | + * specified by URI and digest. |
| 113 | + * |
| 114 | + * @return the internal parameters map, or {@code null} if not set |
| 115 | + */ |
| 116 | + public Map<String, Object> getInternalParameters() { |
| 117 | + return internalParameters; |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Gets the materials that influenced the build. |
| 122 | + * |
| 123 | + * <p>Considered incomplete unless resolved materials are present.</p> |
| 124 | + * |
| 125 | + * @return the list of resolved dependencies, or {@code null} if not set |
| 126 | + */ |
| 127 | + public List<ResourceDescriptor> getResolvedDependencies() { |
| 128 | + return resolvedDependencies; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public int hashCode() { |
| 133 | + return Objects.hash(buildType, externalParameters, internalParameters, resolvedDependencies); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Sets the URI indicating what type of build was performed. |
| 138 | + * |
| 139 | + * @param buildType the build type URI |
| 140 | + * @return this for chaining |
| 141 | + */ |
| 142 | + public BuildDefinition setBuildType(String buildType) { |
| 143 | + this.buildType = buildType; |
| 144 | + return this; |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Sets the inputs passed to the build. |
| 149 | + * |
| 150 | + * @param externalParameters the external parameters map |
| 151 | + * @return this for chaining |
| 152 | + */ |
| 153 | + public BuildDefinition setExternalParameters(Map<String, Object> externalParameters) { |
| 154 | + this.externalParameters = externalParameters; |
| 155 | + return this; |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Sets the artifacts the build depends on. |
| 160 | + * |
| 161 | + * @param internalParameters the internal parameters map |
| 162 | + * @return this for chaining |
| 163 | + */ |
| 164 | + public BuildDefinition setInternalParameters(Map<String, Object> internalParameters) { |
| 165 | + this.internalParameters = internalParameters; |
| 166 | + return this; |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * Sets the materials that influenced the build. |
| 171 | + * |
| 172 | + * @param resolvedDependencies the list of resolved dependencies |
| 173 | + * @return this for chaining |
| 174 | + */ |
| 175 | + public BuildDefinition setResolvedDependencies(List<ResourceDescriptor> resolvedDependencies) { |
| 176 | + this.resolvedDependencies = resolvedDependencies; |
| 177 | + return this; |
| 178 | + } |
| 179 | + |
| 180 | + @Override |
| 181 | + public String toString() { |
| 182 | + return "BuildDefinition{buildType='" + buildType + '\'' |
| 183 | + + ", externalParameters=" + externalParameters |
| 184 | + + ", internalParameters=" + internalParameters |
| 185 | + + ", resolvedDependencies=" + resolvedDependencies + '}'; |
| 186 | + } |
| 187 | +} |
0 commit comments