Search in sources :

Example 26 with DefaultBuildTargetSourcePath

use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.

the class JvmLibraryArgInterpreterTest method compilerArgWithPrebuiltJarValueReturnsJsr199Javac.

@Test
public void compilerArgWithPrebuiltJarValueReturnsJsr199Javac() throws Exception {
    Path javacJarPath = Paths.get("langtools").resolve("javac.jar");
    BuildTarget target = BuildTargetFactory.newInstance("//langtools:javac");
    PrebuiltJarBuilder.createBuilder(target).setBinaryJar(javacJarPath).build(ruleResolver);
    SourcePath sourcePath = new DefaultBuildTargetSourcePath(target);
    Either<BuiltInJavac, SourcePath> either = Either.ofRight(sourcePath);
    arg.compiler = Optional.of(either);
    JavacOptions options = createJavacOptions(arg);
    Javac javac = options.getJavac();
    assertEquals(pathResolver.getRelativePath(sourcePath), pathResolver.getRelativePath(options.getJavacJarPath().get()));
    assertEquals(Optional.empty(), options.getJavacPath());
    assertTrue(javac.getClass().getName(), javac instanceof Jsr199Javac);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 27 with DefaultBuildTargetSourcePath

use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.

the class MavenUberJarTest method onlyJavaDepsIncluded.

@Test
public void onlyJavaDepsIncluded() throws NoSuchBuildTargetException {
    BuildTarget pythonTarget = BuildTargetFactory.newInstance("//:python");
    BuildTarget javaTarget = BuildTargetFactory.newInstance("//:java");
    PythonLibraryBuilder pythonLibraryBuilder = PythonLibraryBuilder.createBuilder(pythonTarget);
    JavaLibraryBuilder javaLibraryBuilder = JavaLibraryBuilder.createBuilder(javaTarget).addResource(new DefaultBuildTargetSourcePath(pythonTarget));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(pythonLibraryBuilder.build(), javaLibraryBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PythonLibrary pythonLibrary = pythonLibraryBuilder.build(resolver, filesystem, targetGraph);
    JavaLibrary javaLibrary = javaLibraryBuilder.build(resolver, filesystem, targetGraph);
    MavenUberJar buildRule = MavenUberJar.create(javaLibrary, javaLibraryBuilder.createBuildRuleParams(resolver, filesystem), Optional.of("com.facebook.buck.jvm.java:java:jar:42"), Optional.empty());
    assertThat(buildRule.getDeps(), Matchers.not(Matchers.hasItem(pythonLibrary)));
}
Also used : PythonLibrary(com.facebook.buck.python.PythonLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) PythonLibraryBuilder(com.facebook.buck.python.PythonLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 28 with DefaultBuildTargetSourcePath

use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.

the class JavaLibrarySymbolsFinderTest method extractSymbolsFromSrcs.

@Test
public void extractSymbolsFromSrcs() throws IOException {
    TestDataHelper.createProjectWorkspaceForScenario(this, "java_library_symbols_finder", tmp).setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmp.getRoot());
    ImmutableSortedSet<SourcePath> srcs = ImmutableSortedSet.<SourcePath>naturalOrder().addAll(Stream.of("Example1.java", "Example2.java").map(Paths::get).map(p -> new PathSourcePath(projectFilesystem, p)).iterator()).add(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//foo:bar"))).build();
    JavaLibrarySymbolsFinder finder = new JavaLibrarySymbolsFinder(srcs, javaFileParser, /* shouldRecordRequiredSymbols */
    true);
    Symbols symbols = finder.extractSymbols();
    assertEquals(ImmutableSet.of("com.example.Example1", "com.example.Example2"), ImmutableSet.copyOf(symbols.provided));
    assertEquals(ImmutableSet.of("com.example.other.Bar", "com.example.other.Foo"), ImmutableSet.copyOf(symbols.required));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 29 with DefaultBuildTargetSourcePath

use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.

the class JavaLibrarySymbolsFinderTest method onlyNonGeneratedSrcsShouldAffectRuleKey.

@Test
@SuppressWarnings("PMD.PrematureDeclaration")
public void onlyNonGeneratedSrcsShouldAffectRuleKey() throws IOException {
    TestDataHelper.createProjectWorkspaceForScenario(this, "java_library_symbols_finder", tmp).setUp();
    final ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmp.getRoot());
    Function<String, SourcePath> convert = src -> new PathSourcePath(projectFilesystem, Paths.get(src));
    SourcePath example1 = convert.apply("Example1.java");
    SourcePath example2 = convert.apply("Example2.java");
    final BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//foo:GenEx.java");
    SourcePath generated = new DefaultBuildTargetSourcePath(fakeBuildTarget);
    final boolean shouldRecordRequiredSymbols = true;
    JavaLibrarySymbolsFinder example1Finder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example1), javaFileParser, shouldRecordRequiredSymbols);
    JavaLibrarySymbolsFinder example2Finder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example2), javaFileParser, shouldRecordRequiredSymbols);
    JavaLibrarySymbolsFinder example1AndGeneratedSrcFinder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example1, generated), javaFileParser, shouldRecordRequiredSymbols);
    // Mock out calls to a SourcePathResolver so we can create a legitimate
    // DefaultRuleKeyFactory.
    final SourcePathRuleFinder ruleFinder = createMock(SourcePathRuleFinder.class);
    final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    expect(ruleFinder.getRule(anyObject(SourcePath.class))).andAnswer(() -> {
        SourcePath input = (SourcePath) EasyMock.getCurrentArguments()[0];
        if (input instanceof ExplicitBuildTargetSourcePath) {
            return Optional.of(new FakeBuildRule(fakeBuildTarget, pathResolver));
        } else {
            return Optional.empty();
        }
    }).anyTimes();
    // Calculates the RuleKey for a JavaSymbolsRule with the specified JavaLibrarySymbolsFinder.
    final FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem)));
    final DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
    Function<JavaLibrarySymbolsFinder, RuleKey> createRuleKey = finder -> {
        JavaSymbolsRule javaSymbolsRule = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), finder, ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), projectFilesystem);
        return ruleKeyFactory.build(javaSymbolsRule);
    };
    RuleKey key1 = createRuleKey.apply(example1Finder);
    RuleKey key2 = createRuleKey.apply(example2Finder);
    RuleKey key3 = createRuleKey.apply(example1AndGeneratedSrcFinder);
    assertNotNull(key1);
    assertNotNull(key2);
    assertNotNull(key3);
    assertNotEquals("Two instances of a JavaSymbolsRule with different srcs should change the RuleKey.", key1, key2);
    assertEquals("Introducing an extra generated .java file to the srcs should not change the RuleKey.", key1, key3);
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ObjectMappers(com.facebook.buck.util.ObjectMappers) SourcePath(com.facebook.buck.rules.SourcePath) TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableList(com.google.common.collect.ImmutableList) JavaFileParser(com.facebook.buck.jvm.java.JavaFileParser) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) EasyMock.createMock(org.easymock.EasyMock.createMock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) IOException(java.io.IOException) EasyMock.expect(org.easymock.EasyMock.expect) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) EasyMock(org.easymock.EasyMock) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) BuildTarget(com.facebook.buck.model.BuildTarget) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) FileHashCache(com.facebook.buck.util.cache.FileHashCache) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 30 with DefaultBuildTargetSourcePath

use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.

the class PrebuiltJarSymbolsFinderTest method createFinderForGeneratedJar.

private PrebuiltJarSymbolsFinder createFinderForGeneratedJar(String target) {
    BuildTarget buildTarget = BuildTargetFactory.newInstance(target);
    SourcePath sourcePath = new DefaultBuildTargetSourcePath(buildTarget);
    return new PrebuiltJarSymbolsFinder(sourcePath);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath)

Aggregations

DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)71 Test (org.junit.Test)64 BuildTarget (com.facebook.buck.model.BuildTarget)53 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)26 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)25 SourcePath (com.facebook.buck.rules.SourcePath)25 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)21 TargetGraph (com.facebook.buck.rules.TargetGraph)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)18 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)18 Path (java.nio.file.Path)16 BuildRule (com.facebook.buck.rules.BuildRule)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)9 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)8 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)7 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5