Skip to content

Commit 0e8796e

Browse files
authored
Load local ivy path from ivy.home and user.home system properties (#2484)
* Load local ivy path from `ivy.home` and `user.home` system properties * Add tests for ivy.home and user.home overrides
1 parent b72d2a0 commit 0e8796e

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

modules/cli/src/main/scala/scala/cli/commands/publish/RepoParams.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ object RepoParams {
179179
}
180180

181181
def ivy2Local(ivy2HomeOpt: Option[os.Path]) = {
182-
val home = ivy2HomeOpt.getOrElse(os.home / ".ivy2")
182+
val home = ivy2HomeOpt
183+
.orElse(sys.props.get("ivy.home").map(prop => os.Path(prop)))
184+
.orElse(sys.props.get("user.home").map(prop => os.Path(prop) / ".ivy2"))
185+
.getOrElse(os.home / ".ivy2")
183186
val base = home / "local"
184187
// not really a Maven repo…
185188
RepoParams(

modules/integration/src/test/scala/scala/cli/integration/PublishLocalTestDefinitions.scala

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,74 @@ abstract class PublishLocalTestDefinitions(val scalaVersionOpt: Option[String])
145145
}
146146
}
147147

148+
test("publish local with ivy.home") {
149+
PublishTestInputs.inputs().fromRoot { root =>
150+
def publishLocal(): os.CommandResult =
151+
os.proc(
152+
TestUtil.cli,
153+
"--power",
154+
"publish",
155+
"local",
156+
".",
157+
"--working-dir",
158+
os.rel / "work-dir",
159+
extraOptions
160+
)
161+
.call(
162+
cwd = root,
163+
env = Map(
164+
"JAVA_OPTS" -> s"-Divy.home=${root / "ivyhome"} -Duser.home${root / "userhome"}"
165+
) // ivy.home takes precedence
166+
)
167+
168+
def output(): String =
169+
os.proc(
170+
TestUtil.cs,
171+
s"-J-Divy.home=${root / "ivyhome"}",
172+
"launch",
173+
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
174+
)
175+
.call(cwd = root)
176+
.out.trim()
177+
178+
publishLocal()
179+
expect(output() == "Hello")
180+
}
181+
}
182+
183+
test("publish local with user.home") {
184+
PublishTestInputs.inputs().fromRoot { root =>
185+
def publishLocal(): os.CommandResult =
186+
os.proc(
187+
TestUtil.cli,
188+
"--power",
189+
"publish",
190+
"local",
191+
".",
192+
"--working-dir",
193+
os.rel / "work-dir",
194+
extraOptions
195+
)
196+
.call(
197+
cwd = root,
198+
env = Map(
199+
"JAVA_OPTS" -> s"-Duser.home=${root / "userhome"}"
200+
)
201+
)
202+
203+
def output(): String =
204+
os.proc(
205+
TestUtil.cs,
206+
s"-J-Divy.home=${root / "userhome" / ".ivy2"}",
207+
"launch",
208+
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
209+
)
210+
.call(cwd = root)
211+
.out.trim()
212+
213+
publishLocal()
214+
expect(output() == "Hello")
215+
}
216+
}
217+
148218
}

0 commit comments

Comments
 (0)