Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ name: Release Drafter
on:
push:
branches:
- main

pull_request:
types: [opened, reopened, synchronize]
- master

permissions:
contents: read
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ fabric.properties
# Editor-based Rest Client
.idea/httpRequests
### Scala template

.bsp
4 changes: 0 additions & 4 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
rules = [
DisableSyntax
// ExplicitResultTypes // Waiting for: https://github.com/scalacenter/scalafix/issues/1583
LeakingImplicitClassVal
NoAutoTupling
NoValInForComprehension
OrganizeImports
RemoveUnused
RedundantSyntax
]

Expand Down
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import BuildHelper.*

ThisBuild / organization := "com.guizmaii"
ThisBuild / scalaVersion := "2.13.18"
ThisBuild / scalaVersion := "3.3.7"

ThisBuild / scalafmtCheck := true
ThisBuild / scalafmtSbtCheck := true
ThisBuild / scalafmtOnCompile := !insideCI.value
ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision // use Scalafix compatible version

ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT"))
ThisBuild / homepage := Some(url("https://github.com/guizmaii-opensource/JRubyConcurrentConstantMemoryExcel"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook
import java.io.{File, FileOutputStream}
import java.nio.file.{Files, Path}
import java.util.UUID
import scala.annotation.{nowarn, switch}
import scala.annotation.switch
import scala.collection.immutable.SortedSet
import scala.collection.mutable.ListBuffer
import scala.io.Codec

sealed abstract class Cell extends Product with Serializable
object Cell {
private[excel] case object BlankCell extends Cell
private[excel] final case class StringCell(value: String) extends Cell
private[excel] final case class NumericCell(value: Double) extends Cell
enum Cell {
case BlankCell
case StringCell(value: String)
case NumericCell(value: Double)
}

object Cell {
private[excel] final val BLANK_CELL = 'b'
private[excel] final val STRING_CELL = 's'
private[excel] final val NUMERIC_CELL = 'n'

implicit private[excel] final val encoder: CellEncoder[Cell] = {
private[excel] given CellEncoder[Cell] = {
case BlankCell => s"$BLANK_CELL:"
case StringCell(value) => s"$STRING_CELL:$value"
case NumericCell(value) => s"$NUMERIC_CELL:$value"
}

implicit private[excel] final val decoder: CellDecoder[Cell] =
private[excel] given CellDecoder[Cell] =
CellDecoder.fromUnsafe { s =>
val Array(cellType, data) = s.split(":", 2)
val Array(cellType, data) = s.split(":", 2): @unchecked
(cellType(0): @switch) match {
case BLANK_CELL => Cell.BlankCell
case STRING_CELL => Cell.StringCell(data)
Expand All @@ -45,13 +46,11 @@ object Cell {
}
}

@nowarn // TODO: Remove this nowarm when upgrading to Scala3
final case class Page private[excel] (index: Int, path: Path)
private[excel] object Page {
implicit final val ordering: Ordering[Page] = Ordering.by(_.index)
given Ordering[Page] = Ordering.by(_.index)
}

@nowarn // TODO: Remove this nowarm when upgrading to Scala3
final case class ConcurrentConstantMemoryState private[excel] (
sheetName: String,
headerData: Array[String],
Expand All @@ -62,16 +61,15 @@ final case class ConcurrentConstantMemoryState private[excel] (

object ConcurrentConstantMemoryExcel {

import kantan.csv._
import kantan.csv.ops._
import kantan.csv.*
import kantan.csv.ops.*
// https://nrinaudo.github.io/kantan.csv/bom.html
import kantan.codecs.resource.bom._
import kantan.codecs.resource.bom.*

private[excel] type Row = Array[Cell]

implicit private[this] final val codec: Codec = Codec.UTF8
implicit private[this] final val scheduler: Scheduler =
Scheduler.computation(name = "ConcurrentConstantMemoryExcel-computation")
private given Codec = Codec.UTF8
private given Scheduler = Scheduler.computation(name = "ConcurrentConstantMemoryExcel-computation")

final val blankCell: Cell = Cell.BlankCell

Expand Down Expand Up @@ -150,7 +148,7 @@ object ConcurrentConstantMemoryExcel {

// TODO: Expose the `swallowIOExceptions` parameter in the `writeFile` function ?
def clean(swallowIOExceptions: Boolean = false): Task[Unit] = Task {
import better.files._ // better-files `delete()` method also works on directories, unlike the Java one.
import better.files.* // better-files `delete()` method also works on directories, unlike the Java one.
cms.tmpDirectory.toScala.delete(swallowIOExceptions)
()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.collection.immutable.ArraySeq

private[excel] object KantanExtension {

implicit final def arrayEncoder[A](implicit CellEncoder: CellEncoder[A]): RowEncoder[Array[A]] =
(array: Array[A]) => ArraySeq.unsafeWrapArray(array).map(CellEncoder.encode)
given arrayEncoder[A](using cellEncoder: CellEncoder[A]): RowEncoder[Array[A]] =
(array: Array[A]) => ArraySeq.unsafeWrapArray(array).map(cellEncoder.encode)

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.io.File
import java.nio.file.Files
import java.util.Date
import scala.annotation.nowarn
import scala.language.implicitConversions

@nowarn("msg=unused value")
class ConcurrentConstantMemoryExcelSpec extends AnyFlatSpec with Matchers {
Expand All @@ -16,14 +17,15 @@ class ConcurrentConstantMemoryExcelSpec extends AnyFlatSpec with Matchers {
true shouldBe true
}

import ConcurrentConstantMemoryExcel._
import ConcurrentConstantMemoryExcel.*

val sheet_name = "SHEET_NAME"
val headers = Array("A", "B", "C")

// Ugly but handy. Don't abuse of that !
implicit final def toCell(value: String): Cell = if (value.isEmpty) blankCell else stringCell(value)
implicit final def toCell(value: Double): Cell = numericCell(value)
given Conversion[String, Cell] = value => if (value.isEmpty) blankCell else stringCell(value)
given Conversion[Double, Cell] = value => numericCell(value)
given Conversion[Int, Cell] = value => numericCell(value.toDouble)

def newCMSPlz: Atomic[ConcurrentConstantMemoryState] = newWorkbookState(sheet_name, headers)
def row(cells: Cell*): Array[Cell] = cells.toArray
Expand Down
7 changes: 2 additions & 5 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ object BuildHelper {
lazy val stdSettings =
Seq(
javacOptions ++= Seq("-source", javaTarget, "-target", javaTarget),
scalacOptions ++= Seq("-Xsource:3"), // TODO: Remove when upgrading to Scala3
// TODO: Re-enable when upgrading to Scala3
// scalacOptions ++= Seq("-no-indent"), // See https://x.com/ghostdogpr/status/1706589471469425074
// TODO: Re-enable when upgrading to Scala3
// scalacOptions ++= Seq("-language:noAutoTupling"), // See https://github.com/scala/scala3/discussions/19255
scalacOptions ++= Seq("-no-indent"), // See https://x.com/ghostdogpr/status/1706589471469425074
scalacOptions ++= Seq("-language:noAutoTupling"), // See https://github.com/scala/scala3/discussions/19255
scalacOptions ++= Seq(s"-release:$javaTarget"),
scalacOptions --= (if (insideCI.value) Nil else Seq("-Xfatal-warnings")),
// format: off
Expand Down