use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class SourceToTargetMapImpl method computeSourceToTargetMap.
@SuppressWarnings("unused")
private static ImmutableMultimap<File, TargetKey> computeSourceToTargetMap(Project project, BlazeProjectData blazeProjectData) {
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
ImmutableMultimap.Builder<File, TargetKey> sourceToTargetMap = ImmutableMultimap.builder();
for (TargetIdeInfo target : blazeProjectData.targetMap.targets()) {
TargetKey key = target.key;
for (ArtifactLocation sourceArtifact : target.sources) {
sourceToTargetMap.put(artifactLocationDecoder.decode(sourceArtifact), key);
}
}
return sourceToTargetMap.build();
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class BlazeSourceJarNavigationPolicy method getSourceJarRoot.
@Nullable
private VirtualFile getSourceJarRoot(Project project, BlazeProjectData blazeProjectData, PsiJavaFile clsFile) {
Library library = findLibrary(project, clsFile);
if (library == null || library.getFiles(OrderRootType.SOURCES).length != 0) {
// If the library already has sources attached, no need to hunt for them.
return null;
}
BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
if (blazeLibrary == null) {
return null;
}
// TODO: If there are multiple source jars, search for one containing this PsiJavaFile.
for (ArtifactLocation jar : blazeLibrary.libraryArtifact.sourceJars) {
VirtualFile root = getSourceJarRoot(project, blazeProjectData.artifactLocationDecoder, jar);
if (root != null) {
return root;
}
}
return null;
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class JarCache method onSync.
void onSync(BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData projectData, BlazeSyncParams.SyncMode syncMode) {
Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, projectData);
boolean fullRefresh = syncMode == SyncMode.FULL;
boolean removeMissingFiles = syncMode == SyncMode.INCREMENTAL;
boolean enabled = updateEnabled();
if (!enabled || fullRefresh) {
clearCache();
}
if (!enabled) {
return;
}
List<BlazeJarLibrary> jarLibraries = libraries.stream().filter(library -> library instanceof BlazeJarLibrary).map(library -> (BlazeJarLibrary) library).collect(Collectors.toList());
ArtifactLocationDecoder artifactLocationDecoder = projectData.artifactLocationDecoder;
BiMap<File, String> sourceFileToCacheKey = HashBiMap.create(jarLibraries.size());
for (BlazeJarLibrary library : jarLibraries) {
File jarFile = artifactLocationDecoder.decode(library.libraryArtifact.jarForIntellijLibrary());
sourceFileToCacheKey.put(jarFile, cacheKeyForJar(jarFile));
for (ArtifactLocation sourceJar : library.libraryArtifact.sourceJars) {
File srcJarFile = artifactLocationDecoder.decode(sourceJar);
sourceFileToCacheKey.put(srcJarFile, cacheKeyForSourceJar(srcJarFile));
}
}
this.traits = new JarCacheSynchronizerTraits(cacheDir, sourceFileToCacheKey);
refresh(context, removeMissingFiles);
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class CPrefetchFileSource method addFilesToPrefetch.
@Override
public void addFilesToPrefetch(Project project, ProjectViewSet projectViewSet, ImportRoots importRoots, BlazeProjectData blazeProjectData, Set<File> files) {
if (!blazeProjectData.workspaceLanguageSettings.isLanguageActive(LanguageClass.C) || !prefetchAllCppSources.getValue()) {
return;
}
// Prefetch all non-project CPP header files encountered during sync
Predicate<ArtifactLocation> shouldPrefetch = location -> {
if (!location.isSource || location.isExternal) {
return false;
}
WorkspacePath path = WorkspacePath.createIfValid(location.relativePath);
if (path == null || importRoots.containsWorkspacePath(path)) {
return false;
}
String extension = FileUtil.getExtension(path.relativePath());
return CFileExtensions.HEADER_EXTENSIONS.contains(extension);
};
ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
for (TargetIdeInfo target : blazeProjectData.targetMap.targets()) {
if (target.cIdeInfo == null) {
continue;
}
target.sources.stream().filter(shouldPrefetch).map(decoder::decode).forEach(files::add);
}
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class BlazeAndroidLiteSyncPlugin method getSdkLibrary.
@Nullable
private static BlazeLibrary getSdkLibrary(BlazeProjectData blazeProjectData) {
List<AndroidSdkIdeInfo> sdkTargets = androidSdkTargets(blazeProjectData.targetMap);
if (sdkTargets.isEmpty()) {
return null;
}
// for now, just add the first one found
// TODO: warn if there's more than one
ArtifactLocation sdk = sdkTargets.stream().map(info -> info.androidJar).filter(Objects::nonNull).findFirst().orElse(null);
return sdk != null ? new BlazeJarLibrary(new LibraryArtifact(null, sdk, ImmutableList.of())) : null;
}
Aggregations