Skip to content

Commit bc4cea9

Browse files
committed
converting Input to directory before analysis
1 parent 00a8a18 commit bc4cea9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ object Main extends IOApp:
8181
lang,
8282
AnalyzerConfig(inex, input, tmp, fmts, out),
8383
) =>
84+
val ext = lang match
85+
case SupportedLanguage.Java(_, _) => ".java"
86+
case SupportedLanguage.Python => ".py"
87+
case SupportedLanguage.EO => ".eo"
8488
for
8589
tempDir <- tmp match
8690
case Some(path) =>
@@ -96,6 +100,38 @@ object Main extends IOApp:
96100
.getOrElse(List())
97101

98102
_ <- warnMissingKeys(parsedKeys, EOAnalyzer.analyzers.map(_.ruleId))
103+
input <- input match
104+
case Input.FromDirectory(dir) => dir.pure[IO]
105+
case Input.FromFile(file) =>
106+
for
107+
singleFileCodeDir <-
108+
(tempDir / "singleFile").unsafeToDirectory.createDirIfDoesntExist
109+
singleFileCodePath =
110+
(singleFileCodeDir / (file.filenameNoExt + ext)).unsafeToFile
111+
singleFileCodeFile <-
112+
singleFileCodePath.unsafeToFile.createFileIfDoesntExist
113+
_ <- readCodeFromFile(ext, file)
114+
.map(_._2)
115+
.through(fs2.text.utf8.encode)
116+
.through(Files[IO].writeAll(singleFileCodePath))
117+
.compile
118+
.drain
119+
yield singleFileCodeDir
120+
case Input.FromStdin =>
121+
for
122+
stdinCodeDir <-
123+
(tempDir / "stdin").unsafeToDirectory.createDirIfDoesntExist
124+
stdinCodeFilePath =
125+
(stdinCodeDir / ("stdin" + ext)).unsafeToFile
126+
stdinCodeFile <- stdinCodeFilePath.createFileIfDoesntExist
127+
_ <-
128+
readCodeFromStdin
129+
.through(fs2.text.utf8.encode)
130+
.through(Files[IO].writeAll(stdinCodeFilePath))
131+
.compile
132+
.drain
133+
yield stdinCodeDir
134+
99135
processedConfig = ProcessedConfig(
100136
filteredAnalyzers = filterAnalyzers(inex),
101137
tempDir = tempDir,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object PolystatConfig:
2323
final case class ProcessedConfig(
2424
filteredAnalyzers: List[EOAnalyzer],
2525
tempDir: Directory,
26-
input: Input,
26+
input: Directory,
2727
fmts: List[OutputFormat],
2828
output: Output,
2929
)

0 commit comments

Comments
 (0)