Skip to content

Commit efcb9ad

Browse files
committed
removed implicit conversions from Directory/File to Path
1 parent 070a47d commit efcb9ad

File tree

7 files changed

+39
-36
lines changed

7 files changed

+39
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object EO:
8484
_ <- cfg.output.dirs.traverse_ { outDir =>
8585
for
8686
_ <- IO.println(s"Cleaning $outDir before writing...")
87-
_ <- outDir.createDirIfDoesntExist.flatMap(_.clean)
87+
_ <- outDir.toPath.createDirIfDoesntExist.flatMap(_.clean)
8888
yield ()
8989
}
9090
_ <- writeToDirs(analyzed)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ object Far:
5151
): IO[OdinAnalysisResult] =
5252
val codeFileNameNoExt: String = pathToCode.filenameNoExt
5353
val createPathToXml: IO[JPath] =
54-
(pathToTmpDir / "xmir").createDirIfDoesntExist.map(
55-
tmp =>
56-
pathToCode
57-
.mount(to = tmp, relativelyTo = pathToSrcRoot)
58-
.replaceExt(newExt = ".xml")
59-
.toNioPath
54+
(pathToTmpDir / "xmir").createDirIfDoesntExist.map(tmp =>
55+
pathToCode
56+
.mount(to = tmp, relativelyTo = pathToSrcRoot)
57+
.replaceExt(newExt = ".xml")
58+
.toPath
59+
.toNioPath
6060
)
6161

6262
for
@@ -65,7 +65,7 @@ object Far:
6565
_ <- IO.delay(
6666
new Syntax(
6767
codeFileNameNoExt,
68-
new InputOf(pathToCode.toNioPath),
68+
new InputOf(pathToCode.toPath.toNioPath),
6969
new OutputTo(pathToXml),
7070
).parse()
7171
)

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ object Java:
9696
// J2EO deletes the tmp directory when there are no files to analyze
9797
// This causes the subsequent call to EO.analyze to fail, because there is no temp directory.
9898
// The line below patches this issue by creating the temp directory if it was deleted by J2EO.
99-
_ <- Files[IO]
100-
.exists(cfg.tempDir)
101-
.ifM(
102-
ifTrue = IO.unit,
103-
ifFalse = Files[IO].createDirectories(dirForEO),
104-
)
99+
_ <- cfg.tempDir.toPath.createDirIfDoesntExist
105100
_ <- EO.analyze(
106101
cfg.copy(input = dirForEO)
107102
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ object Main extends IOApp:
129129
def analyze(filtered: NonEmptyList[EOAnalyzer]): IO[Unit] =
130130
for
131131
tempDir <- tmp match
132-
case Some(path) =>
133-
IO.println(s"Cleaning ${path.absolute}...") *>
134-
path.createDirIfDoesntExist.flatMap(_.clean)
132+
case Some(dir) =>
133+
IO.println(s"Cleaning ${dir.toPath.absolute}...") *>
134+
dir.clean
135135
case None =>
136136
Files[IO].createTempDirectory.flatMap(
137137
Directory.fromPathFailFast

src/main/scala/org/polystat/cli/util/FileTypes.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ object FileTypes:
1010
):
1111
override def toString = underlying.toString
1212
def toPath: Path = underlying
13+
def /(s: String): Path = underlying / s
1314

14-
given Conversion[Directory, Path] = _.underlying
1515
object Directory:
1616

1717
def fromPath(path: Path): IO[Option[Directory]] =
@@ -25,7 +25,10 @@ object FileTypes:
2525
def fromPathFailFast(path: Path): IO[Directory] =
2626
fromPath(path).flatMap {
2727
case Some(dir) => IO.pure(dir)
28-
case None => IO.raiseError(new Exception(s"$path must be a directory!"))
28+
case None =>
29+
IO.raiseError(
30+
new Exception(s"$path is either not a directory or does not exist!")
31+
)
2932
}
3033

3134
def fromPathUnsafe(path: Path): Directory = Directory(path)
@@ -40,8 +43,8 @@ object FileTypes:
4043
class File private[FileTypes] (private[FileTypes] val underlying: Path):
4144
override def toString(): String = underlying.toString
4245
def toPath = underlying
46+
def extName = underlying.extName
4347

44-
given Conversion[File, Path] = _.underlying
4548
object File:
4649
def fromPath(path: Path): IO[Option[File]] =
4750
Files[IO]
@@ -55,7 +58,11 @@ object FileTypes:
5558
fromPath(path).flatMap {
5659
case Some(file) => IO.pure(file)
5760
case None =>
58-
IO.raiseError(new Exception(s"$path must be a regular file!"))
61+
IO.raiseError(
62+
new Exception(
63+
s"$path is either not a regular file or does not exist!"
64+
)
65+
)
5966
}
6067

6168
def fromPathUnsafe(path: Path): File = File(path)

src/main/scala/org/polystat/cli/util/InputUtils.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,39 @@ object InputUtils:
5858
Stream
5959
.emit(file)
6060
.filter(_.extName.endsWith(ext))
61-
.flatMap(path =>
61+
.flatMap(file =>
6262
Files[IO]
63-
.readAll(path)
63+
.readAll(file.toPath)
6464
.through(utf8.decode)
65-
.map(code => (path, code))
65+
.map(code => (file, code))
6666
)
6767

6868
def readCodeFromDir(ext: String, dir: Directory): Stream[IO, (File, String)] =
6969
Files[IO]
70-
.walk(dir)
70+
.walk(dir.toPath)
7171
.evalMapFilter(path =>
7272
File.fromPath(path).map(_.filter(_.extName.endsWith(ext)))
7373
)
74-
.flatMap(path =>
74+
.flatMap(file =>
7575
Files[IO]
76-
.readAll(path)
76+
.readAll(file.toPath)
7777
.through(utf8.decode)
78-
.map(code => (path, code))
78+
.map(code => (file, code))
7979
)
8080

8181
def readCodeFromStdin: Stream[IO, String] = stdinUtf8[IO](4096).bufferAll
8282

83-
def readConfigFromFile(path: File): IO[PolystatUsage.Analyze] =
84-
HoconConfig(path).config.load
83+
def readConfigFromFile(file: File): IO[PolystatUsage.Analyze] =
84+
HoconConfig(file.toPath).config.load
8585

86-
def writeOutputTo(path: Path)(output: String): IO[Unit] =
86+
def writeOutputTo(file: File)(output: String): IO[Unit] =
8787
for
88-
_ <- path.parent
88+
_ <- file.toPath.parent
8989
.map(Files[IO].createDirectories)
9090
.getOrElse(IO.unit)
9191
_ <- Stream
9292
.emits(output.getBytes)
93-
.through(Files[IO].writeAll(path))
93+
.through(Files[IO].writeAll(file.toPath))
9494
.compile
9595
.drain
9696
yield ()

src/main/scala/org/polystat/sarif/SarifOutput.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import io.circe.Encoder
99
import io.circe.Json
1010
import io.circe.syntax.*
1111
import org.polystat.odin.analysis.EOOdinAnalyzer.OdinAnalysisResult
12+
import org.polystat.cli.util.FileTypes.*
1213

1314
import OdinAnalysisResult.*
1415
import Sarif.*
1516

16-
final case class SarifOutput(filePath: Path, errors: List[OdinAnalysisResult]):
17+
final case class SarifOutput(filePath: File, errors: List[OdinAnalysisResult]):
1718
private val sarifRun: SarifRun = SarifOutput.sarifRun(filePath, errors)
1819

1920
val sarif: SarifLog = SarifLog(Seq(sarifRun))
@@ -24,15 +25,15 @@ end SarifOutput
2425

2526
object SarifOutput:
2627

27-
def sarifRun(filePath: Path, errors: List[OdinAnalysisResult]): SarifRun =
28+
def sarifRun(filePath: File, errors: List[OdinAnalysisResult]): SarifRun =
2829
SarifRun(
2930
tool = SarifTool(SarifDriver()),
3031
results = errors.mapFilter(SarifOutput.sarifResult),
3132
invocations = errors.map(SarifOutput.sarifInvocation),
3233
artifacts = Seq(
3334
SarifArtifact(location =
3435
SarifArtifactLocation(uri =
35-
filePath.absolute.toNioPath.toUri.toString
36+
filePath.toPath.absolute.toNioPath.toUri.toString
3637
)
3738
)
3839
),

0 commit comments

Comments
 (0)