use of com.facebook.buck.jvm.java.JavaLibrary in project buck by facebook.
the class KotlinTestDescription 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(testTarget, ruleFinder, params, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavacOptions javacOptions = JavacOptionsFactory.create(templateJavacOptions, params, resolver, ruleFinder, args);
KotlincToJarStepFactory stepFactory = new KotlincToJarStepFactory(kotlinBuckConfig.getKotlinCompiler().get(), args.extraKotlincArguments);
BuildRuleParams testsLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps)))).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).build()), params.getExtraDeps()).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
JavaLibrary testsLibrary = resolver.addToIndex(new DefaultKotlinLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), templateJavacOptions.getGeneratedSourceFolderName(), Optional.empty(), /* proguardConfig */
ImmutableList.of(), /* postprocessClassesCommands */
ImmutableSortedSet.of(), /* exportedDeps */
ImmutableSortedSet.of(), /* providedDeps */
JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()), false, /* trackClassUsage */
ImmutableSet.of(), /* additionalClasspathEntries */
stepFactory, args.resourcesRoot, args.manifestFile, args.mavenCoords, ImmutableSortedSet.of(), /* tests */
ImmutableSet.of()));
return new KotlinTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, testsLibrary, ImmutableSet.<Either<SourcePath, Path>>of(kotlinBuckConfig.getPathToRuntimeJar()), args.labels, args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(), args.vmArgs, ImmutableMap.of(), /* nativeLibsEnvironment */
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.JavaLibrary in project buck by facebook.
the class IjProject method write.
/**
* Write the project to disk.
*
* @param runPostGenerationCleaner Whether or not the post-generation cleaner should be run.
* @return set of {@link BuildTarget}s which should be built in order for the project to index
* correctly.
* @throws IOException
*/
public ImmutableSet<BuildTarget> write(boolean runPostGenerationCleaner, boolean removeUnusedLibraries, boolean excludeArtifacts) throws IOException {
final ImmutableSet.Builder<BuildTarget> requiredBuildTargets = ImmutableSet.builder();
IjLibraryFactory libraryFactory = new DefaultIjLibraryFactory(new IjLibraryFactoryResolver() {
@Override
public Path getPath(SourcePath path) {
Optional<BuildRule> rule = ruleFinder.getRule(path);
if (rule.isPresent()) {
requiredBuildTargets.add(rule.get().getBuildTarget());
}
return projectFilesystem.getRootPath().relativize(sourcePathResolver.getAbsolutePath(path));
}
@Override
public Optional<SourcePath> getPathIfJavaLibrary(TargetNode<?, ?> targetNode) {
BuildRule rule = buildRuleResolver.getRule(targetNode.getBuildTarget());
if (!(rule instanceof JavaLibrary)) {
return Optional.empty();
}
if (rule instanceof AndroidPrebuiltAar) {
AndroidPrebuiltAar aarRule = (AndroidPrebuiltAar) rule;
return Optional.ofNullable(aarRule.getBinaryJar());
}
requiredBuildTargets.add(rule.getBuildTarget());
return Optional.ofNullable(rule.getSourcePathToOutput());
}
});
IjModuleFactoryResolver moduleFactoryResolver = new IjModuleFactoryResolver() {
@Override
public Optional<Path> getDummyRDotJavaPath(TargetNode<?, ?> targetNode) {
BuildTarget dummyRDotJavaTarget = AndroidLibraryGraphEnhancer.getDummyRDotJavaTarget(targetNode.getBuildTarget());
Optional<BuildRule> dummyRDotJavaRule = buildRuleResolver.getRuleOptional(dummyRDotJavaTarget);
if (dummyRDotJavaRule.isPresent()) {
requiredBuildTargets.add(dummyRDotJavaTarget);
return Optional.of(DummyRDotJava.getRDotJavaBinFolder(dummyRDotJavaTarget, projectFilesystem));
}
return Optional.empty();
}
@Override
public Path getAndroidManifestPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
return sourcePathResolver.getAbsolutePath(targetNode.getConstructorArg().manifest);
}
@Override
public Optional<Path> getLibraryAndroidManifestPath(TargetNode<AndroidLibraryDescription.Arg, ?> targetNode) {
Optional<SourcePath> manifestPath = targetNode.getConstructorArg().manifest;
Optional<Path> defaultAndroidManifestPath = intellijConfig.getAndroidManifest().map(Path::toAbsolutePath);
return manifestPath.map(sourcePathResolver::getAbsolutePath).map(Optional::of).orElse(defaultAndroidManifestPath);
}
@Override
public Optional<Path> getProguardConfigPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
return targetNode.getConstructorArg().proguardConfig.map(this::getRelativePathAndRecordRule);
}
@Override
public Optional<Path> getAndroidResourcePath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
return AndroidResourceDescription.getResDirectoryForProject(buildRuleResolver, targetNode).map(this::getRelativePathAndRecordRule);
}
@Override
public Optional<Path> getAssetsPath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
return AndroidResourceDescription.getAssetsDirectoryForProject(buildRuleResolver, targetNode).map(this::getRelativePathAndRecordRule);
}
@Override
public Optional<Path> getAnnotationOutputPath(TargetNode<? extends JvmLibraryArg, ?> targetNode) {
AnnotationProcessingParams annotationProcessingParams = targetNode.getConstructorArg().buildAnnotationProcessingParams(targetNode.getBuildTarget(), projectFilesystem, buildRuleResolver, ImmutableSet.of());
if (annotationProcessingParams == null || annotationProcessingParams.isEmpty()) {
return Optional.empty();
}
return Optional.ofNullable(annotationProcessingParams.getGeneratedSourceFolderName());
}
private Path getRelativePathAndRecordRule(SourcePath sourcePath) {
requiredBuildTargets.addAll(OptionalCompat.asSet(ruleFinder.getRule(sourcePath).map(BuildRule::getBuildTarget)));
return sourcePathResolver.getRelativePath(sourcePath);
}
};
IjModuleGraph moduleGraph = IjModuleGraph.from(projectConfig, targetGraphAndTargets.getTargetGraph(), libraryFactory, new IjModuleFactory(projectFilesystem, moduleFactoryResolver, projectConfig, excludeArtifacts), aggregationMode);
JavaPackageFinder parsingJavaPackageFinder = ParsingJavaPackageFinder.preparse(javaFileParser, projectFilesystem, IjProjectTemplateDataPreparer.createPackageLookupPathSet(moduleGraph), javaPackageFinder);
IjProjectWriter writer = new IjProjectWriter(new IjProjectTemplateDataPreparer(parsingJavaPackageFinder, moduleGraph, projectFilesystem), projectConfig, projectFilesystem, moduleGraph);
writer.write(runPostGenerationCleaner, removeUnusedLibraries);
return requiredBuildTargets.build();
}
use of com.facebook.buck.jvm.java.JavaLibrary in project buck by facebook.
the class TestRunning method getReportCommand.
/**
* Returns the ShellCommand object that is supposed to generate a code coverage report from data
* obtained during the test run. This method will also generate a set of source paths to the class
* files tested during the test run.
*/
private static Step getReportCommand(ImmutableSet<JavaLibrary> rulesUnderTest, DefaultJavaPackageFinder defaultJavaPackageFinder, JavaRuntimeLauncher javaRuntimeLauncher, ProjectFilesystem filesystem, SourcePathResolver sourcePathResolver, SourcePathRuleFinder ruleFinder, Path outputDirectory, CoverageReportFormat format, String title, boolean useIntermediateClassesDir, Optional<String> coverageIncludes, Optional<String> coverageExcludes) {
ImmutableSet.Builder<String> srcDirectories = ImmutableSet.builder();
ImmutableSet.Builder<Path> pathsToJars = ImmutableSet.builder();
// Add all source directories of java libraries that we are testing to -sourcepath.
for (JavaLibrary rule : rulesUnderTest) {
ImmutableSet<String> sourceFolderPath = getPathToSourceFolders(rule, sourcePathResolver, ruleFinder, defaultJavaPackageFinder);
if (!sourceFolderPath.isEmpty()) {
srcDirectories.addAll(sourceFolderPath);
}
Path classesItem = null;
if (useIntermediateClassesDir) {
classesItem = DefaultJavaLibrary.getClassesDir(rule.getBuildTarget(), filesystem);
} else {
SourcePath path = rule.getSourcePathToOutput();
if (path != null) {
classesItem = sourcePathResolver.getRelativePath(path);
}
}
if (classesItem == null) {
continue;
}
pathsToJars.add(classesItem);
}
return new GenerateCodeCoverageReportStep(javaRuntimeLauncher, filesystem, srcDirectories.build(), pathsToJars.build(), outputDirectory, format, title, coverageIncludes, coverageExcludes);
}
use of com.facebook.buck.jvm.java.JavaLibrary 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.JavaLibrary in project buck by facebook.
the class GwtBinary method getClasspathEntries.
/**
* The classpath entries needed to run {@code com.google.gwt.dev.Compiler} to build the module
* specified by {@link #modules}.
*/
@VisibleForTesting
Iterable<Path> getClasspathEntries(SourcePathResolver pathResolver) {
ImmutableSet.Builder<Path> classpathEntries = ImmutableSet.builder();
classpathEntries.addAll(pathResolver.getAllAbsolutePaths(gwtModuleJars));
for (BuildRule dep : getDeclaredDeps()) {
if (!(dep instanceof JavaLibrary)) {
continue;
}
JavaLibrary javaLibrary = (JavaLibrary) dep;
for (SourcePath path : javaLibrary.getOutputClasspaths()) {
classpathEntries.add(pathResolver.getAbsolutePath(path));
}
}
return classpathEntries.build();
}
Aggregations