@Test public void shouldSetInputsFromSourcePaths() { ExportFileBuilder builder = ExportFileBuilder.newExportFileBuilder(target) .setSrc(new TestSourcePath("chips")) .setOut("cake"); ExportFile exportFile = (ExportFile) builder.build(new BuildRuleResolver()); assertIterablesEquals(singleton(Paths.get("chips")), exportFile.getSource()); BuildRuleResolver ruleResolver = new BuildRuleResolver(); FakeBuildRule rule = ruleResolver.addToIndex( new FakeBuildRule( BuildTargetFactory.newInstance("//example:one"), new SourcePathResolver(ruleResolver))); builder.setSrc(new BuildTargetSourcePath(rule.getBuildTarget())); exportFile = (ExportFile) builder.build(ruleResolver); assertTrue(Iterables.isEmpty(exportFile.getSource())); builder.setSrc(null); exportFile = (ExportFile) builder.build(new BuildRuleResolver()); assertIterablesEquals(singleton(Paths.get("example.html")), exportFile.getSource()); }
@Test public void getOutputName() { ExportFile exportFile = (ExportFile) ExportFileBuilder.newExportFileBuilder(target) .setOut("cake") .build(new BuildRuleResolver()); assertEquals("cake", exportFile.getOutputName()); }
@Test public void shouldSetSrcAndOutToNameParameterIfNeitherAreSet() throws IOException { ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem(); ExportFile exportFile = (ExportFile) ExportFileBuilder.newExportFileBuilder(target) .build(new BuildRuleResolver(), projectFilesystem); List<Step> steps = exportFile.getBuildSteps(context, new FakeBuildableContext()); MoreAsserts.assertSteps( "The output directory should be created and then the file should be copied there.", ImmutableList.of( "mkdir -p /opt/src/buck/buck-out/gen", "cp " + projectFilesystem.resolve("example.html") + " buck-out/gen/example.html"), steps, TestExecutionContext.newInstance()); assertEquals(Paths.get("buck-out/gen/example.html"), exportFile.getPathToOutput()); }
public void init() throws IOException { Inode root = vfs.getRootInode(); exportFile .getExports() .map(FsExport::getPath) .forEach( path -> { Splitter splitter = Splitter.on('/').omitEmptyStrings(); Inode inode = root; for (String s : splitter.split(path)) { try { inode = tryToCreateIfMissing(vfs, inode, s); } catch (IOException e) { return; } } }); }