getTargetsInPackage(String originalPattern,
PackageIdentifier packageIdentifier, boolean rulesOnly)
throws TargetParsingException, InterruptedException;
/**
* Computes the set containing the targets found below the given {@code directory}, passing it in
* batches to {@code callback}. Conceptually, this method should look for all packages that start
* with the {@code directory} (as a proper prefix directory, i.e., "foo/ba" is not a proper prefix
* of "foo/bar/"), and then collect all targets in each such package (subject to
* {@code rulesOnly}) as if calling {@link #getTargetsInPackage}. The specified directory is not
* necessarily a valid package name.
*
* Note that the {@code directory} can be empty, which corresponds to the "//..." pattern.
* Implementations may choose not to support this case and throw an {@link
* IllegalArgumentException} exception instead, or may restrict the set of directories that are
* considered by default.
*
*
If the {@code directory} points to a package, then that package should also be part of the
* result.
*
* @param originalPattern the original target pattern for error reporting purposes
* @param directory the directory in which to look for packages
* @param rulesOnly whether to return rules only
* @param blacklistedSubdirectories a set of transitive subdirectories beneath {@code directory}
* to ignore
* @param excludedSubdirectories another set of transitive subdirectories beneath
* {@code directory} to ignore
* @param callback the callback to receive the result, possibly in multiple batches.
* @param exceptionClass The class type of the parameterized exception.
* @throws TargetParsingException under implementation-specific failure conditions
*/
public abstract void findTargetsBeneathDirectory(
RepositoryName repository,
String originalPattern,
String directory,
boolean rulesOnly,
ImmutableSet blacklistedSubdirectories,
ImmutableSet excludedSubdirectories,
BatchCallback callback,
Class exceptionClass)
throws TargetParsingException, E, InterruptedException;
/**
* Async version of {@link #findTargetsBeneathDirectory}
*
* Default implementation is synchronous.
*/
public ListenableFuture findTargetsBeneathDirectoryAsync(
RepositoryName repository,
String originalPattern,
String directory,
boolean rulesOnly,
ImmutableSet blacklistedSubdirectories,
ImmutableSet excludedSubdirectories,
ThreadSafeBatchCallback callback,
Class exceptionClass,
ListeningExecutorService executor) {
try {
findTargetsBeneathDirectory(
repository,
originalPattern,
directory,
rulesOnly,
blacklistedSubdirectories,
excludedSubdirectories,
callback,
exceptionClass);
return Futures.immediateFuture(null);
} catch (TargetParsingException e) {
return Futures.immediateFailedFuture(e);
} catch (InterruptedException e) {
return Futures.immediateCancelledFuture();
} catch (Exception e) {
if (exceptionClass.isInstance(e)) {
return Futures.immediateFailedFuture(e);
}
throw new IllegalStateException(e);
}
}
/**
* Returns true, if and only if the given package identifier corresponds to a package, i.e., a
* file with the name {@code packageName/BUILD} exists in the appropriate repository.
*/
public abstract boolean isPackage(PackageIdentifier packageIdentifier)
throws InterruptedException;
/**
* Returns the target kind of the given target, for example {@code cc_library rule}.
*/
public abstract String getTargetKind(T target);
}