use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class TargetsCommandTest method testGetMatchingAppleLibraryBuildTarget.
@Test
public void testGetMatchingAppleLibraryBuildTarget() throws CmdLineException, IOException {
BuildTarget libraryTarget = BuildTargetFactory.newInstance("//foo:lib");
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/foo.m")))).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(libraryNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
// No target depends on the referenced file.
SortedMap<String, TargetNode<?, ?>> matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/bar.m"))), Optional.empty(), Optional.empty(), false, "BUCK");
assertTrue(matchingBuildRules.isEmpty());
// The AppleLibrary matches the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/foo.m"))), Optional.empty(), Optional.empty(), false, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib"), matchingBuildRules.keySet());
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class IjModuleFactoryTest method testAndroidPrebuiltAar.
@Test
public void testAndroidPrebuiltAar() {
final SourcePath androidSupportBinaryPath = new FakeSourcePath("third_party/java/support/support.aar");
final Path androidSupportSourcesPath = Paths.get("third_party/java/support/support-sources.jar");
final String androidSupportJavadocUrl = "file:///support/docs";
final TargetNode<?, ?> androidPrebuiltAar = AndroidPrebuiltAarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/support:support")).setBinaryAar(androidSupportBinaryPath).setSourcesJar(androidSupportSourcesPath).setJavadocUrl(androidSupportJavadocUrl).build();
final BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
final SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
IjLibraryFactoryResolver ijLibraryFactoryResolver = new IjLibraryFactoryResolver() {
@Override
public Path getPath(SourcePath path) {
return sourcePathResolver.getRelativePath(path);
}
@Override
public Optional<SourcePath> getPathIfJavaLibrary(TargetNode<?, ?> targetNode) {
if (targetNode.equals(androidPrebuiltAar)) {
return Optional.of(androidSupportBinaryPath);
}
return Optional.empty();
}
};
Optional<IjLibrary> library = new DefaultIjLibraryFactory(ijLibraryFactoryResolver).getLibrary(androidPrebuiltAar);
assertTrue(library.isPresent());
assertEquals(library.get().getBinaryJar(), Optional.of(sourcePathResolver.getRelativePath(androidSupportBinaryPath)));
assertEquals(library.get().getSourceJar(), Optional.of(androidSupportSourcesPath));
assertEquals(library.get().getJavadocUrl(), Optional.of(androidSupportJavadocUrl));
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class IjModuleGraphTest method createModuleGraph.
public static IjModuleGraph createModuleGraph(ImmutableSet<TargetNode<?, ?>> targets, final ImmutableMap<TargetNode<?, ?>, SourcePath> javaLibraryPaths, final Function<? super TargetNode<?, ?>, Optional<Path>> rDotJavaClassPathResolver, AggregationMode aggregationMode) {
final SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
IjLibraryFactoryResolver sourceOnlyResolver = new IjLibraryFactoryResolver() {
@Override
public Path getPath(SourcePath path) {
return sourcePathResolver.getAbsolutePath(path);
}
@Override
public Optional<SourcePath> getPathIfJavaLibrary(TargetNode<?, ?> targetNode) {
return Optional.ofNullable(javaLibraryPaths.get(targetNode));
}
};
BuckConfig buckConfig = FakeBuckConfig.builder().build();
IjProjectConfig projectConfig = IjProjectBuckConfig.create(buckConfig);
IjModuleFactory moduleFactory = new IjModuleFactory(new FakeProjectFilesystem(), new IjModuleFactoryResolver() {
@Override
public Optional<Path> getDummyRDotJavaPath(TargetNode<?, ?> targetNode) {
return rDotJavaClassPathResolver.apply(targetNode);
}
@Override
public Path getAndroidManifestPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
return Paths.get("TestAndroidManifest.xml");
}
@Override
public Optional<Path> getLibraryAndroidManifestPath(TargetNode<AndroidLibraryDescription.Arg, ?> targetNode) {
return Optional.empty();
}
@Override
public Optional<Path> getProguardConfigPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
return Optional.empty();
}
@Override
public Optional<Path> getAndroidResourcePath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
return Optional.empty();
}
@Override
public Optional<Path> getAssetsPath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
return Optional.empty();
}
@Override
public Optional<Path> getAnnotationOutputPath(TargetNode<? extends JvmLibraryArg, ?> targetNode) {
return Optional.empty();
}
}, projectConfig, false);
IjLibraryFactory libraryFactory = new DefaultIjLibraryFactory(sourceOnlyResolver);
return IjModuleGraph.from(projectConfig, TargetGraphFactory.newInstance(targets), libraryFactory, moduleFactory, aggregationMode);
}
Aggregations