use of com.intellij.util.Consumer in project android by JetBrains.
the class AndroidGradleTestCase method invokeGradle.
@NotNull
private static GradleInvocationResult invokeGradle(@NotNull Project project, @NotNull Consumer<GradleBuildInvoker> gradleInvocationTask) throws InterruptedException {
Ref<GradleInvocationResult> resultRef = new Ref<>();
CountDownLatch latch = new CountDownLatch(1);
GradleBuildInvoker gradleBuildInvoker = GradleBuildInvoker.getInstance(project);
GradleBuildInvoker.AfterGradleInvocationTask task = result -> {
resultRef.set(result);
latch.countDown();
};
gradleBuildInvoker.add(task);
try {
gradleInvocationTask.consume(gradleBuildInvoker);
} finally {
gradleBuildInvoker.remove(task);
}
latch.await();
GradleInvocationResult result = resultRef.get();
assert result != null;
return result;
}
use of com.intellij.util.Consumer in project android by JetBrains.
the class ErrorReporter method submit.
@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String description, @Nullable Component parentComponent, @NotNull Consumer<SubmittedReportInfo> callback) {
IdeaLoggingEvent event = events[0];
ErrorBean bean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);
final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
bean.setDescription(description);
bean.setMessage(event.getMessage());
Throwable t = event.getThrowable();
if (t != null) {
final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
if (pluginId != null) {
final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
if (ideaPluginDescriptor != null && (!ideaPluginDescriptor.isBundled() || ideaPluginDescriptor.allowBundledUpdate())) {
bean.setPluginName(ideaPluginDescriptor.getName());
bean.setPluginVersion(ideaPluginDescriptor.getVersion());
}
}
}
Object data = event.getData();
// Early escape (and no UI impact) if these are analytics events being pushed from the platform
if (handleAnalyticsReports(t, data)) {
return true;
}
if (data instanceof AbstractMessage) {
bean.setAttachments(((AbstractMessage) data).getIncludedAttachments());
}
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
Consumer<String> successCallback = token -> {
final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
callback.consume(reportInfo);
ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null).setImportant(false).notify(project);
};
Consumer<Exception> errorCallback = e -> {
String message = AndroidBundle.message("error.report.at.b.android", e.getMessage());
ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER).setImportant(false).notify(project);
};
Task.Backgroundable feedbackTask;
if (data instanceof ErrorReportCustomizer) {
feedbackTask = ((ErrorReportCustomizer) data).makeReportingTask(project, FEEDBACK_TASK_TITLE, true, bean, successCallback, errorCallback);
} else {
List<Pair<String, String>> kv = IdeaITNProxy.getKeyValuePairs(null, null, bean, IdeaLogger.getOurCompilationTimestamp(), ApplicationManager.getApplication(), (ApplicationInfoEx) ApplicationInfo.getInstance(), ApplicationNamesInfo.getInstance(), UpdateSettings.getInstance());
feedbackTask = new SubmitCrashReportTask(project, FEEDBACK_TASK_TITLE, true, t, pair2map(kv), successCallback, errorCallback);
}
if (project == null) {
feedbackTask.run(new EmptyProgressIndicator());
} else {
ProgressManager.getInstance().run(feedbackTask);
}
return true;
}
use of com.intellij.util.Consumer in project intellij-plugins by JetBrains.
the class ShowUiRouterStatesNewDiagramAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
UsageTrigger.trigger(USAGE_KEY);
final Project project = e.getProject();
if (project == null)
return;
final AngularUiRouterDiagramProvider diagramProvider = (AngularUiRouterDiagramProvider) DiagramProvider.findByID(AngularUiRouterDiagramProvider.ANGULAR_UI_ROUTER);
if (diagramProvider == null)
return;
List<Pair<String, AngularUiRouterGraphBuilder>> graphBuilders = new ArrayList<>();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ApplicationManager.getApplication().runReadAction(() -> {
final AngularUiRouterDiagramBuilder builder = new AngularUiRouterDiagramBuilder(project);
builder.build();
final Map<VirtualFile, RootTemplate> rootTemplates = builder.getRootTemplates();
for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getDefiningFiles2States().entrySet()) {
final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), null, entry.getKey());
graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
}
for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getRootTemplates2States().entrySet()) {
final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), rootTemplates.get(entry.getKey()), entry.getKey());
graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
}
});
}, "Building " + diagramProvider.getPresentableName() + " diagram", false, project);
final AngularUiRouterProviderContext routerProviderContext = AngularUiRouterProviderContext.getInstance(project);
routerProviderContext.reset();
final Consumer<AngularUiRouterGraphBuilder> consumer = graphBuilder -> {
final AngularUiRouterGraphBuilder.GraphNodesBuilder nodesBuilder = graphBuilder.createDataModel(diagramProvider);
routerProviderContext.registerNodesBuilder(nodesBuilder);
final DiagramObject element = nodesBuilder.getRootNode().getIdentifyingElement();
final Runnable callback = show(element, diagramProvider, project, null, Collections.emptyList());
if (callback != null) {
callback.run();
}
};
if (graphBuilders.isEmpty()) {
Messages.showInfoMessage(project, "No router states found.", DESCRIPTION);
return;
}
if (graphBuilders.size() == 1)
consumer.consume(graphBuilders.get(0).getSecond());
else
filterGraphBuilders(project, graphBuilders, consumer);
}
use of com.intellij.util.Consumer in project intellij-plugins by JetBrains.
the class ValidateFlashConfigurationsPrecompileTask method getProblems.
static Collection<Trinity<Module, FlexBuildConfiguration, FlashProjectStructureProblem>> getProblems(final CompileScope scope, final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCsToCompile) {
final Collection<Trinity<Module, FlexBuildConfiguration, FlashProjectStructureProblem>> problems = new ArrayList<>();
for (final Pair<Module, FlexBuildConfiguration> moduleAndBC : modulesAndBCsToCompile) {
final Module module = moduleAndBC.first;
final FlexBuildConfiguration bc = moduleAndBC.second;
final Consumer<FlashProjectStructureProblem> errorConsumer = problem -> problems.add(Trinity.create(module, bc, problem));
checkConfiguration(module, bc, false, errorConsumer);
final RunConfiguration runConfig = CompileStepBeforeRun.getRunConfiguration(scope);
if (bc.getNature().isApp() && runConfig instanceof FlashRunConfiguration) {
final FlashRunnerParameters params = ((FlashRunConfiguration) runConfig).getRunnerParameters();
if (module.getName().equals(params.getModuleName()) && bc.getName().equals(params.getBCName())) {
if (bc.getNature().isDesktopPlatform()) {
FlashRunnerParameters.checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getAirDesktopPackagingOptions(), errorConsumer, false, "does not matter");
} else if (bc.getNature().isMobilePlatform()) {
switch(params.getMobileRunTarget()) {
case Emulator:
switch(params.getAppDescriptorForEmulator()) {
case Android:
FlashRunnerParameters.checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getAndroidPackagingOptions(), errorConsumer, false, "does not matter");
break;
case IOS:
FlashRunnerParameters.checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getIosPackagingOptions(), errorConsumer, false, "does not matter");
break;
}
break;
case AndroidDevice:
checkPackagingOptions(module, bc.getSdk(), bc.getAndroidPackagingOptions(), false, PathUtil.getParentPath(bc.getActualOutputFilePath()), errorConsumer);
break;
case iOSSimulator:
checkPackagingOptions(module, bc.getSdk(), bc.getIosPackagingOptions(), true, PathUtil.getParentPath(bc.getActualOutputFilePath()), errorConsumer);
break;
case iOSDevice:
checkPackagingOptions(module, bc.getSdk(), bc.getIosPackagingOptions(), false, PathUtil.getParentPath(bc.getActualOutputFilePath()), errorConsumer);
break;
}
}
}
}
}
checkSimilarOutputFiles(modulesAndBCsToCompile, trinity -> problems.add(trinity));
return problems;
}
Aggregations