Skip to content

Commit 20427e6

Browse files
committed
Fixing code style issues.
1 parent 21560a2 commit 20427e6

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

src/main/scala/de/upb/cs/swt/delphi/cli/CsvOutput.scala

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ import java.io.{BufferedWriter, FileWriter}
2020

2121
import de.upb.cs.swt.delphi.cli.artifacts.Result
2222
import au.com.bytecode.opencsv.CSVWriter
23-
import de.upb.cs.swt.delphi.cli.commands.SearchCommand.information
24-
import de.vandermeer.asciitable.{AsciiTable, CWC_LongestLine}
25-
import de.vandermeer.skb.interfaces.transformers.textformat.TextAlignment
2623

27-
import scala.collection.mutable.ListBuffer
2824
import scala.collection.JavaConverters._
2925

3026
/**
@@ -38,32 +34,35 @@ import scala.collection.JavaConverters._
3834
class CsvOutput(config: Config) {
3935

4036
def exportResult(value: Any): Unit = {
41-
var table = value match {
42-
case results : Seq[Result] if results.head.isInstanceOf[Result] => resultsToCsv(results)
43-
case _ => {
44-
println("Error: results are in unknown format.")
45-
return
37+
printToCsv(
38+
value match {
39+
case results :
40+
Seq[Result] if results.headOption.getOrElse(Seq.empty[Array[String]]).isInstanceOf[Result] => resultsToCsv(results)
41+
case _ => Seq.empty[Array[String]]
4642
}
47-
}
43+
)
44+
}
4845

46+
def printToCsv(table : Seq[Array[String]]): Unit = {
4947
val outputFile = new BufferedWriter(new FileWriter(config.csv, /* append = */false))
5048
val csvWriter = new CSVWriter(outputFile)
5149
csvWriter.writeAll(seqAsJavaList(table))
5250
outputFile.close()
53-
println("Results written to file '" + config.csv + "'")
5451
}
5552

5653
def resultsToCsv(results : Seq[Result]) : Seq[Array[String]] = {
57-
if (results.size != 0) {
58-
val fieldNames = results.head.fieldNames()
59-
val tableHeader : Array[String] = (fieldNames.+:("discovered at").+:("version").+:("groupId").+:("artifactId").+:("source").+:("Id")).toArray
60-
val tableBody: Seq[Array[String]] = results.map {
54+
if (results.isEmpty) {
55+
Seq.empty[Array[String]]
56+
} else {
57+
val fieldNames = results.headOption.get.fieldNames()
58+
val tableHeader : Array[String] =
59+
fieldNames.+:("discovered at").+:("version").+:("groupId").+:("artifactId").+:("source").+:("Id").toArray
60+
results.map {
6161
e => {
62-
Array(e.id, e.metadata.source, e.metadata.artifactId, e.metadata.groupId, e.metadata.version, e.metadata.discovered).++(fieldNames.map(f => e.metricResults(f).toString))
62+
Array(e.id, e.metadata.source, e.metadata.artifactId, e.metadata.groupId, e.metadata.version,
63+
e.metadata.discovered).++(fieldNames.map(f => e.metricResults(f).toString))
6364
}
64-
}
65-
return tableBody.+:(tableHeader)
65+
}.+:(tableHeader)
6666
}
67-
return Seq.empty[Array[String]]
6867
}
6968
}

src/main/scala/de/upb/cs/swt/delphi/cli/DelphiCLI.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ object DelphiCLI extends App {
3232

3333
implicit val system = ActorSystem()
3434

35-
3635
val cliParser = {
3736
new scopt.OptionParser[Config]("delphi-cli") {
3837
head("Delphi Command Line Tool", s"(${BuildInfo.version})")
@@ -55,7 +54,8 @@ object DelphiCLI extends App {
5554
.children(
5655
arg[String]("id").action((x, c) => c.copy(id = x)).text("The ID of the project to retrieve"),
5756
opt[Unit]('f', "file").action((_, c) => c.copy(opts = List("file"))).text("Use to load the ID from file, " +
58-
"with the filepath given in place of the ID"), opt[String]("csv").action((x, c) => c.copy(csv = x)).text("Path to the output .csv file (overwrites existing file)")
57+
"with the filepath given in place of the ID"),
58+
opt[String]("csv").action((x, c) => c.copy(csv = x)).text("Path to the output .csv file (overwrites existing file)")
5959
)
6060

6161
cmd("search").action((s, c) => c.copy(mode = "search"))

src/main/scala/de/upb/cs/swt/delphi/cli/commands/RetrieveCommand.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ object RetrieveCommand extends Command with SprayJsonSupport with DefaultJsonPro
7474
success(config)(s"Found ${unmarshalled.size} item(s).")
7575
reportResult(config)(unmarshalled)
7676

77-
if(!config.csv.equals(""))
77+
if(!config.csv.equals("")) {
7878
exportResult(config)(unmarshalled)
79+
information(config)("Results written to file '" + config.csv + "'")
80+
}
7981

8082
Success(unmarshalled)
8183
}

src/main/scala/de/upb/cs/swt/delphi/cli/commands/SearchCommand.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import akka.util.ByteString
2929
import de.upb.cs.swt.delphi.cli.Config
3030
import de.upb.cs.swt.delphi.cli.artifacts.SearchResult
3131
import de.upb.cs.swt.delphi.cli.artifacts.SearchResultJson._
32+
import de.upb.cs.swt.delphi.cli.commands.RetrieveCommand.information
3233
import spray.json.DefaultJsonProtocol
3334

3435
import scala.concurrent.duration._
@@ -111,8 +112,10 @@ object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProto
111112

112113
information(config)(f"Query took $queryRuntime%.2fs.")
113114

114-
if(!config.csv.equals(""))
115+
if(!config.csv.equals("")) {
115116
exportResult(config)(results)
117+
information(config)("Results written to file '" + config.csv + "'")
118+
}
116119
}
117120

118121
case class Query(query: String,

0 commit comments

Comments
 (0)