blob: e83115b7c38c0e21ad5e3d72f6aba38577fde647 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
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.pkgcache;
15
Ulf Adamsde3e9d52016-02-10 12:07:44 +000016import com.google.common.base.Preconditions;
17import com.google.common.collect.ImmutableSet;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018import com.google.common.collect.Iterables;
Lukacs Berki6e91eb92015-09-21 09:12:37 +000019import com.google.devtools.build.lib.cmdline.Label;
Klaus Aehlig949b7b52017-02-27 13:56:15 +000020import com.google.devtools.build.lib.events.ExtendedEventHandler;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010021import com.google.devtools.build.lib.packages.Target;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010022
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010023/**
24 * This event is fired after the loading phase is complete.
25 */
Klaus Aehlig949b7b52017-02-27 13:56:15 +000026public final class LoadingPhaseCompleteEvent implements ExtendedEventHandler.Postable {
Ulf Adamsde3e9d52016-02-10 12:07:44 +000027 private final ImmutableSet<Target> targets;
28 private final ImmutableSet<Target> filteredTargets;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010029 private final PackageManager.PackageManagerStatistics pkgManagerStats;
30 private final long timeInMs;
31
32 /**
33 * Construct the event.
34 *
35 * @param targets the set of active targets that remain
36 * @param pkgManagerStats statistics about the package cache
37 */
Ulf Adamsde3e9d52016-02-10 12:07:44 +000038 public LoadingPhaseCompleteEvent(ImmutableSet<Target> targets,
39 ImmutableSet<Target> filteredTargets, PackageManager.PackageManagerStatistics pkgManagerStats,
40 long timeInMs) {
41 this.targets = Preconditions.checkNotNull(targets);
42 this.filteredTargets = Preconditions.checkNotNull(filteredTargets);
43 this.pkgManagerStats = Preconditions.checkNotNull(pkgManagerStats);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010044 this.timeInMs = timeInMs;
45 }
46
47 /**
48 * @return The set of active targets remaining, which is a subset of the
49 * targets we attempted to load.
50 */
Ulf Adamsde3e9d52016-02-10 12:07:44 +000051 public ImmutableSet<Target> getTargets() {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010052 return targets;
53 }
54
55 /**
56 * @return The set of filtered targets.
57 */
Ulf Adamsde3e9d52016-02-10 12:07:44 +000058 public ImmutableSet<Target> getFilteredTargets() {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010059 return filteredTargets;
60 }
61
62 /**
63 * @return The set of active target labels remaining, which is a subset of the
64 * targets we attempted to load.
65 */
66 public Iterable<Label> getLabels() {
laurentlb3d2a68c2017-06-30 00:32:04 +020067 return Iterables.transform(targets, Target::getLabel);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010068 }
69
70 public long getTimeInMs() {
71 return timeInMs;
72 }
73
74 /**
nharmatac4335cf2017-07-18 21:39:13 +020075 * Returns package manager statistics.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010076 */
77 public PackageManager.PackageManagerStatistics getPkgManagerStats() {
78 return pkgManagerStats;
79 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010080}