Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AVSystem/scala-commons
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.19.0
Choose a base ref
...
head repository: AVSystem/scala-commons
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Apr 11, 2024

  1. Hocon config companions

    sebaciv committed Apr 11, 2024
    Copy the full SHA
    00c88ac View commit details

Commits on Sep 23, 2024

  1. Copy the full SHA
    35f9d91 View commit details
  2. Copy the full SHA
    24c80dc View commit details
  3. Copy the full SHA
    b60fe6b View commit details

Commits on Sep 26, 2024

  1. Copy the full SHA
    e9b4d63 View commit details
  2. Improve SizeInBytes doc

    sebaciv committed Sep 26, 2024
    Copy the full SHA
    31369b4 View commit details

Commits on Sep 28, 2024

  1. Copy the full SHA
    65c5f75 View commit details
  2. Copy the full SHA
    0ab4592 View commit details
  3. Copy the full SHA
    131b4a3 View commit details

Commits on Sep 30, 2024

  1. Merge pull request #638 from scala-steward/update/sbt-scalajs-1.17.0

    Update sbt-scalajs, scalajs-compiler, ... to 1.17.0
    ddworak authored Sep 30, 2024
    Copy the full SHA
    4519050 View commit details
  2. Merge pull request #562 from AVSystem/config-utils

    Hocon config companions
    ddworak authored Sep 30, 2024
    Copy the full SHA
    af0e222 View commit details

Commits on Oct 1, 2024

  1. Copy the full SHA
    3219229 View commit details
  2. Copy the full SHA
    49fecc1 View commit details
  3. Copy the full SHA
    eba9ebe View commit details
  4. Copy the full SHA
    84110bd View commit details

Commits on Oct 2, 2024

  1. Copy the full SHA
    23952b7 View commit details
  2. Merge pull request #637 from scala-steward/update/scala-compiler-2.13.15

    Update scala-compiler, scala-library, ... to 2.13.15
    halotukozak authored Oct 2, 2024
    Copy the full SHA
    7dffad2 View commit details

Commits on Oct 4, 2024

  1. Merge pull request #639 from scala-steward/update/jetty-client-12.0.14

    Update jetty-client to 12.0.14
    ddworak authored Oct 4, 2024
    Copy the full SHA
    1b246ae View commit details

Commits on Oct 8, 2024

  1. Copy the full SHA
    9857973 View commit details

Commits on Oct 10, 2024

  1. Copy the full SHA
    5b34185 View commit details
  2. Merge pull request #641 from scala-steward/update/sbt-ci-release-1.7.0

    Update sbt-ci-release to 1.7.0
    ddworak authored Oct 10, 2024
    Copy the full SHA
    8452f55 View commit details

Commits on Oct 14, 2024

  1. Copy the full SHA
    9507278 View commit details

Commits on Oct 20, 2024

  1. Copy the full SHA
    457126b View commit details

Commits on Oct 21, 2024

  1. Merge pull request #644 from scala-steward/update/sbt-1.10.3

    Update sbt, scripted-plugin to 1.10.3
    ddworak authored Oct 21, 2024
    Copy the full SHA
    e8f2a8c View commit details
  2. Merge pull request #643 from scala-steward/update/sbt-ci-release-1.8.0

    Update sbt-ci-release to 1.8.0
    ddworak authored Oct 21, 2024
    Copy the full SHA
    3bfea63 View commit details
  3. Merge pull request #642 from scala-steward/update/pekko-stream-1.1.2

    Update pekko-stream to 1.1.2
    ddworak authored Oct 21, 2024
    Copy the full SHA
    eca36e4 View commit details

Commits on Oct 22, 2024

  1. Copy the full SHA
    fe1a1c1 View commit details

Commits on Oct 28, 2024

  1. Copy the full SHA
    95147a2 View commit details

Commits on Oct 29, 2024

  1. Merge pull request #647 from scala-steward/update/sbt-1.10.4

    Update sbt, scripted-plugin to 1.10.4
    ddworak authored Oct 29, 2024
    Copy the full SHA
    ee2436b View commit details
  2. Merge pull request #646 from scala-steward/update/sbt-ci-release-1.9.0

    Update sbt-ci-release to 1.9.0
    ddworak authored Oct 29, 2024
    Copy the full SHA
    739098e View commit details

Commits on Nov 5, 2024

  1. Copy the full SHA
    c76b61f View commit details

Commits on Nov 7, 2024

  1. Merge pull request #648 from scala-steward/update/sbt-1.10.5

    Update sbt, scripted-plugin to 1.10.5
    ddworak authored Nov 7, 2024
    Copy the full SHA
    6b0a531 View commit details
  2. Copy the full SHA
    529ca8d View commit details
  3. Copy the full SHA
    5352348 View commit details

Commits on Nov 12, 2024

  1. Merge pull request #649 from scala-steward/update/jetty-client-12.0.15

    Update jetty-client to 12.0.15
    ddworak authored Nov 12, 2024
    Copy the full SHA
    1496462 View commit details
  2. Copy the full SHA
    a304685 View commit details
  3. Merge pull request #651 from scala-steward/update/mongodb-driver-core…

    …-5.2.1
    
    Update mongodb-driver-core, ... to 5.2.1
    ddworak authored Nov 12, 2024
    Copy the full SHA
    44ea6a8 View commit details

Commits on Nov 13, 2024

  1. Update POM

    - update maintainer list
    - remove link to avsystem.com as requested by AVS marketing / SEO (other sponsored libraries e.g. guava do not provide this field either)
    ddworak committed Nov 13, 2024
    Copy the full SHA
    c01929f View commit details

Commits on Dec 1, 2024

  1. Copy the full SHA
    360c51d View commit details

Commits on Dec 12, 2024

  1. Merge pull request #654 from scala-steward/update/sbt-1.10.6

    Update sbt, scripted-plugin to 1.10.6
    ddworak authored Dec 12, 2024
    Copy the full SHA
    0ab61ba View commit details

Commits on Dec 13, 2024

  1. Copy the full SHA
    8a9bdcb View commit details

Commits on Dec 17, 2024

  1. Merge pull request #656 from scala-steward/update/jetty-client-12.0.16

    Update jetty-client to 12.0.16
    ddworak authored Dec 17, 2024
    Copy the full SHA
    86d605d View commit details
  2. Copy the full SHA
    dc4f58e View commit details

Commits on Dec 23, 2024

  1. Merge pull request #659 from scala-steward/update/guava-33.4.0-jre

    Update guava to 33.4.0-jre
    ddworak authored Dec 23, 2024
    Copy the full SHA
    6dce0ab View commit details

Commits on Dec 24, 2024

  1. Copy the full SHA
    c6e9696 View commit details
  2. Copy the full SHA
    6feaa16 View commit details
  3. Copy the full SHA
    b1a50d1 View commit details
  4. Copy the full SHA
    1fcc7dd View commit details

Commits on Jan 10, 2025

  1. Copy the full SHA
    8be39c7 View commit details
  2. Copy the full SHA
    ebab263 View commit details
14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -16,15 +16,14 @@ on:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REDIS_VERSION: 6.2.12

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.14]
scala: [2.13.16]
java: [temurin@17, temurin@21]
runs-on: ${{ matrix.os }}
steps:
@@ -52,12 +51,6 @@ jobs:
- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Cache Redis
uses: actions/cache@v2
with:
path: ./redis-${{ env.REDIS_VERSION }}
key: ${{ runner.os }}-redis-cache-v2-${{ env.REDIS_VERSION }}

- name: Setup Node.js
uses: actions/setup-node@v2
with:
@@ -69,9 +62,6 @@ jobs:
mongodb-version: 7.0
mongodb-replica-set: test-rs

- name: Setup Redis
run: ./install-redis.sh

- name: Check that workflows are up to date
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck

@@ -85,7 +75,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.14]
scala: [2.13.16]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
[`OptRef`](http://avsystem.github.io/scala-commons/api/com/avsystem/commons/misc/OptRef.html) (implemented as value
classes)
* [Components](docs/Components.md) and Dependency Injection library
* `commons-redis` - [Scala driver for Redis](docs/RedisDriver.md)
* `commons-redis` (DEPRECATED) - [Scala driver for Redis](docs/RedisDriver.md)
* `commons-macros` contains implementations of macros used in other modules and reusable macro utilities:
* `MacroCommons` trait with several convenience functions for implementing macros
* `TypeClassDerivation` - implements infrastructure for automatic type class derivation
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ final class AnalyzerPlugin(val global: Global) extends Plugin { plugin =>
private object component extends PluginComponent {
val global: plugin.global.type = plugin.global
val runsAfter = List("typer")
override val runsBefore = List("patmat", "silencer")
override val runsBefore = List("patmat")
val phaseName = "avsAnalyze"

import global._
Original file line number Diff line number Diff line change
@@ -511,17 +511,17 @@ object SharedExtensionsUtils extends SharedExtensions {
*/
def unless(pre: PartialFunction[A, B]): PartialFunction[A, B] = pre orElse pf

def applyNOpt(a: A): NOpt[B] = pf.applyOrElse(a, NoValueMarkerFunc) match {
def applyNOpt(a: A): NOpt[B] = pf.applyOrElse[A, Any](a, NoValueMarkerFunc) match {
case NoValueMarker => NOpt.Empty
case rawValue => NOpt.some(rawValue.asInstanceOf[B])
}

def applyOpt(a: A): Opt[B] = pf.applyOrElse(a, NoValueMarkerFunc) match {
def applyOpt(a: A): Opt[B] = pf.applyOrElse[A, Any](a, NoValueMarkerFunc) match {
case NoValueMarker => Opt.Empty
case rawValue => Opt(rawValue.asInstanceOf[B])
}

def fold[C](a: A)(forEmpty: A => C, forNonEmpty: B => C): C = pf.applyOrElse(a, NoValueMarkerFunc) match {
def fold[C](a: A)(forEmpty: A => C, forNonEmpty: B => C): C = pf.applyOrElse[A, Any](a, NoValueMarkerFunc) match {
case NoValueMarker => forEmpty(a)
case rawValue => forNonEmpty(rawValue.asInstanceOf[B])
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ package serialization

import com.avsystem.commons.serialization.CodecTestData.HasDefaults

import scala.annotation.nowarn

object IgnoreTransientDefaultMarkerTest {
final case class NestedHasDefaults(
@transientDefault flag: Boolean = false,
@@ -19,6 +21,7 @@ object IgnoreTransientDefaultMarkerTest {
object HasOptParam extends HasGenCodec[HasOptParam]
}

@nowarn("msg=a type was inferred to be `Any`")
class IgnoreTransientDefaultMarkerTest extends AbstractCodecTest {
import IgnoreTransientDefaultMarkerTest.*

3 changes: 3 additions & 0 deletions docs/RedisDriver.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Redis driver

**⚠️ WARNING: This module is deprecated and scheduled for removal in a future release.
It has not been actively tested since v2.21.0. Please migrate to an alternative solution. **

`commons-redis` - Scala driver for Redis

```scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.avsystem.commons
package hocon

import com.avsystem.commons.meta.MacroInstances
import com.avsystem.commons.serialization.GenCodec.ReadFailure
import com.avsystem.commons.serialization.{GenCodec, GenKeyCodec, GenObjectCodec}
import com.typesafe.config.{Config, ConfigFactory, ConfigObject, ConfigRenderOptions}

import java.time.{Period, Duration as JDuration}
import scala.concurrent.duration.*
import scala.jdk.javaapi.DurationConverters

trait HoconGenCodecs {
implicit def configCodec: GenCodec[Config] = HoconGenCodecs.ConfigCodec
implicit def finiteDurationCodec: GenCodec[FiniteDuration] = HoconGenCodecs.FiniteDurationCodec
implicit def jDurationCodec: GenCodec[JDuration] = HoconGenCodecs.JavaDurationCodec
implicit def periodCodec: GenCodec[Period] = HoconGenCodecs.PeriodCodec
implicit def sizeInBytesCodec: GenCodec[SizeInBytes] = HoconGenCodecs.SizeInBytesCodec
implicit def classKeyCodec: GenKeyCodec[Class[?]] = HoconGenCodecs.ClassKeyCodec
implicit def classCodec: GenCodec[Class[?]] = HoconGenCodecs.ClassCodec
}
object HoconGenCodecs {
implicit final val ConfigCodec: GenCodec[Config] = GenCodec.nullable(
input =>
input.readCustom(ConfigValueMarker).fold(ConfigFactory.parseString(input.readSimple().readString())) {
case obj: ConfigObject => obj.toConfig
case v => throw new ReadFailure(s"expected a config OBJECT, got ${v.valueType}")
},
(output, value) =>
if (!output.writeCustom(ConfigValueMarker, value.root)) {
val renderOptions = ConfigRenderOptions.defaults().setOriginComments(false)
output.writeSimple().writeString(value.root.render(renderOptions))
},
)

implicit final val FiniteDurationCodec: GenCodec[FiniteDuration] = GenCodec.nullable(
input => input.readCustom(DurationMarker).map(DurationConverters.toScala).getOrElse(input.readSimple().readLong().millis),
(output, value) => if (!output.writeCustom(DurationMarker, DurationConverters.toJava(value))) output.writeSimple().writeLong(value.toMillis),
)

implicit final val JavaDurationCodec: GenCodec[JDuration] = GenCodec.nullable(
input => input.readCustom(DurationMarker).getOrElse(JDuration.ofMillis(input.readSimple().readLong())),
(output, value) => if (!output.writeCustom(DurationMarker, value)) output.writeSimple().writeLong(value.toMillis),
)

implicit final val PeriodCodec: GenCodec[Period] = GenCodec.nullable(
input => input.readCustom(PeriodMarker).getOrElse(Period.parse(input.readSimple().readString())),
(output, value) => if (!output.writeCustom(PeriodMarker, value)) output.writeSimple().writeString(value.toString),
)

implicit final val SizeInBytesCodec: GenCodec[SizeInBytes] = GenCodec.nonNull(
input => SizeInBytes(input.readCustom(SizeInBytesMarker).getOrElse(input.readSimple().readLong())),
(output, value) => if (!output.writeCustom(SizeInBytesMarker, value.bytes)) output.writeSimple().writeLong(value.bytes),
)

implicit final val ClassKeyCodec: GenKeyCodec[Class[?]] =
GenKeyCodec.create(Class.forName, _.getName)

implicit final val ClassCodec: GenCodec[Class[?]] =
GenCodec.nullableString(Class.forName, _.getName)
}

object DefaultHoconGenCodecs extends HoconGenCodecs

trait ConfigObjectCodec[T] {
def objectCodec: GenObjectCodec[T]
}

abstract class AbstractConfigCompanion[Implicits <: HoconGenCodecs, T](
implicits: Implicits
)(implicit instances: MacroInstances[Implicits, ConfigObjectCodec[T]]
) {
implicit lazy val codec: GenCodec[T] = instances(implicits, this).objectCodec

final def read(config: Config): T = HoconInput.read[T](config)
}

/**
* Base class for companion objects of configuration case classes and sealed traits
* (typically deserialized from HOCON files).
*
* [[DefaultConfigCompanion]] is equivalent to [[com.avsystem.commons.serialization.HasGenCodec HasGenCodec]]
* except that it automatically imports codecs from [[HoconGenCodecs]] - codecs for third party types often used
* in configuration.
*/
abstract class DefaultConfigCompanion[T](implicit macroCodec: MacroInstances[HoconGenCodecs, ConfigObjectCodec[T]])
extends AbstractConfigCompanion[HoconGenCodecs, T](DefaultHoconGenCodecs)
13 changes: 11 additions & 2 deletions hocon/src/main/scala/com/avsystem/commons/hocon/HoconOutput.scala
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ package com.avsystem.commons
package hocon

import com.avsystem.commons.annotation.explicitGenerics
import com.avsystem.commons.serialization._
import com.avsystem.commons.serialization.*
import com.avsystem.commons.serialization.cbor.RawCbor
import com.avsystem.commons.serialization.json.RawJson
import com.typesafe.config.{ConfigValue, ConfigValueFactory}

object HoconOutput {
@@ -31,7 +33,14 @@ class HoconOutput(consumer: ConfigValue => Unit) extends OutputAndSimpleOutput {
def writeList(): HoconListOutput = new HoconListOutput(consumer)
def writeObject(): HoconObjectOutput = new HoconObjectOutput(consumer)

//TODO: writeCustom
// TODO: handle other markers in writeCustom? Unfortunately typesafe config does not provide a methods to write
// duration to nice string representation etc.
override def writeCustom[T](typeMarker: TypeMarker[T], value: T): Boolean =
typeMarker match {
case ConfigValueMarker => consumer(value); true
case PeriodMarker => anyRef(value.toString.toLowerCase.stripPrefix("p")); true
case _ => false
}
}

class HoconListOutput(consumer: ConfigValue => Unit) extends ListOutput {
15 changes: 15 additions & 0 deletions hocon/src/main/scala/com/avsystem/commons/hocon/SizeInBytes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.avsystem.commons
package hocon

/**
* To read the size in bytes represented in [[https://github.com/lightbend/config/blob/master/HOCON.md#size-in-bytes-format HOCON format]],
* use this type together with [[com.avsystem.commons.hocon.SizeInBytesMarker]] when deserializing data from HOCON.
*
* @see [[com.avsystem.commons.hocon.HoconGenCodecs.SizeInBytesCodec]]
*/
final case class SizeInBytes(bytes: Long)
object SizeInBytes {
final val Zero = SizeInBytes(0)
final val `1KiB` = SizeInBytes(1024L)
final val `1MiB` = SizeInBytes(1024 * 1024L)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.avsystem.commons
package hocon

import com.avsystem.commons.hocon.HoconInputTest.CustomCodecsClass
import com.avsystem.commons.serialization.{GenCodecRoundtripTest, Input, Output}
import com.typesafe.config.ConfigValue
import com.typesafe.config.{ConfigFactory, ConfigValue}

import java.time.{Duration, Period}
import scala.concurrent.duration.*

class HoconGenCodecRoundtripTest extends GenCodecRoundtripTest {
type Raw = ConfigValue
@@ -15,4 +19,17 @@ class HoconGenCodecRoundtripTest extends GenCodecRoundtripTest {

def createInput(raw: ConfigValue): Input =
new HoconInput(raw)

test("custom codes class") {
val value = CustomCodecsClass(
duration = 1.minute,
jDuration = Duration.ofMinutes(5),
fileSize = SizeInBytes.`1KiB`,
embeddedConfig = ConfigFactory.parseMap(JMap("something" -> "abc")),
period = Period.ofWeeks(2),
clazz = classOf[HoconGenCodecRoundtripTest],
clazzMap = Map(classOf[HoconGenCodecRoundtripTest] -> "abc"),
)
testRoundtrip(value)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
package com.avsystem.commons
package hocon

import java.time.{Duration, Period}

import com.avsystem.commons.serialization.json.JsonStringOutput
import com.avsystem.commons.serialization.{GenCodecRoundtripTest, Input, Output}
import com.typesafe.config.{ConfigFactory, ConfigMemorySize, ConfigValue, ConfigValueFactory, ConfigValueType}
import com.typesafe.config.*

import java.time.{Duration, Period}
import scala.concurrent.duration.*

object HoconInputTest {
case class CustomCodecsClass(
duration: FiniteDuration,
jDuration: Duration,
fileSize: SizeInBytes,
embeddedConfig: Config,
period: Period,
clazz: Class[?],
clazzMap: Map[Class[?], String],
)
object CustomCodecsClass extends DefaultConfigCompanion[CustomCodecsClass]
}

class HoconInputTest extends GenCodecRoundtripTest {

import HoconInputTest.*

type Raw = ConfigValue

def writeToOutput(write: Output => Unit): ConfigValue = {
@@ -56,4 +73,32 @@ class HoconInputTest extends GenCodecRoundtripTest {
test("number reading") {
assert(rawInput(42.0).readNumber().doubleValue == 42.0)
}

test("class reading") {
val config = ConfigFactory.parseString(
"""{
| duration = 1m
| jDuration = 5m
| fileSize = 1KiB
| embeddedConfig {
| something = "abc"
| }
| period = "7d"
| clazz = "com.avsystem.commons.hocon.HoconInputTest"
| clazzMap {
| "com.avsystem.commons.hocon.HoconInputTest" = "abc"
| }
|}""".stripMargin
)
val expected = CustomCodecsClass(
duration = 1.minute,
jDuration = Duration.ofMinutes(5),
fileSize = SizeInBytes.`1KiB`,
embeddedConfig = ConfigFactory.parseMap(JMap("something" -> "abc")),
period = Period.ofDays(7),
clazz = classOf[HoconInputTest],
clazzMap = Map(classOf[HoconInputTest] -> "abc"),
)
assert(CustomCodecsClass.read(config) == expected)
}
}
9 changes: 0 additions & 9 deletions install-redis.sh

This file was deleted.

Loading