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();
}
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);
}
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")));
}
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);
}
}
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;
}
Aggregations