001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      https://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.release.plugin.slsa.v1_2;
018
019import java.util.ArrayList;
020import java.util.HashMap;
021import java.util.List;
022import java.util.Map;
023import java.util.Objects;
024
025import com.fasterxml.jackson.annotation.JsonProperty;
026
027/**
028 * Entity that executed the build and is trusted to have correctly performed the operation and populated the provenance.
029 *
030 * @see <a href="https://slsa.dev/spec/v1.2">SLSA v1.2 Specification</a>
031 * @since 1.10.0
032 */
033public class Builder {
034
035    /** Orchestrator dependencies that may affect provenance generation. */
036    @JsonProperty("builderDependencies")
037    private List<ResourceDescriptor> builderDependencies = new ArrayList<>();
038    /** Identifier URI of the builder. */
039    @JsonProperty("id")
040    private String id;
041    /** Map of build platform component names to their versions. */
042    @JsonProperty("version")
043    private Map<String, String> version = new HashMap<>();
044
045    /** Creates a new Builder instance. */
046    public Builder() {
047    }
048
049    @Override
050    public boolean equals(final Object o) {
051        if (!(o instanceof Builder)) {
052            return false;
053        }
054        final Builder that = (Builder) o;
055        return Objects.equals(id, that.id)
056                && Objects.equals(builderDependencies, that.builderDependencies)
057                && Objects.equals(version, that.version);
058    }
059
060    /**
061     * Gets orchestrator dependencies that do not run within the build workload and do not affect the build output,
062     * but may affect provenance generation or security guarantees.
063     *
064     * @return The list of builder dependencies, or {@code null} if not set.
065     */
066    public List<ResourceDescriptor> getBuilderDependencies() {
067        return builderDependencies;
068    }
069
070    /**
071     * Gets the identifier of the builder.
072     *
073     * @return The builder identifier URI.
074     */
075    public String getId() {
076        return id;
077    }
078
079    /**
080     * Gets a map of build platform component names to their versions.
081     *
082     * @return The version map, or {@code null} if not set.
083     */
084    public Map<String, String> getVersion() {
085        return version;
086    }
087
088    @Override
089    public int hashCode() {
090        return Objects.hash(id, builderDependencies, version);
091    }
092
093    /**
094     * Sets the orchestrator dependencies that may affect provenance generation or security guarantees.
095     *
096     * @param builderDependencies The list of builder dependencies.
097     * @return this for chaining.
098     */
099    public Builder setBuilderDependencies(final List<ResourceDescriptor> builderDependencies) {
100        this.builderDependencies = builderDependencies;
101        return this;
102    }
103
104    /**
105     * Sets the identifier of the builder.
106     *
107     * @param id The builder identifier URI.
108     * @return this for chaining.
109     */
110    public Builder setId(final String id) {
111        this.id = id;
112        return this;
113    }
114
115    /**
116     * Sets the map of build platform component names to their versions.
117     *
118     * @param version The version map.
119     * @return this for chaining.
120     */
121    public Builder setVersion(final Map<String, String> version) {
122        this.version = version;
123        return this;
124    }
125
126    @Override
127    public String toString() {
128        return "Builder{id='" + id + "', builderDependencies=" + builderDependencies + ", version=" + version + '}';
129    }
130}