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());
}
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);
}
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);
}
}
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);
}
});
}
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);
}
}
}
Aggregations