Search in sources :

Example 51 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class MiniAaptTest method testProcessFileNamesInDirectory.

@Test
public void testProcessFileNamesInDirectory() throws IOException, ResourceParseException {
    filesystem.touch(Paths.get("res/drawable/icon.png"));
    filesystem.touch(Paths.get("res/drawable/another_icon.png.orig"));
    filesystem.touch(Paths.get("res/drawable-ldpi/nine_patch.9.png"));
    filesystem.touch(Paths.get("res/drawable-ldpi/.DS_Store"));
    filesystem.touch(Paths.get("res/transition-v19/some_transition.xml"));
    filesystem.writeContentsToPath("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<resources>" + "<bool name=\"v\">false</bool>" + "</resources>", Paths.get("res/values/value.xml~"));
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
    aapt.processFileNamesInDirectory(filesystem, Paths.get("res/drawable"));
    aapt.processFileNamesInDirectory(filesystem, Paths.get("res/drawable-ldpi"));
    aapt.processFileNamesInDirectory(filesystem, Paths.get("res/transition-v19"));
    aapt.processValues(filesystem, new BuckEventBus(new FakeClock(0), new BuildId("")), Paths.get("res/values"));
    assertEquals(ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "icon"), new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "nine_patch"), new FakeRDotTxtEntry(IdType.INT, RType.TRANSITION, "some_transition")), aapt.getResourceCollector().getResources());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Example 52 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class TestWithBuckd method before.

@Override
protected void before() throws IOException, InterruptedException {
    // In case root_restrict_files is enabled in /etc/watchmanconfig, assume
    // this is one of the entries so it doesn't give up.
    temporaryPaths.newFolder(".git");
    temporaryPaths.newFile(".arcconfig");
    Watchman watchman = Watchman.build(ImmutableSet.of(temporaryPaths.getRoot()), getWatchmanEnv(), new TestConsole(), new FakeClock(0), Optional.empty());
    // We assume watchman has been installed and configured properly on the system, and that setting
    // up the watch is successful.
    assumeFalse(watchman == Watchman.NULL_WATCHMAN);
}
Also used : Watchman(com.facebook.buck.io.Watchman) FakeClock(com.facebook.buck.timing.FakeClock) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 53 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class PrebuiltJarSymbolsFinderTest method createFinderForFileWithEntries.

private PrebuiltJarSymbolsFinder createFinderForFileWithEntries(String jarFileName, Iterable<String> entries) throws IOException {
    Clock clock = new FakeClock(1);
    Path jarFile = tmp.newFile(jarFileName);
    try (OutputStream stream = new BufferedOutputStream(java.nio.file.Files.newOutputStream(jarFile));
        CustomZipOutputStream out = ZipOutputStreams.newOutputStream(stream, ZipOutputStreams.HandleDuplicates.THROW_EXCEPTION, clock)) {
        for (String entry : entries) {
            out.putNextEntry(new ZipEntry(entry));
        }
    }
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    SourcePath sourcePath = new PathSourcePath(filesystem, Paths.get(jarFileName));
    return new PrebuiltJarSymbolsFinder(sourcePath);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeClock(com.facebook.buck.timing.FakeClock) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) ZipEntry(java.util.zip.ZipEntry) PathSourcePath(com.facebook.buck.rules.PathSourcePath) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Clock(com.facebook.buck.timing.Clock) FakeClock(com.facebook.buck.timing.FakeClock) BufferedOutputStream(java.io.BufferedOutputStream)

Example 54 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class IjProjectDataPreparerTest method testExcludePaths.

@Test
public void testExcludePaths() throws Exception {
    /**
     * Fake filesystem structure
     * .idea
     *  |- misc.xml
     * .git
     *  |- HEAD
     * java
     *  |- com
     *     |- BUCK
     *     |- data
     *        |- wsad.txt
     *     |- src
     *        |- BUCK
     *        |- Source.java
     *        |- foo
     *           |- Foo.java
     *     |- src2
     *        |- Code.java
     *  |- org
     *     |- bar
     *        |- Bar.java
     * lib
     *  |- BUCK
     *  |- guava.jar
     */
    ImmutableSet<Path> paths = ImmutableSet.of(Paths.get(".idea/misc.xml"), Paths.get(".git/HEAD"), Paths.get("java/com/BUCK"), Paths.get("java/com/data/wsad.txt"), Paths.get("java/com/src/BUCK"), Paths.get("java/com/src/Source.java"), Paths.get("java/com/src/foo/Foo.java"), Paths.get("java/org/bar/Bar.java"), Paths.get("lib/BUCK"), Paths.get("lib/guava.jar"));
    FakeProjectFilesystem filesystemForExcludesTest = new FakeProjectFilesystem(new FakeClock(0), Paths.get(".").toAbsolutePath(), paths);
    TargetNode<?, ?> guavaTargetNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//lib:guava")).setBinaryJar(Paths.get("lib/guava.jar")).build();
    TargetNode<?, ?> srcTargetNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/src:src")).addDep(guavaTargetNode.getBuildTarget()).addSrc(Paths.get("java/com/src/Source.java")).build();
    TargetNode<?, ?> src2TargetNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com:src2")).addDep(guavaTargetNode.getBuildTarget()).addSrc(Paths.get("java/com/src2/Code.java")).build();
    TargetNode<?, ?> rootTargetNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:root")).build();
    IjModuleGraph moduleGraph = IjModuleGraphTest.createModuleGraph(ImmutableSet.of(guavaTargetNode, srcTargetNode, src2TargetNode, rootTargetNode));
    IjModule srcModule = IjModuleGraphTest.getModuleForTarget(moduleGraph, srcTargetNode);
    IjModule src2Module = IjModuleGraphTest.getModuleForTarget(moduleGraph, src2TargetNode);
    IjModule rootModule = IjModuleGraphTest.getModuleForTarget(moduleGraph, rootTargetNode);
    IjProjectTemplateDataPreparer dataPreparer = new IjProjectTemplateDataPreparer(javaPackageFinder, moduleGraph, filesystemForExcludesTest);
    assertEquals(ImmutableSet.of(Paths.get("java/com/src/foo")), distillExcludeFolders(dataPreparer.createExcludes(srcModule)));
    assertEquals(ImmutableSet.of(Paths.get("java/com/data")), distillExcludeFolders(dataPreparer.createExcludes(src2Module)));
    // In this case it's fine to exclude "lib" as there is no source code there.
    assertEquals(ImmutableSet.of(Paths.get(".git"), Paths.get("java/org"), Paths.get("lib")), distillExcludeFolders(dataPreparer.createExcludes(rootModule)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Aggregations

FakeClock (com.facebook.buck.timing.FakeClock)54 Test (org.junit.Test)48 BuckEventBus (com.facebook.buck.event.BuckEventBus)36 EventBus (com.google.common.eventbus.EventBus)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)17 WatchEvent (java.nio.file.WatchEvent)13 BuildId (com.facebook.buck.model.BuildId)12 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 ProjectBuildFileParser (com.facebook.buck.json.ProjectBuildFileParser)8 Path (java.nio.file.Path)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 Subscribe (com.google.common.eventbus.Subscribe)6 ArrayList (java.util.ArrayList)6 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)5 SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)5 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)4 FakeExecutor (com.facebook.buck.testutil.FakeExecutor)4 BuckEvent (com.facebook.buck.event.BuckEvent)3 WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)2