Search in sources :

Example 66 with ProjectViewSet

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;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) BuildTargetFinder(com.google.idea.blaze.base.sync.BuildTargetFinder)

Example 67 with ProjectViewSet

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();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Nullable(javax.annotation.Nullable)

Example 68 with ProjectViewSet

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");
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Test(org.junit.Test)

Example 69 with ProjectViewSet

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) Presentation(com.intellij.openapi.actionSystem.Presentation) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeProjectAction(com.google.idea.blaze.base.actions.BlazeProjectAction) Strings(com.google.common.base.Strings) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) Library(com.intellij.openapi.roots.libraries.Library) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ImmutableList(com.google.common.collect.ImmutableList) BlazeSyncManager(com.google.idea.blaze.base.sync.BlazeSyncManager) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Nullable(javax.annotation.Nullable) WorkspacePathUtil(com.google.idea.blaze.base.util.WorkspacePathUtil) Set(java.util.Set) Sets(com.google.common.collect.Sets) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 70 with ProjectViewSet

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)));
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Test(org.junit.Test)

Aggregations

ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)74 File (java.io.File)30 Test (org.junit.Test)29 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)21 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)17 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)17 ImmutableList (com.google.common.collect.ImmutableList)16 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)16 Project (com.intellij.openapi.project.Project)16 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)15 Nullable (javax.annotation.Nullable)15 List (java.util.List)14 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)12 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)11 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)11 Kind (com.google.idea.blaze.base.model.primitives.Kind)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 Set (java.util.Set)11 Lists (com.google.common.collect.Lists)10 Collectors (java.util.stream.Collectors)10