Search in sources :

Example 21 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary 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)

Aggregations

BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)21 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)9 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)9 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)7 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)7 ImmutableList (com.google.common.collect.ImmutableList)6 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)6 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Nullable (javax.annotation.Nullable)6 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5 Kind (com.google.idea.blaze.base.model.primitives.Kind)5 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)5 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)5 Test (org.junit.Test)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)4 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)4