use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder 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.sync.workspace.ArtifactLocationDecoder 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.sync.workspace.ArtifactLocationDecoder 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.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeCreateResourceUtils method setupResDirectoryChoices.
static void setupResDirectoryChoices(Project project, @Nullable VirtualFile contextFile, JBLabel resDirLabel, ComboboxWithBrowseButton resDirComboAndBrowser) {
// Reset the item list before filling it back up.
resDirComboAndBrowser.getComboBox().removeAllItems();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData != null) {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData != null) {
ImmutableCollection<TargetKey> rulesRelatedToContext = null;
File fileFromContext = null;
if (contextFile != null) {
fileFromContext = VfsUtilCore.virtualToIoFile(contextFile);
rulesRelatedToContext = SourceToTargetMap.getInstance(project).getRulesForSourceFile(fileFromContext);
if (rulesRelatedToContext.isEmpty()) {
rulesRelatedToContext = null;
}
}
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
// Sort:
// - contextFile/res if contextFile is a directory,
// to optimize the right click on directory case, or the "closest" string
// match to the contextFile from the res directories known to blaze
// - the rest of the direct dirs, then transitive dirs of the context rules,
// then any known res dir in the project
// as a backup, in alphabetical order.
Set<File> resourceDirs = Sets.newTreeSet();
Set<File> transitiveDirs = Sets.newTreeSet();
Set<File> allResDirs = Sets.newTreeSet();
for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
Collection<File> resources = artifactLocationDecoder.decodeAll(androidResourceModule.resources);
Collection<File> transitiveResources = artifactLocationDecoder.decodeAll(androidResourceModule.transitiveResources);
// labelsRelatedToContext should include deps,
// but as a first pass we only check the rules themselves
// for resources. If we come up empty, then have anyResDir as a backup.
allResDirs.addAll(transitiveResources);
if (rulesRelatedToContext != null && !rulesRelatedToContext.contains(androidResourceModule.targetKey)) {
continue;
}
resourceDirs.addAll(resources);
transitiveDirs.addAll(transitiveResources);
}
// No need to show some directories twice.
transitiveDirs.removeAll(resourceDirs);
JComboBox resDirCombo = resDirComboAndBrowser.getComboBox();
// Allow the user to browse and overwrite some of the entries,
// in case our inference is wrong.
resDirCombo.setEditable(true);
// After the use confirms the choice, a directory will be created if it is missing.
if (fileFromContext != null && fileFromContext.isDirectory()) {
File closestDirToContext = new File(fileFromContext.getPath(), "res");
resDirCombo.setSelectedItem(closestDirToContext);
} else {
// If we're not completely sure, let people know there are options
// via the placeholder text, and put the most likely on top.
String placeHolder = PLACEHOLDER_TEXT;
resDirCombo.addItem(placeHolder);
resDirCombo.setSelectedItem(placeHolder);
if (fileFromContext != null) {
File closestDirToContext = findClosestDirToContext(fileFromContext.getPath(), resourceDirs);
closestDirToContext = closestDirToContext != null ? closestDirToContext : findClosestDirToContext(fileFromContext.getPath(), transitiveDirs);
if (closestDirToContext != null) {
resDirCombo.addItem(closestDirToContext);
resourceDirs.remove(closestDirToContext);
transitiveDirs.remove(closestDirToContext);
}
}
}
if (!resourceDirs.isEmpty() || !transitiveDirs.isEmpty()) {
for (File resourceDir : resourceDirs) {
resDirCombo.addItem(resourceDir);
}
for (File resourceDir : transitiveDirs) {
resDirCombo.addItem(resourceDir);
}
} else {
for (File resourceDir : allResDirs) {
resDirCombo.addItem(resourceDir);
}
}
resDirComboAndBrowser.setVisible(true);
resDirLabel.setVisible(true);
}
}
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeRenderErrorContributor method reportIssues.
@Override
public Collection<RenderErrorModel.Issue> reportIssues() {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null || !logger.hasErrors()) {
return getIssues();
}
TargetMap targetMap = blazeProjectData.targetMap;
ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
AndroidResourceModule resourceModule = AndroidResourceModuleRegistry.getInstance(project).get(module);
if (resourceModule == null) {
return getIssues();
}
TargetIdeInfo target = targetMap.get(resourceModule.targetKey);
if (target == null) {
return getIssues();
}
reportGeneratedResources(resourceModule, targetMap, decoder);
reportNonStandardAndroidManifestName(target, decoder);
reportResourceTargetShouldDependOnClassTarget(target, targetMap, decoder);
return getIssues();
}
Aggregations