use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method addProtoLegacyLibrariesFromDirectDeps.
private void addProtoLegacyLibrariesFromDirectDeps(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, Map<LibraryKey, BlazeJarLibrary> result) {
List<TargetKey> version1Targets = Lists.newArrayList();
List<TargetKey> immutableTargets = Lists.newArrayList();
List<TargetKey> mutableTargets = Lists.newArrayList();
for (TargetKey targetKey : workspaceBuilder.directDeps) {
TargetIdeInfo target = targetMap.get(targetKey);
if (target == null) {
continue;
}
ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
if (protoLibraryLegacyInfo == null) {
continue;
}
switch(protoLibraryLegacyInfo.apiFlavor) {
case VERSION_1:
version1Targets.add(targetKey);
break;
case IMMUTABLE:
immutableTargets.add(targetKey);
break;
case MUTABLE:
mutableTargets.add(targetKey);
break;
case BOTH:
mutableTargets.add(targetKey);
immutableTargets.add(targetKey);
break;
default:
// Can't happen
break;
}
}
addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1, version1Targets, result);
addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE, immutableTargets, result);
addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.MUTABLE, mutableTargets, result);
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeJavaMainClassRunConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
PsiClass mainClass = getMainClass(context);
if (mainClass == null) {
return false;
}
// Try setting source element to a main method so ApplicationConfigurationProducer
// can't override our configuration by producing a more specific one.
PsiMethod mainMethod = PsiMethodUtil.findMainMethod(mainClass);
if (mainMethod == null) {
sourceElement.set(mainClass);
} else {
sourceElement.set(mainMethod);
}
TargetIdeInfo target = getTarget(context.getProject(), mainClass);
if (target == null) {
return false;
}
configuration.setTargetInfo(target.toTargetInfo());
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
configuration.setGeneratedName();
return true;
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeJavaMainClassRunConfigurationProducer method getTarget.
@Nullable
private static TargetIdeInfo getTarget(Project project, PsiClass mainClass) {
File mainClassFile = RunUtil.getFileForClass(mainClass);
if (mainClassFile == null) {
return null;
}
Collection<TargetIdeInfo> javaBinaryTargets = findJavaBinaryTargets(project, mainClassFile);
String qualifiedName = mainClass.getQualifiedName();
String className = mainClass.getName();
if (qualifiedName == null || className == null) {
// out of date psi element; just take the first match
return Iterables.getFirst(javaBinaryTargets, null);
}
// first look for a matching main_class
TargetIdeInfo match = javaBinaryTargets.stream().filter(target -> target.javaIdeInfo != null && qualifiedName.equals(target.javaIdeInfo.javaBinaryMainClass)).findFirst().orElse(null);
if (match != null) {
return match;
}
match = javaBinaryTargets.stream().filter(target -> className.equals(target.key.label.targetName().toString())).findFirst().orElse(null);
if (match != null) {
return match;
}
return Iterables.getFirst(javaBinaryTargets, null);
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeJavaMainClassRunConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
if (!Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.RUN)) {
return false;
}
PsiClass mainClass = getMainClass(context);
if (mainClass == null) {
return false;
}
TargetIdeInfo target = getTarget(context.getProject(), mainClass);
if (target == null) {
return false;
}
return Objects.equals(configuration.getTarget(), target.key.label);
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testIdlClassJarIsAddedAsLibrary.
@Test
public void testIdlClassJarIsAddedAsLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//example:lib").setBuildFile(source("example/BUILD")).setKind("android_binary").addSource(source("example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("example").setIdlJar(LibraryArtifact.builder().setInterfaceJar(gen("example/libidl.jar")).addSourceJar(gen("example/libidl.srcjar")).build()).setHasIdlSources(true)));
TargetMap targetMap = targetMapBuilder.build();
BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
List<BlazeJarLibrary> jars = Lists.newArrayList();
List<BlazeJarLibrary> genJars = Lists.newArrayList();
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
for (TargetIdeInfo target : targetMap.targets()) {
if (importRoots.importAsSource(target.key.label)) {
syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
}
}
assertThat(genJars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("libidl.jar");
}
Aggregations