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);
}
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);
}
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());
}
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());
}
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);
}
Aggregations