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);
}
});
}
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);
}
});
}
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);
}
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);
}
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;
}
Aggregations