adgar | f3e66ad | 2019-08-15 13:18:51 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Bazel Authors. All rights reserved. |
| 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.devtools.build.lib.runtime; |
| 16 | |
| 17 | import com.google.common.collect.ImmutableList; |
| 18 | import com.google.devtools.build.lib.buildeventstream.BuildEventContext; |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil; |
adgar | f3e66ad | 2019-08-15 13:18:51 -0700 | [diff] [blame] | 20 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 21 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId; |
adgar | f3e66ad | 2019-08-15 13:18:51 -0700 | [diff] [blame] | 22 | import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint; |
| 23 | import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; |
| 24 | import java.util.Collection; |
| 25 | import java.util.Map; |
| 26 | |
| 27 | /** |
| 28 | * Build event announcing supplementary metadata accompanying the build in the form of key-value |
| 29 | * string pairs. |
| 30 | */ |
| 31 | public class BuildMetadataEvent implements BuildEventWithOrderConstraint { |
| 32 | |
| 33 | private final Map<String, String> buildMetadata; |
| 34 | |
| 35 | /** |
| 36 | * Construct the build metadata event. |
| 37 | * |
| 38 | * @param buildMetadata the supplementary build metadata for a single build. |
| 39 | */ |
| 40 | public BuildMetadataEvent(Map<String, String> buildMetadata) { |
| 41 | this.buildMetadata = buildMetadata; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public BuildEventId getEventId() { |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 46 | return BuildEventIdUtil.buildMetadataId(); |
adgar | f3e66ad | 2019-08-15 13:18:51 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Collection<BuildEventId> getChildrenEvents() { |
| 51 | return ImmutableList.of(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) { |
| 56 | BuildEventStreamProtos.BuildMetadata.Builder metadataBuilder = |
| 57 | BuildEventStreamProtos.BuildMetadata.newBuilder(); |
| 58 | for (Map.Entry<String, String> entry : buildMetadata.entrySet()) { |
| 59 | metadataBuilder.putMetadata(entry.getKey(), entry.getValue()); |
| 60 | } |
| 61 | return GenericBuildEvent.protoChaining(this).setBuildMetadata(metadataBuilder.build()).build(); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public Collection<BuildEventId> postedAfter() { |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 66 | return ImmutableList.of(BuildEventIdUtil.buildStartedId()); |
adgar | f3e66ad | 2019-08-15 13:18:51 -0700 | [diff] [blame] | 67 | } |
| 68 | } |