aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/pkgcache/PackageManager.java
blob: 13f38cd1e510ac95bf8ca621228dd91e68c01499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.pkgcache;

import com.google.devtools.build.lib.concurrent.ThreadSafety;
import com.google.devtools.build.lib.packages.CachingPackageLocator;
import java.io.PrintStream;

/**
 * A PackageManager keeps state about loaded packages around for quick lookup, and provides related
 * functionality: Recursive package finding, loaded package checking, etc.
 */
public interface PackageManager extends PackageProvider, CachingPackageLocator {
  PackageManagerStatistics getAndClearStatistics();

  /**
   * Dump the contents of the package manager in human-readable form.
   * Used by 'bazel dump' and the BuildTool's unexpected exception handler.
   */
  void dump(PrintStream printStream);

  /**
   * Returns the package locator used by this package manager.
   *
   * <p>If you are tempted to call {@code getPackagePath().getPathEntries().get(0)}, be warned that
   * this is probably not the value you are looking for!  Look at the methods of {@code
   * BazelRuntime} instead.
   */
  @ThreadSafety.ThreadSafe
  PathPackageLocator getPackagePath();

  /**
   * Collects statistics of the package manager since the last sync.
   */
  interface PackageManagerStatistics {
    public static final PackageManagerStatistics ZERO = new PackageManagerStatistics() {
        @Override public int getPackagesLoaded() {
          return 0;
        }
    };

    /**
     * Returns the number of packages loaded since the last sync.
     */
    int getPackagesLoaded();
  }

  /**
   * Retrieve a target pattern parser that works with this package manager.
   */
  TargetPatternPreloader newTargetPatternPreloader();

  /**
   * Construct a new {@link TransitivePackageLoader}.
   */
  TransitivePackageLoader newTransitiveLoader();
}