blob: 1be6275466e5e724f867f6097b6ea3bb74df8a66 [file] [log] [blame]
Googlerf526ed02018-09-20 03:59:54 -07001// Copyright 2018 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.
14package com.google.devtools.build.lib.skyframe;
15
16import java.util.concurrent.atomic.AtomicInteger;
17
18/**
19 * A class that, when being told the end of a target being configured, keeps track of the
20 * configuration progress and provides it as a human-readable string intended for the progress bar.
21 */
22public class ConfiguredTargetProgressReceiver {
23
24 private AtomicInteger configuredTargetsCompleted = new AtomicInteger();
25
26 /** Register that a target has been configured. */
27 void doneConfigureTarget() {
28 configuredTargetsCompleted.incrementAndGet();
29 }
30
31 /**
32 * Reset all instance variables of this object to a state equal to that of a newly
33 * constructed object.
34 */
35 public void reset() {
36 configuredTargetsCompleted.set(0);
37 }
38
39 /**
40 * Return a snapshot of the configuration progress as human-readable description of the number of
41 * targets configured so far.
42 */
43 public String getProgressString() {
44 String progress = "" + configuredTargetsCompleted + " ";
45 progress += (configuredTargetsCompleted.get() != 1) ? "targets" : "target";
46 progress += " configured";
47 return progress;
48 }
49}