Search in sources :

Example 11 with ReadAction

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

the class ArtifactCompilerUtil method createOutputToArtifactMap.

public static MultiMap<String, Artifact> createOutputToArtifactMap(final Project project) {
    final MultiMap<String, Artifact> result = MultiMap.create(FileUtil.PATH_HASHING_STRATEGY);
    new ReadAction() {

        protected void run(@NotNull final Result r) {
            for (Artifact artifact : ArtifactManager.getInstance(project).getArtifacts()) {
                String outputPath = artifact.getOutputFilePath();
                if (!StringUtil.isEmpty(outputPath)) {
                    result.putValue(outputPath, artifact);
                }
            }
        }
    }.execute();
    return result;
}
Also used : ReadAction(com.intellij.openapi.application.ReadAction) Artifact(com.intellij.packaging.artifacts.Artifact) Result(com.intellij.openapi.application.Result)

Example 12 with ReadAction

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

the class GenerateBinaryStubsFix method getFixTask.

/**
   * Returns fix task that is used to generate stubs
   *
   * @param fileToRunTaskIn file where task should run
   * @return task itself
   */
@NotNull
public Backgroundable getFixTask(@NotNull final PsiFile fileToRunTaskIn) {
    final Project project = fileToRunTaskIn.getProject();
    final String folder = fileToRunTaskIn.getContainingDirectory().getVirtualFile().getCanonicalPath();
    return new Task.Backgroundable(project, "Generating skeletons for binary module", false) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final List<String> assemblyRefs = new ReadAction<List<String>>() {

                @Override
                protected void run(@NotNull Result<List<String>> result) throws Throwable {
                    result.setResult(collectAssemblyReferences(fileToRunTaskIn));
                }
            }.execute().getResultObject();
            try {
                final PySkeletonRefresher refresher = new PySkeletonRefresher(project, null, mySdk, null, null, folder);
                if (needBinaryList(myQualifiedName)) {
                    if (!generateSkeletonsForList(refresher, indicator, folder))
                        return;
                } else {
                    //noinspection unchecked
                    refresher.generateSkeleton(myQualifiedName, "", assemblyRefs, Consumer.EMPTY_CONSUMER);
                }
                final VirtualFile skeletonDir;
                skeletonDir = LocalFileSystem.getInstance().findFileByPath(refresher.getSkeletonsPath());
                if (skeletonDir != null) {
                    skeletonDir.refresh(true, true);
                }
            } catch (InvalidSdkException e) {
                LOG.error(e);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PySkeletonRefresher(com.jetbrains.python.sdk.skeletons.PySkeletonRefresher) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadAction(com.intellij.openapi.application.ReadAction) Backgroundable(com.intellij.openapi.progress.Task.Backgroundable) InvalidSdkException(com.jetbrains.python.sdk.InvalidSdkException) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ReadAction

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

the class GradleSyncTest method shouldUseLibrary.

@Test
public void shouldUseLibrary() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    Project project = ideFrame.getProject();
    // Make sure the library was added.
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    String libraryName = "org.apache.http.legacy-" + TestUtils.getLatestAndroidPlatform();
    Library library = libraryTable.getLibraryByName(libraryName);
    // Verify that the library has the right j
    VirtualFile[] jarFiles = library.getFiles(CLASSES);
    assertThat(jarFiles).asList().hasSize(1);
    VirtualFile jarFile = jarFiles[0];
    assertEquals("org.apache.http.legacy.jar", jarFile.getName());
    // Verify that the module depends on the library
    Module appModule = ideFrame.getModule("app");
    AtomicBoolean dependencyFound = new AtomicBoolean();
    new ReadAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(appModule).getModifiableModel();
            try {
                for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
                    if (orderEntry instanceof LibraryOrderEntry) {
                        LibraryOrderEntry libraryDependency = (LibraryOrderEntry) orderEntry;
                        if (libraryDependency.getLibrary() == library) {
                            dependencyFound.set(true);
                        }
                    }
                }
            } finally {
                modifiableModel.dispose();
            }
        }
    }.execute();
    assertTrue("Module app should depend on library '" + library.getName() + "'", dependencyFound.get());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Result(com.intellij.openapi.application.Result) Project(com.intellij.openapi.project.Project) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ReadAction(com.intellij.openapi.application.ReadAction) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 14 with ReadAction

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

the class IdeFrameFixture method parseBuildFileForModule.

@NotNull
public GradleBuildModelFixture parseBuildFileForModule(@NotNull String moduleName) {
    Module module = getModule(moduleName);
    VirtualFile buildFile = getGradleBuildFile(module);
    Ref<GradleBuildModel> buildModelRef = new Ref<>();
    new ReadAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            buildModelRef.set(GradleBuildModel.parseBuildFile(buildFile, getProject()));
        }
    }.execute();
    return new GradleBuildModelFixture(buildModelRef.get());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Ref(com.intellij.openapi.util.Ref) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ReadAction(com.intellij.openapi.application.ReadAction) Module(com.intellij.openapi.module.Module) Result(com.intellij.openapi.application.Result) GradleInvocationResult(com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult) GradleBuildModelFixture(com.android.tools.idea.tests.gui.framework.fixture.gradle.GradleBuildModelFixture) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ReadAction (com.intellij.openapi.application.ReadAction)14 Result (com.intellij.openapi.application.Result)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 NotNull (org.jetbrains.annotations.NotNull)7 Module (com.intellij.openapi.module.Module)3 GenericCompilerCache (com.intellij.compiler.impl.generic.GenericCompilerCache)2 Notification (com.intellij.notification.Notification)2 RunResult (com.intellij.openapi.application.RunResult)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 Artifact (com.intellij.packaging.artifacts.Artifact)2 THashSet (gnu.trove.THashSet)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 GradleInvocationResult (com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult)1 GradleBuildModelFixture (com.android.tools.idea.tests.gui.framework.fixture.gradle.GradleBuildModelFixture)1 GenericCompilerPersistentData (com.intellij.compiler.impl.generic.GenericCompilerPersistentData)1 NotificationListener (com.intellij.notification.NotificationListener)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1