Search in sources :

Example 1 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class AddSourceToProjectHelper method getContext.

/**
 * Returns the location context related to a source file to be added to the project.
 */
@Nullable
static LocationContext getContext(Project project, File file) {
    BlazeProjectData syncData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (syncData == null) {
        return null;
    }
    WorkspacePath workspacePath = getWorkspacePath(project, file);
    if (workspacePath == null || isBuildSystemOutputArtifact(project, workspacePath)) {
        return null;
    }
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet == null) {
        return null;
    }
    WorkspacePath parent = workspacePath.getParent();
    if (parent == null) {
        return null;
    }
    WorkspacePath blazePackage = findBlazePackagePath(project, parent);
    return blazePackage != null ? new LocationContext(project, syncData, projectViewSet, file, workspacePath, blazePackage) : null;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Nullable(javax.annotation.Nullable)

Example 2 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class AdditionalLanguagesHelper method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(VirtualFile file, FileEditor fileEditor) {
    String ext = file.getExtension();
    if (ext == null) {
        return null;
    }
    LanguageClass language = LanguageClass.fromExtension(ext);
    if (language == null || notifiedLanguages.contains(language)) {
        return null;
    }
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        return null;
    }
    WorkspaceLanguageSettings settings = projectData.workspaceLanguageSettings;
    if (settings.isLanguageActive(language)) {
        return null;
    }
    if (!LanguageSupport.supportedLanguagesForWorkspaceType(settings.getWorkspaceType()).contains(language)) {
        return null;
    }
    String langName = language.getName();
    String message = String.format("Do you want to enable %s plugin %s support?", Blaze.buildSystemName(project), langName);
    EditorNotificationPanel panel = new EditorNotificationPanel();
    panel.setText(message);
    panel.createActionLabel(String.format("Enable %s support", langName), () -> {
        enableLanguageSupport(project, ImmutableList.of(language));
        suppressNotifications(language);
    });
    panel.createActionLabel("Don't show again", () -> suppressNotifications(language));
    return panel;
}
Also used : EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) Nullable(javax.annotation.Nullable)

Example 3 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class OpenBlazeWorkspaceFileAction method actionPerformedInBlazeProject.

@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return;
    }
    new OpenBlazeWorkspaceFileActionDialog(project, blazeProjectData.workspacePathResolver).show();
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData)

Example 4 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class PrefetchProjectInitializer method prefetchProjectFiles.

private static void prefetchProjectFiles(Project project) {
    if (!Blaze.isBlazeProject(project)) {
        return;
    }
    BlazeProjectData projectData = getBlazeProjectData(project);
    ProjectViewSet projectViewSet = getProjectViewSet(project);
    if (projectViewSet == null) {
        return;
    }
    PrefetchIndexingTask.submitPrefetchingTask(project, PrefetchService.getInstance().prefetchProjectFiles(project, projectViewSet, projectData), "Initial Prefetching");
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData)

Example 5 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BuildTarget target = getBuildTarget(context);
    if (target == null) {
        return false;
    }
    if (!Objects.equals(configuration.getTarget(), target.label)) {
        return false;
    }
    // We don't know any details about how the various factories set up configurations from here.
    // Simply returning true at this point would be overly broad
    // (all configs with a matching target would be identified).
    // A complete equality check, meanwhile, would be too restrictive
    // (things like config name and user flags shouldn't count)
    // - not to mention we lack the equals() implementations needed to perform such a check!
    // So we compromise: if the target, suggested name, and command name match,
    // we consider it close enough. The suggested name is checked because it tends
    // to cover what the handler considers important,
    // and ignores changes the user may have made to the name.
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(configuration.getProject()).getBlazeProjectData();
    if (blazeProjectData == null) {
        return false;
    }
    BlazeCommandRunConfiguration generatedConfiguration = new BlazeCommandRunConfiguration(configuration.getProject(), configuration.getFactory(), configuration.getName());
    setupConfiguration(configuration.getProject(), blazeProjectData, generatedConfiguration, target);
    // ignore filtered test configs, produced by other configuration producers.
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState != null && handlerState.getTestFilterFlag() != null) {
        return false;
    }
    return Objects.equals(configuration.suggestedName(), generatedConfiguration.suggestedName()) && Objects.equals(configuration.getHandler().getCommandName(), generatedConfiguration.getHandler().getCommandName());
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)

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