use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImplTest method testTargetIdeInfoIsSerializable.
@Test
public void testTargetIdeInfoIsSerializable() {
IntellijIdeInfo.TargetIdeInfo ideProto = IntellijIdeInfo.TargetIdeInfo.newBuilder().setLabel("//test:test").setKindString("android_binary").addDependencies("//test:dep").addTags("tag").setJavaIdeInfo(IntellijIdeInfo.JavaIdeInfo.newBuilder().addJars(IntellijIdeInfo.LibraryArtifact.newBuilder().setJar(artifactLocation("jar.jar")).build()).addGeneratedJars(IntellijIdeInfo.LibraryArtifact.newBuilder().setJar(artifactLocation("jar.jar")).build()).addSources(artifactLocation("source.java"))).setAndroidIdeInfo(IntellijIdeInfo.AndroidIdeInfo.newBuilder().addResources(artifactLocation("res")).setApk(artifactLocation("apk")).addDependencyApk(artifactLocation("apk")).setJavaPackage("package")).build();
TargetIdeInfo target = IdeInfoFromProtobuf.makeTargetIdeInfo(ideProto);
TestUtils.assertIsSerializable(target);
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class IdeInfoFromProtobuf method makeTargetIdeInfo.
@Nullable
public static TargetIdeInfo makeTargetIdeInfo(IntellijIdeInfo.TargetIdeInfo message) {
Kind kind = getKind(message);
if (kind == null) {
return null;
}
TargetKey key = getKey(message);
ArtifactLocation buildFile = getBuildFile(message);
final Collection<Dependency> dependencies;
if (message.getDepsCount() > 0) {
dependencies = message.getDepsList().stream().map(IdeInfoFromProtobuf::makeDependency).collect(toList());
} else {
dependencies = Lists.newArrayListWithCapacity(message.getDependenciesCount() + message.getRuntimeDepsCount());
dependencies.addAll(makeDependencyListFromLabelList(message.getDependenciesList(), DependencyType.COMPILE_TIME));
dependencies.addAll(makeDependencyListFromLabelList(message.getRuntimeDepsList(), DependencyType.RUNTIME));
}
Collection<String> tags = ImmutableList.copyOf(message.getTagsList());
Collection<ArtifactLocation> sources = Lists.newArrayList();
CIdeInfo cIdeInfo = null;
if (message.hasCIdeInfo()) {
cIdeInfo = makeCIdeInfo(message.getCIdeInfo());
sources.addAll(cIdeInfo.sources);
sources.addAll(cIdeInfo.headers);
sources.addAll(cIdeInfo.textualHeaders);
}
CToolchainIdeInfo cToolchainIdeInfo = null;
if (message.hasCToolchainIdeInfo()) {
cToolchainIdeInfo = makeCToolchainIdeInfo(message.getCToolchainIdeInfo());
}
JavaIdeInfo javaIdeInfo = null;
if (message.hasJavaIdeInfo()) {
javaIdeInfo = makeJavaIdeInfo(message.getJavaIdeInfo());
Collection<ArtifactLocation> javaSources = makeArtifactLocationList(message.getJavaIdeInfo().getSourcesList());
sources.addAll(javaSources);
}
AndroidIdeInfo androidIdeInfo = null;
if (message.hasAndroidIdeInfo()) {
androidIdeInfo = makeAndroidIdeInfo(message.getAndroidIdeInfo());
}
AndroidSdkIdeInfo androidSdkIdeInfo = null;
if (message.hasAndroidSdkIdeInfo()) {
androidSdkIdeInfo = makeAndroidSdkIdeInfo(message.getAndroidSdkIdeInfo());
}
AndroidAarIdeInfo androidAarIdeInfo = null;
if (message.hasAndroidAarIdeInfo()) {
androidAarIdeInfo = makeAndroidAarIdeInfo(message.getAndroidAarIdeInfo());
}
PyIdeInfo pyIdeInfo = null;
if (message.hasPyIdeInfo()) {
pyIdeInfo = makePyIdeInfo(message.getPyIdeInfo());
sources.addAll(pyIdeInfo.sources);
}
GoIdeInfo goIdeInfo = null;
if (message.hasGoIdeInfo()) {
goIdeInfo = makeGoIdeInfo(message.getGoIdeInfo());
sources.addAll(goIdeInfo.sources);
}
JsIdeInfo jsIdeInfo = null;
if (message.hasJsIdeInfo()) {
jsIdeInfo = makeJsIdeInfo(message.getJsIdeInfo());
sources.addAll(jsIdeInfo.sources);
}
TsIdeInfo tsIdeInfo = null;
if (message.hasTsIdeInfo()) {
tsIdeInfo = makeTsIdeInfo(message.getTsIdeInfo());
sources.addAll(tsIdeInfo.sources);
}
DartIdeInfo dartIdeInfo = null;
if (message.hasDartIdeInfo()) {
dartIdeInfo = makeDartIdeInfo(message.getDartIdeInfo());
sources.addAll(dartIdeInfo.sources);
}
TestIdeInfo testIdeInfo = null;
if (message.hasTestInfo()) {
testIdeInfo = makeTestIdeInfo(message.getTestInfo());
}
ProtoLibraryLegacyInfo protoLibraryLegacyInfo = null;
if (message.hasProtoLibraryLegacyJavaIdeInfo()) {
protoLibraryLegacyInfo = makeProtoLibraryLegacyInfo(message.getProtoLibraryLegacyJavaIdeInfo());
}
JavaToolchainIdeInfo javaToolchainIdeInfo = null;
if (message.hasJavaToolchainIdeInfo()) {
javaToolchainIdeInfo = makeJavaToolchainIdeInfo(message.getJavaToolchainIdeInfo());
}
return new TargetIdeInfo(key, kind, buildFile, dependencies, tags, sources, cIdeInfo, cToolchainIdeInfo, javaIdeInfo, androidIdeInfo, androidSdkIdeInfo, androidAarIdeInfo, pyIdeInfo, goIdeInfo, jsIdeInfo, tsIdeInfo, dartIdeInfo, testIdeInfo, protoLibraryLegacyInfo, javaToolchainIdeInfo);
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo 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.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeGoRootsProvider method createGoPathSourceRoot.
/**
* Creates the .gopath root under the project data directory. Then {@link #createSymLinks} for
* each go target discovered in the target map into the root directory.
*/
public static synchronized void createGoPathSourceRoot(Project project, BlazeProjectData projectData) {
File goRoot = getGoRoot(project);
if (goRoot == null) {
return;
}
FileOperationProvider provider = FileOperationProvider.getInstance();
if (provider.exists(goRoot)) {
try {
provider.deleteRecursively(goRoot);
} catch (IOException e) {
logger.error(e);
return;
}
}
if (!provider.mkdirs(goRoot)) {
logger.error("Failed to create " + goRoot);
return;
}
ArtifactLocationDecoder decoder = projectData.artifactLocationDecoder;
for (TargetIdeInfo target : projectData.targetMap.targets()) {
if (target.goIdeInfo == null || target.goIdeInfo.importPath == null) {
continue;
}
String importPath = target.goIdeInfo.importPath;
createSymLinks(goRoot, importPath, getGoSources(target, decoder, projectData.blazeInfo));
}
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeGoTestLocator method findTestPackage.
/**
* @param path for "//foo/bar:baz" would be "foo/bar/baz".
*/
@SuppressWarnings("rawtypes")
private static List<Location> findTestPackage(Project project, String path) {
TargetIdeInfo target = getGoTestTarget(project, path);
if (target == null) {
return ImmutableList.of();
}
// Exactly one source file, we'll go to the file.
if (target.sources.size() == 1) {
List<VirtualFile> goFiles = getGoFiles(project, target);
if (!goFiles.isEmpty()) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(goFiles.get(0));
if (psiFile != null) {
return ImmutableList.of(new PsiLocation<>(psiFile));
}
}
}
// More than one source file or we failed to get one source file, we'll point to the rule.
PsiElement rule = BuildReferenceManager.getInstance(project).resolveLabel(target.key.label);
if (!(rule instanceof FuncallExpression)) {
return ImmutableList.of();
}
Kind kind = ((FuncallExpression) rule).getRuleKind();
if (kind != null && kind.languageClass.equals(LanguageClass.GO) && kind.ruleType.equals(RuleType.TEST)) {
return ImmutableList.of(new PsiLocation<>(rule));
}
return ImmutableList.of();
}
Aggregations