Search in sources :

Example 6 with ArtifactLocationDecoder

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();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File)

Example 7 with ArtifactLocationDecoder

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);
}
Also used : SyncMode(com.google.idea.blaze.base.sync.BlazeSyncParams.SyncMode) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) FileCache(com.google.idea.blaze.base.filecache.FileCache) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) Map(java.util.Map) Project(com.intellij.openapi.project.Project) BlazeJavaUserSettings(com.google.idea.blaze.java.settings.BlazeJavaUserSettings) FileUtil(com.intellij.openapi.util.io.FileUtil) FileSizeScanner(com.google.idea.blaze.base.io.FileSizeScanner) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) BiMap(com.google.common.collect.BiMap) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) Collection(java.util.Collection) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) IOException(java.io.IOException) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) FileCacheSynchronizerTraits(com.google.idea.blaze.base.filecache.FileCacheSynchronizerTraits) Paths(java.nio.file.Paths) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Preconditions(com.google.common.base.Preconditions) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) FileCacheSynchronizer(com.google.idea.blaze.base.filecache.FileCacheSynchronizer) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) File(java.io.File)

Example 8 with ArtifactLocationDecoder

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);
    }
}
Also used : LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ImmutableSet(com.google.common.collect.ImmutableSet) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Predicate(java.util.function.Predicate) PrefetchFileSource(com.google.idea.blaze.base.prefetch.PrefetchFileSource) Set(java.util.Set) File(java.io.File) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BoolExperiment(com.google.idea.common.experiments.BoolExperiment) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FileUtil(com.intellij.openapi.util.io.FileUtil) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 9 with ArtifactLocationDecoder

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);
        }
    }
}
Also used : AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) JComboBox(javax.swing.JComboBox) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) BlazeAndroidSyncData(com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 10 with ArtifactLocationDecoder

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();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Aggregations

ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)27 File (java.io.File)15 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)13 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)12 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)12 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)12 Nullable (javax.annotation.Nullable)12 ImmutableList (com.google.common.collect.ImmutableList)9 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)9 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)8 BlazeImportSettingsManager (com.google.idea.blaze.base.settings.BlazeImportSettingsManager)8 Project (com.intellij.openapi.project.Project)8 List (java.util.List)8 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)6 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)6 Logger (com.intellij.openapi.diagnostic.Logger)6 Maps (com.google.common.collect.Maps)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5