Search in sources :

Example 96 with Result

use of com.intellij.openapi.application.Result in project android by JetBrains.

the class NewModuleModel method handleFinished.

@Override
protected void handleFinished() {
    if (myTemplateFile.getValueOrNull() == null) {
        // If here, the user opted to skip creating any module at all, or is just adding a new Activity
        return;
    }
    // By the time we run handleFinished(), we must have a Project
    if (!myProject.get().isPresent()) {
        getLog().error("NewModuleModel did not collect expected information and will not complete. Please report this error.");
        return;
    }
    Map<String, Object> renderTemplateValues = myRenderTemplateValues.getValueOrNull();
    Map<String, Object> templateValues = new HashMap<>();
    if (renderTemplateValues != null) {
        templateValues.putAll(renderTemplateValues);
    }
    templateValues.putAll(myTemplateValues);
    templateValues.put(ATTR_IS_LIBRARY_MODULE, myIsLibrary.get());
    Project project = myProject.getValue();
    boolean canRender = renderModule(true, templateValues, project);
    if (!canRender) {
        // If here, there was a render conflict and the user chose to cancel creating the template
        return;
    }
    boolean success = new WriteCommandAction<Boolean>(project, "New Module") {

        @Override
        protected void run(@NotNull Result<Boolean> result) throws Throwable {
            boolean success = renderModule(false, templateValues, project);
            result.setResult(success);
        }
    }.execute().getResultObject();
    if (!success) {
        getLog().warn("A problem occurred while creating a new Module. Please check the log file for possible errors.");
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 97 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class AppEngineSupportProvider method addProjectLibrary.

private static Library addProjectLibrary(final Module module, final String name, final List<String> jarDirectories, final VirtualFile[] sources) {
    return new WriteAction<Library>() {

        protected void run(@NotNull final Result<Library> result) {
            final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(module.getProject());
            Library library = libraryTable.getLibraryByName(name);
            if (library == null) {
                library = libraryTable.createLibrary(name);
                final Library.ModifiableModel model = library.getModifiableModel();
                for (String path : jarDirectories) {
                    String url = VfsUtilCore.pathToUrl(path);
                    VirtualFileManager.getInstance().refreshAndFindFileByUrl(url);
                    model.addJarDirectory(url, false);
                }
                for (VirtualFile sourceRoot : sources) {
                    model.addRoot(sourceRoot, OrderRootType.SOURCES);
                }
                model.commit();
            }
            result.setResult(library);
        }
    }.execute().getResultObject();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) WriteAction(com.intellij.openapi.application.WriteAction) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull) ValidationResult(com.intellij.facet.ui.ValidationResult) Result(com.intellij.openapi.application.Result)

Example 98 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class AppEngineUploader method createUploader.

@Nullable
public static AppEngineUploader createUploader(@NotNull Project project, @NotNull Artifact artifact, @NotNull AppEngineServerConfiguration configuration, @NotNull ServerRuntimeInstance.DeploymentOperationCallback callback, @NotNull LoggingHandler loggingHandler) {
    final String explodedPath = artifact.getOutputPath();
    if (explodedPath == null) {
        callback.errorOccurred("Output path isn't specified for '" + artifact.getName() + "' artifact");
        return null;
    }
    final AppEngineFacet appEngineFacet = AppEngineUtil.findAppEngineFacet(project, artifact);
    if (appEngineFacet == null) {
        callback.errorOccurred("App Engine facet not found in '" + artifact.getName() + "' artifact");
        return null;
    }
    final AppEngineSdk sdk = appEngineFacet.getSdk();
    if (!sdk.getAppCfgFile().exists()) {
        callback.errorOccurred("Path to App Engine SDK isn't specified correctly in App Engine Facet settings");
        return null;
    }
    PackagingElementResolvingContext context = ArtifactManager.getInstance(project).getResolvingContext();
    VirtualFile descriptorFile = ArtifactUtil.findSourceFileByOutputPath(artifact, "WEB-INF/appengine-web.xml", context);
    final AppEngineWebApp root = AppEngineFacet.getDescriptorRoot(descriptorFile, appEngineFacet.getModule().getProject());
    if (root != null) {
        final GenericDomValue<String> application = root.getApplication();
        if (StringUtil.isEmptyOrSpaces(application.getValue())) {
            final String name = Messages.showInputDialog(project, "<html>Application name is not specified in appengine-web.xml.<br>" + "Enter application name (see your <a href=\"http://appengine.google.com\">AppEngine account</a>):</html>", CommonBundle.getErrorTitle(), null, "", null);
            if (name == null)
                return null;
            final PsiFile file = application.getXmlTag().getContainingFile();
            new WriteCommandAction(project, file) {

                protected void run(@NotNull final Result result) {
                    application.setStringValue(name);
                }
            }.execute();
            final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document != null) {
                FileDocumentManager.getInstance().saveDocument(document);
            }
        }
    }
    AppEngineAuthData authData = AppEngineAccountDialog.createAuthData(project, configuration);
    if (authData == null)
        return null;
    return new AppEngineUploader(project, artifact, appEngineFacet, sdk, authData, callback, loggingHandler);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PackagingElementResolvingContext(com.intellij.packaging.elements.PackagingElementResolvingContext) Document(com.intellij.openapi.editor.Document) AppEngineWebApp(com.intellij.appengine.descriptor.dom.AppEngineWebApp) Result(com.intellij.openapi.application.Result) AppEngineFacet(com.intellij.appengine.facet.AppEngineFacet) PsiFile(com.intellij.psi.PsiFile) AppEngineSdk(com.intellij.appengine.sdk.AppEngineSdk) AppEngineAuthData(com.intellij.appengine.cloud.AppEngineAuthData) Nullable(org.jetbrains.annotations.Nullable)

Example 99 with Result

use of com.intellij.openapi.application.Result 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 100 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class GradleImportingTestCase method setUp.

@Override
public void setUp() throws Exception {
    myJdkHome = IdeaTestUtil.requireRealJdkHome();
    super.setUp();
    assumeThat(gradleVersion, versionMatcherRule.getMatcher());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
            if (oldJdk != null) {
                ProjectJdkTable.getInstance().removeJdk(oldJdk);
            }
            VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
            Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
            assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
            ProjectJdkTable.getInstance().addJdk(jdk);
        }
    }.execute();
    myProjectSettings = new GradleProjectSettings();
    GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx128m -XX:MaxPermSize=64m");
    System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
    configureWrapper();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)298 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)186 NotNull (org.jetbrains.annotations.NotNull)116 WriteAction (com.intellij.openapi.application.WriteAction)93 VirtualFile (com.intellij.openapi.vfs.VirtualFile)83 Project (com.intellij.openapi.project.Project)58 Module (com.intellij.openapi.module.Module)32 File (java.io.File)32 PsiFile (com.intellij.psi.PsiFile)31 Document (com.intellij.openapi.editor.Document)28 XmlFile (com.intellij.psi.xml.XmlFile)28 IOException (java.io.IOException)28 XmlTag (com.intellij.psi.xml.XmlTag)24 Nullable (org.jetbrains.annotations.Nullable)17 ReadAction (com.intellij.openapi.application.ReadAction)16 ArrayList (java.util.ArrayList)15 Editor (com.intellij.openapi.editor.Editor)13 PsiElement (com.intellij.psi.PsiElement)13 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)10