diff options
author | Nathan Harmata <nharmata@google.com> | 2016-02-04 23:14:29 +0000 |
---|---|---|
committer | David Chen <dzc@google.com> | 2016-02-05 00:45:47 +0000 |
commit | c5a15d3e91cae97dc616b7371d3e7eeb2d71889c (patch) | |
tree | 1933199b7a82797bd864154c4ceab97b2eac1fca /src/main/java/com/google | |
parent | 223976c8f178c6e30bcbd0c331e35d1bd34593ff (diff) |
Move the Globber interface into its own file.
--
MOS_MIGRATED_REVID=113893917
Diffstat (limited to 'src/main/java/com/google')
6 files changed, 60 insertions, 37 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java b/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java index 5838867853..748d9abc8f 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java +++ b/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java @@ -22,6 +22,7 @@ import com.google.common.collect.Sets; import com.google.common.util.concurrent.SettableFuture; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.concurrent.ThreadSafety; +import com.google.devtools.build.lib.packages.Globber.BadGlobException; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.Path; @@ -47,12 +48,6 @@ import java.util.concurrent.atomic.AtomicReference; // Used outside of Bazel! @ThreadSafety.ThreadCompatible public class GlobCache { - public static class BadGlobException extends Exception { - BadGlobException(String message) { - super(message); - } - } - /** * A mapping from glob expressions (e.g. "*.java") to the list of files it * matched (in the order returned by VFS) at the time the package was diff --git a/src/main/java/com/google/devtools/build/lib/packages/Globber.java b/src/main/java/com/google/devtools/build/lib/packages/Globber.java new file mode 100644 index 0000000000..d3e3f135f2 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/packages/Globber.java @@ -0,0 +1,55 @@ +// Copyright 2016 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.packages; + +import com.google.devtools.build.lib.util.Pair; + +import java.io.IOException; +import java.util.List; +import java.util.Set; + +/** Interface for evaluating globs during package loading. */ +public interface Globber { + /** An opaque token for fetching the result of a glob computation. */ + abstract static class Token {} + + /** Used to indicate an invalid glob pattern. */ + static class BadGlobException extends Exception { + public BadGlobException(String message) { + super(message); + } + } + + /** + * Asynchronously starts the given glob computation and returns a token for fetching the + * result. + * + * @throws BadGlobException if any of the patterns in {@code includes} or {@code excludes} are + * invalid. + */ + Token runAsync(List<String> includes, List<String> excludes, boolean excludeDirs) + throws BadGlobException; + + /** Fetches the result of a previously started glob computation. */ + List<String> fetch(Token token) throws IOException, InterruptedException; + + /** Should be called when the globber is about to be discarded due to an interrupt. */ + void onInterrupt(); + + /** Should be called when the globber is no longer needed. */ + void onCompletion(); + + /** Returns all the glob computations requested before {@link #onCompletion} was called. */ + Set<Pair<String, Boolean>> getGlobPatterns(); +} diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java index c861bfe4f2..1201d72442 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Package.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java @@ -33,7 +33,6 @@ import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.AttributeMap.AcceptsLabelAttribute; import com.google.devtools.build.lib.packages.License.DistributionType; -import com.google.devtools.build.lib.packages.PackageFactory.Globber; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.Canonicalizer; diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java index b2aa1f6b24..c1f30df5bf 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java @@ -29,7 +29,7 @@ import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.events.NullEventHandler; import com.google.devtools.build.lib.events.StoredEventHandler; -import com.google.devtools.build.lib.packages.GlobCache.BadGlobException; +import com.google.devtools.build.lib.packages.Globber.BadGlobException; import com.google.devtools.build.lib.packages.License.DistributionType; import com.google.devtools.build.lib.packages.Preprocessor.AstAfterPreprocessing; import com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap; @@ -124,31 +124,6 @@ public final class PackageFactory { throws EvalException; } - /** Interface for evaluating globs during package loading. */ - public static interface Globber { - /** An opaque token for fetching the result of a glob computation. */ - abstract static class Token {} - - /** - * Asynchronously starts the given glob computation and returns a token for fetching the - * result. - */ - Token runAsync(List<String> includes, List<String> excludes, boolean excludeDirs) - throws BadGlobException; - - /** Fetches the result of a previously started glob computation. */ - List<String> fetch(Token token) throws IOException, InterruptedException; - - /** Should be called when the globber is about to be discarded due to an interrupt. */ - void onInterrupt(); - - /** Should be called when the globber is no longer needed. */ - void onCompletion(); - - /** Returns all the glob computations requested before {@link #onCompletion} was called. */ - Set<Pair<String, Boolean>> getGlobPatterns(); - } - /** * An extension to the global namespace of the BUILD language. */ @@ -531,7 +506,7 @@ public final class PackageFactory { if (async) { try { context.globber.runAsync(includes, excludes, excludeDirs); - } catch (GlobCache.BadGlobException e) { + } catch (BadGlobException e) { // Ignore: errors will appear during the actual evaluation of the package. } globList = GlobList.captureResults(includes, excludes, ImmutableList.<String>of()); @@ -563,7 +538,7 @@ public final class PackageFactory { "error globbing [" + Joiner.on(", ").join(includes) + "]: " + expected.getMessage())); context.pkgBuilder.setContainsErrors(); return GlobList.captureResults(includes, excludes, ImmutableList.<String>of()); - } catch (GlobCache.BadGlobException e) { + } catch (BadGlobException e) { throw new EvalException(ast.getLocation(), e.getMessage()); } } diff --git a/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java b/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java index 1bf5654348..1cca195e3f 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java @@ -17,7 +17,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.StoredEventHandler; -import com.google.devtools.build.lib.packages.PackageFactory.Globber; import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.ParserInputSource; diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java index 03b0f5f5c4..13c0e9243a 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java @@ -31,12 +31,12 @@ import com.google.devtools.build.lib.events.StoredEventHandler; import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; import com.google.devtools.build.lib.packages.BuildFileNotFoundException; import com.google.devtools.build.lib.packages.CachingPackageLocator; +import com.google.devtools.build.lib.packages.Globber; import com.google.devtools.build.lib.packages.InvalidPackageNameException; import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.packages.Package.LegacyBuilder; import com.google.devtools.build.lib.packages.PackageFactory; -import com.google.devtools.build.lib.packages.PackageFactory.Globber; import com.google.devtools.build.lib.packages.Preprocessor; import com.google.devtools.build.lib.packages.Preprocessor.AstAfterPreprocessing; import com.google.devtools.build.lib.packages.RuleVisibility; |