Search in sources :

Example 11 with BlazeProjectData

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) PyFile(com.jetbrains.python.psi.PyFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Nullable(javax.annotation.Nullable)

Example 12 with BlazeProjectData

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;
}
Also used : BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) PythonPluginUtils(com.google.idea.blaze.python.PythonPluginUtils) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ImmutableSet(com.google.common.collect.ImmutableSet) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) PluginUtils(com.google.idea.blaze.base.plugin.PluginUtils) Collection(java.util.Collection) Set(java.util.Set) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) ImmutableList(com.google.common.collect.ImmutableList) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots)

Example 13 with BlazeProjectData

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);
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 14 with BlazeProjectData

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));
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 15 with BlazeProjectData

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Aggregations

BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)82 File (java.io.File)31 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)28 Nullable (javax.annotation.Nullable)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)23 Test (org.junit.Test)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)17 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)15 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)13 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)13 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)13 Project (com.intellij.openapi.project.Project)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)11 ImmutableList (com.google.common.collect.ImmutableList)10 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)10 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 List (java.util.List)8 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)7