Search in sources :

Example 6 with GuiTask

use of org.fest.swing.edt.GuiTask in project intellij-community by JetBrains.

the class GuiTestBase method closeAllProjects.

@SuppressWarnings("UnusedDeclaration")
protected // Called by GuiTestRunner via reflection.
void closeAllProjects() {
    pause(new Condition("Close all projects") {

        @Override
        public boolean test() {
            final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            execute(new GuiTask() {

                @Override
                protected void executeInEDT() throws Throwable {
                    TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> {
                        for (Project project : openProjects) {
                            assertTrue("Failed to close project " + quote(project.getName()), closeAndDispose(project));
                        }
                    });
                }
            });
            return ProjectManager.getInstance().getOpenProjects().length == 0;
        }
    }, SHORT_TIMEOUT);
    //noinspection ConstantConditions
    boolean welcomeFrameShown = execute(new GuiQuery<Boolean>() {

        @Override
        protected Boolean executeInEDT() throws Throwable {
            Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            if (openProjects.length == 0) {
                WelcomeFrame.showNow();
                WindowManagerImpl windowManager = (WindowManagerImpl) WindowManager.getInstance();
                windowManager.disposeRootFrame();
                return true;
            }
            return false;
        }
    });
    if (welcomeFrameShown) {
        pause(new Condition("'Welcome' frame to show up") {

            @Override
            public boolean test() {
                for (Frame frame : Frame.getFrames()) {
                    if (frame == WelcomeFrame.getInstance() && frame.isShowing()) {
                        return true;
                    }
                }
                return false;
            }
        }, SHORT_TIMEOUT);
    }
}
Also used : Condition(org.fest.swing.timing.Condition) GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) WelcomeFrame(com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame) WindowManagerImpl(com.intellij.openapi.wm.impl.WindowManagerImpl)

Example 7 with GuiTask

use of org.fest.swing.edt.GuiTask in project android by JetBrains.

the class GradleSyncTest method sdkCreationForAddons.

// https://code.google.com/p/android/issues/detail?id=185313
@Test
public void sdkCreationForAddons() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    Project project = ideFrame.getProject();
    Module appModule = ideFrame.getModule("app");
    GradleBuildFile buildFile = GradleBuildFile.get(appModule);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            runWriteCommandAction(project, () -> buildFile.setValue(BuildFileKey.COMPILE_SDK_VERSION, "Google Inc.:Google APIs:24"));
        }
    });
    ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
    Sdk sdk = ModuleRootManager.getInstance(appModule).getSdk();
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    assertThat(data).isInstanceOf(AndroidSdkAdditionalData.class);
    AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
    IAndroidTarget buildTarget = androidSdkData.getBuildTarget(sdkData);
    // By checking that there are no additional libraries in the SDK, we are verifying that an additional SDK was not created for add-ons.
    assertThat(buildTarget.getAdditionalLibraries()).hasSize(0);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) Test(org.junit.Test)

Example 8 with GuiTask

use of org.fest.swing.edt.GuiTask in project android by JetBrains.

the class GradleSyncTest method gradleModelCache.

@Test
public void gradleModelCache() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrameFixture = guiTest.ideFrame();
    File projectPath = ideFrameFixture.getProjectPath();
    ideFrameFixture.closeProject();
    AtomicBoolean syncSkipped = new AtomicBoolean(false);
    // Reopen project and verify that sync was skipped (i.e. model loaded from cache)
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
            Project project = projectManager.convertAndLoadProject(projectPath.getPath());
            GradleSyncState.subscribe(project, new GradleSyncListener.Adapter() {

                @Override
                public void syncSkipped(@NotNull Project project) {
                    syncSkipped.set(true);
                }
            });
            projectManager.openProject(project);
        }
    });
    Wait.seconds(5).expecting("sync to be skipped").until(syncSkipped::get);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull) Test(org.junit.Test)

Example 9 with GuiTask

use of org.fest.swing.edt.GuiTask in project android by JetBrains.

the class GradleSyncTest method aarSourceAttachments.

@Test
public void aarSourceAttachments() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    Project project = ideFrame.getProject();
    Module appModule = ideFrame.getModule("app");
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            runWriteCommandAction(project, () -> {
                GradleBuildModel buildModel = GradleBuildModel.get(appModule);
                String newDependency = "com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar";
                buildModel.dependencies().addArtifact(COMPILE, newDependency);
                buildModel.applyChanges();
            });
        }
    });
    ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
    // Verify that the library has sources.
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    String libraryName = "mapbox-android-sdk-0.7.4";
    Library library = libraryTable.getLibraryByName(libraryName);
    VirtualFile[] files = library.getFiles(SOURCES);
    assertThat(files).asList().hasSize(1);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 10 with GuiTask

use of org.fest.swing.edt.GuiTask in project android by JetBrains.

the class ConvertToWebpActionTest method invokeConvertToWebpAction.

private static void invokeConvertToWebpAction(@NotNull Project project, @NotNull VirtualFile res) {
    // Ideally I'd invoke the context menu on the res node, "Convert to WebP Format",
    // but the pane fixture doesn't support invoking context menu actions yet.
    // Shortcut:
    //ProjectViewFixture.PaneFixture pane = projectFrame.getProjectView().selectAndroidPane();
    //pane.selectByPath("app", "res");
    Map<String, Object> data = Maps.newHashMap();
    data.put(CommonDataKeys.VIRTUAL_FILE_ARRAY.getName(), new VirtualFile[] { res });
    data.put(CommonDataKeys.PROJECT.getName(), project);
    DataContext context = SimpleDataContext.getSimpleContext(data, null);
    AnActionEvent actionEvent = new AnActionEvent(null, context, "test", new Presentation(), ActionManager.getInstance(), 0);
    ConvertToWebpAction action = new ConvertToWebpAction();
    GuiActionRunner.execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(() -> action.actionPerformed(actionEvent));
        }
    });
}
Also used : ConvertToWebpAction(com.android.tools.idea.rendering.webp.ConvertToWebpAction) GuiTask(org.fest.swing.edt.GuiTask) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext)

Aggregations

GuiTask (org.fest.swing.edt.GuiTask)38 NotNull (org.jetbrains.annotations.NotNull)16 Condition (org.fest.swing.timing.Condition)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Project (com.intellij.openapi.project.Project)7 FileEditor (com.intellij.openapi.fileEditor.FileEditor)5 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)5 Module (com.intellij.openapi.module.Module)5 File (java.io.File)4 Test (org.junit.Test)4 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3 JBList (com.intellij.ui.components.JBList)3 Assert.assertNotNull (junit.framework.Assert.assertNotNull)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)2 ProjectView (com.intellij.ide.projectView.ProjectView)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2