From b1854274e6fe127b9528fd182a9a89925e7ef16c Mon Sep 17 00:00:00 2001 From: Jose Labra Date: Thu, 6 Oct 2022 16:22:15 +0200 Subject: [PATCH] Local changes from flight --- .../main/scala/es/weso/utils/FileUtils.scala | 58 +++---------------- .../main/scala/es/weso/utils/notes/Roadmap.md | 18 ++++++ project/build.properties | 2 +- 3 files changed, 26 insertions(+), 52 deletions(-) create mode 100644 modules/utils/src/main/scala/es/weso/utils/notes/Roadmap.md diff --git a/modules/utils/src/main/scala/es/weso/utils/FileUtils.scala b/modules/utils/src/main/scala/es/weso/utils/FileUtils.scala index 90ea0b1..1f4a058 100644 --- a/modules/utils/src/main/scala/es/weso/utils/FileUtils.scala +++ b/modules/utils/src/main/scala/es/weso/utils/FileUtils.scala @@ -12,7 +12,11 @@ import cats.implicits._ object FileUtils { - def getFilesFromFolderWithExt(path: String, ext: String, ignoreFiles: List[String]): IO[List[File]] = IO { + def getFilesFromFolderWithExt( + path: String, + ext: String, + ignoreFiles: List[String] + ): IO[List[File]] = IO { val d = new File(path) if (d.exists && d.isDirectory) { d.listFiles.filter { file => @@ -45,36 +49,6 @@ object FileUtils { (splits.init.mkString("."), splits.last) } - /** Ensures to close a file. Follows the [[https://wiki.scala-lang.org/display/SYGN/Loan Loan pattern]] - */ - /* def using[A <: { def close(): Unit }, B](resource: A)(f: A => B): B = { - try { - f(resource) - } finally { - resource.close() - } - } */ - - /** Gets the contents of a file - * - * @param file - * file - */ - /*def getContents(file: File): EitherT[IO, String, CharSequence] = { - try { - using(Source.fromFile(file)("UTF-8")) { source => - EitherT.pure[IO,String](source.getLines.mkString("\n")) - } - } catch { - case e: FileNotFoundException => - EitherT.leftT[IO,CharSequence](s"Error reading file ${file.getAbsolutePath}: ${e.getMessage}") - case e: IOException => - EitherT.leftT[IO,CharSequence](s"IO Exception reading file ${file.getAbsolutePath}: ${e.getMessage}") - case e: Exception => - EitherT.leftT[IO,CharSequence](s"Exception reading file ${file.getAbsolutePath}: ${e.getMessage}") - } - }*/ - /** Gets the contents of a file * * @param fileName @@ -96,23 +70,7 @@ object FileUtils { ) with NoStackTrace - /* - def getContents(fileName: String): EitherT[IO, String, CharSequence] = { - try { - using(Source.fromFile(fileName)("UTF-8")) { source => - EitherT.pure[IO,String](source.getLines.mkString("\n")) - } - } catch { - case e: FileNotFoundException => - EitherT.leftT[IO,CharSequence](s"Error reading file ${fileName}: ${e.getMessage}") - case e: IOException => - EitherT.leftT[IO,CharSequence](s"IO Exception reading file ${fileName}: ${e.getMessage}") - case e: Exception => - EitherT.leftT[IO,CharSequence](s"Exception reading file ${fileName}: ${e.getMessage}") - } - } */ - - def getStream(fileName: String): Either[String, InputStreamReader] = { + def getStream(fileName: String): Either[String, InputStreamReader] = try { val source = Source.fromFile(fileName)("UTF-8") source.reader().asRight @@ -124,7 +82,6 @@ object FileUtils { case e: Exception => Left(s"Exception reading file ${fileName}: ${e.getMessage}") } - } /** Write contents to a file * @@ -151,9 +108,8 @@ object FileUtils { * @return * String with the line numbers of the char sequence */ - def formatLines(cs: CharSequence): String = { + def formatLines(cs: CharSequence): String = cs.toString.linesIterator.zipWithIndex.map(p => (p._2 + 1).toString + " " + p._1).mkString("\n") - } lazy val currentFolderURL: String = Paths.get(".").normalize.toUri.toURL.toExternalForm diff --git a/modules/utils/src/main/scala/es/weso/utils/notes/Roadmap.md b/modules/utils/src/main/scala/es/weso/utils/notes/Roadmap.md new file mode 100644 index 0000000..fff5867 --- /dev/null +++ b/modules/utils/src/main/scala/es/weso/utils/notes/Roadmap.md @@ -0,0 +1,18 @@ +# Roadmap + +We think that this whole repo should dissapear and be replaced for single purpose repos/components. In order to do that, we will include a list of the modules and potential repos: + +## Current modules + +- `typing`: Contains a generic `Typing` type class, it can be extracted to its own repo +- `validating`: contains a generic `Checker` trait that has been implemented in Cats. It was originally implemented using the `Eff` library. +- `utilsTest`: this module includes JsonMatchers which are no longer used +- `testSuite`: this module could be extracted as a single repo + + +The `utils` folder contains the following packages: +- `json`: contains several utilities to work with Json entities in Scala like `DecoderUtils`, `JsonCompare`, `JsonTest` and `JsonTwirl` +- `EitherUtils` contains two helper methods to work with Either values, `sequence` and `takeSingle` +- `FileUtils` contains some helper methods to work with files: `getContents`, `getFileFromFolderWithExt`, `writeFile`, `formatLines`, etc. + + diff --git a/project/build.properties b/project/build.properties index 4ff6415..b1e589d 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 \ No newline at end of file +sbt.version=1.7.1 \ No newline at end of file