Search in sources :

Example 6 with DefaultJavaLibrary

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

the class GroovyLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
        BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
        BuildRule libraryRule = resolver.requireRule(libraryTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
    BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))));
    JavacOptions javacOptions = JavacOptionsFactory.create(defaultJavacOptions, params, resolver, ruleFinder, args).withAbiGenerationMode(JavacOptions.AbiGenerationMode.CLASS);
    return new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), Optional.empty(), Optional.empty(), ImmutableList.of(), exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), /* trackClassUsage */
    false, /* additionalClasspathEntries */
    ImmutableSet.of(), new GroovycToJarStepFactory(groovyBuckConfig.getGroovyCompiler().get(), Optional.of(args.extraGroovycArguments), javacOptions), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses);
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary)

Example 7 with DefaultJavaLibrary

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

the class GroovyTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
        BuildTarget testTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
        BuildRule testRule = resolver.requireRule(testTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    JavacOptions javacOptions = JavacOptionsFactory.create(defaultJavacOptions, params, resolver, ruleFinder, args).withAbiGenerationMode(JavacOptions.AbiGenerationMode.CLASS);
    GroovycToJarStepFactory stepFactory = new GroovycToJarStepFactory(groovyBuckConfig.getGroovyCompiler().get(), Optional.of(args.extraGroovycArguments), javacOptions);
    BuildRuleParams testsLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(defaultJavacOptions.getInputs(ruleFinder)))).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
    JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), defaultJavacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
    Optional.empty(), /* postprocessClassesCommands */
    ImmutableList.of(), /* exportDeps */
    ImmutableSortedSet.of(), /* providedDeps */
    ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()), /* trackClassUsage */
    false, /* additionalClasspathEntries */
    ImmutableSet.of(), stepFactory, args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses));
    return new JavaTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, testsLibrary, /* additionalClasspathEntries */
    ImmutableSet.of(), args.labels, args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(), args.vmArgs, /* nativeLibsEnvironment */
    ImmutableMap.of(), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel, args.stdErrLogLevel);
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) Optional(java.util.Optional) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTest(com.facebook.buck.jvm.java.JavaTest) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary)

Example 8 with DefaultJavaLibrary

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

the class ScalaLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams rawParams, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    if (CalculateAbi.isAbiTarget(rawParams.getBuildTarget())) {
        BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(rawParams.getBuildTarget());
        BuildRule libraryRule = resolver.requireRule(libraryTarget);
        return CalculateAbi.of(rawParams.getBuildTarget(), ruleFinder, rawParams, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Tool scalac = scalaBuckConfig.getScalac(resolver);
    final BuildRule scalaLibrary = resolver.getRule(scalaBuckConfig.getScalaLibraryTarget());
    BuildRuleParams params = rawParams.copyReplacingDeclaredAndExtraDeps(() -> ImmutableSortedSet.<BuildRule>naturalOrder().addAll(rawParams.getDeclaredDeps().get()).add(scalaLibrary).build(), rawParams.getExtraDeps());
    BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))), scalac.getDeps(ruleFinder)));
    return new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), /* generatedSourceFolder */
    Optional.empty(), /* proguardConfig */
    Optional.empty(), /* postprocessClassesCommands */
    ImmutableList.of(), params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), /* trackClassUsage */
    false, /* additionalClasspathEntries */
    ImmutableSet.of(), new ScalacToJarStepFactory(scalac, scalaBuckConfig.getCompilerFlags(), args.extraArguments, resolver.getAllRules(scalaBuckConfig.getCompilerPlugins())), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, /* classesToRemoveFromJar */
    ImmutableSet.of());
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) Tool(com.facebook.buck.rules.Tool)

Example 9 with DefaultJavaLibrary

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

the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testObserverMethods.

@Test
public void testObserverMethods() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    DefaultJavaLibrary accumulateClassNames = JavaLibraryBuilder.createBuilder("//foo:bar").build(resolver);
    accumulateClassNames.getBuildOutputInitializer().setBuildOutput(new JavaLibrary.Data(ImmutableSortedMap.of("com/example/Foo", HashCode.fromString("cafebabe"))));
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).build();
    DexProducedFromJavaLibrary preDexWithClasses = new DexProducedFromJavaLibrary(params, accumulateClassNames);
    assertNull(preDexWithClasses.getSourcePathToOutput());
    assertEquals(BuildTargets.getGenPath(params.getProjectFilesystem(), buildTarget, "%s.dex.jar"), preDexWithClasses.getPathToDex());
}
Also used : JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) Test(org.junit.Test)

Example 10 with DefaultJavaLibrary

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

the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testGetBuildStepsWhenThereAreNoClassesToDex.

@Test
public void testGetBuildStepsWhenThereAreNoClassesToDex() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    DefaultJavaLibrary javaLibrary = JavaLibraryBuilder.createBuilder("//foo:bar").build(resolver);
    javaLibrary.getBuildOutputInitializer().setBuildOutput(new JavaLibrary.Data(ImmutableSortedMap.of()));
    BuildContext context = FakeBuildContext.NOOP_CONTEXT;
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar#dex");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
    DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(params, javaLibrary);
    List<Step> steps = preDex.getBuildSteps(context, buildableContext);
    Path dexOutput = BuildTargets.getGenPath(projectFilesystem, buildTarget, "%s.dex.jar");
    ExecutionContext executionContext = TestExecutionContext.newBuilder().build();
    MoreAsserts.assertSteps("Do not generate a .dex.jar file.", ImmutableList.of(String.format("rm -f %s", projectFilesystem.resolve(dexOutput)), String.format("mkdir -p %s", projectFilesystem.resolve(dexOutput.getParent())), "record_empty_dx"), steps, executionContext);
    Step recordArtifactAndMetadataStep = steps.get(2);
    assertThat(recordArtifactAndMetadataStep.getShortName(), startsWith("record_"));
    int exitCode = recordArtifactAndMetadataStep.execute(executionContext).getExitCode();
    assertEquals(0, exitCode);
}
Also used : Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) EstimateDexWeightStep(com.facebook.buck.dalvik.EstimateDexWeightStep) Step(com.facebook.buck.step.Step) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

DefaultJavaLibrary (com.facebook.buck.jvm.java.DefaultJavaLibrary)10 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)8 BuildTarget (com.facebook.buck.model.BuildTarget)7 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)6 BuildRule (com.facebook.buck.rules.BuildRule)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 JavacOptions (com.facebook.buck.jvm.java.JavacOptions)3 Optional (java.util.Optional)3 Test (org.junit.Test)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 FakeJavaLibrary (com.facebook.buck.jvm.java.FakeJavaLibrary)2 JavaTest (com.facebook.buck.jvm.java.JavaTest)2 JavaTestDescription (com.facebook.buck.jvm.java.JavaTestDescription)2 JavacToJarStepFactory (com.facebook.buck.jvm.java.JavacToJarStepFactory)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)2 Tool (com.facebook.buck.rules.Tool)2 ImmutableMap (com.google.common.collect.ImmutableMap)2