Skip to content

Commit 33c981a

Browse files
author
nikololiahim
committed
download j2eo with coursier API
1 parent 30c70ba commit 33c981a

3 files changed

Lines changed: 29 additions & 31 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ out/
1616
hadoop_tmp
1717
**.jar
1818
!native-image-configs/*.json
19-
**.sarif
19+
**.sarif
20+
https/**

build.sbt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ releasePublishArtifactsAction := PgpKeys.publishSigned.value
3535
resolvers += Opts.resolver.sonatypeSnapshots
3636

3737
excludeDependencies ++= Seq(
38-
"org.scalatest" % "scalatest_2.13"
38+
"org.scalatest" % "scalatest_2.13",
39+
"org.scala-lang.modules" % "scala-xml_3",
3940
)
4041

4142
libraryDependencies ++= Seq(
@@ -53,6 +54,10 @@ libraryDependencies ++= Seq(
5354
"org.typelevel" %% "cats-parse" % "0.3.7",
5455
)
5556

57+
libraryDependencies ++= Seq(
58+
"io.get-coursier" %% "coursier" % "2.1.0-M6-26-gcec901e9a"
59+
).map(_.cross(CrossVersion.for3Use2_13))
60+
5661
packageOptions := Seq(
5762
sbt.Package.ManifestAttributes(
5863
("EO-Version", "https://github.com/polystat/polystat-cli/issues/18")

src/main/scala/org/polystat/cli/Java.scala

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,41 @@ import org.polystat.cli.util.InputUtils.*
1818
import sys.process.*
1919
import PolystatConfig.*
2020
import org.polystat.cli.util.FileTypes.*
21+
import coursier.`package`.{Organization, Module, ModuleName}
22+
import coursier.{Fetch, Dependency}
23+
import coursier.cache.FileCache
2124

2225
object Java:
23-
2426
private def j2eoPath(using j2eoVersion: String) = Path(
25-
s"j2eo-v$j2eoVersion.jar"
27+
s"https/repo1.maven.org/maven2/org/polystat/j2eo/${j2eoVersion}/j2eo-${j2eoVersion}.jar"
2628
)
2729
val DEFAULT_J2EO_VERSION = BuildInfo.j2eoVersion
28-
private def j2eoUrl(using j2eoVesion: String) =
29-
s"https://search.maven.org/remotecontent?filepath=org/polystat/j2eo/$j2eoVesion/j2eo-$j2eoVesion.jar"
30+
private def j2eoUrl(using j2eoVersion: String) =
31+
s"https://search.maven.org/remotecontent?filepath=org/polystat/j2eo/$j2eoVersion/j2eo-$j2eoVersion.jar"
3032

31-
private def defaultJ2EO(using j2eoVesion: String): IO[Path] =
33+
private def defaultJ2EO(using j2eoVersion: String): IO[Path] =
3234
Files[IO]
3335
.exists(j2eoPath)
3436
.ifM(
3537
ifTrue = IO.pure(j2eoPath),
3638
ifFalse = downloadJ2EO,
3739
)
3840

39-
private def downloadJ2EO(using j2eoVesion: String): IO[Path] =
40-
EmberClientBuilder
41-
.default[IO]
42-
.build
43-
.map(client => FollowRedirect(2, _ => true)(client))
44-
.use[Unit] { client =>
45-
client
46-
.run(
47-
Request[IO](
48-
GET,
49-
uri = Uri.unsafeFromString(j2eoUrl),
50-
)
51-
)
52-
.use(resp =>
53-
IO.println(
54-
s"$j2eoPath was not found in the current working directory. Downloading..."
55-
) *>
56-
resp.body
57-
.through(Files[IO].writeAll(j2eoPath))
58-
.compile
59-
.drain
41+
private def downloadJ2EO(using j2eoVersion: String): IO[Path] =
42+
val localCache = FileCache().withLocation(java.io.File("."))
43+
IO.delay(
44+
Fetch(localCache)
45+
.addDependencies(
46+
Dependency(
47+
Module(
48+
organization = Organization("org.polystat"),
49+
name = ModuleName("j2eo"),
50+
),
51+
version = j2eoVersion,
6052
)
61-
}
62-
.as(j2eoPath)
63-
end downloadJ2EO
53+
)
54+
.run()
55+
).as(j2eoPath)
6456

6557
private def runJ2EO(
6658
j2eoVersion: Option[String],

0 commit comments

Comments
 (0)