Skip to content

Commit

Permalink
fix structure pre scala3
Browse files Browse the repository at this point in the history
  • Loading branch information
barryoneill committed May 14, 2024
1 parent 8987cd7 commit f2f9800
Show file tree
Hide file tree
Showing 39 changed files with 109 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.laserdisc.mysql.binlog.models

import cats.implicits._
import doobie._
import doobie.implicits._
import cats.implicits.*
import doobie.*
import doobie.implicits.*
import cats.effect.MonadCancel

case class BinaryLogs(fileName: String, size: Long)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.laserdisc.mysql.binlog.models

import java.io.Serializable
import com.github.shyiko.mysql.binlog.event.DeleteRowsEventData as JDeleteRowsEventData

import com.github.shyiko.mysql.binlog.event.{DeleteRowsEventData => JDeleteRowsEventData}

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
object DeleteRowsEventData {
def unapply(arg: JDeleteRowsEventData): Option[(Long, List[Array[Serializable]], Array[Int])] =
Some((arg.getTableId, arg.getRows.asScala.toList, arg.getIncludedColumns.stream().toArray))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{EventHeaderV4 => JEventHeaderV4, EventType}
import com.github.shyiko.mysql.binlog.event.{EventHeaderV4 as JEventHeaderV4, EventType}

object EventHeaderV4 {
def unapply(arg: JEventHeaderV4): Option[(EventType, Long, Long)] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{QueryEventData => JQueryEventData}
import com.github.shyiko.mysql.binlog.event.QueryEventData as JQueryEventData

object QueryEventData {
def truncateTable(sql: String) = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{RotateEventData => JRotateEventData}
import com.github.shyiko.mysql.binlog.event.RotateEventData as JRotateEventData

object RotateEventData {
def unapply(arg: JRotateEventData): Option[(String, Long)] =
Some((arg.getBinlogFilename, arg.getBinlogPosition))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.laserdisc.mysql.binlog.models

import doobie._
import doobie.implicits._
import doobie.*
import doobie.implicits.*

import scala.collection.mutable
import cats.effect.MonadCancel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{TableMapEventData => JTableMapEventData}
import com.github.shyiko.mysql.binlog.event.TableMapEventData as JTableMapEventData

object TableMapEventData {
def unapply(arg: JTableMapEventData): Option[(Long, String, String)] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package io.laserdisc.mysql.binlog.models

import java.io
import com.github.shyiko.mysql.binlog.event.UpdateRowsEventData as JUpdateRowsEventData

import com.github.shyiko.mysql.binlog.event.{UpdateRowsEventData => JUpdateRowsEventData}

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

object UpdateRowsEventData {
def unapply(
arg: JUpdateRowsEventData
): Some[(Long, List[(Array[io.Serializable], Array[io.Serializable])], Array[Int])] = {
): Some[(Long, List[(Array[Serializable], Array[Serializable])], Array[Int])] = {
val beforeAfter =
arg.getRows.asScala.toList.map(entry => entry.getKey -> entry.getValue)
Some((arg.getTableId, beforeAfter, arg.getIncludedColumns.stream().toArray))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.laserdisc.mysql.binlog.models

import java.io.Serializable
import com.github.shyiko.mysql.binlog.event.WriteRowsEventData as JWriteRowsEventData

import com.github.shyiko.mysql.binlog.event.{WriteRowsEventData => JWriteRowsEventData}

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

object WriteRowsEventData {
def unapply(arg: JWriteRowsEventData): Option[(Long, List[Array[Serializable]], Array[Int])] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{XidEventData => JXidEventData}
import com.github.shyiko.mysql.binlog.event.XidEventData as JXidEventData

object XidEventData {
def unapply(arg: JXidEventData): Option[Long] = Some(arg.getXid)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.laserdisc.mysql.binlog

import cats.effect.Sync
import cats.implicits._
import cats.implicits.*
import com.github.shyiko.mysql.binlog.BinaryLogClient
import org.typelevel.log4cats.Logger
import io.laserdisc.mysql.binlog.checkpoint.BinlogOffset
import io.laserdisc.mysql.binlog.config.BinLogConfig
import io.laserdisc.mysql.binlog.config.{BinLogConfig, BinLogConfigOps}
import org.typelevel.log4cats.Logger

package object client {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.circe.Json
import io.laserdisc.mysql.binlog.event.EventMessage

import scala.collection.mutable
import cats.implicits._
import cats.implicits.*
import io.laserdisc.mysql.json

package object compaction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.laserdisc.mysql.binlog

import cats.effect._
import doobie._
import cats.effect.*
import doobie.*
import doobie.hikari.HikariTransactor
import io.laserdisc.mysql.binlog.config.BinLogConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.laserdisc.mysql.binlog.stream

import cats.effect.std.{Dispatcher, Queue}
import cats.effect.{Async, IO, LiftIO}
import cats.implicits._
import cats.implicits.*
import com.github.shyiko.mysql.binlog.BinaryLogClient
import com.github.shyiko.mysql.binlog.event.Event
import fs2.Stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package io.laserdisc.mysql.binlog.stream

import cats.data.State
import cats.effect.{Ref, Sync}
import cats.implicits._
import cats.implicits.*
import com.github.shyiko.mysql.binlog.BinaryLogClient
import com.github.shyiko.mysql.binlog.event.EventType.{EXT_UPDATE_ROWS, UPDATE_ROWS}
import com.github.shyiko.mysql.binlog.event.deserialization.json.JsonBinary
import com.github.shyiko.mysql.binlog.event.{Event, EventData, EventHeaderV4 => JEventHeaderV4, EventType}
import com.github.shyiko.mysql.binlog.event.{Event, EventData, EventHeaderV4 as JEventHeaderV4, EventType}
import io.circe.Json
import io.laserdisc.mysql.binlog.event.EventMessage
import io.laserdisc.mysql.binlog.models._
import io.laserdisc.mysql.binlog.models.*
import org.typelevel.log4cats.Logger

import java.math.BigDecimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.laserdisc.mysql.binlog

import cats.effect.kernel.Ref
import cats.effect.{Concurrent, Sync}
import cats.implicits._
import cats.implicits.*
import com.github.shyiko.mysql.binlog.event.Event
import org.typelevel.log4cats.Logger
import io.laserdisc.mysql.binlog.event.EventMessage
Expand All @@ -13,14 +13,14 @@ package object stream {
schema: String
): fs2.Pipe[F, Event, EventMessage] =
_.through(streamTransactionPackages[F](transactionState, schema)).flatMap(pkg =>
fs2.Stream.eval(warnBigTransactionPackage(pkg)) >> fs2.Stream(pkg.events: _*)
fs2.Stream.eval(warnBigTransactionPackage(pkg)) >> fs2.Stream(pkg.events*)
)

def streamCompactedEvents[F[_]: Concurrent: Logger](
transactionState: Ref[F, TransactionState],
schema: String
): fs2.Pipe[F, Event, EventMessage] =
_.through(streamTransactionPackages[F](transactionState, schema)).flatMap(pkg => fs2.Stream(compaction.compact(pkg.events): _*))
_.through(streamTransactionPackages[F](transactionState, schema)).flatMap(pkg => fs2.Stream(compaction.compact(pkg.events)*))

def streamTransactionPackages[F[_]: Concurrent: Logger](
transactionState: Ref[F, TransactionState],
Expand Down
28 changes: 8 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sbt.Keys.scalaSource

organization := "io.laserdisc"
name := "mysql-binlog-stream"

ThisBuild / scalaVersion := "2.13.14"
lazy val scala213 = "2.13.14"
lazy val scala3 = "3.4.1"
lazy val supportedScalaVersions = List(scala213, scala3)

ThisBuild / crossScalaVersions := supportedScalaVersions
ThisBuild / scalaVersion := scala3

lazy val commonSettings = Seq(
organization := "io.laserdisc",
Expand All @@ -13,26 +17,10 @@ lazy val commonSettings = Seq(
),
licenses ++= Seq(("MIT", url("http://opensource.org/licenses/MIT"))),
homepage := Some(url("https://github.com/laserdisc-io/fs2-aws")),
Compile / scalaSource := baseDirectory.value / "app",
Compile / resourceDirectory := baseDirectory.value / "conf",
Test / scalaSource := baseDirectory.value / "test",
Test / resourceDirectory := baseDirectory.value / "test_resources",
Test / parallelExecution := false,
Test / fork := true,
scalacOptions ++= Seq(
"-encoding",
"UTF-8", // source files are in UTF-8
"-deprecation", // warn about use of deprecated APIs
"-unchecked", // warn about unchecked type parameters
"-feature", // warn about misused language features
"-language:higherKinds", // allow higher kinded types without `import scala.language.higherKinds`
"-language:implicitConversions", // allow use of implicit conversions
"-language:postfixOps", // enable postfix ops
"-Xlint:_,-byname-implicit", // enable handy linter warnings
"-Xfatal-warnings", // turn compiler warnings into errors
"-Ywarn-macros:after" // allows the compiler to resolve implicit imports being flagged as unused
),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")
scalacOptions ++= BuildOptions.scalacOptions(scalaVersion.value),
libraryDependencies ++= BuildOptions.compilerPlugins(scalaVersion.value)
)

lazy val noPublishSettings = Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.laserdisc.mysql

import io.circe._
import io.circe.parser._
import io.circe.*
import io.circe.parser.*

package object json {
def flatHash(doc: String, removeKey: String = ""): Either[Exception, String] =
Expand Down Expand Up @@ -37,7 +37,7 @@ package object json {
def onBoolean(v: Boolean) = List(v.toString)
def onNumber(v: JsonNumber) = List(v.toString)
def onString(v: String) = List(v.trim)
def onNull = Nil
def onNull = List.empty[String]
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EventMessageTest extends AnyWordSpec with Matchers {
"EventMessage" should {
"be orderable by Offset" in {

import OffsetTest._
import OffsetTest.*
import OffsetOrdering.ordering

evtMsg(FILE_A, offset = 123) should be < evtMsg(FILE_B, offset = 999)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.laserdisc.mysql.binlog.event

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import OffsetTest._
import OffsetTest.*

object OffsetTest {
val FILE_A = "mysql-bin-changelog.001450"
Expand Down
65 changes: 65 additions & 0 deletions project/BuildOptions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import sbt.*

object BuildOptions {

def scalacOptions(scalaVersion: String): Seq[String] =
Scalac.Common ++ (CrossVersion.partialVersion(scalaVersion) match {
case Some((3, _)) => Scalac.Version3x
case Some((2, _)) => Scalac.Version2x
case _ => Seq.empty
})

def compilerPlugins(scalaVersion: String): Seq[sbt.ModuleID] =
Compiler.Common ++ (CrossVersion.partialVersion(scalaVersion) match {
case Some((2, _)) => Compiler.Scala2x
case _ => Seq.empty
})

object Scalac {

lazy val Common: Seq[String] = Seq(
"-encoding",
"UTF-8",
"-deprecation",
"-unchecked",
"-feature",
"-language:existentials,experimental.macros,higherKinds,implicitConversions,postfixOps",
"-Wconf:src=src_managed/.*:silent",
"-Xfatal-warnings"
)

lazy val Version3x: Seq[String] = Seq(
"-Yretain-trees",
"-Ykind-projector:underscores",
"-source:future",
"-language:adhocExtensions",
"-Wconf:msg=`= _` has been deprecated; use `= uninitialized` instead.:s"
)

lazy val Version2x: Seq[String] = Seq(
"-Xlint:-unused,_",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Ywarn-unused:implicits",
"-Ywarn-unused:imports",
"-Xsource:3",
"-Xlint:_,-byname-implicit", // enable handy linter warnings except byname-implicit (see https://github.com/scala/bug/issues/12072)
"-P:kind-projector:underscore-placeholders",
"-Xlint",
"-Ywarn-macros:after"
)

}

object Compiler {

lazy val Common: Seq[ModuleID] = Seq("org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0")

lazy val Scala2x: Seq[ModuleID] = Seq(
compilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.3").cross(CrossVersion.full)),
compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")
)

}

}

0 comments on commit f2f9800

Please sign in to comment.