Search in sources :

Example 1 with NotificationData

use of com.intellij.openapi.externalSystem.service.notification.NotificationData in project android by JetBrains.

the class ExternalNdkBuildIssuesReporterTest method testReportWithError.

public void testReportWithError() throws Exception {
    if (SystemInfo.isWindows) {
        // Do not run tests on Windows (see http://b.android.com/222904)
        return;
    }
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    String nativeToolOutput = "Failed to compile something";
    when(mySyncIssue.getData()).thenReturn(nativeToolOutput);
    VirtualFile buildFile = getGradleBuildFile(appModule);
    assertNotNull(buildFile);
    int line = 6;
    int column = 8;
    SourcePosition sourcePosition = new SourcePosition(line, column, 0);
    SourceFilePosition sourceFilePosition = new SourceFilePosition(virtualToIoFile(buildFile), sourcePosition);
    Message compilerMessage = new Message(ERROR, nativeToolOutput, sourceFilePosition);
    List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
    when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
    myReporter.report(mySyncIssue, appModule, buildFile);
    assertNull(mySyncMessagesStub.getFirstReportedMessage());
    NotificationData notification = mySyncMessagesStub.getNotification();
    assertNotNull(notification);
    assertTrue(myErrorHandler.isInvoked());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) SyncMessageSubject.syncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) SourcePosition(com.android.ide.common.blame.SourcePosition) Module(com.intellij.openapi.module.Module) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 2 with NotificationData

use of com.intellij.openapi.externalSystem.service.notification.NotificationData in project android by JetBrains.

the class SyncMessages method report.

public void report(@NotNull SyncMessage message) {
    String title = message.getGroup();
    String text = join(message.getText(), "\n");
    NotificationCategory category = message.getType().convertToCategory();
    PositionInFile position = message.getPosition();
    NotificationData notification = createNotification(title, text, category, position);
    Navigatable navigatable = message.getNavigatable();
    notification.setNavigatable(navigatable);
    List<NotificationHyperlink> quickFixes = message.getQuickFixes();
    if (!quickFixes.isEmpty()) {
        updateNotification(notification, text, quickFixes);
    }
    report(notification);
}
Also used : PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) Navigatable(com.intellij.pom.Navigatable) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 3 with NotificationData

use of com.intellij.openapi.externalSystem.service.notification.NotificationData in project intellij-community by JetBrains.

the class GradleExecuteTaskAction method actionPerformed.

@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    ExecuteGradleTaskHistoryService historyService = ExecuteGradleTaskHistoryService.getInstance(project);
    GradleRunTaskDialog dialog = new GradleRunTaskDialog(project, historyService.getHistory());
    String lastWorkingDirectory = historyService.getWorkDirectory();
    if (lastWorkingDirectory.length() == 0) {
        lastWorkingDirectory = obtainAppropriateWorkingDirectory(e);
    }
    dialog.setWorkDirectory(lastWorkingDirectory);
    if (StringUtil.isEmptyOrSpaces(historyService.getCanceledCommand())) {
        if (historyService.getHistory().size() > 0) {
            dialog.setCommandLine(historyService.getHistory().get(0));
        }
    } else {
        dialog.setCommandLine(historyService.getCanceledCommand());
    }
    if (!dialog.showAndGet()) {
        historyService.setCanceledCommand(dialog.getCommandLine());
        return;
    }
    historyService.setCanceledCommand(null);
    String fullCommandLine = dialog.getCommandLine();
    fullCommandLine = fullCommandLine.trim();
    String workDirectory = dialog.getWorkDirectory();
    historyService.addCommand(fullCommandLine, workDirectory);
    final ExternalTaskExecutionInfo taskExecutionInfo;
    try {
        taskExecutionInfo = buildTaskInfo(workDirectory, fullCommandLine);
    } catch (CommandLineArgumentException ex) {
        final NotificationData notificationData = new NotificationData("<b>Command-line arguments cannot be parsed</b>", "<i>" + fullCommandLine + "</i> \n" + ex.getMessage(), NotificationCategory.WARNING, NotificationSource.TASK_EXECUTION);
        notificationData.setBalloonNotification(true);
        ExternalSystemNotificationManager.getInstance(project).showNotification(GradleConstants.SYSTEM_ID, notificationData);
        return;
    }
    RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
    ExternalSystemUtil.runTask(taskExecutionInfo.getSettings(), taskExecutionInfo.getExecutorId(), project, GradleConstants.SYSTEM_ID);
    RunnerAndConfigurationSettings configuration = ExternalSystemUtil.createExternalSystemRunnerAndConfigurationSettings(taskExecutionInfo.getSettings(), project, GradleConstants.SYSTEM_ID);
    if (configuration == null)
        return;
    final RunnerAndConfigurationSettings existingConfiguration = runManager.findConfigurationByName(configuration.getName());
    if (existingConfiguration == null) {
        runManager.setTemporaryConfiguration(configuration);
    } else {
        runManager.setSelectedConfiguration(existingConfiguration);
    }
}
Also used : Project(com.intellij.openapi.project.Project) RunManagerEx(com.intellij.execution.RunManagerEx) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) GradleRunTaskDialog(org.jetbrains.plugins.gradle.service.task.GradleRunTaskDialog) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) ExecuteGradleTaskHistoryService(org.jetbrains.plugins.gradle.service.task.ExecuteGradleTaskHistoryService) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 4 with NotificationData

use of com.intellij.openapi.externalSystem.service.notification.NotificationData in project intellij-community by JetBrains.

the class ImportMavenRepositoriesTask method performTask.

private void performTask() {
    if (myProject.isDisposed())
        return;
    if (ApplicationManager.getApplication().isUnitTestMode())
        return;
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final List<PsiFile> psiFileList = ContainerUtil.newArrayList();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
            continue;
        final String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
        if (modulePath == null)
            continue;
        String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
        if (StringUtil.isEmpty(buildScript))
            continue;
        VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
        if (virtualFile == null)
            continue;
        final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
        if (psiFile == null)
            continue;
        psiFileList.add(psiFile);
    }
    final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
    final Set<MavenRemoteRepository> mavenRemoteRepositories = new ReadAction<Set<MavenRemoteRepository>>() {

        @Override
        protected void run(@NotNull Result<Set<MavenRemoteRepository>> result) throws Throwable {
            Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
            for (PsiFile psiFile : psiFiles) {
                List<GrClosableBlock> repositoriesBlocks = ContainerUtil.newArrayList();
                repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
                for (GrClosableBlock closableBlock : findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
                    repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
                }
                for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
                    myRemoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
                }
            }
            result.setResult(myRemoteRepositories);
        }
    }.execute().getResultObject();
    if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty())
        return;
    // register imported maven repository URLs but do not force to download the index
    // the index can be downloaded and/or updated later using Maven Configuration UI (Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories)
    MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
    MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(indexes -> {
        if (myProject.isDisposed())
            return;
        final List<String> repositoriesWithEmptyIndex = ContainerUtil.mapNotNull(indexes, index -> index.getUpdateTimestamp() == -1 && MavenRepositoriesHolder.getInstance(myProject).contains(index.getRepositoryPathOrUrl()) ? index.getRepositoryPathOrUrl() : null);
        if (!repositoriesWithEmptyIndex.isEmpty()) {
            final NotificationData notificationData = new NotificationData(GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.title"), "\n<br>" + GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.text", StringUtil.join(repositoriesWithEmptyIndex, "<br>")), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
            notificationData.setBalloonNotification(true);
            notificationData.setBalloonGroup(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP);
            notificationData.setListener("#open", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenRepositoriesConfigurable.class);
                }
            });
            notificationData.setListener("#disable", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    final int result = Messages.showYesNoDialog(myProject, "Notification will be disabled for all projects.\n\n" + "Settings | Appearance & Behavior | Notifications | " + UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP + "\ncan be used to configure the notification.", "Unindexed Maven Repositories Gradle Detection", "Disable Notification", CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
                    if (result == Messages.YES) {
                        NotificationsConfigurationImpl.getInstanceImpl().changeSettings(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP, NotificationDisplayType.NONE, false, false);
                        notification.hideBalloon();
                    }
                }
            });
            ExternalSystemNotificationManager.getInstance(myProject).showNotification(GradleConstants.SYSTEM_ID, notificationData);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) ModuleManager(com.intellij.openapi.module.ModuleManager) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Result(com.intellij.openapi.application.Result) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ReadAction(com.intellij.openapi.application.ReadAction) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenRepositoriesConfigurable(org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable) Module(com.intellij.openapi.module.Module) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) NotificationListener(com.intellij.notification.NotificationListener)

Example 5 with NotificationData

use of com.intellij.openapi.externalSystem.service.notification.NotificationData in project intellij-community by JetBrains.

the class BaseGradleProjectResolverExtension method populateModuleDependencies.

@Override
public void populateModuleDependencies(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule, @NotNull final DataNode<ProjectData> ideProject) {
    ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
    if (externalProject != null) {
        final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap = ideProject.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS);
        final Map<String, String> artifactsMap = ideProject.getUserData(CONFIGURATION_ARTIFACTS);
        assert artifactsMap != null;
        if (resolverCtx.isResolveModulePerSourceSet()) {
            assert sourceSetMap != null;
            processSourceSets(resolverCtx, gradleModule, externalProject, ideModule, new SourceSetsProcessor() {

                @Override
                public void process(@NotNull DataNode<? extends ModuleData> dataNode, @NotNull ExternalSourceSet sourceSet) {
                    buildDependencies(resolverCtx, sourceSetMap, artifactsMap, dataNode, sourceSet.getDependencies(), ideProject);
                }
            });
            return;
        }
    }
    final List<? extends IdeaDependency> dependencies = gradleModule.getDependencies().getAll();
    if (dependencies == null)
        return;
    List<String> orphanModules = ContainerUtil.newArrayList();
    for (IdeaDependency dependency : dependencies) {
        if (dependency == null) {
            continue;
        }
        DependencyScope scope = parseScope(dependency.getScope());
        if (dependency instanceof IdeaModuleDependency) {
            ModuleDependencyData d = buildDependency(resolverCtx, ideModule, (IdeaModuleDependency) dependency, ideProject);
            d.setExported(dependency.getExported());
            if (scope != null) {
                d.setScope(scope);
            }
            ideModule.createChild(ProjectKeys.MODULE_DEPENDENCY, d);
            ModuleData targetModule = d.getTarget();
            if (targetModule.getId().isEmpty() && targetModule.getLinkedExternalProjectPath().isEmpty()) {
                orphanModules.add(targetModule.getExternalName());
            }
        } else if (dependency instanceof IdeaSingleEntryLibraryDependency) {
            LibraryDependencyData d = buildDependency(gradleModule, ideModule, (IdeaSingleEntryLibraryDependency) dependency, ideProject);
            d.setExported(dependency.getExported());
            if (scope != null) {
                d.setScope(scope);
            }
            ideModule.createChild(ProjectKeys.LIBRARY_DEPENDENCY, d);
        }
    }
    if (!orphanModules.isEmpty()) {
        ExternalSystemTaskId taskId = resolverCtx.getExternalSystemTaskId();
        Project project = taskId.findProject();
        if (project != null) {
            String msg = "Can't find the following module" + (orphanModules.size() > 1 ? "s" : "") + ": " + StringUtil.join(orphanModules, ", ") + "\nIt can be caused by composite build configuration inside your *.gradle scripts with Gradle version older than 3.3." + "\nTry Gradle 3.3 or better or enable 'Create separate module per source set' option";
            NotificationData notification = new NotificationData("Gradle project structure problems", msg, NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
            ExternalSystemNotificationManager.getInstance(project).showNotification(taskId.getProjectSystemId(), notification);
        }
    }
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) DependencyScope(com.intellij.openapi.roots.DependencyScope) GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) Project(com.intellij.openapi.project.Project) Pair(com.intellij.openapi.util.Pair) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Aggregations

NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)9 Project (com.intellij.openapi.project.Project)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NotificationCategory (com.intellij.openapi.externalSystem.service.notification.NotificationCategory)3 Message (com.android.ide.common.blame.Message)2 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)2 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)2 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 ExternalTaskExecutionInfo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo)2 Module (com.intellij.openapi.module.Module)2 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)2 NotNull (org.jetbrains.annotations.NotNull)2 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)1 SourcePosition (com.android.ide.common.blame.SourcePosition)1 SyncErrorHandler (com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler)1 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)1 SyncMessageSubject.syncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage)1 RunManager (com.intellij.execution.RunManager)1