Skip to content

Commit

Permalink
1.0.0-RC1 Effort Started
Browse files Browse the repository at this point in the history
This new major version aims to bring a new and hopefully cleaner project structure.
The `scalaz` based configuration is moved to a different module to isolate better from the core.
In the future a `cats` based version will be added as well.
More core utilities were added and the old ones were brushed up for better consistency and clarity.
  • Loading branch information
tupol committed Jul 25, 2020
1 parent 7973dd5 commit bd513df
Show file tree
Hide file tree
Showing 59 changed files with 2,052 additions and 902 deletions.
15 changes: 15 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version = "2.1.0"
maxColumn = 120
align = most
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses = true
spaces {
inImportCurlyBraces = true
}
optIn.annotationNewlines = true

rewrite.rules = [SortImports, RedundantBraces]
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ cache:
- $HOME/.ivy2

scala:
- 2.11.12
- 2.12.12

script:
- sbt clean +compile +coverage +test +coverageReport
- sbt clean +compile +coverage +test +coverageReport +coverageAggregate

after_success:
- bash <(curl -s https://codecov.io/bash)
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
This project contains some basic utilities that can help setting up a Scala project.

The main utilities available:
- [Configuration framework](docs/configuration-framework.md)
- Convertion to byte array in the [`byteable`](src/main/scala/org/tupol/utils/byteable.scala) package.
- `Try` utilities in the [`utils`](src/main/scala/org/tupol/utils/utils.scala) package.
- [Configuration framework](config-z/docs/configuration-framework.md)
- Conversion to byte array in the [`byteable`](core/src/main/scala/org/tupol/utils/ByteableOps.scala) package.
- `Try`, `Future`, `Either`, `Product`, `Map` and other utilities in the [`utils`](core/src/main/scala/org/tupol/utils/) package.

***Attention!*** The [Configuration framework](docs/configuration-framework.md) is deprecated, as the
[PureConfig](https://pureconfig.github.io/) framework is much more mature and provides a better
overall solution.
***Attention!*** The [Configuration framework](config-z/docs/configuration-framework.md) might be
deprecated, as the [PureConfig](https://pureconfig.github.io/) framework is much more mature and
provides a better overall solution.

## Prerequisites ##

* Java 6 or higher
* Scala 2.11,or 2.12
* Java 8 or higher (matching the Scala version)
* Scala 2.12


## Getting Scala Utils ##
Expand All @@ -35,29 +35,36 @@ where the latest artifacts can be found.
Usage with SBT, adding a dependency to the latest version of scala utils to your sbt build definition file:

```scala
libraryDependencies += "org.tupol" %% "scala-utils" % "0.2.0"
libraryDependencies += "org.tupol" %% "scala-utils" % "1.0.0-RC01-SNAPSHOT"
```

The Sonatype snapshots repo needs to be added as well:

```scala
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
```


## Usage

Some usage examples can be found under [`src/test/scala/examples`](src/test/scala/examples).
Some `config-z` usage examples can be found under [`config-z/src/test/scala/examples`](config-z/src/test/scala/examples).


## What's new?

**0.2.1-SNAPSHOT**
- Deprecated the `configuration` framework in favour of `pureconfig`
- Added `Try.mapFailure` for exception wrapping or conversion
- Added `Traversable[Try[_]].separate` function to split failures from successes
**1.0.0-RC01** Effort Started

This new major version aims to bring a new and hopefully cleaner project structure.
The `scalaz` based configuration is moved to a different module to isolate better from the core.
In the future a `cats` based version will be added as well.

For previous versions please consult the [release notes](RELEASE-NOTES.md).
More core utilities were added and the old ones were brushed up for better consistency and clarity.

Attention! This version is no longer cross compiling across Scala 2.11 and 2.12.
Only Scala 2.12 is supported at the moment.

## Credits & Thanks ##
The previous versions are still available and can evolve independently on the [`0.2.x`](https://github.com/tupol/scala-utils/tree/0.2.x) branch.

- [Daan Hoogenboezem](https://github.com/daanhoogenboezem) For sketching the initial configuration framework.


## License ##
Expand Down
13 changes: 10 additions & 3 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes

## 1.0.0-RC01

- Major project refactoring and cleanup
- The core utilities that have no external dependencies are moved to the `core` module
- The config utilities framework is moved to the `config-z` module
- Added more utilities, for `Future`, `Either` and guarding code through `Bracket`s


## 0.2.0
- `Configurator`s can also be used as `Extractor`s
Expand All @@ -8,7 +15,7 @@
- Added extractors for time related properties: `Duration`, `Timestamp`, `Date`, `LocalDateTime` and `LocalDate`

## 0.1.0
- [`Configurator`](docs/configuration-framework.md)s framework
- [`byteable`](src/main/scala/org/tupol/utils/byteable.scala) to convert various data types into array of bytes
- [`utils`](src/main/scala/org/tupol/utils/utils.scala) with various utilities for `Map`s, `Product`s and `Try`s
- `Configurator`s framework
- `byteable` to convert various data types into array of bytes
- `utils` with various utilities for `Map`s, `Product`s and `Try`s

203 changes: 97 additions & 106 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,116 +1,107 @@

name := "scala-utils"

organization := "org.tupol"

scalaVersion := "2.11.12"

crossScalaVersions := Seq("2.11.12", "2.12.6")

// ------------------------------
// DEPENDENCIES AND RESOLVERS

updateOptions := updateOptions.value.withCachedResolution(true)

libraryDependencies ++= Seq(
"com.typesafe.scala-logging" % "scala-logging" % "3.9.0" cross CrossVersion.binary,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalaz" % "scalaz-core" % "7.2.26" cross CrossVersion.binary,
"org.scalacheck" % "scalacheck" % "1.14.0" % "test" cross CrossVersion.binary,
"org.scalatest" % "scalatest" % "3.0.5" % "test" cross CrossVersion.binary,
"com.typesafe" % "config" % "1.3.0"
)
// ------------------------------
// TESTING
parallelExecution in Test := false

fork in Test := true

publishArtifact in Test := true

// ------------------------------
// TEST COVERAGE

scoverage.ScoverageKeys.coverageExcludedFiles := ".*BuildInfo.*"


// ------------------------------
// PUBLISHING
isSnapshot := version.value.trim.endsWith("SNAPSHOT")

useGpg := true

// Nexus (see https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html)
publishTo := {
val repo = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at repo + "content/repositories/snapshots")
else
Some("releases" at repo + "service/local/staging/deploy/maven2")
}

publishArtifact in Test := true

publishMavenStyle := true

pomIncludeRepository := { x => false }


licenses := Seq("MIT-style" -> url("https://opensource.org/licenses/MIT"))

homepage := Some(url("https://github.com/tupol/scala-utils"))

scmInfo := Some(
ScmInfo(
url("https://github.com/tupol/scala-utils.git"),
"scm:[email protected]:tupol/scala-utils.git"
import Dependencies.{Versions, _}
import com.typesafe.sbt.SbtPgp.autoImportImpl.useGpg
import sbt.Keys.{libraryDependencies, organization}
import sbt.url
import sbtbuildinfo.BuildInfoPlugin.autoImport.{buildInfoKeys, buildInfoOptions}
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._

lazy val publishSettings = Seq(
isSnapshot := version.value.trim.endsWith("SNAPSHOT"),
useGpg := true,
// Nexus (see https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html)
publishTo := {
val repo = "https://oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at repo + "content/repositories/snapshots")
else Some("releases" at repo + "service/local/staging/deploy/maven2")
},
publishArtifact in Test := true,
publishMavenStyle := true,
pomIncludeRepository := { x => false },
licenses := Seq("MIT-style" -> url("https://opensource.org/licenses/MIT")),
homepage := Some(url("https://github.com/tupol/scala-utils")),
scmInfo := Some(
ScmInfo(
url("https://github.com/tupol/scala-utils.git"),
"scm:[email protected]:tupol/scala-utils.git"
)
),
developers := List(
Developer(
id = "tupol",
name = "Tupol",
email = "[email protected]",
url = url("https://github.com/tupol")
)
),
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies, // : ReleaseStep
inquireVersions, // : ReleaseStep
runClean, // : ReleaseStep
runTest, // : ReleaseStep
setReleaseVersion, // : ReleaseStep
commitReleaseVersion, // : ReleaseStep, performs the initial git checks
tagRelease, // : ReleaseStep
releaseStepCommand(s"""sonatypeOpen "${organization.value}" "${name.value} v${version.value}""""),
releaseStepCommand("+publishSigned"),
releaseStepCommand("+sonatypeRelease"),
setNextVersion, // : ReleaseStep
commitNextVersion, // : ReleaseStep
pushChanges // : ReleaseStep, also checks that an upstream branch is properly configured
)
)

developers := List(
Developer(
id = "tupol",
name = "Tupol",
email = "[email protected]",
url = url("https://github.com/tupol")
)
lazy val coverageSettings = Seq(
coverageEnabled in Test := true,
coverageMinimum in Test := 95,
coverageFailOnMinimum in Test := true,
coverageExcludedPackages := ".*BuildInfo.*"
)
lazy val basicSettings = Seq(
organization := "org.tupol",
name := "scala-utils",
scalaVersion := Versions.scala,
crossScalaVersions := Versions.crossScala,
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-Ywarn-unused-import"
),
updateOptions := updateOptions.value.withCachedResolution(true),
libraryDependencies ++= CoreTestDependencies,
scoverage.ScoverageKeys.coverageExcludedFiles := ".*BuildInfo.*"

import ReleaseTransformations._
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies, // : ReleaseStep
inquireVersions, // : ReleaseStep
runClean, // : ReleaseStep
runTest, // : ReleaseStep
setReleaseVersion, // : ReleaseStep
commitReleaseVersion, // : ReleaseStep, performs the initial git checks
tagRelease, // : ReleaseStep
releaseStepCommand(s"""sonatypeOpen "${organization.value}" "${name.value} v${version.value}""""),
releaseStepCommand("+publishSigned"),
releaseStepCommand("+sonatypeRelease"),
setNextVersion, // : ReleaseStep
commitNextVersion, // : ReleaseStep
pushChanges // : ReleaseStep, also checks that an upstream branch is properly configured
)
val commonSettings = basicSettings ++ coverageSettings ++ publishSettings

// ------------------------------
// BUILD-INFO
lazy val root = (project in file(".")).
enablePlugins(BuildInfoPlugin).
settings(

lazy val core = (project in file("core"))
.enablePlugins(BuildInfoPlugin)
.settings(commonSettings: _*)
.settings(
name := "scala-utils-core",
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "org.tupol.utils.info"
buildInfoOptions := Seq[BuildInfoOption](BuildInfoOption.BuildTime, BuildInfoOption.ToMap, BuildInfoOption.ToJson),
buildInfoPackage := "org.tupol.utils",
libraryDependencies ++= CoreDependencies,
publishArtifact in Test := true
)

buildInfoKeys ++= Seq[BuildInfoKey](
resolvers,
libraryDependencies in Test,
BuildInfoKey.map(name) { case (k, v) => "project" + k.capitalize -> v.capitalize },
BuildInfoKey.action("buildTime") {
System.currentTimeMillis
} // re-computed each time at compile
)

buildInfoOptions += BuildInfoOption.BuildTime
buildInfoOptions += BuildInfoOption.ToMap
buildInfoOptions += BuildInfoOption.ToJson
lazy val config_z = (project in file("config-z"))
.enablePlugins(BuildInfoPlugin)
.settings(commonSettings: _*)
.settings(
name := "scala-utils-config-z",
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoOptions := Seq[BuildInfoOption](BuildInfoOption.BuildTime, BuildInfoOption.ToMap, BuildInfoOption.ToJson),
buildInfoPackage := "org.tupol.utils.config",
libraryDependencies ++= ConfigZDependencies
)
.dependsOn(core % "test->test;compile->compile")

lazy val scala_utils = Project(
id = "scala-utils",
base = file(".")
).settings(commonSettings: _*)
.dependsOn(core % "test->test;compile->compile", config_z)
.aggregate(core, config_z)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ In order to create a new configuration we need the following:

### Simple Configuration Example

The full example is available in [`examples.MySimpleExample`](src/test/scala/examples/MySimpleExample.scala).
The full example is available in [`examples.MySimpleExample`](../src/test/scala/examples/MySimpleExample.scala).

#### 1. Create a case class to configure or select an existing one

Expand Down Expand Up @@ -96,7 +96,7 @@ object MySimpleExample extends Configurator[MySimpleExample] {

1. Normally we define the configurator factory in a companion object attached to the case class that we want to configure.

2. The only top level import is `import org.tupol.utils.config.Configurator`.
2. The only top level import is `import org.tupol.utils.configz.Configurator`.
We are quite keen on keeping the top level imports clean, and only import locally what we need.
The subsequent sets of imports are inside the `MySimpleExample` object scope and in the `validationNel` function scope.

Expand Down Expand Up @@ -134,7 +134,7 @@ object MySimpleExample extends Configurator[MySimpleExample] {

Just as described previously, we can also create configuration objects that are based on other configuration objects.

The full example is available in [`examples.MyComplexExample`](src/test/scala/examples/MyComplexExample.scala).
The full example is available in [`examples.MyComplexExample`](../src/test/scala/examples/MyComplexExample.scala).


#### 1. Create a case class to configure or select an existing one
Expand Down Expand Up @@ -241,3 +241,7 @@ This pattern can simplify a lot the way complex configuration objects are create

3. For the final line to work, `MySimpleExample.validationNel(config)` needs to be defined.


## Credits & Thanks ##

- [Daan Hoogenboezem](https://github.com/daanhoogenboezem) For sketching the initial configuration framework.
Loading

0 comments on commit bd513df

Please sign in to comment.