use of com.facebook.buck.android.AndroidPrebuiltAar in project buck by facebook.
the class Project method writeJsonConfig.
private void writeJsonConfig(File jsonTempFile, List<SerializableModule> modules) throws IOException {
List<SerializablePrebuiltJarRule> libraries = Lists.newArrayListWithCapacity(libraryJars.size());
for (BuildRule libraryJar : libraryJars) {
Preconditions.checkState(libraryJar instanceof PrebuiltJar);
String name = getIntellijNameForRule(libraryJar, null);
PrebuiltJar prebuiltJar = (PrebuiltJar) libraryJar;
Path binaryJarAbsolutePath = resolver.getAbsolutePath(prebuiltJar.getSourcePathToOutput());
String binaryJar = MorePaths.pathWithUnixSeparators(projectFilesystem.relativize(binaryJarAbsolutePath));
String sourceJar = prebuiltJar.getSourceJar().map(resolver::getAbsolutePath).map(projectFilesystem::relativize).map(MorePaths::pathWithUnixSeparators).orElse(null);
String javadocUrl = prebuiltJar.getJavadocUrl().orElse(null);
libraries.add(new SerializablePrebuiltJarRule(name, binaryJar, sourceJar, javadocUrl));
}
List<SerializableAndroidAar> aars = Lists.newArrayListWithCapacity(androidAars.size());
for (BuildRule aar : androidAars) {
Preconditions.checkState(aar instanceof AndroidPrebuiltAar);
AndroidPrebuiltAar preBuiltAar = (AndroidPrebuiltAar) aar;
String name = getIntellijNameForAar(preBuiltAar);
aars.add(createSerializableAndroidAar(name, preBuiltAar));
}
writeJsonConfig(jsonTempFile, modules, libraries, aars);
}
use of com.facebook.buck.android.AndroidPrebuiltAar in project buck by facebook.
the class Project method walkRuleAndAdd.
/**
* Walks the dependencies of a build rule and adds the appropriate DependentModules to the
* specified dependencies collection. All library dependencies will be added before any module
* dependencies. See {@code ProjectTest#testThatJarsAreListedBeforeModules()} for details on why
* this behavior is important.
*/
@SuppressWarnings("PMD.LooseCoupling")
private void walkRuleAndAdd(final BuildRule rule, final boolean isForTests, final LinkedHashSet<SerializableDependentModule> dependencies, @Nullable final BuildRule srcTarget) {
final Path basePathForRule = rule.getBuildTarget().getBasePath();
Set<BuildRule> targetsToWalk;
if (rule instanceof JavaTest) {
targetsToWalk = ((JavaTest) rule).getCompiledTestsLibrary().getDeps();
} else {
targetsToWalk = rule.getDeps();
}
new AbstractBreadthFirstTraversal<BuildRule>(targetsToWalk) {
private final LinkedHashSet<SerializableDependentModule> librariesToAdd = Sets.newLinkedHashSet();
private final LinkedHashSet<SerializableDependentModule> modulesToAdd = Sets.newLinkedHashSet();
@Override
public ImmutableSet<BuildRule> visit(BuildRule dep) {
// Hack: we don't want uber R.java to show up in the deps that IntelliJ sees.
if (dep.getBuildTarget().toString().endsWith("_uber_r_dot_java")) {
return ImmutableSet.of();
}
ImmutableSet<BuildRule> depsToVisit;
if (rule.getProperties().is(PACKAGING) || dep instanceof AndroidResource || dep == rule) {
depsToVisit = dep.getDeps();
} else if (dep.getProperties().is(LIBRARY) && dep instanceof ExportDependencies) {
depsToVisit = ((ExportDependencies) dep).getExportedDeps();
} else {
depsToVisit = ImmutableSet.of();
}
// should contain the union of :lib and :test's deps as dependent modules.
if (isForTests && depsToVisit.isEmpty() && dep.getBuildTarget().getBasePath().equals(basePathForRule) && !dep.equals(srcTarget)) {
depsToVisit = dep.getDeps();
}
SerializableDependentModule dependentModule;
if (androidAars.contains(dep)) {
AndroidPrebuiltAar aar = androidAars.getParentAar(dep);
dependentModule = SerializableDependentModule.newLibrary(aar.getBuildTarget(), getIntellijNameForAar(aar));
} else if (dep instanceof PrebuiltJar) {
libraryJars.add(dep);
String libraryName = getIntellijNameForRule(dep);
dependentModule = SerializableDependentModule.newLibrary(dep.getBuildTarget(), libraryName);
} else if (dep instanceof AndroidPrebuiltAar) {
androidAars.add((AndroidPrebuiltAar) dep);
String libraryName = getIntellijNameForAar(dep);
dependentModule = SerializableDependentModule.newLibrary(dep.getBuildTarget(), libraryName);
} else if ((dep instanceof CxxLibrary) || (dep instanceof NdkLibrary) || (dep instanceof JavaLibrary) || (dep instanceof AndroidResource)) {
String moduleName = getIntellijNameForRule(dep);
dependentModule = SerializableDependentModule.newModule(dep.getBuildTarget(), moduleName);
} else {
return depsToVisit;
}
if (librariesToAdd.contains(dependentModule) || modulesToAdd.contains(dependentModule)) {
return depsToVisit;
}
if (isForTests) {
dependentModule.scope = "TEST";
} else {
// If the dependentModule has already been added in the "TEST" scope, then it should be
// removed and then re-added using the current (compile) scope.
String currentScope = dependentModule.scope;
dependentModule.scope = "TEST";
if (dependencies.contains(dependentModule)) {
dependencies.remove(dependentModule);
}
dependentModule.scope = currentScope;
}
// dependencies collection once the traversal is complete in the onComplete() method.
if (dependentModule.isLibrary()) {
librariesToAdd.add(dependentModule);
} else {
modulesToAdd.add(dependentModule);
}
return depsToVisit;
}
@Override
protected void onComplete() {
dependencies.addAll(librariesToAdd);
dependencies.addAll(modulesToAdd);
}
}.start();
}
use of com.facebook.buck.android.AndroidPrebuiltAar 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();
}
Aggregations