use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project intellij-community by JetBrains.
the class GradleTaskManager method executeTasks.
@Override
public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List<String> taskNames, @NotNull String projectPath, @Nullable GradleExecutionSettings settings, @Nullable final String jvmAgentSetup, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
// TODO add support for external process mode
if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
for (GradleTaskManagerExtension gradleTaskManagerExtension : GradleTaskManagerExtension.EP_NAME.getExtensions()) {
if (gradleTaskManagerExtension.executeTasks(id, taskNames, projectPath, settings, jvmAgentSetup, listener)) {
return;
}
}
}
GradleExecutionSettings effectiveSettings = settings == null ? new GradleExecutionSettings(null, null, DistributionType.BUNDLED, false) : settings;
Function<ProjectConnection, Void> f = connection -> {
final List<String> initScripts = ContainerUtil.newArrayList();
final GradleProjectResolverExtension projectResolverChain = GradleProjectResolver.createProjectResolverChain(effectiveSettings);
for (GradleProjectResolverExtension resolverExtension = projectResolverChain; resolverExtension != null; resolverExtension = resolverExtension.getNext()) {
final String resolverClassName = resolverExtension.getClass().getName();
resolverExtension.enhanceTaskProcessing(taskNames, jvmAgentSetup, script -> {
if (StringUtil.isNotEmpty(script)) {
ContainerUtil.addAllNotNull(initScripts, "//-- Generated by " + resolverClassName, script, "//");
}
});
}
final String initScript = effectiveSettings.getUserData(INIT_SCRIPT_KEY);
if (StringUtil.isNotEmpty(initScript)) {
ContainerUtil.addAll(initScripts, "//-- Additional script", initScript, "//");
}
if (!initScripts.isEmpty()) {
try {
File tempFile = GradleExecutionHelper.writeToFileGradleInitScript(StringUtil.join(initScripts, SystemProperties.getLineSeparator()));
effectiveSettings.withArguments(GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath());
} catch (IOException e) {
throw new ExternalSystemException(e);
}
}
GradleVersion gradleVersion = GradleExecutionHelper.getGradleVersion(connection);
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.5")) < 0) {
listener.onStatusChange(new ExternalSystemTaskExecutionEvent(id, new ExternalSystemProgressEventUnsupportedImpl(gradleVersion + " does not support executions view")));
}
for (GradleBuildParticipant buildParticipant : effectiveSettings.getExecutionWorkspace().getBuildParticipants()) {
effectiveSettings.withArguments(GradleConstants.INCLUDE_BUILD_CMD_OPTION, buildParticipant.getProjectPath());
}
BuildLauncher launcher = myHelper.getBuildLauncher(id, connection, effectiveSettings, listener);
launcher.forTasks(ArrayUtil.toStringArray(taskNames));
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
myCancellationMap.put(id, new UnsupportedCancellationToken());
} else {
final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
launcher.withCancellationToken(cancellationTokenSource.token());
myCancellationMap.put(id, cancellationTokenSource);
}
try {
launcher.run();
} finally {
myCancellationMap.remove(id);
}
return null;
};
myHelper.execute(projectPath, effectiveSettings, f);
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project intellij-community by JetBrains.
the class GradleExecutionHelper method execute.
public <T> T execute(@NotNull String projectPath, @Nullable GradleExecutionSettings settings, @NotNull Function<ProjectConnection, T> f) {
final String projectDir;
final File projectPathFile = new File(projectPath);
if (projectPathFile.isFile() && projectPath.endsWith(GradleConstants.EXTENSION) && projectPathFile.getParent() != null) {
projectDir = projectPathFile.getParent();
} else {
projectDir = projectPath;
}
String userDir = null;
if (!GradleEnvironment.ADJUST_USER_DIR) {
try {
userDir = System.getProperty("user.dir");
if (userDir != null)
System.setProperty("user.dir", projectDir);
} catch (Exception ignore) {
}
}
ProjectConnection connection = getConnection(projectDir, settings);
try {
return f.fun(connection);
} catch (ExternalSystemException e) {
throw e;
} catch (Throwable e) {
LOG.debug("Gradle execution error", e);
Throwable rootCause = ExceptionUtil.getRootCause(e);
throw new ExternalSystemException(ExceptionUtil.getMessage(rootCause));
} finally {
try {
connection.close();
if (userDir != null) {
// restore original user.dir property
System.setProperty("user.dir", userDir);
}
} catch (Throwable e) {
LOG.debug("Gradle connection close error", e);
}
}
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class SimulatedSyncErrors method registerSyncErrorToSimulate.
public static void registerSyncErrorToSimulate(@NotNull String errorMessage) {
verifyIsTestMode();
ExternalSystemException exception = new ExternalSystemException(errorMessage);
store(exception);
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class SimulatedSyncErrors method registerSyncErrorToSimulate.
public static void registerSyncErrorToSimulate(@NotNull Throwable cause) {
verifyIsTestMode();
ExternalSystemException exception = new ExternalSystemException(cause.getMessage());
exception.initCause(cause);
store(exception);
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class SimulatedSyncErrors method simulateRegisteredSyncError.
public static void simulateRegisteredSyncError() {
Application application = ApplicationManager.getApplication();
ExternalSystemException error = application.getUserData(SIMULATED_ERROR_KEY);
if (error != null) {
verifyIsTestMode();
application.putUserData(SIMULATED_ERROR_KEY, null);
throw error;
}
}
Aggregations