[maven] [IDEA-377261] fix local repo attribute

GitOrigin-RevId: 43c4ef32eec2e8520acba5266be7295587400048
This commit is contained in:
Alexander Bubenchikov
2025-08-12 16:45:20 +00:00
committed by intellij-monorepo-bot
parent ef526147ef
commit 958868a69d
3 changed files with 33 additions and 4 deletions
@@ -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())
}
}
@@ -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<RuntimeException> {
MavenRunConfigurationType.runConfiguration(
project, params, mavenGeneralSettings,
project, params, generalSettings,
settings,
ProgramRunner.Callback { descriptor ->
descriptor.processHandler!!.addProcessListener(MyTestExecutionListener(stdout, stderr, system, sema, descriptor))
@@ -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("""
<groupId>test</groupId>
<artifactId>project</artifactId>
<version>1</version>
"""
)
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"
}