mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Gradle|Exec] cleanup: use GradleExecutionHelper's static methods directly
The GradleExecutionHelper#execute function does not need to be overridden. Therefore, the GradleExecutionHelper class can be converted to the canonical utility class. Issues IDEA-363359, IDEA-344664 GitOrigin-RevId: e79da247877fa953b776fbb6fc1f6140fb9608b5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
46e5149c0c
commit
56122ac611
+40
-27
@@ -51,22 +51,37 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.plugins.gradle.GradleConnectorService.withGradleConnection;
|
||||
|
||||
public class GradleExecutionHelper {
|
||||
public final class GradleExecutionHelper {
|
||||
|
||||
/**
|
||||
* @deprecated Use helper methods without object instantiation.
|
||||
* All method is this class is static.
|
||||
*/
|
||||
@Deprecated
|
||||
public GradleExecutionHelper() { }
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(GradleExecutionHelper.class);
|
||||
|
||||
public <T> T execute(@NotNull String projectPath,
|
||||
@Nullable GradleExecutionSettings settings,
|
||||
@NotNull Function<? super ProjectConnection, ? extends T> f) {
|
||||
/**
|
||||
* @deprecated Use instead the static variant of this method.
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T execute(
|
||||
@NotNull String projectPath,
|
||||
@Nullable GradleExecutionSettings settings,
|
||||
@NotNull Function<? super ProjectConnection, ? extends T> f
|
||||
) {
|
||||
return execute(projectPath, settings, null, null, null, f);
|
||||
}
|
||||
|
||||
public <T> T execute(@NotNull String projectPath,
|
||||
@Nullable GradleExecutionSettings settings,
|
||||
@Nullable ExternalSystemTaskId taskId,
|
||||
@Nullable ExternalSystemTaskNotificationListener listener,
|
||||
@Nullable CancellationToken cancellationToken,
|
||||
@NotNull Function<? super ProjectConnection, ? extends T> f) {
|
||||
public static <T> T execute(
|
||||
@NotNull String projectPath,
|
||||
@Nullable GradleExecutionSettings settings,
|
||||
@Nullable ExternalSystemTaskId taskId,
|
||||
@Nullable ExternalSystemTaskNotificationListener listener,
|
||||
@Nullable CancellationToken cancellationToken,
|
||||
@NotNull Function<? super ProjectConnection, ? extends T> f
|
||||
) {
|
||||
String projectDir;
|
||||
File projectPathFile = new File(projectPath);
|
||||
if (projectPathFile.isFile() && projectPath.endsWith(GradleConstants.EXTENSION) && projectPathFile.getParent() != null) {
|
||||
@@ -82,23 +97,21 @@ public class GradleExecutionHelper {
|
||||
else {
|
||||
projectDir = projectPath;
|
||||
}
|
||||
return withGradleConnection(
|
||||
projectDir, taskId, settings, listener, cancellationToken,
|
||||
connection -> {
|
||||
try {
|
||||
return SystemPropertiesAdjuster.executeAdjusted(projectDir, () -> f.fun(connection));
|
||||
}
|
||||
catch (ExternalSystemException | ProcessCanceledException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.warn("Gradle execution error", e);
|
||||
Throwable rootCause = ExceptionUtil.getRootCause(e);
|
||||
ExternalSystemException externalSystemException = new ExternalSystemException(ExceptionUtil.getMessage(rootCause), e);
|
||||
externalSystemException.initCause(e);
|
||||
throw externalSystemException;
|
||||
}
|
||||
});
|
||||
return withGradleConnection(projectDir, taskId, settings, listener, cancellationToken, connection -> {
|
||||
try {
|
||||
return SystemPropertiesAdjuster.executeAdjusted(projectDir, () -> f.fun(connection));
|
||||
}
|
||||
catch (ExternalSystemException | ProcessCanceledException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.warn("Gradle execution error", e);
|
||||
Throwable rootCause = ExceptionUtil.getRootCause(e);
|
||||
ExternalSystemException externalSystemException = new ExternalSystemException(ExceptionUtil.getMessage(rootCause), e);
|
||||
externalSystemException.initCause(e);
|
||||
throw externalSystemException;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ import org.jetbrains.plugins.gradle.model.data.BuildParticipant;
|
||||
import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData;
|
||||
import org.jetbrains.plugins.gradle.model.data.CompositeBuildData;
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData;
|
||||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper;
|
||||
import org.jetbrains.plugins.gradle.settings.DistributionType;
|
||||
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
@@ -203,7 +204,7 @@ public final class GradleBuildSrcProjectsResolver {
|
||||
return;
|
||||
}
|
||||
|
||||
final DataNode<ProjectData> buildSrcProjectDataNode = myProjectResolver.getHelper().execute(
|
||||
final DataNode<ProjectData> buildSrcProjectDataNode = GradleExecutionHelper.execute(
|
||||
buildSrcResolverCtx.getProjectPath(),
|
||||
buildSrcResolverCtx.getSettings(),
|
||||
buildSrcResolverCtx.getExternalSystemTaskId(),
|
||||
|
||||
+7
-15
@@ -94,7 +94,6 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(GradleProjectResolver.class);
|
||||
|
||||
private final @NotNull GradleExecutionHelper myHelper;
|
||||
private final @NotNull GradleLibraryNamesMixer myLibraryNamesMixer = new GradleLibraryNamesMixer();
|
||||
private final @NotNull MultiMap<ExternalSystemTaskId, CancellationTokenSource> myCancellationMap = MultiMap.createConcurrent();
|
||||
|
||||
@@ -109,15 +108,13 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
|
||||
|
||||
public static final boolean DEBUG_ORPHAN_MODULES_PROCESSING = Boolean.getBoolean("external.system.debug.orphan.modules.processing");
|
||||
|
||||
// This constructor is called by external system API, see AbstractExternalSystemFacadeImpl class constructor.
|
||||
/**
|
||||
* This constructor is called by the external system API.
|
||||
*
|
||||
* @see com.intellij.openapi.externalSystem.service.AbstractExternalSystemFacadeImpl#AbstractExternalSystemFacadeImpl
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public GradleProjectResolver() {
|
||||
this(new GradleExecutionHelper());
|
||||
}
|
||||
|
||||
public GradleProjectResolver(@NotNull GradleExecutionHelper helper) {
|
||||
myHelper = helper;
|
||||
}
|
||||
public GradleProjectResolver() { }
|
||||
|
||||
@Override
|
||||
public @Nullable DataNode<ProjectData> resolveProjectInfo(
|
||||
@@ -187,7 +184,7 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
|
||||
|
||||
final GradleProjectResolverExtension projectResolverChain = createProjectResolverChain(resolverContext);
|
||||
var projectDataFunction = getProjectDataFunction(resolverContext, projectResolverChain);
|
||||
final DataNode<ProjectData> projectDataNode = myHelper.execute(
|
||||
final DataNode<ProjectData> projectDataNode = GradleExecutionHelper.execute(
|
||||
resolverContext.getProjectPath(),
|
||||
resolverContext.getSettings(),
|
||||
resolverContext.getExternalSystemTaskId(),
|
||||
@@ -219,11 +216,6 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
|
||||
return new ProjectConnectionDataNodeFunction(resolverContext, projectResolverChain);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
GradleExecutionHelper getHelper() {
|
||||
return myHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancelTask(@NotNull ExternalSystemTaskId id, @NotNull ExternalSystemTaskNotificationListener listener) {
|
||||
for (CancellationTokenSource cancellationTokenSource : myCancellationMap.get(id)) {
|
||||
|
||||
@@ -71,7 +71,6 @@ public class GradleTaskManager implements ExternalSystemTaskManager<GradleExecut
|
||||
public static final Key<String> INIT_SCRIPT_PREFIX_KEY = Key.create("INIT_SCRIPT_PREFIX_KEY");
|
||||
public static final Key<Collection<VersionSpecificInitScript>> VERSION_SPECIFIC_SCRIPTS_KEY = Key.create("VERSION_SPECIFIC_SCRIPTS_KEY");
|
||||
private static final Logger LOG = Logger.getInstance(GradleTaskManager.class);
|
||||
private final GradleExecutionHelper myHelper = new GradleExecutionHelper();
|
||||
|
||||
private final Map<ExternalSystemTaskId, CancellationTokenSource> myCancellationMap = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -118,7 +117,7 @@ public class GradleTaskManager implements ExternalSystemTaskManager<GradleExecut
|
||||
String rootProjectPath = determineRootProject(projectPath);
|
||||
GradleWrapperHelper.ensureInstalledWrapper(id, rootProjectPath, settings, listener, cancellationToken);
|
||||
}
|
||||
myHelper.execute(projectPath, settings, id, listener, cancellationToken, connection -> {
|
||||
GradleExecutionHelper.execute(projectPath, settings, id, listener, cancellationToken, connection -> {
|
||||
executeTasks(projectPath, id, settings, listener, connection, cancellationToken);
|
||||
return null;
|
||||
});
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@ import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
|
||||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType.EXECUTE_TASK
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.gradle.tooling.ProjectConnection
|
||||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper
|
||||
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings
|
||||
import org.junit.Test
|
||||
@@ -37,8 +38,10 @@ class GradleConnectorServiceIntegrationTest : GradleImportingTestCase() {
|
||||
private fun getExecutionSettings(projectPath: String): GradleExecutionSettings =
|
||||
ExternalSystemApiUtil.getExecutionSettings(myProject, projectPath, externalSystemId)
|
||||
|
||||
private fun requestConnection(projectPath: String, executionSettings: GradleExecutionSettings) = GradleExecutionHelper()
|
||||
.execute(projectPath, executionSettings, ExternalSystemTaskId.create(externalSystemId, EXECUTE_TASK, myProject), null, null) { it }
|
||||
private fun requestConnection(projectPath: String, executionSettings: GradleExecutionSettings): ProjectConnection {
|
||||
val taskId = ExternalSystemTaskId.create(externalSystemId, EXECUTE_TASK, myProject)
|
||||
return GradleExecutionHelper.execute(projectPath, executionSettings, taskId, null, null) { it }
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** It's sufficient to run the test against single gradle version. */
|
||||
|
||||
Reference in New Issue
Block a user