Skip to content

Commit 187fc53

Browse files
committed
added an option to specify a j2eo version to download
1 parent 9458684 commit 187fc53

File tree

5 files changed

+69
-33
lines changed

5 files changed

+69
-33
lines changed

src/main/scala/org/polystat/HoconConfig.scala

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ case class HoconConfig(path: Path):
5050
case (dirs, files, console) =>
5151
Output(dirs = dirs, files = files, console = console)
5252
}
53+
54+
private val j2eoVersion = hocon(keys.j2eoVersion).as[String].option
5355
private val outputFormats =
5456
hocon(keys.outputFormats).as[List[OutputFormat]].default(List.empty)
5557
private val inex: ConfigValue[IO, Option[IncludeExclude]] =
@@ -60,22 +62,32 @@ case class HoconConfig(path: Path):
6062
.option
6163

6264
val config: ConfigValue[IO, PolystatUsage.Analyze] =
63-
(j2eo, inex, input, tmp, outputs, outputFormats, lang).parMapN {
64-
case (j2eo, inex, input, tmp, outputs, outputFormats, lang) =>
65-
PolystatUsage.Analyze(
66-
language = lang match
67-
case Java(_) => Java(j2eo)
68-
case other => other
69-
,
70-
config = AnalyzerConfig(
71-
inex = inex,
72-
input = input,
73-
tmp = tmp,
74-
outputFormats = outputFormats,
75-
output = outputs,
76-
),
77-
)
78-
}
65+
(j2eo, j2eoVersion, inex, input, tmp, outputs, outputFormats, lang)
66+
.parMapN {
67+
case (
68+
j2eo,
69+
j2eoVersion,
70+
inex,
71+
input,
72+
tmp,
73+
outputs,
74+
outputFormats,
75+
lang,
76+
) =>
77+
PolystatUsage.Analyze(
78+
language = lang match
79+
case Java(_, _) => Java(j2eo, j2eoVersion)
80+
case other => other
81+
,
82+
config = AnalyzerConfig(
83+
inex = inex,
84+
input = input,
85+
tmp = tmp,
86+
outputFormats = outputFormats,
87+
output = outputs,
88+
),
89+
)
90+
}
7991
end HoconConfig
8092

8193
object HoconConfig:
@@ -94,13 +106,16 @@ object HoconConfig:
94106
val outputsConsole = s"$outputs.console"
95107
val outputsDirs = s"$outputs.dirs"
96108
val outputsFiles = s"$outputs.files"
109+
val j2eoVersion = "j2eoVersion"
97110
val explanation = s"""
98111
|$toplevel.$inputLanguage
99112
| The type of input files which will be analyzed. This key must be present.
100113
| Possible values:
101114
| "java" - only ".java" files will be analyzed.
102115
| "eo" - only ".eo" files will be analyzed.
103116
| "python" - only ".py" files will be analyzed.
117+
|$toplevel.$j2eoVersion
118+
| Specifies the version of J2EO to download.
104119
|$toplevel.$j2eo
105120
| Specifies the path to the J2EO executable.
106121
| If not specified, defaults to looking for j2eo.jar in the current working directory.
@@ -142,7 +157,7 @@ object HoconConfig:
142157
extension (s: String)
143158
def asSupportedLang: Option[SupportedLanguage] = s match
144159
case "eo" => Some(EO)
145-
case "java" => Some(Java(None))
160+
case "java" => Some(Java(None, None))
146161
case "python" => Some(Python)
147162
case _ => None
148163

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ import InputUtils.*
1919
object Java:
2020

2121
private val DEFAULT_J2EO_PATH = Path("j2eo.jar")
22-
private val J2EO_URL =
23-
"https://search.maven.org/remotecontent?filepath=org/polystat/j2eo/0.5.0/j2eo-0.5.0.jar"
22+
val DEFAULT_J2EO_VERSION = "0.5.0"
23+
private def j2eoUrl(j2eoVesion: String) =
24+
s"https://search.maven.org/remotecontent?filepath=org/polystat/j2eo/$j2eoVesion/j2eo-$j2eoVesion.jar"
2425

25-
private def defaultJ2EO: IO[Path] =
26+
private def defaultJ2EO(j2eoVesion: String): IO[Path] =
2627
Files[IO]
2728
.exists(DEFAULT_J2EO_PATH)
2829
.ifM(
2930
ifTrue = IO.pure(DEFAULT_J2EO_PATH),
30-
ifFalse = downloadJ2EO.as(DEFAULT_J2EO_PATH),
31+
ifFalse = downloadJ2EO(j2eoVesion),
3132
)
3233

33-
private def downloadJ2EO: IO[Unit] =
34+
private def downloadJ2EO(j2eoVesion: String): IO[Path] =
3435
EmberClientBuilder
3536
.default[IO]
3637
.build
@@ -40,7 +41,7 @@ object Java:
4041
.run(
4142
Request[IO](
4243
GET,
43-
uri = Uri.unsafeFromString(J2EO_URL),
44+
uri = Uri.unsafeFromString(j2eoUrl(j2eoVesion)),
4445
)
4546
)
4647
.use(resp =>
@@ -53,17 +54,21 @@ object Java:
5354
.drain
5455
)
5556
}
57+
.as(DEFAULT_J2EO_PATH)
5658
end downloadJ2EO
5759

5860
private def runJ2EO(
61+
j2eoVersion: Option[String],
5962
j2eo: Option[Path],
6063
inputDir: Path,
6164
outputDir: Path,
6265
): IO[Unit] =
6366
val command =
6467
s"java -jar ${j2eo.getOrElse(DEFAULT_J2EO_PATH)} -o $outputDir $inputDir"
6568
for
66-
j2eo <- j2eo.map(IO.pure).getOrElse(defaultJ2EO)
69+
j2eo <- j2eo
70+
.map(IO.pure)
71+
.getOrElse(defaultJ2EO(j2eoVersion.getOrElse(DEFAULT_J2EO_VERSION)))
6772
_ <- Files[IO]
6873
.exists(j2eo)
6974
.ifM(
@@ -77,7 +82,11 @@ object Java:
7782
end for
7883
end runJ2EO
7984

80-
def analyze(j2eo: Option[Path], cfg: ProcessedConfig): IO[Unit] =
85+
def analyze(
86+
j2eoVersion: Option[String],
87+
j2eo: Option[Path],
88+
cfg: ProcessedConfig,
89+
): IO[Unit] =
8190
for
8291
tmp <- cfg.tempDir
8392
_ <- cfg.input match // writing EO files to tempDir
@@ -88,12 +97,17 @@ object Java:
8897
path / "stdin.eo"
8998
)
9099
_ <- writeOutputTo(stdinTmp)(code)
91-
_ <- runJ2EO(j2eo, inputDir = stdinTmp, outputDir = tmp)
100+
_ <- runJ2EO(
101+
j2eoVersion,
102+
j2eo,
103+
inputDir = stdinTmp,
104+
outputDir = tmp,
105+
)
92106
yield ()
93107
case Input.FromFile(path) =>
94-
runJ2EO(j2eo, inputDir = path, outputDir = tmp)
108+
runJ2EO(j2eoVersion, j2eo, inputDir = path, outputDir = tmp)
95109
case Input.FromDirectory(path) =>
96-
runJ2EO(j2eo, inputDir = path, outputDir = tmp)
110+
runJ2EO(j2eoVersion, j2eo, inputDir = path, outputDir = tmp)
97111
_ <- EO.analyze(
98112
cfg.copy(input = Input.FromDirectory(tmp))
99113
)

src/main/scala/org/polystat/Main.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ object Main extends IOApp:
8282
val analysisResults: IO[Unit] =
8383
lang match
8484
case SupportedLanguage.EO => EO.analyze(processedConfig)
85-
case SupportedLanguage.Java(j2eo) =>
86-
Java.analyze(j2eo, processedConfig)
85+
case SupportedLanguage.Java(j2eo, j2eoVersion) =>
86+
Java.analyze(j2eoVersion, j2eo, processedConfig)
8787
case SupportedLanguage.Python => Python.analyze(processedConfig)
8888
analysisResults
8989
end execute

src/main/scala/org/polystat/PolystatConfig.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object PolystatConfig:
2828

2929
enum SupportedLanguage:
3030
case EO, Python
31-
case Java(j2eo: Option[Path])
31+
case Java(j2eo: Option[Path], j2eoVersion: Option[String])
3232
end SupportedLanguage
3333

3434
enum PolystatUsage:

src/main/scala/org/polystat/PolystatOpts.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ object PolystatOpts:
4545
name = "java",
4646
help = "Analyze Java files",
4747
) {
48-
(analyzerConfig, j2eo).mapN((conf, j2eo) =>
48+
(analyzerConfig, j2eo, j2eoVersion).mapN((conf, j2eo, j2eoVesion) =>
4949
conf.map(conf =>
50-
PolystatUsage.Analyze(SupportedLanguage.Java(j2eo), conf)
50+
PolystatUsage.Analyze(SupportedLanguage.Java(j2eo, j2eoVesion), conf)
5151
)
5252
)
5353
}
5454

55+
def j2eoVersion: Opts[Option[String]] = Opts
56+
.option[String](
57+
long = "j2eo-version",
58+
help = "Version of j2eo to download.",
59+
)
60+
.orNone
61+
5562
def j2eo: Opts[Option[Path]] = Opts
5663
.option[JPath](
5764
long = "j2eo",

0 commit comments

Comments
 (0)