Permalink
Browse files

Integrates sbt-org-policies plugin (#24)

  • Loading branch information...
juanpedromoreno committed Mar 28, 2017
1 parent 7471850 commit c85571f6d8de6b13a3457282d40d8b2abb08e23d
@@ -0,0 +1,23 @@
style = defaultWithAlign
maxColumn = 100
continuationIndent.callSite = 2
newlines {
sometimesBeforeColonInMethodReturnType = false
}
align {
arrowEnumeratorGenerator = false
ifWhileOpenParen = false
openParenCallSite = false
openParenDefnSite = false
}
docstrings = JavaDoc
rewrite {
rules = [SortImports, RedundantBraces]
redundantBraces.maxLines = 1
}
@@ -15,6 +15,3 @@ after_success:
- if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then
sbt compile publishSigned;
fi
- if [ "$TRAVIS_PULL_REQUEST" = "true" ]; then
echo "Not in master branch, skipping deploy and release";
fi
@@ -1,10 +1,9 @@
#Scala Exercises - Doobie library
# Scala Exercises - Doobie library
------------------------
This repository hosts a content library for the [Scala Exercises](https://www.scala-exercises.org/) platform, including interactive exercises related to the [Doobie](https://github.com/tpolecat/doobie) functional JDBC layer.
## About Scala exercises
## About Scala exercises
"Scala Exercises" brings exercises for the Stdlib, Cats, Shapeless and many other great libraries for Scala to your browser. Offering hundreds of solvable exercises organized into several categories covering the basics of the Scala language and it's most important libraries.
@@ -15,7 +14,7 @@ Scala Exercises is available at [scala-exercises.org](https://scala-exercises.or
Contributions welcome! Please join our [Gitter channel](https://gitter.im/scala-exercises/scala-exercises)
to get involved, or visit our [GitHub site](https://github.com/scala-exercises).
##License
## License
Copyright (C) 2015-2016 47 Degrees, LLC.
Reactive, scalable software solutions.
@@ -1,52 +1,24 @@
val scalaExerciesV = "0.4.0-SNAPSHOT"
def dep(artifactId: String) = "org.scala-exercises" %% artifactId % scalaExerciesV
lazy val doobie = (project in file("."))
.settings(publishSettings:_*)
.enablePlugins(ExerciseCompilerPlugin)
.settings(
organization := "org.scala-exercises",
name := "exercises-doobie",
scalaVersion := "2.11.8",
parallelExecution in Test := false,
version := "0.3.0-SNAPSHOT",
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "2.2.4",
"org.scala-exercises" %% "exercise-compiler" % version.value,
"org.scala-exercises" %% "definitions" % version.value,
"org.scalacheck" %% "scalacheck" % "1.12.5",
"com.github.alexarchambault" %% "scalacheck-shapeless_1.12" % "0.3.1",
"org.tpolecat" %% "doobie-core" % "0.3.0",
"org.tpolecat" %% "doobie-contrib-h2" % "0.3.0",
compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.0")
dep("exercise-compiler"),
dep("definitions"),
%%("doobie-core"),
%%("doobie-h2"),
%%("scalatest"),
%%("scalacheck"),
%%("scheckShapeless")
)
)
// Distribution
lazy val gpgFolder = sys.env.getOrElse("PGP_FOLDER", ".")
lazy val publishSettings = Seq(
organizationName := "Scala Exercises",
organizationHomepage := Some(new URL("https://scala-exercises.org")),
startYear := Some(2016),
description := "Scala Exercises: The path to enlightenment",
homepage := Some(url("https://scala-exercises.org")),
pgpPassphrase := Some(sys.env.getOrElse("PGP_PASSPHRASE", "").toCharArray),
pgpPublicRing := file(s"$gpgFolder/pubring.gpg"),
pgpSecretRing := file(s"$gpgFolder/secring.gpg"),
credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", sys.env.getOrElse("PUBLISH_USERNAME", ""), sys.env.getOrElse("PUBLISH_PASSWORD", "")),
scmInfo := Some(ScmInfo(url("https://github.com/scala-exercises/exercises-doobie"), "https://github.com/scala-exercises/exercises-doobie.git")),
licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := Function.const(false),
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("Snapshots" at nexus + "content/repositories/snapshots")
else
Some("Releases" at nexus + "service/local/staging/deploy/maven2")
}
)
pgpPassphrase := Some(getEnvVar("PGP_PASSPHRASE").getOrElse("").toCharArray)
pgpPublicRing := file(s"$gpgFolder/pubring.gpg")
pgpSecretRing := file(s"$gpgFolder/secring.gpg")
@@ -0,0 +1,47 @@
import de.heikoseeberger.sbtheader.HeaderPattern
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import sbt.Keys._
import sbt._
import sbtorgpolicies._
import sbtorgpolicies.model._
import sbtorgpolicies.OrgPoliciesPlugin.autoImport._
object ProjectPlugin extends AutoPlugin {
override def trigger: PluginTrigger = allRequirements
override def requires: Plugins = plugins.JvmPlugin && OrgPoliciesPlugin
override def projectSettings: Seq[Def.Setting[_]] =
Seq(
description := "Scala Exercises: The path to enlightenment",
startYear := Option(2016),
orgGithubSetting := GitHubSettings(
organization = "scala-exercises",
project = name.value,
organizationName = "Scala Exercises",
groupId = "org.scala-exercises",
organizationHomePage = url("https://www.scala-exercises.org"),
organizationEmail = "hello@47deg.com"
),
orgLicenseSetting := ApacheLicense,
scalaVersion := "2.11.8",
scalaOrganization := "org.scala-lang",
crossScalaVersions := Seq("2.11.8"),
resolvers ++= Seq(
Resolver.mavenLocal,
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
scalacOptions := sbtorgpolicies.model.scalacCommonOptions,
headers := Map(
"scala" -> (HeaderPattern.cStyleBlockComment,
s"""|/*
| * scala-exercises - ${name.value}
| * Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
| */
|
|""".stripMargin)
)
)
}
@@ -1 +1 @@
sbt.version = 0.13.12
sbt.version=0.13.13
@@ -2,5 +2,5 @@ resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots")
)
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.3.0-SNAPSHOT", "0.13", "2.10")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.4.0-SNAPSHOT", "0.13", "2.10")
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.3.2")
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-doobie
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/
package doobie
import doobie.DoobieUtils.CountryTable._
@@ -9,76 +14,76 @@ import scalaz.Scalaz._
import scalaz._
/** ==Introduction==
* doobie is a monadic API that provides a number of data types that all work the same way
* but describe computations in different contexts.
*
* In the doobie high level API the most common types we will deal with have the form
* ConnectionIO[A], specifying computations that take place in a context where a
* java.sql.Connection is available, ultimately producing a value of type A.
*
* doobie programs are values. You can compose small programs to build larger programs. Once you
* have constructed a program you wish to run, you interpret it into an effectful target monad of
* your choice (Task or IO for example) and drop it into your main application wherever you like.
*
* ==First programs==
*
* {{{
* import doobie.imports._
* import scalaz._, Scalaz._
* import scalaz.concurrent.Task
* }}}
*
* So let’s start with a ConnectionIO program that simply returns a constant.
*
* {{{
* val program = 42.point[ConnectionIO]
* program: ConnectionIO[Int] = Return(42)
* }}}
*
* This is a perfectly respectable doobie program, but we can’t run it as-is; we need a Connection
* first. There are several ways to do this, but here let’s use a Transactor.
*
* {{{
* val xa = DriverManagerTransactor[Task](
* driver = "org.postgresql.Driver",
* url = "jdbc:postgresql:world",
* user = "postgres",
* pass = ""
* )
* }}}
*
* A Transactor is simply a structure that knows how to connect to a database, hand out
* connections, and clean them up; and with this knowledge it can transform ConnectionIO ~> Task,
* which gives us something we can run. Specifically it gives us a Task that, when run, will
* connect to the database and run our program in a single transaction.
*
* The DriverManagerTransactor simply delegates to the java.sql.DriverManager to allocate
* connections, which is fine for development but inefficient for production use.
*
* @param name connecting_to_database
*/
* doobie is a monadic API that provides a number of data types that all work the same way
* but describe computations in different contexts.
*
* In the doobie high level API the most common types we will deal with have the form
* ConnectionIO[A], specifying computations that take place in a context where a
* java.sql.Connection is available, ultimately producing a value of type A.
*
* doobie programs are values. You can compose small programs to build larger programs. Once you
* have constructed a program you wish to run, you interpret it into an effectful target monad of
* your choice (Task or IO for example) and drop it into your main application wherever you like.
*
* ==First programs==
*
* {{{
* import doobie.imports._
* import scalaz._, Scalaz._
* import scalaz.concurrent.Task
* }}}
*
* So let’s start with a ConnectionIO program that simply returns a constant.
*
* {{{
* val program = 42.point[ConnectionIO]
* program: ConnectionIO[Int] = Return(42)
* }}}
*
* This is a perfectly respectable doobie program, but we can’t run it as-is; we need a Connection
* first. There are several ways to do this, but here let’s use a Transactor.
*
* {{{
* val xa = DriverManagerTransactor[Task](
* driver = "org.postgresql.Driver",
* url = "jdbc:postgresql:world",
* user = "postgres",
* pass = ""
* )
* }}}
*
* A Transactor is simply a structure that knows how to connect to a database, hand out
* connections, and clean them up; and with this knowledge it can transform ConnectionIO ~> Task,
* which gives us something we can run. Specifically it gives us a Task that, when run, will
* connect to the database and run our program in a single transaction.
*
* The DriverManagerTransactor simply delegates to the java.sql.DriverManager to allocate
* connections, which is fine for development but inefficient for production use.
*
* @param name connecting_to_database
*/
object ConnectingToDatabaseSection extends FlatSpec with Matchers with Section {
/**
* Right, so let’s do this.
*/
def constantValue(res0: Int) =
* Right, so let’s do this.
*/
def constantValue(res0: Int) =
42.point[ConnectionIO].transact(xa).run should be(res0)
/** We have computed a constant. It’s not very interesting because we never ask the database to
* perform any work, but it’s a first step
*
* We are gonna connect to a database to compute a constant.
* Let’s use the sql string interpolator to construct a query that asks the database to compute
* a constant. The meaning of this program is “run the query, interpret the resultset as
* a stream of Int values, and yield its one and only element.”
*/
* perform any work, but it’s a first step
*
* We are gonna connect to a database to compute a constant.
* Let’s use the sql string interpolator to construct a query that asks the database to compute
* a constant. The meaning of this program is “run the query, interpret the resultset as
* a stream of Int values, and yield its one and only element.”
*/
def constantValueFromDatabase(res0: Int) =
sql"select 42".query[Int].unique.transact(xa).run should be(res0)
/** What if we want to do more than one thing in a transaction? Easy! ConnectionIO is a monad,
* so we can use a for comprehension to compose two smaller programs into one larger program.
*/
* so we can use a for comprehension to compose two smaller programs into one larger program.
*/
def combineTwoPrograms(res0: (Int, Int)) = {
val largerProgram = for {
a <- sql"select 42".query[Int].unique
@@ -89,10 +94,10 @@ object ConnectingToDatabaseSection extends FlatSpec with Matchers with Section {
}
/** The astute among you will note that we don’t actually need a monad to do this; an applicative
* functor is all we need here. So we could also write the above program as:
*/
* functor is all we need here. So we could also write the above program as:
*/
def combineTwoProgramsWithApplicative(res0: Int) = {
val oneProgram = sql"select 42".query[Int].unique
val oneProgram = sql"select 42".query[Int].unique
val anotherProgram = sql"select power(5, 2)".query[Int].unique
(oneProgram |@| anotherProgram) { _ + _ }.transact(xa).run should be(res0)
@@ -1,14 +1,18 @@
/*
* scala-exercises - exercises-doobie
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/
package doobie
import org.scalaexercises.definitions.{Library, Section}
/** doobie is a pure functional JDBC layer for Scala.
*
* @param name doobie
*/
*
* @param name doobie
*/
object DoobieLibrary extends Library {
override def owner: String = "scala-exercises"
override def owner: String = "scala-exercises"
override def repository: String = "exercises-doobie"
override def color = Some("#E35E31")
@@ -1,9 +1,14 @@
/*
* scala-exercises - exercises-doobie
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/
package doobie
import java.sql.Connection
import doobie.Model._
import doobie.free.{ drivermanager => FD }
import doobie.free.{drivermanager => FD}
import doobie.imports._
import scalaz.concurrent.Task
Oops, something went wrong.

0 comments on commit c85571f

Please sign in to comment.