Skip to content

Commit

Permalink
Upgrade to Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
austek committed Nov 25, 2023
1 parent cfe4463 commit 9d302fa
Show file tree
Hide file tree
Showing 31 changed files with 114 additions and 107 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.12]
scala: [3.3.1]
java: [temurin@17, temurin@20]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.12]
scala: [3.3.1]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -131,12 +131,12 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.13.12)
- name: Download target directories (3.3.1)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.12-${{ matrix.java }}
name: target-${{ matrix.os }}-3.3.1-${{ matrix.java }}

- name: Inflate target directories (2.13.12)
- name: Inflate target directories (3.3.1)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# **Note** that config order in this file is important since what comes afterwards takes precedence
version = 3.7.3
version = 3.7.15
project.git = true
runner.dialect = scala213
runner.dialect = scala3
align = true
align.arrowEnumeratorGenerator = true
align.tokens = [
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Dependencies.*
import PublishSettings.*
import TestEnvironment.*

ThisBuild / scalaVersion := scala213
ThisBuild / scalaVersion := scalaV

lazy val plugin = project
.in(file("modules/plugin"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.austek.example.pulsar.avro

import com.github.austek.example.Order
import com.github.austek.example.config.ConsumerAppConfig
import com.sksamuel.pulsar4s._
import com.sksamuel.pulsar4s.*
import com.typesafe.scalalogging.StrictLogging
import org.apache.pulsar.client.api.{Schema, SubscriptionInitialPosition, SubscriptionType}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.austek.example.pulsar.avro

import OrderRandomization._
import OrderRandomization.*
import com.github.austek.example.Order
import com.github.austek.example.config.ProviderAppConfig
import com.sksamuel.pulsar4s._
import com.sksamuel.pulsar4s.*
import org.apache.pulsar.client.api.Schema
import util.randomization.Randomization._
import util.randomization.Randomization.*

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.austek.example.pulsar.avro

import com.github.austek.example._
import com.github.austek.example.*
import org.scalacheck.{Arbitrary, Gen}
import util.randomization.Randomization._
import util.randomization.Randomization.*

import java.nio.ByteBuffer
import java.util.UUID
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

object OrderRandomization {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.scalacheck.rng.Seed
import org.scalacheck.{Arbitrary, Gen}

import java.util.UUID
import scala.reflect.ClassTag
import scala.util.{Failure, Random, Success, Try}

final case class RandomDataException(private val message: String = "", private val cause: Throwable = None.orNull) extends Exception(message, cause)
Expand All @@ -27,19 +28,19 @@ trait Randomization {

def randomUUID: UUID = UUID.randomUUID

def random[T: Arbitrary](implicit m: Manifest[T]): T = randomSuchThat[T](1, _ => true).head
def random[T: Arbitrary](using ct: ClassTag[T]): T = randomSuchThat[T](1, _ => true).head

def random[T: Arbitrary](size: Int)(implicit m: Manifest[T]): Seq[T] = randomSuchThat[T](size, _ => true)
def random[T: Arbitrary](size: Int)(using ct: ClassTag[T]): Seq[T] = randomSuchThat[T](size, _ => true)

def randomSuchThat[T: Arbitrary](n: Int, f: T => Boolean)(implicit m: Manifest[T]): Seq[T] = {
def randomSuchThat[T: Arbitrary](n: Int, f: T => Boolean)(using ct: ClassTag[T]): Seq[T] = {
Try(
Gen.listOfN(n, Arbitrary.arbitrary[T].suchThat(f)).apply(Gen.Parameters.default, Seed.random())
) match {
case Success(Some(v)) => v
case Success(None) => throw RandomDataException(s"Could not generate a random value for ${m.runtimeClass.getSimpleName}")
case Success(None) => throw RandomDataException(s"Could not generate a random value for ${ct.runtimeClass.getSimpleName}")
case Failure(exception) =>
throw RandomDataException(
s"Failed to generate a random value for ${m.runtimeClass.getSimpleName}: ${exception.getLocalizedMessage}",
s"Failed to generate a random value for ${ct.runtimeClass.getSimpleName}: ${exception.getLocalizedMessage}",
exception
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.github.austek.plugin.avro.implicits.AvroSupportImplicits.{fromPactEit
import com.google.protobuf.struct.Value
import com.google.protobuf.struct.Value.Kind.StringValue

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

case class FieldRule(value: String, rules: Seq[MatchingRule])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package com.github.austek.plugin.avro
import au.com.dius.pact.core.model.matchingrules.{MatchingRule, MatchingRuleCategory}
import com.github.austek.pact.RuleParser.parseRules
import com.github.austek.plugin.avro.AvroPluginConstants.MatchingRuleCategoryName
import com.github.austek.plugin.avro.error._
import com.github.austek.plugin.avro.error.*
import com.github.austek.plugin.avro.utils.StringUtils._
import com.google.protobuf.ByteString
import com.google.protobuf.struct.Value
import com.google.protobuf.struct.Value.Kind._
import com.google.protobuf.struct.Value.Kind.*
import com.typesafe.scalalogging.StrictLogging
import org.apache.avro.Schema
import org.apache.avro.Schema.Type._
import org.apache.avro.generic._
import org.apache.avro.Schema.Type.*
import org.apache.avro.generic.*
import org.apache.avro.io.EncoderFactory

import java.io.ByteArrayOutputStream
import java.nio.charset.StandardCharsets
import java.util
import scala.annotation.tailrec
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
import scala.util.{Failure, Success, Try, Using}

case class AvroFieldName(value: String)
Expand Down Expand Up @@ -400,7 +400,6 @@ object Avro {
case ARRAY => AvroArray(rootPath, fieldName, schemaField.schema(), configValue)
case MAP => AvroMap(rootPath, fieldName, schemaField.schema(), configValue)
case UNION => handleAvroUnion(rootPath, schemaField, fieldName, configValue)
case t => Left(Seq(PluginErrorException(FieldUnsupportedTypeException(t, fieldName, configValue))))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.austek.plugin.avro

import com.github.austek.plugin.avro.AvroPactConstants._
import com.github.austek.plugin.avro.AvroPluginConstants._
import com.github.austek.plugin.avro.ContentTypeConstants._
import com.github.austek.plugin.avro.AvroPactConstants.*
import com.github.austek.plugin.avro.AvroPluginConstants.*
import com.github.austek.plugin.avro.ContentTypeConstants.*
import com.github.austek.plugin.avro.compare.CompareContentsResponseBuilder
import com.github.austek.plugin.avro.error.{PluginError, PluginErrorException, PluginErrorMessage, PluginErrorMessages}
import com.github.austek.plugin.avro.interaction.InteractionResponseBuilder
import com.github.austek.plugin.avro.utils._
import com.github.austek.plugin.avro.utils.*
import com.google.protobuf.empty.Empty
import com.google.protobuf.struct.{Struct, Value}
import com.typesafe.scalalogging.StrictLogging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.austek.plugin.avro.compare

import au.com.dius.pact.core.matchers._
import au.com.dius.pact.core.matchers.*
import com.github.austek.plugin.avro.error.PluginError
import com.github.austek.plugin.avro.implicits.RecordImplicits._
import com.github.austek.plugin.avro.implicits.RecordImplicits.*
import com.typesafe.scalalogging.StrictLogging
import org.apache.avro.generic.GenericRecord

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

object AvroContentMatcher extends StrictLogging {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import au.com.dius.pact.core.matchers.MatchingContext
import au.com.dius.pact.core.model.matchingrules.{MatchingRule, MatchingRuleCategory, MatchingRuleGroup}
import au.com.dius.pact.core.support.Json
import com.github.austek.plugin.avro.AvroPluginConstants.MatchingRuleCategoryName
import com.github.austek.plugin.avro.ContentTypeConstants._
import com.github.austek.plugin.avro.ContentTypeConstants.*
import com.github.austek.plugin.avro.error.{PluginError, PluginErrorException, PluginErrorMessage, PluginErrorMessages}
import com.github.austek.plugin.avro.utils._
import com.github.austek.plugin.avro.utils.*
import com.google.protobuf.ByteString
import com.google.protobuf.struct.Struct.toJavaProto
import com.typesafe.scalalogging.StrictLogging
import io.pact.plugin.pact_plugin._
import io.pact.plugin.pact_plugin.*
import io.pact.plugins.jvm.core.Utils.{INSTANCE => PactCoreUtils}
import org.apache.avro.Schema
import org.apache.avro.Schema.Type.{RECORD, UNION}
import org.apache.avro.generic.GenericRecord

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
import scala.util.matching.Regex

object CompareContentsResponseBuilder extends StrictLogging {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.austek.plugin.avro.implicits

import au.com.dius.pact.core.model.PathExpressionsKt._
import au.com.dius.pact.core.model.PathExpressionsKt.*

object PathExpressionImplicits {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.github.austek.plugin.avro.implicits

import au.com.dius.pact.core.matchers._
import au.com.dius.pact.core.matchers.*
import com.github.austek.plugin.avro.error.{PluginError, PluginErrorException}
import com.github.austek.plugin.avro.implicits.PathExpressionImplicits._
import com.github.austek.plugin.avro.implicits.PathExpressionImplicits.*
import com.github.austek.plugin.avro.matchers
import com.typesafe.scalalogging.StrictLogging
import org.apache.avro.generic.{GenericDatumWriter, GenericRecord}
import org.apache.avro.io.EncoderFactory

import java.io.ByteArrayOutputStream
import java.nio.charset.StandardCharsets
import scala.jdk.CollectionConverters._
import scala.util._
import scala.jdk.CollectionConverters.*
import scala.util.*

object RecordImplicits extends StrictLogging {

Expand Down Expand Up @@ -54,7 +54,7 @@ object RecordImplicits extends StrictLogging {
path: List[String],
other: GenericRecord
)(implicit context: MatchingContext): Either[Seq[PluginError[_]], List[BodyItemMatchResult]] = {
import SchemaFieldImplicits._
import SchemaFieldImplicits.*

logger.debug(s">>> Record.compare($path, $record, $other)")
if (record.getSchema.getName == other.getSchema.getName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.github.austek.plugin.avro.implicits

import au.com.dius.pact.core.matchers.{BodyItemMatchResult => AvroBodyItemMatchResult, _}
import au.com.dius.pact.core.model.PathExpressionsKt._
import au.com.dius.pact.core.model.PathExpressionsKt.*
import com.github.austek.plugin.avro.error.{PluginError, PluginErrorException, PluginErrorMessage, PluginErrorMessages}
import com.github.austek.plugin.avro.implicits.PathExpressionImplicits._
import com.github.austek.plugin.avro.implicits.RecordImplicits._
import com.github.austek.plugin.avro.implicits.SchemaTypeImplicits._
import com.github.austek.plugin.avro.implicits.PathExpressionImplicits.*
import com.github.austek.plugin.avro.implicits.RecordImplicits.*
import com.github.austek.plugin.avro.implicits.SchemaTypeImplicits.*
import com.github.austek.plugin.avro.matchers.{BodyItemMatchResult, BodyMismatch}
import com.typesafe.scalalogging.StrictLogging
import org.apache.avro.Schema
import org.apache.avro.Schema.Type._
import org.apache.avro.Schema.Type.*
import org.apache.avro.generic.GenericData.{EnumSymbol, Fixed}
import org.apache.avro.generic.GenericRecord
import org.apache.avro.util.Utf8

import java.util
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

object SchemaFieldImplicits extends StrictLogging {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.austek.plugin.avro.implicits

import org.apache.avro.Schema.Type
import org.apache.avro.Schema.Type._
import org.apache.avro.Schema.Type.*
import org.apache.avro.generic.GenericRecord

object SchemaTypeImplicits {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package com.github.austek.plugin.avro.interaction

import au.com.dius.pact.core.model.matchingrules.{MatchingRule => _, MatchingRules => _, _}
import com.github.austek.plugin.avro.Avro.AvroRecord
import com.github.austek.plugin.avro.AvroPluginConstants._
import com.github.austek.plugin.avro.AvroPluginConstants.*
import com.github.austek.plugin.avro.AvroSchemaBase16Hash
import com.github.austek.plugin.avro.error.{PluginError, PluginErrorMessage}
import com.github.austek.plugin.avro.utils.Util._
import com.github.austek.plugin.avro.utils.Util.*
import com.google.protobuf.ByteString
import com.google.protobuf.struct.{Struct, Value}
import com.typesafe.scalalogging.StrictLogging
import io.pact.plugin.pact_plugin.Body.ContentTypeHint
import io.pact.plugin.pact_plugin._
import io.pact.plugin.pact_plugin.*
import org.apache.avro.Schema
import org.apache.avro.Schema.Type._
import org.apache.avro.Schema.Type.*

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

object InteractionBuilder extends StrictLogging {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.austek.plugin.avro.interaction

import com.github.austek.plugin.avro.AvroPluginConstants._
import com.github.austek.plugin.avro.AvroPluginConstants.*
import com.github.austek.plugin.avro.AvroSchemaBase16Hash
import com.github.austek.plugin.avro.error.{PluginErrorException, PluginErrorMessage, PluginErrorMessages}
import com.google.protobuf.struct.{Struct, Value}
import com.typesafe.scalalogging.StrictLogging
import io.pact.plugin.pact_plugin._
import io.pact.plugin.pact_plugin.*
import org.apache.avro.Schema

object InteractionResponseBuilder extends StrictLogging {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.github.austek.plugin.avro.matchers

import au.com.dius.pact.core.matchers.{BodyItemMatchResult => AvroBodyItemMatchResult, BodyMismatch}
import com.github.austek.plugin.avro.error.{PluginError, PluginErrorException}
import com.github.austek.plugin.avro.implicits.RecordImplicits._
import com.github.austek.plugin.avro.implicits.RecordImplicits.*
import org.apache.avro.Schema
import org.apache.avro.generic.GenericRecord

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

object BodyItemMatchResult {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.apache.avro.generic.{GenericDatumReader, GenericRecord}
import org.apache.avro.io.DecoderFactory

import java.io.{ByteArrayInputStream, File, InputStream}
import scala.util._
import scala.util.*

object AvroUtils extends StrictLogging {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.austek.plugin.avro.utils
import au.com.dius.pact.core.support.json.JsonValue
import com.google.protobuf.struct.{ListValue, NullValue, Struct, Value}

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
object Util {

def jsonToValue(json: JsonValue): Value = {
Expand Down
Loading

0 comments on commit 9d302fa

Please sign in to comment.