use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazeRenderErrorContributorTest method createTargetMapWithMissingClassDependency.
private void createTargetMapWithMissingClassDependency() {
Label parentTarget = Label.create("//com/google/example:app");
Label independentLibraryTarget = Label.create("//com/google/example/independent:library");
Label independentLibrary2Target = Label.create("//com/google/example/independent:library2");
Label dependentLibraryTarget = Label.create("//com/google/example/dependent:library");
Label resourcesTarget = Label.create("//com/google/example:resources");
ArtifactLocation manifest = artifact("com/google/example/AndroidManifest.xml", true);
ArtifactLocation resources = artifact("com/google/example/res", true);
ArtifactLocation buildFile = artifact("com/google/example/BUILD", true);
AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
registry.put(module, AndroidResourceModule.builder(TargetKey.forPlainTarget(resourcesTarget)).addResource(resources).build());
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(parentTarget).setBuildFile(buildFile).addDependency(independentLibraryTarget).addDependency(resourcesTarget)).addTarget(TargetIdeInfo.builder().setLabel(independentLibraryTarget).setBuildFile(buildFile).setJavaInfo(JavaIdeInfo.builder()).addDependency(independentLibrary2Target)).addTarget(TargetIdeInfo.builder().setLabel(independentLibrary2Target).setBuildFile(buildFile).setJavaInfo(JavaIdeInfo.builder())).addTarget(TargetIdeInfo.builder().setLabel(resourcesTarget).setBuildFile(buildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(manifest).addResource(resources)).addDependency(dependentLibraryTarget)).addTarget(TargetIdeInfo.builder().setLabel(dependentLibraryTarget).setBuildFile(buildFile).setJavaInfo(JavaIdeInfo.builder())).build();
projectDataManager.setTargetMap(targetMap);
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazeAndroidProjectStructureSyncer method getRunConfigurationTargets.
// Collect potential android run configuration targets
private static List<TargetIdeInfo> getRunConfigurationTargets(Project project, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Set<TargetKey> androidResourceModules) {
List<TargetIdeInfo> result = Lists.newArrayList();
Set<Label> runConfigurationModuleTargets = Sets.newHashSet();
// Doing this now will cut down on root changes later
for (TargetExpression targetExpression : projectViewSet.listItems(TargetSection.KEY)) {
if (!(targetExpression instanceof Label)) {
continue;
}
Label label = (Label) targetExpression;
runConfigurationModuleTargets.add(label);
}
// Get any pre-existing targets
for (RunConfiguration runConfiguration : RunManager.getInstance(project).getAllConfigurationsList()) {
BlazeAndroidRunConfigurationHandler handler = BlazeAndroidRunConfigurationHandler.getHandlerFrom(runConfiguration);
if (handler == null) {
continue;
}
runConfigurationModuleTargets.add(handler.getLabel());
}
for (Label label : runConfigurationModuleTargets) {
TargetKey targetKey = TargetKey.forPlainTarget(label);
// If it's a resource module, it will already have been created
if (androidResourceModules.contains(targetKey)) {
continue;
}
// Ensure the label is a supported android rule that exists
TargetIdeInfo target = blazeProjectData.targetMap.get(targetKey);
if (target == null) {
continue;
}
if (!target.kindIsOneOf(Kind.ANDROID_BINARY, Kind.ANDROID_TEST)) {
continue;
}
result.add(target);
}
return result;
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BuildFileUtils method findBuildTarget.
@Nullable
static PsiElement findBuildTarget(Project project, BlazePackage parentPackage, File file) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return null;
}
File parentFile = parentPackage.buildFile.getFile().getParentFile();
WorkspacePath packagePath = parentFile != null ? blazeProjectData.workspacePathResolver.getWorkspacePath(parentFile) : null;
if (packagePath == null) {
return null;
}
Label label = SourceToTargetMap.getInstance(project).getTargetsToBuildForSourceFile(file).stream().filter(l -> l.blazePackage().equals(packagePath)).findFirst().orElse(null);
if (label == null) {
return null;
}
return BuildReferenceManager.getInstance(project).resolveLabel(label);
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class CopyBlazeTargetPathAction method updateForBlazeProject.
@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
Label label = findTarget(project, e);
ActionPresentationHelper.of(e).hideIf(label == null).commit();
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazeGoTestLocator method getGoTestTarget.
@Nullable
private static TargetIdeInfo getGoTestTarget(Project project, String path) {
WorkspacePath targetPackage = WorkspacePath.createIfValid(PathUtil.getParentPath(path));
if (targetPackage == null) {
return null;
}
TargetName targetName = TargetName.createIfValid(PathUtil.getFileName(path));
if (targetName == null) {
return null;
}
Label label = Label.create(targetPackage, targetName);
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
return null;
}
TargetIdeInfo target = projectData.targetMap.get(TargetKey.forPlainTarget(label));
if (target != null && target.kind.languageClass.equals(LanguageClass.GO) && target.kind.ruleType.equals(RuleType.TEST)) {
return target;
}
return null;
}
Aggregations