use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidResourceDescriptionTest method testNonAssetFilesAndDirsAreIgnored.
@Test
public void testNonAssetFilesAndDirsAreIgnored() throws IOException {
tmpFolder.newFolder("res");
tmpFolder.newFile("res/image.png");
tmpFolder.newFile("res/layout.xml");
tmpFolder.newFile("res/_file");
tmpFolder.newFile("res/.gitkeep");
tmpFolder.newFile("res/.svn");
tmpFolder.newFile("res/.git");
tmpFolder.newFile("res/.ds_store");
tmpFolder.newFile("res/.scc");
tmpFolder.newFile("res/CVS");
tmpFolder.newFile("res/thumbs.db");
tmpFolder.newFile("res/picasa.ini");
tmpFolder.newFile("res/file.bak~");
tmpFolder.newFolder("res", "dirs", "values");
tmpFolder.newFile("res/dirs/values/strings.xml");
tmpFolder.newFile("res/dirs/values/strings.xml.orig");
tmpFolder.newFolder("res", "dirs", ".gitkeep");
tmpFolder.newFile("res/dirs/.gitkeep/ignore");
tmpFolder.newFolder("res", "dirs", ".svn");
tmpFolder.newFile("res/dirs/.svn/ignore");
tmpFolder.newFolder("res", "dirs", ".git");
tmpFolder.newFile("res/dirs/.git/ignore");
tmpFolder.newFolder("res", "dirs", ".ds_store");
tmpFolder.newFile("res/dirs/.ds_store/ignore");
tmpFolder.newFolder("res", "dirs", ".scc");
tmpFolder.newFile("res/dirs/.scc/ignore");
tmpFolder.newFolder("res", "dirs", "CVS");
tmpFolder.newFile("res/dirs/CVS/ignore");
tmpFolder.newFolder("res", "dirs", "thumbs.db");
tmpFolder.newFile("res/dirs/thumbs.db/ignore");
tmpFolder.newFolder("res", "dirs", "picasa.ini");
tmpFolder.newFile("res/dirs/picasa.ini/ignore");
tmpFolder.newFolder("res", "dirs", "file.bak~");
tmpFolder.newFile("res/dirs/file.bak~/ignore");
tmpFolder.newFolder("res", "dirs", "_dir");
tmpFolder.newFile("res/dirs/_dir/ignore");
AndroidResourceDescription description = new AndroidResourceDescription(false);
ProjectFilesystem filesystem = new ProjectFilesystem(tmpFolder.getRoot().toPath());
Map<Path, SourcePath> inputs = description.collectInputFiles(filesystem, Paths.get("res"));
assertThat(inputs, equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get("image.png"), new FakeSourcePath(filesystem, "res/image.png"), Paths.get("layout.xml"), new FakeSourcePath(filesystem, "res/layout.xml"), Paths.get("_file"), new FakeSourcePath(filesystem, "res/_file"), Paths.get("dirs/values/strings.xml"), new FakeSourcePath(filesystem, "res/dirs/values/strings.xml"))));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class ConcatStepTest method testConcatFiles.
@Test
public void testConcatFiles() throws IOException {
// Create three files containing "foo", "bar", and "baz"
// and see if they are correctly concatenated.
File dest = temp.newFile();
ImmutableList.Builder<Path> inputsBuilder = ImmutableList.builder();
String[] fileContents = { "foo", "bar", "baz" };
for (int i = 0; i < fileContents.length; i++) {
File src = temp.newFile();
PrintStream out = new PrintStream(src);
out.print(fileContents[i]);
inputsBuilder.add(src.toPath());
out.close();
}
ProjectFilesystem filesystem = new ProjectFilesystem(temp.getRoot().toPath());
ExecutionContext context = TestExecutionContext.newInstance();
ConcatStep step = new ConcatStep(filesystem, inputsBuilder.build(), dest.toPath());
step.execute(context);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(dest)));
assertEquals(reader.readLine(), "foobarbaz");
reader.close();
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidResourceTest method testGetRDotJavaPackageWhenPackageIsSpecified.
@Test
public void testGetRDotJavaPackageWhenPackageIsSpecified() throws IOException {
ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem, "//java/src/com/facebook/base:res");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
AndroidResource androidResource = new AndroidResource(params, ruleFinder, /* deps */
ImmutableSortedSet.of(), new FakeSourcePath("foo/res"), ImmutableSortedMap.of(Paths.get("values/strings.xml"), new FakeSourcePath("foo/res/values/strings.xml")), /* rDotJavaPackage */
"com.example.android", /* assets */
null, /* assetsSrcs */
ImmutableSortedMap.of(), /* manifestFile */
null, /* hasWhitelistedStrings */
false);
projectFilesystem.writeContentsToPath("com.example.android\n", resolver.getRelativePath(androidResource.getPathToRDotJavaPackageFile()));
FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo();
androidResource.initializeFromDisk(onDiskBuildInfo);
assertEquals("com.example.android", androidResource.getRDotJavaPackage());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidResourceTest method testGetRDotJavaPackageWhenPackageIsNotSpecified.
@Test
public void testGetRDotJavaPackageWhenPackageIsNotSpecified() throws IOException {
ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem, "//java/src/com/facebook/base:res");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
AndroidResource androidResource = new AndroidResource(params, ruleFinder, /* deps */
ImmutableSortedSet.of(), new FakeSourcePath("foo/res"), ImmutableSortedMap.of(Paths.get("values/strings.xml"), new FakeSourcePath("foo/res/values/strings.xml")), /* rDotJavaPackage */
null, /* assets */
null, /* assetsSrcs */
ImmutableSortedMap.of(), /* manifestFile */
new PathSourcePath(projectFilesystem, Paths.get("foo/AndroidManifest.xml")), /* hasWhitelistedStrings */
false);
projectFilesystem.writeContentsToPath("com.ex.pkg\n", resolver.getRelativePath(androidResource.getPathToRDotJavaPackageFile()));
FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo();
androidResource.initializeFromDisk(onDiskBuildInfo);
assertEquals("com.ex.pkg", androidResource.getRDotJavaPackage());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidResourceTest method testInputRuleKeyChangesIfDependencySymbolsChanges.
@Test
public void testInputRuleKeyChangesIfDependencySymbolsChanges() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
TargetNode<?, ?> depNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep"), filesystem).setManifest(new FakeSourcePath("manifest")).setRes(Paths.get("res")).build();
TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:rule"), filesystem).setDeps(ImmutableSortedSet.of(depNode.getBuildTarget())).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, resourceNode);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
AndroidResource dep = (AndroidResource) resolver.requireRule(depNode.getBuildTarget());
AndroidResource resource = (AndroidResource) resolver.requireRule(resourceNode.getBuildTarget());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getPathToTextSymbolsFile()));
RuleKey original = new InputBasedRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(resource);
fileHashCache.invalidateAll();
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getPathToTextSymbolsFile()));
RuleKey changed = new InputBasedRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(resource);
assertThat(original, Matchers.not(Matchers.equalTo(changed)));
}
Aggregations