From 958868a69dd38497f3ef42e5cbd755ffe4e177cd Mon Sep 17 00:00:00 2001 From: Alexander Bubenchikov Date: Tue, 12 Aug 2025 14:49:48 +0200 Subject: [PATCH] [maven] [IDEA-377261] fix local repo attribute GitOrigin-RevId: 43c4ef32eec2e8520acba5266be7295587400048 --- .../execution/run/MavenShCommandLineState.kt | 5 +++- .../maven/execution/MavenExecutionTest.kt | 8 +++++-- .../execution/ScriptMavenExecutionTest.kt | 24 ++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/run/MavenShCommandLineState.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/run/MavenShCommandLineState.kt index 4c884811ab17..b9dfaed62b9c 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/run/MavenShCommandLineState.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/run/MavenShCommandLineState.kt @@ -332,7 +332,10 @@ class MavenShCommandLineState(val environment: ExecutionEnvironment, private val args.addAll("-s", generalSettings.userSettingsFile.asTargetPathString()) } if (generalSettings.localRepository.isNotBlank()) { - args.addProperty("-Dmaven.repo.local=${MavenSettingsCache.getInstance(myConfiguration.project).getEffectiveUserLocalRepo()}") + args.addProperty("maven.repo.local", Path.of(generalSettings.localRepository).asEelPath().toString()) + } + else { + args.addProperty("maven.repo.local", MavenSettingsCache.getInstance(myConfiguration.project).getEffectiveUserLocalRepo().asEelPath().toString()) } } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenExecutionTest.kt b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenExecutionTest.kt index ca4aa7ba2380..44d3a74a6bf0 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenExecutionTest.kt +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenExecutionTest.kt @@ -17,6 +17,7 @@ import com.intellij.openapi.util.io.toCanonicalPath import com.intellij.openapi.util.registry.Registry import com.intellij.util.concurrency.Semaphore import kotlinx.coroutines.runBlocking +import org.jetbrains.idea.maven.project.MavenGeneralSettings import org.junit.Test import kotlin.io.path.exists import kotlin.time.Duration @@ -66,7 +67,10 @@ abstract class MavenExecutionTest : MavenExecutionTestCase() { } - protected fun execute(params: MavenRunnerParameters, settings: MavenRunnerSettings = MavenRunnerSettings(), maxTimeToWait: Duration = 1.minutes): ExecutionInfo { + protected fun execute(params: MavenRunnerParameters, + settings: MavenRunnerSettings = MavenRunnerSettings(), + generalSettings: MavenGeneralSettings = mavenGeneralSettings, + maxTimeToWait: Duration = 1.minutes): ExecutionInfo { val sema = Semaphore() val stdout = StringBuilder() val stderr = StringBuilder() @@ -74,7 +78,7 @@ abstract class MavenExecutionTest : MavenExecutionTestCase() { sema.down() edt { MavenRunConfigurationType.runConfiguration( - project, params, mavenGeneralSettings, + project, params, generalSettings, settings, ProgramRunner.Callback { descriptor -> descriptor.processHandler!!.addProcessListener(MyTestExecutionListener(stdout, stderr, system, sema, descriptor)) diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/ScriptMavenExecutionTest.kt b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/ScriptMavenExecutionTest.kt index 4d08c002e221..93d029da4382 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/ScriptMavenExecutionTest.kt +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/ScriptMavenExecutionTest.kt @@ -189,9 +189,31 @@ class ScriptMavenExecutionTest : MavenExecutionTest() { val mavenOptsLineEnd = executionInfo.stdout.indexOf("\n", mavenOptsLineStarts) val mavenOptsLine = executionInfo.stdout.substring(mavenOptsLineStarts, mavenOptsLineEnd) assertTrue("MAVEN_OPTS should contain parameters, but was ${mavenOptsLine}", mavenOptsLine.contains("-XMyJavaParameter")) - } + @Test + fun testShouldExecuteMavenScriptWithLocalCache() = runBlocking { + importProjectAsync(""" + test + project + 1 + """ + ) + createFakeProjectWrapper() + mavenGeneralSettings.mavenHomeType = MavenWrapper + val executionInfo = execute(params = MavenRunnerParameters( + true, projectPath.toCanonicalPath(), + null as String?, + mutableListOf("verify"), emptyList()), + generalSettings = mavenGeneralSettings.clone().also { + it.setLocalRepository("/my/Path/To/Local/Repository") + } + ) + assertTrue("Should run wrapper", executionInfo.stdout.contains(wrapperOutput)) + assertTrue("Should proper pass local repository: ${executionInfo.system}", executionInfo.system.contains(" -Dmaven.repo.local=/my/Path/To/Local/Repository ")) + + } + companion object { const val wrapperOutput = "WRAPPER REPLACEMENT in Intellij tests" }