private ResolvedTargets<Void> getTargetsInPackage(
     String originalPattern, PathFragment packageNameFragment, FilteringPolicy policy)
     throws TargetParsingException, InterruptedException {
   TargetPatternResolverUtil.validatePatternPackage(originalPattern, packageNameFragment, this);
   try {
     PackageIdentifier packageId = PackageIdentifier.createInDefaultRepo(packageNameFragment);
     Package pkg = packageProvider.getPackage(env.getListener(), packageId);
     ResolvedTargets<Target> packageTargets =
         TargetPatternResolverUtil.resolvePackageTargets(pkg, policy);
     ImmutableList.Builder<SkyKey> builder = ImmutableList.builder();
     for (Target target : packageTargets.getTargets()) {
       builder.add(TransitiveTraversalValue.key(target.getLabel()));
     }
     ImmutableList<SkyKey> skyKeys = builder.build();
     env.getValuesOrThrow(skyKeys, NoSuchPackageException.class, NoSuchTargetException.class);
     if (env.valuesMissing()) {
       throw new MissingDepException();
     }
     return ResolvedTargets.empty();
   } catch (NoSuchThingException e) {
     String message =
         TargetPatternResolverUtil.getParsingErrorMessage(
             "package contains errors", originalPattern);
     throw new TargetParsingException(message, e);
   }
 }
 @Override
 public ResolvedTargets<Void> findTargetsBeneathDirectory(
     String originalPattern,
     String directory,
     boolean rulesOnly,
     ImmutableSet<String> excludedSubdirectories)
     throws TargetParsingException, InterruptedException {
   FilteringPolicy policy =
       rulesOnly ? FilteringPolicies.RULES_ONLY : FilteringPolicies.NO_FILTER;
   ImmutableSet<PathFragment> excludedPathFragments =
       TargetPatternResolverUtil.getPathFragments(excludedSubdirectories);
   PathFragment pathFragment = TargetPatternResolverUtil.getPathFragment(directory);
   for (Path root : pkgPath.getPathEntries()) {
     RootedPath rootedPath = RootedPath.toRootedPath(root, pathFragment);
     SkyValue token =
         env.getValue(
             PrepareDepsOfTargetsUnderDirectoryValue.key(
                 rootedPath, excludedPathFragments, policy));
     if (token == null) {
       // A null token value means there is a missing dependency, because RecursivePkgFunction
       // never throws.
       throw new MissingDepException();
     }
   }
   return ResolvedTargets.empty();
 }
 @Override
 public ResolvedTargets<Void> getExplicitTarget(String targetName)
     throws TargetParsingException, InterruptedException {
   Label label = TargetPatternResolverUtil.label(targetName);
   try {
     Target target = packageProvider.getTarget(env.getListener(), label);
     SkyKey key = TransitiveTraversalValue.key(target.getLabel());
     SkyValue token =
         env.getValueOrThrow(key, NoSuchPackageException.class, NoSuchTargetException.class);
     if (token == null) {
       throw new MissingDepException();
     }
     return ResolvedTargets.empty();
   } catch (NoSuchThingException e) {
     throw new TargetParsingException(e.getMessage(), e);
   }
 }