Пример #1
0
 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;
 }
Пример #2
0
  @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());
  }
  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);
  }
Пример #4
0
 @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 final void initializeRuntime() throws Exception {
   BlazeDirectories directories =
       new BlazeDirectories(
           scratch.dir("install_base"), scratch.dir("output_base"), scratch.dir("pkg"));
   this.runtime =
       new BlazeRuntime.Builder()
           .setDirectories(directories)
           .setStartupOptionsProvider(
               OptionsParser.newOptionsParser(BlazeServerStartupOptions.class))
           .setConfigurationFactory(
               new ConfigurationFactory(Mockito.mock(ConfigurationCollectionFactory.class)))
           .build();
 }
Пример #6
0
  @Test
  public void testSetGlobPaths() throws Exception {
    // This pattern matches no files.
    String pattern = "fake*.java";
    assertThat(cache.getKeySet()).doesNotContain(pattern);

    List<String> results = cache.getGlob(pattern, false);

    assertThat(cache.getKeySet()).contains(Pair.of(pattern, false));
    assertThat(results).isEmpty();

    cache.setGlobPaths(
        pattern,
        false,
        Futures.<List<Path>>immediateFuture(
            Lists.newArrayList(
                scratch.resolve("isolated/fake.txt"), scratch.resolve("isolated/fake.py"))));

    assertThat(cache.getGlob(pattern, false)).containsExactly("fake.py", "fake.txt");
  }
Пример #7
0
  @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());
  }
Пример #8
0
 @After
 public void tearDown() throws Exception {
   FileSystemUtils.deleteTreesBelow(scratch.getFileSystem().getRootDirectory());
 }