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;
}
Aggregations