@Test public void testGlobsUpToDate() throws Exception { assertTrue(cache.globsUpToDate()); // Initialize the cache cache.getGlob("*.txt"); assertTrue(cache.globsUpToDate()); cache.getGlob("*.js"); assertTrue(cache.globsUpToDate()); // Change the filesystem scratch.file("isolated/third.txt", "# this is third.txt"); assertFalse(cache.globsUpToDate()); // Fool the cache to observe the method's behavior. cache.setGlobPaths( "*.txt", false, Futures.<List<Path>>immediateFuture( Lists.newArrayList( scratch.resolve("isolated/first.txt"), scratch.resolve("isolated/second.txt"), scratch.resolve("isolated/third.txt")))); assertTrue(cache.globsUpToDate()); }
public WorkspaceFactoryHelper(boolean allowOverride, String... args) { Path root = null; Path workspaceFilePath = null; try { Scratch scratch = new Scratch("/"); root = scratch.dir("/workspace"); workspaceFilePath = scratch.file("/workspace/WORKSPACE", args); } catch (IOException e) { fail("Shouldn't happen: " + e.getMessage()); } StoredEventHandler eventHandler = new StoredEventHandler(); builder = Package.newExternalPackageBuilder( Package.Builder.DefaultHelper.INSTANCE, workspaceFilePath, ""); this.factory = new WorkspaceFactory( builder, TestRuleClassProvider.getRuleClassProvider(), ImmutableList.<PackageFactory.EnvironmentExtension>of(), Mutability.create("test"), allowOverride, root, root); Exception exception = null; try { factory.parse(ParserInputSource.create(workspaceFilePath), eventHandler); } catch (BuildFileContainsErrorsException e) { exception = e; } catch (IOException | InterruptedException e) { fail("Shouldn't happen: " + e.getMessage()); } this.events = eventHandler.getEvents(); this.exception = exception; }
protected Rule createRule(String pkgPath, String ruleName, String... ruleDef) throws Exception { Scratch scratch = new Scratch(); EventCollectionApparatus events = new EventCollectionApparatus(); PackageFactoryApparatus packages = new PackageFactoryApparatus(events, scratch); Path buildFile = scratch.file(pkgPath + "/BUILD", ruleDef); pkg = packages.createPackage(pkgPath, buildFile); return pkg.getRule(ruleName); }
@Before public void setUp() throws Exception { errorMessage = "An error just happened."; anOutput = new Artifact( scratch.file("/out/foo"), Root.asDerivedRoot(scratch.dir("/"), scratch.dir("/out"))); outputs = ImmutableList.of(anOutput); failAction = new FailAction(NULL_ACTION_OWNER, outputs, errorMessage); actionGraph.registerAction(failAction); assertSame(failAction, actionGraph.getGeneratingAction(anOutput)); }
@Before public void setUp() throws Exception { buildFile = scratch.file("isolated/BUILD", "# contents don't matter in this test"); scratch.file("isolated/sub/BUILD", "# contents don't matter in this test"); packageDirectory = buildFile.getParentDirectory(); scratch.file("isolated/first.txt", "# this is first.txt"); scratch.file("isolated/second.txt", "# this is second.txt"); scratch.file("isolated/first.js", "# this is first.js"); scratch.file("isolated/second.js", "# this is second.js"); // Files in subdirectories scratch.file("isolated/foo/first.js", "# this is foo/first.js"); scratch.file("isolated/foo/second.js", "# this is foo/second.js"); scratch.file("isolated/bar/first.js", "# this is bar/first.js"); scratch.file("isolated/bar/second.js", "# this is bar/second.js"); scratch.file("isolated/sub/sub.js", "# this is sub/sub.js"); cache = new GlobCache( packageDirectory, PackageIdentifier.createInDefaultRepo("isolated"), new CachingPackageLocator() { @Override public Path getBuildFileForPackage(PackageIdentifier packageId) { String packageName = packageId.getPackageFragment().getPathString(); if (packageName.equals("isolated")) { return scratch.resolve("isolated/BUILD"); } else if (packageName.equals("isolated/sub")) { return scratch.resolve("isolated/sub/BUILD"); } else { return null; } } }, null, TestUtils.getPool()); }