Search in sources :

Example 1 with JavaLibraryDescription

use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.

the class AndroidLibraryDescriptionTest method rulesMatchingDepQueryBecomeFirstOrderDeps.

@Test
public void rulesMatchingDepQueryBecomeFirstOrderDeps() throws Exception {
    // Set up target graph: rule -> lib -> sublib -> bottom
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> bottomNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:bottom")).build();
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> sublibNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:sublib")).addDep(bottomNode.getBuildTarget()).build();
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> libNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addDep(sublibNode.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(bottomNode, libNode, sublibNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule bottomRule = resolver.addToIndex(new FakeBuildRule(bottomNode.getBuildTarget(), pathResolver));
    FakeBuildRule sublibRule = resolver.addToIndex(new FakeBuildRule(sublibNode.getBuildTarget(), pathResolver, ImmutableSortedSet.of(bottomRule)));
    FakeBuildRule libRule = resolver.addToIndex(new FakeBuildRule(libNode.getBuildTarget(), pathResolver, ImmutableSortedSet.of(sublibRule)));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRule javaLibrary = AndroidLibraryBuilder.createBuilder(target).addDep(libNode.getBuildTarget()).setDepsQuery(Query.of("filter('.*lib', deps($declared_deps))")).build(resolver, targetGraph);
    assertThat(javaLibrary.getDeps(), Matchers.hasItems(libRule, sublibRule));
    // The bottom rule should be filtered since it does not match the regex
    assertThat(javaLibrary.getDeps(), Matchers.not(Matchers.hasItem(bottomRule)));
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 2 with JavaLibraryDescription

use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.

the class IjModuleFactory method getSourceLevel.

private Optional<String> getSourceLevel(Iterable<TargetNode<?, ?>> targetNodes) {
    Optional<String> result = Optional.empty();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        if (!(targetNode.getDescription() instanceof JavaLibraryDescription)) {
            continue;
        }
        JavacOptions defaultJavacOptions = projectConfig.getJavaBuckConfig().getDefaultJavacOptions();
        String defaultSourceLevel = defaultJavacOptions.getSourceLevel();
        String defaultTargetLevel = defaultJavacOptions.getTargetLevel();
        JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) targetNode.getConstructorArg();
        if (!defaultSourceLevel.equals(arg.source.orElse(defaultSourceLevel)) || !defaultTargetLevel.equals(arg.target.orElse(defaultTargetLevel))) {
            result = arg.source;
        }
    }
    if (result.isPresent()) {
        result = Optional.of(JavaLanguageLevelHelper.normalizeSourceLevel(result.get()));
    }
    return result;
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) JvmLibraryArg(com.facebook.buck.jvm.java.JvmLibraryArg)

Example 3 with JavaLibraryDescription

use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.

the class TestRunningTest method testMixedSourceFile.

/**
   * If the source paths specified contains one source path to a non-generated file then
   * we should return the correct source tmp corresponding to that non-generated source path.
   * Especially when the generated file comes first in the ordered set.
   */
@Test
public void testMixedSourceFile() throws Exception {
    BuildTarget genSrcTarget = BuildTargetFactory.newInstance("//:gensrc");
    TargetNode<GenruleDescription.Arg, GenruleDescription> sourceGenerator = GenruleBuilder.newGenruleBuilder(genSrcTarget).setOut("com/facebook/GeneratedFile.java").build();
    Path pathToNonGenFile1 = Paths.get("package/src/SourceFile1.java");
    Path pathToNonGenFile2 = Paths.get("package/src-gen/SourceFile2.java");
    BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//foo:bar");
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> javaLibraryNode = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(pathToNonGenFile1).addSrc(pathToNonGenFile2).addSrcTarget(genSrcTarget).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(sourceGenerator, javaLibraryNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    JavaLibrary javaLibrary = (JavaLibrary) ruleResolver.requireRule(javaLibraryTarget);
    DefaultJavaPackageFinder defaultJavaPackageFinder = createMock(DefaultJavaPackageFinder.class);
    expect(defaultJavaPackageFinder.getPathsFromRoot()).andReturn(pathsFromRoot).times(2);
    expect(defaultJavaPackageFinder.getPathElements()).andReturn(pathElements).times(2);
    replay(defaultJavaPackageFinder);
    ImmutableSet<String> result = TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
    Path rootPath = javaLibrary.getProjectFilesystem().getRootPath();
    ImmutableSet<String> expected = ImmutableSet.of(rootPath.resolve("package/src-gen").toString() + "/", rootPath.resolve("package/src").toString() + "/");
    assertEquals("The non-generated source files are under two different source folders.", expected, result);
    verify(defaultJavaPackageFinder);
}
Also used : Path(java.nio.file.Path) GenruleDescription(com.facebook.buck.shell.GenruleDescription) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 4 with JavaLibraryDescription

use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.

the class TestRunningTest method testUnifiedSourceFile.

/**
   * If the source paths specified are from the new unified source tmp then we should return
   * the correct source tmp corresponding to the unified source path.
   */
@Test
public void testUnifiedSourceFile() throws Exception {
    Path pathToNonGenFile = Paths.get("java/package/src/SourceFile1.java");
    BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//foo:bar");
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> javaLibraryNode = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(pathToNonGenFile).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibraryNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    JavaLibrary javaLibrary = (JavaLibrary) ruleResolver.requireRule(javaLibraryTarget);
    DefaultJavaPackageFinder defaultJavaPackageFinder = createMock(DefaultJavaPackageFinder.class);
    expect(defaultJavaPackageFinder.getPathsFromRoot()).andReturn(pathsFromRoot);
    Object[] mocks = new Object[] { defaultJavaPackageFinder };
    replay(mocks);
    ImmutableSet<String> result = TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
    assertEquals("All non-generated source files are under one source tmp.", ImmutableSet.of("java/"), result);
    verify(mocks);
}
Also used : Path(java.nio.file.Path) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 5 with JavaLibraryDescription

use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.

the class KnownBuildRuleTypesTest method createJavaLibrary.

private DefaultJavaLibrary createJavaLibrary(KnownBuildRuleTypes buildRuleTypes) throws NoSuchBuildTargetException {
    JavaLibraryDescription description = (JavaLibraryDescription) buildRuleTypes.getDescription(Description.getBuildRuleType(JavaLibraryDescription.class));
    JavaLibraryDescription.Arg arg = new JavaLibraryDescription.Arg();
    populateJavaArg(arg);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    return (DefaultJavaLibrary) description.createBuildRule(TargetGraph.EMPTY, buildRuleParams, resolver, arg);
}
Also used : JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary)

Aggregations

JavaLibraryDescription (com.facebook.buck.jvm.java.JavaLibraryDescription)9 BuildTarget (com.facebook.buck.model.BuildTarget)6 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)6 TargetGraph (com.facebook.buck.rules.TargetGraph)6 Test (org.junit.Test)6 DefaultJavaPackageFinder (com.facebook.buck.jvm.java.DefaultJavaPackageFinder)5 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)5 Path (java.nio.file.Path)5 GenruleDescription (com.facebook.buck.shell.GenruleDescription)3 AndroidAarDescription (com.facebook.buck.android.AndroidAarDescription)1 AndroidBinaryDescription (com.facebook.buck.android.AndroidBinaryDescription)1 AndroidBuckConfig (com.facebook.buck.android.AndroidBuckConfig)1 AndroidBuildConfigDescription (com.facebook.buck.android.AndroidBuildConfigDescription)1 AndroidInstrumentationApkDescription (com.facebook.buck.android.AndroidInstrumentationApkDescription)1 AndroidInstrumentationTestDescription (com.facebook.buck.android.AndroidInstrumentationTestDescription)1 AndroidLibraryDescription (com.facebook.buck.android.AndroidLibraryDescription)1 AndroidManifestDescription (com.facebook.buck.android.AndroidManifestDescription)1