use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class PartialSyncAction method getTargets.
private static List<TargetExpression> getTargets(Project project, @Nullable VirtualFile virtualFile) {
if (virtualFile == null) {
return ImmutableList.of();
}
List<TargetExpression> targets = Lists.newArrayList();
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
SourceToTargetMap.getInstance(project);
if (!virtualFile.isDirectory()) {
targets.addAll(SourceToTargetMap.getInstance(project).getTargetsToBuildForSourceFile(new File(virtualFile.getPath())));
}
if (targets.isEmpty()) {
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet != null) {
BuildSystem buildSystem = Blaze.getBuildSystem(project);
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, buildSystem).add(projectViewSet).build();
BuildTargetFinder buildTargetFinder = new BuildTargetFinder(project, workspaceRoot, importRoots);
TargetExpression targetExpression = buildTargetFinder.findTargetForFile(new File(virtualFile.getPath()));
if (targetExpression != null) {
targets.add(targetExpression);
}
}
}
return targets;
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class ImportRoots method forProjectSafe.
/**
* Returns the ImportRoots for the project, or null if it's not a blaze project.
*/
@Nullable
public static ImportRoots forProjectSafe(Project project) {
WorkspaceRoot root = WorkspaceRoot.fromProjectSafe(project);
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (root == null || projectViewSet == null) {
return null;
}
return ImportRoots.builder(root, Blaze.getBuildSystem(project)).add(projectViewSet).build();
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeGoSyncPluginTest method testGoWorkspaceTypeError.
@Test
public void testGoWorkspaceTypeError() {
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(ProjectView.builder().add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.GO)).build()).build();
WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
LanguageSupport.validateLanguageSettings(context, workspaceLanguageSettings);
errorCollector.assertIssueContaining("Workspace type 'go' is not supported by this plugin");
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class AddLibraryTargetDirectoryToProjectViewAction method getDirectoryToAddForLibrary.
@Nullable
static WorkspacePath getDirectoryToAddForLibrary(Project project, Library library) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return null;
}
BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
if (blazeLibrary == null) {
return null;
}
TargetKey originatingTarget = findOriginatingTargetForLibrary(blazeProjectData, blazeLibrary);
if (originatingTarget == null) {
return null;
}
TargetIdeInfo target = blazeProjectData.targetMap.get(originatingTarget);
if (target == null) {
return null;
}
// It makes no sense to add directories for java_imports and the like
if (!target.kind.isOneOf(Kind.JAVA_LIBRARY, Kind.ANDROID_LIBRARY, Kind.PROTO_LIBRARY)) {
return null;
}
if (target.buildFile == null) {
return null;
}
File buildFile = new File(target.buildFile.getRelativePath());
WorkspacePath workspacePath = new WorkspacePath(Strings.nullToEmpty(buildFile.getParent()));
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet == null) {
return null;
}
boolean exists = WorkspacePathUtil.isUnderAnyWorkspacePath(projectViewSet.listItems(DirectorySection.KEY).stream().filter(entry -> entry.included).map(entry -> entry.directory).collect(toList()), workspacePath);
if (exists) {
return null;
}
return workspacePath;
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeDartSyncPluginTest method testDartLanguageAvailable.
@Test
public void testDartLanguageAvailable() {
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(ProjectView.builder().add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.JAVA)).add(ListSection.builder(AdditionalLanguagesSection.KEY).add(LanguageClass.DART)).build()).build();
WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
errorCollector.assertNoIssues();
assertThat(workspaceLanguageSettings).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.DART, LanguageClass.GENERIC, LanguageClass.JAVA)));
}
Aggregations