use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class BlazePyBinaryConfigurationProducer method getTargetLabel.
@Nullable
private static TargetInfo getTargetLabel(PsiFile psiFile) {
VirtualFile vf = psiFile.getVirtualFile();
if (vf == null) {
return null;
}
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(psiFile.getProject()).getBlazeProjectData();
if (projectData == null) {
return null;
}
File file = new File(vf.getPath());
String fileName = FileUtil.getNameWithoutExtension(file);
return SourceToTargetFinder.findTargetsForSourceFile(psiFile.getProject(), file, Optional.of(RuleType.BINARY)).stream().filter(t -> acceptTarget(fileName, t)).findFirst().orElse(null);
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class AlwaysPresentPythonSyncPlugin method validate.
@Override
public boolean validate(Project project, BlazeContext context, BlazeProjectData blazeProjectData) {
ImportRoots importRoots = ImportRoots.forProjectSafe(project);
if (importRoots == null) {
return true;
}
boolean hasPythonTarget = blazeProjectData.targetMap.targets().stream().filter(target -> importRoots.importAsSource(target.key.label)).anyMatch(target -> target.kindIsOneOf(Kind.allKindsForLanguage(LanguageClass.PYTHON)));
if (!hasPythonTarget) {
return true;
}
String pluginId = PythonPluginUtils.getPythonPluginId();
if (!PluginUtils.isPluginEnabled(pluginId)) {
IssueOutput.warn("Your project appears to contain Python targets. To enable Python support, " + "install/enable the JetBrains python plugin, then restart the IDE").navigatable(PluginUtils.installOrEnablePluginNavigable(pluginId)).submit(context);
return false;
}
return true;
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class BlazePyResolverUtils method resolvePath.
/**
* Looks for a PsiDirectory or PyFile at the given workspace-relative path (appending '.py' to the
* path when looking for py files).
*/
@Nullable
public static PsiElement resolvePath(PyQualifiedNameResolveContext context, String relativePath) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(context.getProject()).getBlazeProjectData();
if (projectData == null) {
return null;
}
WorkspacePathResolver pathResolver = projectData.workspacePathResolver;
File file = pathResolver.resolveToFile(relativePath);
return resolveFile(context.getPsiManager(), file);
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class BlazePyResolverUtils method resolveGenfilesPath.
/**
* Looks for a PsiDirectory or PyFile at the given 'blaze-genfiles'-relative path (appending '.py'
* to the path when looking for py files).
*/
@Nullable
public static PsiElement resolveGenfilesPath(PyQualifiedNameResolveContext context, String relativePath) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(context.getProject()).getBlazeProjectData();
if (projectData == null) {
return null;
}
File genfiles = projectData.blazeInfo.getGenfilesDirectory();
return resolveFile(context.getPsiManager(), new File(genfiles, relativePath));
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class KotlinSyncTest method testKotlinClassesPresentInClassPath.
@Test
public void testKotlinClassesPresentInClassPath() {
setProjectView("directories:", " src/main/kotlin/com/google", "targets:", " //src/main/kotlin/com/google:lib", "additional_languages:", " kotlin");
workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName1.kt"), "package com.google;", "public class ClassWithUniqueName1 {}");
workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName2.kt"), "package com.google;", "public class ClassWithUniqueName2 {}");
workspace.createDirectory(new WorkspacePath("external/com_github_jetbrains_kotlin"));
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/kotlin/com/google/BUILD")).setLabel("//src/main/kotlin/com/google:lib").setKind("kt_jvm_library").addSource(sourceRoot("src/main/kotlin/com/google/ClassWithUniqueName1.scala")).addSource(sourceRoot("src/main/kotlin/com/google/ClassWithUniqueName2.scala")).setJavaInfo(JavaIdeInfo.builder())).build();
setTargetMap(targetMap);
BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
runBlazeSync(syncParams);
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();
assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
assertThat(blazeProjectData.workspaceLanguageSettings).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.JAVA, LanguageClass.KOTLIN)));
BlazeJavaSyncData javaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
assertThat(javaSyncData).isNotNull();
List<BlazeContentEntry> contentEntries = javaSyncData.importResult.contentEntries;
assertThat(contentEntries).hasSize(1);
BlazeContentEntry contentEntry = contentEntries.get(0);
assertThat(contentEntry.contentRoot.getPath()).isEqualTo(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/com/google")).getPath());
assertThat(contentEntry.sources).hasSize(1);
BlazeSourceDirectory sourceDir = contentEntry.sources.get(0);
assertThat(sourceDir.getPackagePrefix()).isEqualTo("com.google");
assertThat(sourceDir.getDirectory().getPath()).isEqualTo(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/com/google")).getPath());
}
Aggregations