Search in sources :

Example 61 with Application

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

the class LintIdeJavaParser method getType.

@Nullable
@Override
public TypeDescriptor getType(@NonNull JavaContext context, @NonNull Node node) {
    final PsiElement element = getPsiElement(node);
    if (element == null) {
        return null;
    }
    Application application = ApplicationManager.getApplication();
    if (application.isReadAccessAllowed()) {
        return getTypeDescriptor(element);
    }
    return application.runReadAction(new Computable<TypeDescriptor>() {

        @Nullable
        @Override
        public TypeDescriptor compute() {
            return getTypeDescriptor(element);
        }
    });
}
Also used : Application(com.intellij.openapi.application.Application) Nullable(com.android.annotations.Nullable) Nullable(com.android.annotations.Nullable)

Example 62 with Application

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

the class LintIdeJavaParser method resolve.

@Nullable
@Override
public ResolvedNode resolve(@NonNull JavaContext context, @NonNull Node node) {
    final PsiElement element = getPsiElement(node);
    if (element == null) {
        return null;
    }
    Application application = ApplicationManager.getApplication();
    if (application.isReadAccessAllowed()) {
        return resolve(element);
    }
    return application.runReadAction(new Computable<ResolvedNode>() {

        @Nullable
        @Override
        public ResolvedNode compute() {
            return resolve(element);
        }
    });
}
Also used : Application(com.intellij.openapi.application.Application) Nullable(com.android.annotations.Nullable) Nullable(com.android.annotations.Nullable)

Example 63 with Application

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

the class ApplicationUtils method invokeWriteActionAndWait.

/**
   * Executes writeAction synchronously on the AWT event dispatch thread.
   */
public static void invokeWriteActionAndWait(ModalityState state, final Runnable writeAction) {
    final Application application = ApplicationManager.getApplication();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            application.runWriteAction(writeAction);
        }
    };
    application.invokeAndWait(runnable, state);
}
Also used : Application(com.intellij.openapi.application.Application)

Example 64 with Application

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

the class GradleExecutionHelper method prepare.

@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
public static void prepare(@NotNull LongRunningOperation operation, @NotNull final ExternalSystemTaskId id, @NotNull GradleExecutionSettings settings, @NotNull final ExternalSystemTaskNotificationListener listener, @NotNull ProjectConnection connection, @NotNull final OutputStream standardOutput, @NotNull final OutputStream standardError) {
    Set<String> jvmArgs = settings.getVmOptions();
    if (!jvmArgs.isEmpty()) {
        // merge gradle args e.g. defined in gradle.properties
        BuildEnvironment buildEnvironment = getBuildEnvironment(connection);
        Collection<String> merged = buildEnvironment != null ? mergeJvmArgs(settings.getServiceDirectory(), buildEnvironment.getJava().getJvmArguments(), jvmArgs) : jvmArgs;
        // filter nulls and empty strings
        List<String> filteredArgs = ContainerUtil.mapNotNull(merged, s -> StringUtil.isEmpty(s) ? null : s);
        operation.setJvmArguments(ArrayUtil.toStringArray(filteredArgs));
    }
    if (settings.isOfflineWork()) {
        settings.withArgument(GradleConstants.OFFLINE_MODE_CMD_OPTION);
    }
    final Application application = ApplicationManager.getApplication();
    if (application != null && application.isUnitTestMode()) {
        if (!settings.getArguments().contains("--quiet")) {
            settings.withArgument("--info");
        }
        settings.withArgument("--recompile-scripts");
    }
    if (!settings.getArguments().isEmpty()) {
        LOG.info("Passing command-line args to Gradle Tooling API: " + StringUtil.join(settings.getArguments(), " "));
        // filter nulls and empty strings
        List<String> filteredArgs = ContainerUtil.mapNotNull(settings.getArguments(), s -> StringUtil.isEmpty(s) ? null : s);
        // TODO remove this replacement when --tests option will become available for tooling API
        replaceTestCommandOptionWithInitScript(filteredArgs);
        operation.withArguments(ArrayUtil.toStringArray(filteredArgs));
    }
    final String javaHome = settings.getJavaHome();
    if (javaHome != null && new File(javaHome).isDirectory()) {
        operation.setJavaHome(new File(javaHome));
    }
    operation.addProgressListener(new ProgressListener() {

        @Override
        public void statusChanged(ProgressEvent event) {
            listener.onStatusChange(new ExternalSystemTaskNotificationEvent(id, event.getDescription()));
        }
    });
    operation.addProgressListener(new org.gradle.tooling.events.ProgressListener() {

        @Override
        public void statusChanged(org.gradle.tooling.events.ProgressEvent event) {
            listener.onStatusChange(GradleProgressEventConverter.convert(id, event));
        }
    });
    operation.setStandardOutput(standardOutput);
    operation.setStandardError(standardError);
}
Also used : ExternalSystemTaskNotificationEvent(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) Application(com.intellij.openapi.application.Application) File(java.io.File)

Example 65 with Application

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

the class GradleExecutionHelper method getConnection.

/**
   * Allows to retrieve gradle api connection to use for the given project.
   *
   * @param projectPath target project path
   * @param settings    execution settings to use
   * @return connection to use
   * @throws IllegalStateException if it's not possible to create the connection
   */
@NotNull
private static ProjectConnection getConnection(@NotNull String projectPath, @Nullable GradleExecutionSettings settings) throws IllegalStateException {
    File projectDir = new File(projectPath);
    GradleConnector connector = GradleConnector.newConnector();
    int ttl = -1;
    if (settings != null) {
        //noinspection EnumSwitchStatementWhichMissesCases
        switch(settings.getDistributionType()) {
            case LOCAL:
                String gradleHome = settings.getGradleHome();
                if (gradleHome != null) {
                    try {
                        // There were problems with symbolic links processing at the gradle side.
                        connector.useInstallation(new File(gradleHome).getCanonicalFile());
                    } catch (IOException e) {
                        connector.useInstallation(new File(settings.getGradleHome()));
                    }
                }
                break;
            case WRAPPED:
                if (settings.getWrapperPropertyFile() != null) {
                    File propertiesFile = new File(settings.getWrapperPropertyFile());
                    if (propertiesFile.exists()) {
                        Distribution distribution = new DistributionFactoryExt(new DefaultExecutorServiceFactory()).getWrappedDistribution(propertiesFile);
                        try {
                            setField(connector, "distribution", distribution);
                        } catch (Exception e) {
                            throw new ExternalSystemException(e);
                        }
                    }
                }
                break;
        }
        // Setup service directory if necessary.
        String serviceDirectory = settings.getServiceDirectory();
        if (serviceDirectory != null) {
            connector.useGradleUserHomeDir(new File(serviceDirectory));
        }
        // Setup logging if necessary.
        if (settings.isVerboseProcessing() && connector instanceof DefaultGradleConnector) {
            ((DefaultGradleConnector) connector).setVerboseLogging(true);
        }
        ttl = (int) settings.getRemoteProcessIdleTtlInMs();
    }
    if (ttl > 0 && connector instanceof DefaultGradleConnector) {
        // do not spawn gradle daemons during test execution
        final Application app = ApplicationManager.getApplication();
        ttl = (app != null && app.isUnitTestMode()) ? 10000 : ttl;
        ((DefaultGradleConnector) connector).daemonMaxIdleTime(ttl, TimeUnit.MILLISECONDS);
    }
    connector.forProjectDirectory(projectDir);
    ProjectConnection connection = connector.connect();
    if (connection == null) {
        throw new IllegalStateException(String.format("Can't create connection to the target project via gradle tooling api. Project path: '%s'", projectPath));
    }
    return connection;
}
Also used : DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) IOException(java.io.IOException) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) IOException(java.io.IOException) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) Distribution(org.gradle.tooling.internal.consumer.Distribution) DefaultExecutorServiceFactory(org.gradle.tooling.internal.consumer.DefaultExecutorServiceFactory) File(java.io.File) DistributionFactoryExt(org.jetbrains.plugins.gradle.service.project.DistributionFactoryExt) Application(com.intellij.openapi.application.Application) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Application (com.intellij.openapi.application.Application)188 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 IOException (java.io.IOException)14 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 ModalityState (com.intellij.openapi.application.ModalityState)8 Ref (com.intellij.openapi.util.Ref)7 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)4 Document (com.intellij.openapi.editor.Document)4 Module (com.intellij.openapi.module.Module)4 Computable (com.intellij.openapi.util.Computable)4 PsiFile (com.intellij.psi.PsiFile)4 File (java.io.File)4 Editor (com.intellij.openapi.editor.Editor)3