List of usage examples for com.intellij.openapi.ui Messages OK
int OK
To view the source code for com.intellij.openapi.ui Messages OK.
Click Source Link
From source file:com.android.tools.idea.actions.AndroidInferNullityAnnotationAction.java
License:Apache License
protected boolean checkModules(@NotNull Project project, @NotNull AnalysisScope scope, @NotNull Map<Module, PsiFile> modules) { Set<Module> modulesWithoutAnnotations = new HashSet<>(); Set<Module> modulesWithLowVersion = new HashSet<>(); for (Module module : modules.keySet()) { AndroidModuleInfo info = AndroidModuleInfo.get(module); if (info != null && info.getBuildSdkVersion() != null && info.getBuildSdkVersion().getFeatureLevel() < MIN_SDK_WITH_NULLABLE) { modulesWithLowVersion.add(module); }/*from w w w . j a v a2s . com*/ GradleBuildModel buildModel = GradleBuildModel.get(module); if (buildModel == null) { LOG.warn("Unable to find Gradle build model for module " + module.getModuleFilePath()); continue; } boolean dependencyFound = false; DependenciesModel dependenciesModel = buildModel.dependencies(); if (dependenciesModel != null) { for (ArtifactDependencyModel dependency : dependenciesModel.artifacts(COMPILE)) { String notation = dependency.compactNotation().value(); if (notation.startsWith(SdkConstants.APPCOMPAT_LIB_ARTIFACT) || notation.startsWith(SdkConstants.SUPPORT_LIB_ARTIFACT) || notation.startsWith(SdkConstants.ANNOTATIONS_LIB_ARTIFACT)) { dependencyFound = true; break; } } } if (!dependencyFound) { modulesWithoutAnnotations.add(module); } } if (!modulesWithLowVersion.isEmpty()) { Messages.showErrorDialog(project, String.format( "Infer Nullity Annotations requires the project sdk level be set to %1$d or greater.", MIN_SDK_WITH_NULLABLE), "Infer Nullity Annotations"); return false; } if (modulesWithoutAnnotations.isEmpty()) { return true; } String moduleNames = StringUtil.join(modulesWithoutAnnotations, Module::getName, ", "); int count = modulesWithoutAnnotations.size(); String message = String.format( "The %1$s %2$s %3$sn't refer to the existing '%4$s' library with Android nullity annotations. \n\n" + "Would you like to add the %5$s now?", pluralize("module", count), moduleNames, count > 1 ? "do" : "does", SupportLibrary.SUPPORT_ANNOTATIONS.getArtifactId(), pluralize("dependency", count)); if (Messages.showOkCancelDialog(project, message, "Infer Nullity Annotations", Messages.getErrorIcon()) == Messages.OK) { LocalHistoryAction action = LocalHistory.getInstance().startAction(ADD_DEPENDENCY); try { new WriteCommandAction(project, ADD_DEPENDENCY) { @Override protected void run(@NotNull Result result) throws Throwable { RepositoryUrlManager manager = RepositoryUrlManager.get(); String annotationsLibraryCoordinate = manager .getLibraryStringCoordinate(SupportLibrary.SUPPORT_ANNOTATIONS, true); for (Module module : modulesWithoutAnnotations) { addDependency(module, annotationsLibraryCoordinate); } GradleSyncInvoker.Request request = new GradleSyncInvoker.Request() .setGenerateSourcesOnSuccess(false); GradleSyncInvoker.getInstance().requestProjectSync(project, request, new GradleSyncListener.Adapter() { @Override public void syncSucceeded(@NotNull Project project) { restartAnalysis(project, scope); } }); } }.execute(); } finally { action.finish(); } } return false; }
From source file:com.android.tools.idea.actions.annotations.InferSupportAnnotationsAction.java
License:Apache License
protected boolean checkModules(@NotNull Project project, @NotNull AnalysisScope scope, @NotNull Map<Module, PsiFile> modules) { Set<Module> modulesWithoutAnnotations = new HashSet<>(); Set<Module> modulesWithLowVersion = new HashSet<>(); for (Module module : modules.keySet()) { AndroidModuleInfo info = AndroidModuleInfo.get(module); if (info != null && info.getBuildSdkVersion() != null && info.getBuildSdkVersion().getFeatureLevel() < MIN_SDK_WITH_NULLABLE) { modulesWithLowVersion.add(module); }//from ww w . j a v a 2 s . c om GradleBuildModel buildModel = GradleBuildModel.get(module); if (buildModel == null) { Logger.getInstance(InferSupportAnnotationsAction.class) .warn("Unable to find Gradle build model for module " + module.getModuleFilePath()); continue; } boolean dependencyFound = false; DependenciesModel dependenciesModel = buildModel.dependencies(); if (dependenciesModel != null) { for (ArtifactDependencyModel dependency : dependenciesModel.artifacts(COMPILE)) { String notation = dependency.compactNotation().value(); if (notation.startsWith(SdkConstants.APPCOMPAT_LIB_ARTIFACT) || notation.startsWith(SdkConstants.SUPPORT_LIB_ARTIFACT) || notation.startsWith(SdkConstants.ANNOTATIONS_LIB_ARTIFACT)) { dependencyFound = true; break; } } } if (!dependencyFound) { modulesWithoutAnnotations.add(module); } } if (!modulesWithLowVersion.isEmpty()) { Messages.showErrorDialog(project, String.format( "Infer Support Annotations requires the project sdk level be set to %1$d or greater.", MIN_SDK_WITH_NULLABLE), "Infer Support Annotations"); return false; } if (modulesWithoutAnnotations.isEmpty()) { return true; } String moduleNames = StringUtil.join(modulesWithoutAnnotations, Module::getName, ", "); int count = modulesWithoutAnnotations.size(); String message = String.format( "The %1$s %2$s %3$sn't refer to the existing '%4$s' library with Android nullity annotations. \n\n" + "Would you like to add the %5$s now?", pluralize("module", count), moduleNames, count > 1 ? "do" : "does", SupportLibrary.SUPPORT_ANNOTATIONS.getArtifactId(), pluralize("dependency", count)); if (Messages.showOkCancelDialog(project, message, "Infer Nullity Annotations", Messages.getErrorIcon()) == Messages.OK) { LocalHistoryAction action = LocalHistory.getInstance().startAction(ADD_DEPENDENCY); try { new WriteCommandAction(project, ADD_DEPENDENCY) { @Override protected void run(@NotNull Result result) throws Throwable { RepositoryUrlManager manager = RepositoryUrlManager.get(); String annotationsLibraryCoordinate = manager .getLibraryStringCoordinate(SupportLibrary.SUPPORT_ANNOTATIONS, true); for (Module module : modulesWithoutAnnotations) { addDependency(module, annotationsLibraryCoordinate); } GradleSyncInvoker.Request request = new GradleSyncInvoker.Request() .setGenerateSourcesOnSuccess(false); GradleSyncInvoker.getInstance().requestProjectSync(project, request, new GradleSyncListener.Adapter() { @Override public void syncSucceeded(@NotNull Project project) { restartAnalysis(project, scope); } }); } }.execute(); } finally { action.finish(); } } return false; }
From source file:com.android.tools.idea.avdmanager.AccelerationErrorSolution.java
License:Apache License
/** * Prompts the user to reboot now, and performs the reboot if accepted. * HAXM Installer may need a reboot only on Windows, so this method is intended to work only on Windows * and only for HAXM installer use case/*from w w w .j av a 2 s. c om*/ * * @param prompt the message to display to the user * @exception ExecutionException if the shutdown command fails to execute * @return No return value */ public static void promptAndReboot(@NotNull String prompt) throws ExecutionException { int response = Messages.showOkCancelDialog((Project) null, prompt, "Reboot Now", Messages.getQuestionIcon()); if (response == Messages.OK) { GeneralCommandLine reboot = new ElevatedCommandLine(); reboot.setExePath("shutdown"); reboot.addParameters("/g", "/t", "10"); // shutdown & restart after a 10 sec delay reboot.setWorkDirectory(FileUtilRt.getTempDirectory()); execute(reboot); } }
From source file:com.android.tools.idea.avdmanager.AvdManagerConnection.java
License:Apache License
/** * Handle the {@link AccelerationErrorCode} found when attempting to start an AVD. * @param project//from w ww.j a va2s .com * @param error * @return a future with a device that was launched delayed, or null if startAvd should proceed to start the AVD. */ @Nullable private ListenableFuture<IDevice> handleAccelerationError(@Nullable final Project project, @NotNull final AvdInfo info, @NotNull AccelerationErrorCode error) { switch (error) { case ALREADY_INSTALLED: return null; case TOOLS_UPDATE_REQUIRED: case PLATFORM_TOOLS_UPDATE_ADVISED: case SYSTEM_IMAGE_UPDATE_ADVISED: // Do not block emulator from running if we need updates (run with degradated performance): return null; case NO_EMULATOR_INSTALLED: // report this error below break; default: Abi abi = Abi.getEnum(info.getAbiType()); boolean isAvdIntel = abi == Abi.X86 || abi == Abi.X86_64; if (!isAvdIntel) { // Do not block Arm and Mips emulators from running without an accelerator: return null; } // report all other errors break; } String accelerator = SystemInfo.isLinux ? "KVM" : "Intel HAXM"; int result = Messages.showOkCancelDialog(project, String.format("%1$s is required to run this AVD.\n%2$s\n\n%3$s\n", accelerator, error.getProblem(), error.getSolutionMessage()), error.getSolution().getDescription(), AllIcons.General.WarningDialog); if (result != Messages.OK || error.getSolution() == AccelerationErrorSolution.SolutionCode.NONE) { return Futures.immediateFailedFuture(new RuntimeException("Could not start AVD")); } final SettableFuture<ListenableFuture<IDevice>> future = SettableFuture.create(); Runnable retry = () -> future.set(startAvd(project, info)); Runnable cancel = () -> future.setException(new RuntimeException("Retry after fixing problem by hand")); Runnable action = AccelerationErrorSolution.getActionForFix(error, project, retry, cancel); ApplicationManager.getApplication().invokeLater(action); return Futures.dereference(future); }
From source file:com.android.tools.idea.avdmanager.InstallSystemImageAction.java
License:Apache License
@Override public void actionPerformed(ActionEvent actionEvent) { String path = getPackagePath(); assert path != null; List<String> requested = ImmutableList.of(path); int response = Messages.showOkCancelDialog("The corresponding system image is missing.\n\nDownload it now?", "Download System Image", Messages.getQuestionIcon()); if (response != Messages.OK) { return;//w ww .j ava2 s. c o m } ModelWizardDialog sdkQuickfixWizard = SdkQuickfixUtils.createDialogForPaths(getProject(), requested); if (sdkQuickfixWizard != null) { sdkQuickfixWizard.show(); refreshAvds(); } }
From source file:com.android.tools.idea.gradle.dependencies.GradleDependencyManager.java
License:Apache License
private static boolean userWantToAddDependencies(@NotNull Module module, @NotNull Collection<GradleCoordinate> missing) { String libraryNames = StringUtil.join(missing, GradleCoordinate::getArtifactId, ", "); String message = String.format( "This operation requires the %1$s %2$s. \n\nWould you like to add %3$s %1$s now?", pluralize("library", missing.size()), libraryNames, pluralize("this", missing.size())); Project project = module.getProject(); return Messages.showOkCancelDialog(project, message, "Add Project Dependency", Messages.getErrorIcon()) == Messages.OK; }
From source file:com.android.tools.idea.gradle.dependencies.GradleDependencyManagerTest.java
License:Apache License
@SuppressWarnings("unused") public void ignore_testDependencyAarIsExplodedForLayoutLib() throws Exception { loadSimpleApplication();//from w w w.j a va 2 s.c o m List<GradleCoordinate> dependencies = Collections.singletonList(RECYCLER_VIEW_DEPENDENCY); GradleDependencyManager dependencyManager = GradleDependencyManager.getInstance(getProject()); assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isNotEmpty(); Messages.setTestDialog(new TestMessagesDialog(Messages.OK)); boolean found = dependencyManager.ensureLibraryIsIncluded(myModules.getAppModule(), dependencies, null); assertThat(found).isTrue(); List<ResourceItem> items = AppResourceRepository.getAppResources(myAndroidFacet, true) .getResourceItem(ResourceType.DECLARE_STYLEABLE, "RecyclerView"); assertThat(items).isNotEmpty(); assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isEmpty(); }
From source file:com.android.tools.idea.gradle.project.PreSyncChecks.java
License:Apache License
private static boolean createWrapperIfNecessary(@NotNull Project project, @NotNull GradleProjectSettings gradleSettings, @Nullable DistributionType distributionType) { boolean createWrapper = false; boolean chooseLocalGradleHome = false; if (distributionType == null) { String msg = createUseWrapperQuestion("Gradle settings for this project are not configured yet."); int answer = showOkCancelDialog(project, msg, GRADLE_SYNC_MSG_TITLE, getQuestionIcon()); createWrapper = answer == Messages.OK; } else if (distributionType == DEFAULT_WRAPPED) { createWrapper = true;//from ww w .ja v a2 s .com } else if (distributionType == LOCAL) { String gradleHome = gradleSettings.getGradleHome(); String msg = null; if (isEmpty(gradleHome)) { msg = createUseWrapperQuestion("The path of the local Gradle distribution to use is not set."); } else { File gradleHomePath = new File(toSystemDependentName(gradleHome)); if (!gradleHomePath.isDirectory()) { String reason = String.format( "The path\n'%1$s'\n, set as a local Gradle distribution, does not belong to an existing directory.", gradleHomePath.getPath()); msg = createUseWrapperQuestion(reason); } else { FullRevision gradleVersion = getGradleVersion(gradleHomePath); if (gradleVersion == null) { String reason = String.format( "The path\n'%1$s'\n, does not belong to a Gradle distribution.", gradleHomePath.getPath()); msg = createUseWrapperQuestion(reason); } else if (!isSupportedGradleVersion(gradleVersion)) { String reason = String.format("Gradle version %1$s is not supported.", gradleHomePath.getPath()); msg = createUseWrapperQuestion(reason); } } } if (msg != null) { int answer = showOkCancelDialog(project, msg, GRADLE_SYNC_MSG_TITLE, getQuestionIcon()); createWrapper = answer == Messages.OK; chooseLocalGradleHome = !createWrapper; } } if (createWrapper) { File projectDirPath = getBaseDirPath(project); // attempt to delete the whole gradle wrapper folder. File gradleDirPath = new File(projectDirPath, SdkConstants.FD_GRADLE); if (!delete(gradleDirPath)) { // deletion failed. Let sync continue. return true; } try { createGradleWrapper(projectDirPath); if (distributionType == null) { gradleSettings.setDistributionType(DEFAULT_WRAPPED); } return true; } catch (IOException e) { LOG.info("Failed to create Gradle wrapper for project '" + project.getName() + "'", e); } } else if (distributionType == null || chooseLocalGradleHome) { ChooseGradleHomeDialog dialog = new ChooseGradleHomeDialog(); if (dialog.showAndGet()) { String enteredGradleHomePath = dialog.getEnteredGradleHomePath(); gradleSettings.setGradleHome(enteredGradleHomePath); gradleSettings.setDistributionType(LOCAL); return true; } } return false; }
From source file:com.android.tools.idea.gradle.project.sync.cleanup.GradleDistributionCleanUpTaskTest.java
License:Apache License
@Override public void setUp() throws Exception { super.setUp(); myTestDialog = new TestMessagesDialog(Messages.OK); Messages.setTestDialog(myTestDialog); myCleanUpTask = new GradleDistributionCleanUpTask(); }
From source file:com.android.tools.idea.run.AndroidRunConfigurationBase.java
License:Apache License
@Override public RunProfileState getState(@NotNull final Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { validateBeforeRun(executor);//from w w w. j a va2 s .co m final Module module = getConfigurationModule().getModule(); assert module != null : "Enforced by fatal validation check in checkConfiguration."; final AndroidFacet facet = AndroidFacet.getInstance(module); assert facet != null : "Enforced by fatal validation check in checkConfiguration."; Project project = env.getProject(); boolean forceColdswap = !InstantRunUtils.isInvokedViaHotswapAction(env); boolean couldHaveHotswapped = false; boolean debug = false; if (executor instanceof DefaultDebugExecutor) { if (!AndroidSdkUtils.activateDdmsIfNecessary(facet.getModule().getProject())) { throw new ExecutionException( "Unable to obtain debug bridge. Please check if there is a different tool using adb that is active."); } debug = true; } DeviceFutures deviceFutures = null; AndroidSessionInfo info = AndroidSessionInfo.findOldSession(project, null, getUniqueID()); // note: we look for this run config with any executor if (info != null && supportsInstantRun()) { // if there is an existing previous session, then see if we can detect devices to fast deploy to deviceFutures = getFastDeployDevices(executor, facet, info); // HACK: We also need to support re-run // In the case of re-run, we need to pick the devices from the previous run, but then terminate the app. // This call to destroyProcess doesn't really belong here in the overall flow, but everything else in the flow just fits // without any changes if we can recover the device first and then terminate the process. The alternative would be for // the ReRun action itself to pass in the device just like it happens for the restart device, but that has the complication // that the ReRun is now a global action and doesn't really know much details about each run (and doing that seems like a hack too.) if (InstantRunUtils.isReRun(env)) { killSession(info); info = null; } } if (info != null && deviceFutures == null) { // If we should not be fast deploying, but there is an existing session, then terminate those sessions. Otherwise, we might end up // with 2 active sessions of the same launch, especially if we first think we can do a fast deploy, then end up doing a full launch boolean continueLaunch = promptAndKillSession(executor, project, info); if (!continueLaunch) { return null; } } else if (info != null && forceColdswap) { // the user could have invoked the hotswap action in this scenario, but they chose to force a coldswap (by pressing run) couldHaveHotswapped = true; // forcibly kill app in case of run action (which forces a cold swap) // normally, installing the apk will force kill the app, but we need to forcibly kill it in the case that there were no changes killSession(info); } // If we are not fast deploying, then figure out (prompting user if needed) where to deploy if (deviceFutures == null) { DeployTarget deployTarget = getDeployTarget(executor, env, debug, facet); if (deployTarget == null) { return null; } DeployTargetState deployTargetState = getDeployTargetContext().getCurrentDeployTargetState(); if (deployTarget.hasCustomRunProfileState(executor)) { return deployTarget.getRunProfileState(executor, env, deployTargetState); } deviceFutures = deployTarget.getDevices(deployTargetState, facet, getDeviceCount(debug), debug, getUniqueID()); if (deviceFutures == null) { // The user deliberately canceled, or some error was encountered and exposed by the chooser. Quietly exit. return null; } } if (deviceFutures.get().isEmpty()) { throw new ExecutionException(AndroidBundle.message("deployment.target.not.found")); } ApplicationIdProvider applicationIdProvider = getApplicationIdProvider(facet); InstantRunContext instantRunContext = null; if (supportsInstantRun() && InstantRunSettings.isInstantRunEnabled()) { InstantRunGradleSupport gradleSupport = canInstantRun(module, deviceFutures.getDevices()); if (gradleSupport == TARGET_PLATFORM_NOT_INSTALLED) { AndroidVersion version = deviceFutures.getDevices().get(0).getVersion(); String message = AndroidBundle.message("instant.run.quickfix.missing.platform", SdkVersionInfo.getVersionWithCodename(version)); int result = Messages.showYesNoDialog(project, message, "Instant Run", "Install and Continue", // yes button "Proceed without Instant Run", // no button Messages.getQuestionIcon()); if (result == Messages.OK) { // if ok, install platform and continue with instant run ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, ImmutableList.of(DetailsTypes.getPlatformPath(version))); if (dialog == null) { LOG.warn( "Unable to get quick fix wizard to install missing platform required for instant run."); } else if (dialog.showAndGet()) { gradleSupport = SUPPORTED; } } } if (gradleSupport == SUPPORTED) { if (!AndroidEnableAdbServiceAction.isAdbServiceEnabled()) { throw new ExecutionException( "Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled."); } InstantRunUtils.setInstantRunEnabled(env, true); instantRunContext = InstantRunGradleUtils.createGradleProjectContext(facet); } else { InstantRunManager.LOG .warn("Instant Run enabled, but not doing an instant run build since: " + gradleSupport); String notificationText = gradleSupport.getUserNotification(); if (notificationText != null) { InstantRunNotificationTask.showNotification(env.getProject(), null, notificationText); } } } else { String msg = "Not using instant run for this launch: "; if (InstantRunSettings.isInstantRunEnabled()) { msg += getType().getDisplayName() + " does not support instant run"; } else { msg += "instant run is disabled"; } InstantRunManager.LOG.info(msg); } // Store the chosen target on the execution environment so before-run tasks can access it. AndroidRunConfigContext runConfigContext = new AndroidRunConfigContext(); env.putCopyableUserData(AndroidRunConfigContext.KEY, runConfigContext); runConfigContext.setTargetDevices(deviceFutures); runConfigContext .setSameExecutorAsPreviousSession(info != null && executor.getId().equals(info.getExecutorId())); runConfigContext.setCleanRerun(InstantRunUtils.isCleanReRun(env)); runConfigContext.setForceColdSwap(forceColdswap, couldHaveHotswapped); // Save the instant run context so that before-run task can access it env.putCopyableUserData(InstantRunContext.KEY, instantRunContext); if (debug) { String error = canDebug(deviceFutures, facet, module.getName()); if (error != null) { throw new ExecutionException(error); } } LaunchOptions launchOptions = getLaunchOptions().setDebug(debug).build(); ProcessHandler processHandler = null; if (info != null && info.getExecutorId().equals(executor.getId())) { processHandler = info.getProcessHandler(); } ApkProvider apkProvider = getApkProvider(facet, applicationIdProvider); LaunchTasksProviderFactory providerFactory = new AndroidLaunchTasksProviderFactory(this, env, facet, applicationIdProvider, apkProvider, deviceFutures, launchOptions, processHandler, instantRunContext); InstantRunStatsService.get(project).notifyBuildStarted(); return new AndroidRunState(env, getName(), module, applicationIdProvider, getConsoleProvider(), deviceFutures, providerFactory, processHandler); }