Search in sources :

Example 31 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class ExcludeLibraryAction method actionPerformedInBlazeProject.

@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return;
    }
    Library library = LibraryActionHelper.findLibraryForAction(e);
    if (library == null) {
        return;
    }
    BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
    if (blazeLibrary == null) {
        Messages.showErrorDialog(project, "Could not find this library in the project.", CommonBundle.getErrorTitle());
        return;
    }
    final LibraryArtifact libraryArtifact = blazeLibrary.libraryArtifact;
    final String path = libraryArtifact.jarForIntellijLibrary().getRelativePath();
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<Glob> existingSection = builder.getLast(ExcludeLibrarySection.KEY);
        builder.replace(existingSection, ListSection.update(ExcludeLibrarySection.KEY, existingSection).add(new Glob(path)));
        return true;
    });
    if (edit == null) {
        Messages.showErrorDialog("Could not modify project view. Check for errors in your project view and try again", "Error");
        return;
    }
    edit.apply();
    BlazeSyncManager.getInstance(project).incrementalProjectSync();
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) Glob(com.google.idea.blaze.base.projectview.section.Glob) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) Library(com.intellij.openapi.roots.libraries.Library) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Example 32 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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 33 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeGoRootsProviderTest method testPackageToTargetMap.

@Test
public void testPackageToTargetMap() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(src("foo/bar/BUILD")).setLabel("//foo/bar:binary").setKind("go_binary").addSource(src("foo/bar/binary.go")).addDependency("//one/two:library").setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/binary.go"))).setImportPath("prefix/foo/bar/binary"))).addTarget(TargetIdeInfo.builder().setBuildFile(src("one/two/BUILD")).setLabel("//one/two:library").setKind("go_library").addSource(src("one/two/library.go")).addSource(src("one/two/three/library.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("one/two/library.go"), src("one/two/three/library.go"))).setImportPath("prefix/one/two/library"))).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(new BlazeProjectData(0L, targetMap, null, null, null, null, new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null)));
    assertThat(BlazeGoRootsProvider.getPackageToTargetMap(getProject())).containsExactly("prefix/foo/bar/binary", TargetKey.forPlainTarget(Label.create("//foo/bar:binary")), "prefix/one/two/library", TargetKey.forPlainTarget(Label.create("//one/two:library")));
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 34 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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 35 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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;
}
Also used : BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImmutableSet(com.google.common.collect.ImmutableSet) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) LibrarySource(com.google.idea.blaze.base.sync.libraries.LibrarySource) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Nullable(javax.annotation.Nullable) Objects(java.util.Objects) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) Nullable(javax.annotation.Nullable)

Aggregations

BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)82 File (java.io.File)31 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)28 Nullable (javax.annotation.Nullable)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)23 Test (org.junit.Test)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)17 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)15 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)13 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)13 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)13 Project (com.intellij.openapi.project.Project)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)11 ImmutableList (com.google.common.collect.ImmutableList)10 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)10 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 List (java.util.List)8 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)7