use of com.google.idea.blaze.base.sync.projectview.ImportRoots in project intellij by bazelbuild.
the class SourceDirectoryCalculator method calculateContentEntries.
public ImmutableList<BlazeContentEntry> calculateContentEntries(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ArtifactLocationDecoder artifactLocationDecoder, ImportRoots importRoots, Collection<SourceArtifact> sources, Map<TargetKey, ArtifactLocation> javaPackageManifests) {
ManifestFilePackageReader manifestFilePackageReader = Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("ReadPackageManifests", EventType.Other));
Map<TargetKey, Map<ArtifactLocation, String>> manifestMap = PackageManifestReader.getInstance().readPackageManifestFiles(project, childContext, artifactLocationDecoder, javaPackageManifests, packageReaderExecutorService);
return new ManifestFilePackageReader(manifestMap);
});
final List<JavaPackageReader> javaPackageReaders = Lists.newArrayList(manifestFilePackageReader, JavaSourcePackageReader.getInstance(), generatedFileJavaPackageReader);
Collection<SourceArtifact> nonGeneratedSources = filterGeneratedArtifacts(sources);
// Sort artifacts and excludes into their respective workspace paths
Multimap<WorkspacePath, SourceArtifact> sourcesUnderDirectoryRoot = sortArtifactLocationsByRootDirectory(context, importRoots, nonGeneratedSources);
List<BlazeContentEntry> result = Lists.newArrayList();
Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("CalculateSourceDirectories", EventType.Other));
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
File contentRoot = workspaceRoot.fileForPath(workspacePath);
ImmutableList<BlazeSourceDirectory> sourceDirectories = calculateSourceDirectoriesForContentRoot(context, workspaceRoot, artifactLocationDecoder, workspacePath, sourcesUnderDirectoryRoot.get(workspacePath), javaPackageReaders);
if (!sourceDirectories.isEmpty()) {
result.add(new BlazeContentEntry(contentRoot, sourceDirectories));
}
}
result.sort(Comparator.comparing(lhs -> lhs.contentRoot));
});
return ImmutableList.copyOf(result);
}
use of com.google.idea.blaze.base.sync.projectview.ImportRoots in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testIdlClassJarIsAddedAsLibrary.
@Test
public void testIdlClassJarIsAddedAsLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//example:lib").setBuildFile(source("example/BUILD")).setKind("android_binary").addSource(source("example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("example").setIdlJar(LibraryArtifact.builder().setInterfaceJar(gen("example/libidl.jar")).addSourceJar(gen("example/libidl.srcjar")).build()).setHasIdlSources(true)));
TargetMap targetMap = targetMapBuilder.build();
BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
List<BlazeJarLibrary> jars = Lists.newArrayList();
List<BlazeJarLibrary> genJars = Lists.newArrayList();
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
for (TargetIdeInfo target : targetMap.targets()) {
if (importRoots.importAsSource(target.key.label)) {
syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
}
}
assertThat(genJars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("libidl.jar");
}
use of com.google.idea.blaze.base.sync.projectview.ImportRoots in project intellij by bazelbuild.
the class WorkspaceRootNode method getChildrenImpl.
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
if (!BlazeUserSettings.getInstance().getCollapseProjectView()) {
return super.getChildrenImpl();
}
Project project = getProject();
if (project == null) {
return super.getChildrenImpl();
}
List<AbstractTreeNode> children = Lists.newArrayList();
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet == null) {
return super.getChildrenImpl();
}
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project)).add(projectViewSet).build();
if (importRoots.rootDirectories().stream().anyMatch(WorkspacePath::isWorkspaceRoot)) {
return super.getChildrenImpl();
}
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
VirtualFile virtualFile = VfsUtil.findFileByIoFile(workspaceRoot.fileForPath(workspacePath), false);
if (virtualFile == null) {
continue;
}
PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile);
if (psiDirectory == null) {
continue;
}
children.add(new BlazePsiDirectoryRootNode(project, psiDirectory, getSettings()));
}
if (children.isEmpty()) {
return super.getChildrenImpl();
}
return children;
}
use of com.google.idea.blaze.base.sync.projectview.ImportRoots in project intellij by bazelbuild.
the class PrefetchServiceImpl method prefetchProjectFiles.
@Override
public ListenableFuture<?> prefetchProjectFiles(Project project, ProjectViewSet projectViewSet, @Nullable BlazeProjectData blazeProjectData) {
BlazeImportSettings importSettings = BlazeImportSettingsManager.getInstance(project).getImportSettings();
if (importSettings == null) {
return Futures.immediateFuture(null);
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromImportSettings(importSettings);
if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
// quick sanity check before trying to prefetch each individual file
return Futures.immediateFuture(null);
}
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, importSettings.getBuildSystem()).add(projectViewSet).build();
Set<File> sourceDirectories = new HashSet<>();
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
sourceDirectories.add(workspaceRoot.fileForPath(workspacePath));
}
Set<File> excludeDirectories = new HashSet<>();
for (WorkspacePath workspacePath : importRoots.excludeDirectories()) {
excludeDirectories.add(workspaceRoot.fileForPath(workspacePath));
}
ListenableFuture<?> sourceFilesFuture = prefetchFiles(project, excludeDirectories, sourceDirectories, /* refetchCachedFiles */
false, /* fetchFileTypes */
true);
Set<File> externalFiles = new HashSet<>();
if (blazeProjectData != null) {
for (PrefetchFileSource fileSource : PrefetchFileSource.EP_NAME.getExtensions()) {
fileSource.addFilesToPrefetch(project, projectViewSet, importRoots, blazeProjectData, externalFiles);
}
}
ListenableFuture<?> externalFilesFuture = prefetchFiles(project, externalFiles, false, false);
return Futures.allAsList(sourceFilesFuture, externalFilesFuture);
}
use of com.google.idea.blaze.base.sync.projectview.ImportRoots in project intellij by bazelbuild.
the class ImportRootsTest method testAllLabelsIncludedUnderWorkspaceRoot.
// if the workspace root is an included directory, all rules should be imported as sources.
@Test
public void testAllLabelsIncludedUnderWorkspaceRoot() {
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(new DirectoryEntry(new WorkspacePath(""), true)).build();
assertThat(importRoots.importAsSource(Label.create("//:target"))).isTrue();
assertThat(importRoots.importAsSource(Label.create("//foo/bar:target"))).isTrue();
}
Aggregations