diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerEnvironmentSetupImpl.kt b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerEnvironmentSetupImpl.kt index 8ca4feee05ff..ede678390f63 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerEnvironmentSetupImpl.kt +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerEnvironmentSetupImpl.kt @@ -115,9 +115,14 @@ internal class GradleServerEnvironmentSetupImpl( targetBuildParametersBuilder.useInstallation(it) } + configureJdk(javaParameters, request, consumerOperationParameters, targetPathMapper, environmentConfiguration) progressIndicator.checkCanceled() - val targetArguments = - prepareTargetEnvironmentRequest(request, consumerOperationParameters, targetPathMapper, environmentConfiguration, progressIndicator) + val targetArguments = prepareTargetEnvironmentRequest( + request, + consumerOperationParameters, + environmentConfiguration, + progressIndicator + ) progressIndicator.checkCanceled() val targetedCommandLineBuilder = javaParameters.toCommandLine(request) @@ -130,7 +135,7 @@ internal class GradleServerEnvironmentSetupImpl( } } - projectUploadRoot = setupTargetProjectDirectories(consumerOperationParameters, request, targetedCommandLineBuilder) + projectUploadRoot = setupTargetProjectDirectories(consumerOperationParameters.projectDir, request, targetedCommandLineBuilder) val remoteEnvironment = request.prepareEnvironment(progressIndicator) targetEnvironment = remoteEnvironment EP.forEachExtensionSafe { @@ -146,6 +151,7 @@ internal class GradleServerEnvironmentSetupImpl( progressIndicator.checkCanceled() targetEnvironmentProvider.supplyEnvironmentAndRunHandlers(remoteEnvironment, progressIndicator) + targetEnvironmentProvider.uploadVolumes(progressIndicator) val pathsToMap = extractPathsToMapFromInitScripts(initScripts) val pathMapperInitScript = createTargetPathMapperInitScript( @@ -168,20 +174,18 @@ internal class GradleServerEnvironmentSetupImpl( return targetedCommandLineBuilder.build() } - private fun setupTargetProjectDirectories(consumerOperationParameters: ConsumerOperationParameters, - request: TargetEnvironmentRequest, - targetedCommandLineBuilder: @NotNull TargetedCommandLineBuilder): TargetEnvironment.UploadRoot { + private fun setupTargetProjectDirectories( + workingDir: File, + request: TargetEnvironmentRequest, + targetedCommandLineBuilder: @NotNull TargetedCommandLineBuilder, + ): TargetEnvironment.UploadRoot { val pathsToUpload: MutableSet = HashSet() - val workingDir = consumerOperationParameters.projectDir val gradleProjectDirectory = FileUtilRt.toSystemDependentName(workingDir.path) pathsToUpload.add(gradleProjectDirectory) - val projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings( - ExternalSystemApiUtil.toCanonicalPath(workingDir.path)) - projectSettings?.modules - ?.filter { Files.exists(Path.of(it)) } - ?.mapTo(pathsToUpload) { FileUtilRt.toSystemDependentName(it) } + val projectModules = getProjectModules(workingDir) + pathsToUpload.addAll(projectModules) val commonAncestor = findCommonAncestor(pathsToUpload) val uploadPath = Paths.get(FileUtilRt.toSystemDependentName(commonAncestor!!)) @@ -208,6 +212,16 @@ internal class GradleServerEnvironmentSetupImpl( return uploadRoot } + private fun getProjectModules(workingDir: File): Set { + val externalProjectPath = ExternalSystemApiUtil.toCanonicalPath(workingDir.path) + val projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(externalProjectPath) + return projectSettings?.modules + ?.filter { Files.exists(Path.of(it)) } + ?.map { FileUtilRt.toSystemDependentName(it) } + ?.toSet() + ?: emptySet() + } + private fun findCommonAncestor(paths: Set): String? { var commonRoot: File? = null for (path in paths) { @@ -258,11 +272,13 @@ internal class GradleServerEnvironmentSetupImpl( return mapperInitScript.toString() } - private fun prepareTargetEnvironmentRequest(request: TargetEnvironmentRequest, - consumerOperationParameters: ConsumerOperationParameters, - targetPathMapper: PathMapper?, - environmentConfiguration: TargetEnvironmentConfiguration, - progressIndicator: TargetProgressIndicator): List?>> { + private fun configureJdk( + javaParameters: SimpleJavaParameters, + request: TargetEnvironmentRequest, + consumerOperationParameters: ConsumerOperationParameters, + targetPathMapper: PathMapper?, + environmentConfiguration: TargetEnvironmentConfiguration, + ) { if (request is LocalTargetEnvironmentRequest) { javaParameters.vmParametersList.addProperty(Main.LOCAL_BUILD_PROPERTY, "true") val javaHomePath = consumerOperationParameters.javaHome.path @@ -276,9 +292,13 @@ internal class GradleServerEnvironmentSetupImpl( environmentConfiguration.addLanguageRuntime(javaLanguageRuntimeConfiguration) } } + } + private fun prepareTargetEnvironmentRequest(request: TargetEnvironmentRequest, + consumerOperationParameters: ConsumerOperationParameters, + environmentConfiguration: TargetEnvironmentConfiguration, + progressIndicator: TargetProgressIndicator): List?>> { val targetArguments = requestFileArgumentsUpload(request, consumerOperationParameters, environmentConfiguration) - EP.forEachExtensionSafe { it.prepareTargetEnvironmentRequest(request, this, progressIndicator) } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/TargetEnvironmentProvider.kt b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/TargetEnvironmentProvider.kt index 9f6c1b788e5d..f9afc6be03ce 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/TargetEnvironmentProvider.kt +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/TargetEnvironmentProvider.kt @@ -32,6 +32,9 @@ internal class TargetEnvironmentProvider { promise.blockingGet(0) // Just rethrows errors. } dependingOnEnvironmentPromise.clear() + } + + fun uploadVolumes(progressIndicator: GradleServerProgressIndicator) { for (upload in uploads) { progressIndicator.checkCanceled() upload.volume.upload(upload.relativePath, progressIndicator)