use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class JavaPrefetchFileSource method addFilesToPrefetch.
@Override
public void addFilesToPrefetch(Project project, ProjectViewSet projectViewSet, ImportRoots importRoots, BlazeProjectData blazeProjectData, Set<File> files) {
BlazeJavaSyncData syncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
if (syncData == null) {
return;
}
// If we have a local jar cache we don't need to prefetch anything
if (JarCache.getInstance(project).isEnabled()) {
return;
}
Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, blazeProjectData);
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
for (BlazeLibrary library : libraries) {
if (!(library instanceof BlazeJarLibrary)) {
continue;
}
BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
files.add(artifactLocationDecoder.decode(jarLibrary.libraryArtifact.jarForIntellijLibrary()));
files.addAll(artifactLocationDecoder.decodeAll(jarLibrary.libraryArtifact.sourceJars));
}
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method buildLibraries.
private ImmutableMap<LibraryKey, BlazeJarLibrary> buildLibraries(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, List<TargetIdeInfo> libraryTargets, List<TargetIdeInfo> protoLibraries) {
// Build library maps
Multimap<TargetKey, BlazeJarLibrary> targetKeyToLibrary = ArrayListMultimap.create();
Map<String, BlazeJarLibrary> jdepsPathToLibrary = Maps.newHashMap();
// Add any output jars from source rules
for (TargetKey key : workspaceBuilder.outputJarsFromSourceTargets.keySet()) {
Collection<BlazeJarLibrary> jars = workspaceBuilder.outputJarsFromSourceTargets.get(key);
targetKeyToLibrary.putAll(key, jars);
for (BlazeJarLibrary library : jars) {
addLibraryToJdeps(jdepsPathToLibrary, library);
}
}
for (TargetIdeInfo target : libraryTargets) {
JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
if (javaIdeInfo == null) {
continue;
}
List<LibraryArtifact> allJars = Lists.newArrayList();
allJars.addAll(javaIdeInfo.jars);
Collection<BlazeJarLibrary> libraries = allJars.stream().map(BlazeJarLibrary::new).collect(Collectors.toList());
targetKeyToLibrary.putAll(target.key, libraries);
for (BlazeJarLibrary library : libraries) {
addLibraryToJdeps(jdepsPathToLibrary, library);
}
}
// proto legacy jdeps support
for (TargetIdeInfo target : protoLibraries) {
ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
if (protoLibraryLegacyInfo == null) {
continue;
}
for (LibraryArtifact libraryArtifact : Iterables.concat(protoLibraryLegacyInfo.jarsV1, protoLibraryLegacyInfo.jarsMutable, protoLibraryLegacyInfo.jarsImmutable)) {
addLibraryToJdeps(jdepsPathToLibrary, new BlazeJarLibrary(libraryArtifact));
}
}
Map<LibraryKey, BlazeJarLibrary> result = Maps.newHashMap();
// Collect jars from jdep references
for (String jdepsPath : workspaceBuilder.jdeps) {
if (sourceFilter.jdepsPathsForExcludedJars.contains(jdepsPath)) {
continue;
}
BlazeJarLibrary library = jdepsPathToLibrary.get(jdepsPath);
if (library == null) {
// It's in the target's jdeps, but our aspect never attached to the target building it
// Perhaps it's an implicit dependency, or not referenced in an attribute we propagate along
// Or it could be that this is a multi-configuration project, and jdeps refers to a
// configuration different from the one we picked for the TargetMap.
// Make a best-effort attempt to add it to the project anyway.
ExecutionPathFragmentAndRelativePath split = ExecutionPathFragmentAndRelativePath.split(jdepsPath);
ArtifactLocation location = ArtifactLocation.builder().setIsSource(false).setRootExecutionPathFragment(split.rootExecutionPathFragment).setRelativePath(split.relativePath).build();
library = new BlazeJarLibrary(new LibraryArtifact(location, null, ImmutableList.of()));
}
result.put(library.key, library);
}
// Collect jars referenced by direct deps from your working set
for (TargetKey deps : workspaceBuilder.directDeps) {
for (BlazeJarLibrary library : targetKeyToLibrary.get(deps)) {
result.put(library.key, library);
}
}
// Collect legacy proto libraries from direct deps
addProtoLegacyLibrariesFromDirectDeps(workspaceBuilder, targetMap, result);
// Collect generated jars from source rules
for (BlazeJarLibrary library : workspaceBuilder.generatedJarsFromSourceTargets) {
result.put(library.key, library);
}
return ImmutableMap.copyOf(result);
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method importWorkspace.
public BlazeJavaImportResult importWorkspace(BlazeContext context) {
WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
for (TargetIdeInfo target : sourceFilter.sourceTargets) {
addTargetAsSource(workspaceBuilder, target, sourceFilter.targetToJavaSources.get(target.key));
}
SourceDirectoryCalculator sourceDirectoryCalculator = new SourceDirectoryCalculator();
ImmutableList<BlazeContentEntry> contentEntries = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, artifactLocationDecoder, importRoots, workspaceBuilder.sourceArtifacts, workspaceBuilder.javaPackageManifests);
int totalContentEntryCount = 0;
for (BlazeContentEntry contentEntry : contentEntries) {
totalContentEntryCount += contentEntry.sources.size();
}
context.output(PrintOutput.log("Java content entry count: " + totalContentEntryCount));
ImmutableMap<LibraryKey, BlazeJarLibrary> libraries = buildLibraries(workspaceBuilder, targetMap, sourceFilter.libraryTargets, sourceFilter.protoLibraries);
duplicateSourceDetector.reportDuplicates(context);
String sourceVersion = findSourceVersion(targetMap);
return new BlazeJavaImportResult(contentEntries, libraries, ImmutableList.copyOf(workspaceBuilder.buildOutputJars.stream().sorted().collect(Collectors.toList())), ImmutableSet.copyOf(workspaceBuilder.addedSourceFiles), sourceVersion);
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testIdlClassJarIsAddedAsLibrary.
@Test
public void testIdlClassJarIsAddedAsLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//example:lib").setBuildFile(source("example/BUILD")).setKind("android_binary").addSource(source("example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("example").setIdlJar(LibraryArtifact.builder().setInterfaceJar(gen("example/libidl.jar")).addSourceJar(gen("example/libidl.srcjar")).build()).setHasIdlSources(true)));
TargetMap targetMap = targetMapBuilder.build();
BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
List<BlazeJarLibrary> jars = Lists.newArrayList();
List<BlazeJarLibrary> genJars = Lists.newArrayList();
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
for (TargetIdeInfo target : targetMap.targets()) {
if (importRoots.importAsSource(target.key.label)) {
syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
}
}
assertThat(genJars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("libidl.jar");
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class BlazeAndroidLibrarySource method getLibraries.
@Override
public List<BlazeLibrary> getLibraries() {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData == null) {
return ImmutableList.of();
}
ImmutableList.Builder<BlazeLibrary> libraries = ImmutableList.builder();
if (syncData.importResult.resourceLibrary != null) {
libraries.add(syncData.importResult.resourceLibrary);
}
if (syncData.importResult.javacJar != null) {
libraries.add(new BlazeJarLibrary(new LibraryArtifact(null, syncData.importResult.javacJar, ImmutableList.of())));
}
libraries.addAll(syncData.importResult.aarLibraries);
return libraries.build();
}
Aggregations