use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class AuditRulesCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
ProjectFilesystem projectFilesystem = params.getCell().getFilesystem();
try (ProjectBuildFileParser parser = params.getCell().createBuildFileParser(new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(params.getObjectMapper())), params.getConsole(), params.getBuckEventBus(), /* ignoreBuckAutodepsFiles */
false)) {
PrintStream out = params.getConsole().getStdOut();
for (String pathToBuildFile : getArguments()) {
if (!json) {
// Print a comment with the path to the build file.
out.printf("# %s\n\n", pathToBuildFile);
}
// Resolve the path specified by the user.
Path path = Paths.get(pathToBuildFile);
if (!path.isAbsolute()) {
Path root = projectFilesystem.getRootPath();
path = root.resolve(path);
}
// Parse the rules from the build file.
List<Map<String, Object>> rawRules;
try {
rawRules = parser.getAll(path);
} catch (BuildFileParseException e) {
throw new HumanReadableException(e);
}
// Format and print the rules from the raw data, filtered by type.
final ImmutableSet<String> types = getTypes();
Predicate<String> includeType = type -> types.isEmpty() || types.contains(type);
printRulesToStdout(params, rawRules, includeType);
}
} catch (BuildFileParseException e) {
throw new HumanReadableException("Unable to create parser");
}
return 0;
}
use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class InterCellIntegrationTest method parseTargetForXCellVisibility.
private void parseTargetForXCellVisibility(String targetName) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
Pair<ProjectWorkspace, ProjectWorkspace> cells = prepare("inter-cell/visibility/primary", "inter-cell/visibility/secondary");
ProjectWorkspace primary = cells.getFirst();
ProjectWorkspace secondary = cells.getSecond();
registerCell(primary, "primary", primary);
registerCell(secondary, "primary", primary);
// We could just do a build, but that's a little extreme since all we need is the target graph
TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
Parser parser = new Parser(new BroadcastEventListener(), primary.asCell().getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
Cell primaryCell = primary.asCell();
BuildTarget namedTarget = BuildTargetFactory.newInstance(primaryCell.getFilesystem(), targetName);
// It's enough that this parses cleanly.
parser.buildTargetGraph(eventBus, primaryCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(namedTarget));
}
use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class IntraCellIntegrationTest method shouldTreatCellBoundariesAsVisibilityBoundariesToo.
@SuppressWarnings("PMD.EmptyCatchBlock")
@Test
public void shouldTreatCellBoundariesAsVisibilityBoundariesToo() throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "intracell/visibility", tmp);
workspace.setUp();
// We don't need to do a build. It's enough to just parse these things.
Cell cell = workspace.asCell();
TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
// This parses cleanly
parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(cell.getFilesystem(), "//just-a-directory:rule")));
Cell childCell = cell.getCell(BuildTargetFactory.newInstance(workspace.getDestPath().resolve("child-repo"), "//:child-target"));
try {
// Whereas, because visibility is limited to the same cell, this won't.
parser.buildTargetGraph(BuckEventBusFactory.newInstance(), childCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(childCell.getFilesystem(), "//:child-target")));
fail("Didn't expect parsing to work because of visibility");
} catch (HumanReadableException e) {
// This is expected
}
}
use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class JavaSymbolFinderIntegrationTest method shouldFindTargetDefiningSymbol.
@Test
public void shouldFindTargetDefiningSymbol() throws IOException, InterruptedException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
workspace.setUp();
ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRoot());
ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());
Config rawConfig = Configs.createDefaultConfig(projectFilesystem.getRootPath());
BuckConfig config = new BuckConfig(rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment, new DefaultCellPathResolver(projectFilesystem.getRootPath(), rawConfig));
ParserConfig parserConfig = config.getView(ParserConfig.class);
PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(config, new ExecutableFinder());
ImmutableSet<Description<?>> allDescriptions = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(projectFilesystem, environment).getAllDescriptions();
SrcRootsFinder srcRootsFinder = new SrcRootsFinder(projectFilesystem);
ProjectBuildFileParserFactory projectBuildFileParserFactory = new DefaultProjectBuildFileParserFactory(ProjectBuildFileParserOptions.builder().setProjectRoot(projectFilesystem.getRootPath()).setPythonInterpreter(pythonBuckConfig.getPythonInterpreter()).setAllowEmptyGlobs(parserConfig.getAllowEmptyGlobs()).setIgnorePaths(projectFilesystem.getIgnorePaths()).setBuildFileName(parserConfig.getBuildFileName()).setDefaultIncludes(parserConfig.getDefaultIncludes()).setDescriptions(allDescriptions).setBuildFileImportWhitelist(parserConfig.getBuildFileImportWhitelist()).build());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
JavaSymbolFinder finder = new JavaSymbolFinder(projectFilesystem, srcRootsFinder, DEFAULT_JAVAC_OPTIONS, new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())), projectBuildFileParserFactory, config, buckEventBus, new TestConsole(), environment);
SetMultimap<String, BuildTarget> foundTargets = finder.findTargetsForSymbols(ImmutableSet.of("com.example.a.A"));
assertEquals("JavaSymbolFinder failed to find the right target.", ImmutableSetMultimap.of("com.example.a.A", BuildTargetFactory.newInstance(projectFilesystem, "//java/com/example/a:a")), foundTargets);
}
use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class ParserTest method targetWithSourceFileChangesHash.
@Test
public void targetWithSourceFileChangesHash() throws Exception {
tempDir.newFolder("foo");
Path testFooBuckFile = tempDir.newFile("foo/BUCK");
Files.write(testFooBuckFile, "java_library(name = 'lib', srcs=glob(['*.java']), visibility=['PUBLIC'])\n".getBytes(UTF_8));
BuildTarget fooLibTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
HashCode original = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory));
Path testFooJavaFile = tempDir.newFile("foo/Foo.java");
Files.write(testFooJavaFile, "// Ceci n'est pas une Javafile\n".getBytes(UTF_8));
HashCode updated = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
assertNotEquals(original, updated);
}
Aggregations