Skip to content

Commit

Permalink
Integrates_sbt-org-policies (#4)
Browse files Browse the repository at this point in the history
* Integrates sbt-org-policies
  • Loading branch information
AdrianRaFo authored and juanpedromoreno committed Mar 31, 2017
1 parent 7fd8311 commit 25554d2
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 119 deletions.
22 changes: 22 additions & 0 deletions .scalafmt.conf
@@ -0,0 +1,22 @@
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
}
4 changes: 1 addition & 3 deletions .travis.yml
Expand Up @@ -6,7 +6,7 @@ jdk:
- oraclejdk8

script:
- sbt compile test
- sbt test

before_install:
- if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then
Expand All @@ -16,5 +16,3 @@ before_install:
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
4 changes: 2 additions & 2 deletions README.md
@@ -1,4 +1,4 @@
#Scala Exercises - Fetch library
# Scala Exercises - Fetch library

------------------------

Expand All @@ -15,7 +15,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.
Expand Down
67 changes: 20 additions & 47 deletions build.sbt
@@ -1,52 +1,25 @@
val scalaExerciesV = "0.4.0-SNAPSHOT"

def dep(artifactId: String) = "org.scala-exercises" %% artifactId % scalaExerciesV

lazy val fetch = (project in file("."))
.settings(publishSettings:_*)
.enablePlugins(ExerciseCompilerPlugin)
.settings(
organization := "org.scala-exercises",
name := "exercises-fetch",
scalaVersion := "2.11.8",
version := "0.3.0-SNAPSHOT",
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
libraryDependencies ++= Seq(
"com.fortysevendeg" %% "fetch" % "0.4.0",
"com.fortysevendeg" %% "fetch-monix" % "0.4.0",
"com.chuusai" %% "shapeless" % "2.2.5",
"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",
compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.3")
.enablePlugins(ExerciseCompilerPlugin)
.settings(
name := "exercises-fetch",
libraryDependencies ++= Seq(
dep("exercise-compiler"),
dep("definitions"),
%%("fetch"),
%%("fetch-monix"),
%%("shapeless"),
%%("scalatest"),
%%("scalacheck"),
%%("scheckShapeless")
)
)
)

// Distribution

lazy val gpgFolder = sys.env.getOrElse("PGP_FOLDER", ".")

lazy val publishSettings = Seq(
organizationName := "Scala Exercises",
organizationHomepage := Some(new URL("http://scala-exercises.org")),
startYear := Some(2016),
description := "Scala Exercises: The path to enlightenment",
homepage := Some(url("http://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-fetch"), "https://github.com/scala-exercises/exercises-fetch.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")
47 changes: 47 additions & 0 deletions project/ProjectPlugin.scala
@@ -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)
)
)
}
2 changes: 1 addition & 1 deletion project/build.properties
@@ -1 +1 @@
sbt.version=0.13.12
sbt.version=0.13.13
4 changes: 2 additions & 2 deletions project/plugins.sbt
@@ -1,3 +1,3 @@
resolvers += 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")
9 changes: 7 additions & 2 deletions src/main/scala/fetchlib/CachingSection.scala
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-fetch
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package fetchlib

import cats.data.NonEmptyList
Expand Down Expand Up @@ -80,7 +85,7 @@ object CachingSection extends FlatSpec with Matchers with Section {
*/
def replaying(res0: Int, res1: Int) = {
def fetchUsers = List(1, 2, 3).traverse(getUser)
val firstEnv = fetchUsers.runE[Id]
val firstEnv = fetchUsers.runE[Id]

firstEnv.rounds.size should be(res0)

Expand Down Expand Up @@ -124,7 +129,7 @@ object CachingSection extends FlatSpec with Matchers with Section {
def customCache(res0: Int) = {

val fetchSameTwice: Fetch[(User, User)] = for {
one <- getUser(1)
one <- getUser(1)
another <- getUser(1)
} yield (one, another)

Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/fetchlib/CatsSection.scala
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-fetch
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package fetchlib

import cats.data.NonEmptyList
Expand All @@ -9,7 +14,6 @@ import fetch.unsafe.implicits._
import fetch.syntax._
import scala.util.Try


import org.scalaexercises.definitions._

/**
Expand Down
48 changes: 27 additions & 21 deletions src/main/scala/fetchlib/ConcurrencyMonadsSection.scala
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-fetch
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package fetchlib

import cats.data.NonEmptyList
Expand Down Expand Up @@ -76,7 +81,7 @@ object ConcurrencyMonadsSection extends FlatSpec with Matchers with Section {
}

val result = Await.result(op, 5 seconds)

result should be(res0)
}

Expand Down Expand Up @@ -105,7 +110,7 @@ object ConcurrencyMonadsSection extends FlatSpec with Matchers with Section {
def monixTask(res0: Tuple2[Int, Int]) = {

val scheduler = Scheduler.Implicits.global
val task = Fetch.run[Task](homePage)
val task = Fetch.run[Task](homePage)

val op = homePage.runA[Task] map {
case (posts, topics) =>
Expand Down Expand Up @@ -186,32 +191,33 @@ object ConcurrencyMonadsSection extends FlatSpec with Matchers with Section {
* Because of this we'll override `map` for not using `flatMap` and `product` for expressing the independence of two computations.
*/
def customTypes(res0: Tuple2[Int, Int]) = {
implicit def taskFetchMonadError(implicit TM: Monad[Task]): FetchMonadError[Task] = new FetchMonadError[Task] {
override def tailRecM[A, B](a: A)(f: A => Task[Either[A, B]]): Task[B] =
TM.tailRecM(a)(f)
implicit def taskFetchMonadError(implicit TM: Monad[Task]): FetchMonadError[Task] =
new FetchMonadError[Task] {
override def tailRecM[A, B](a: A)(f: A => Task[Either[A, B]]): Task[B] =
TM.tailRecM(a)(f)

override def map[A, B](fa: Task[A])(f: A => B): Task[B] =
fa.map(f)
override def map[A, B](fa: Task[A])(f: A => B): Task[B] =
fa.map(f)

override def product[A, B](fa: Task[A], fb: Task[B]): Task[(A, B)] =
Task.zip2(Task.fork(fa), Task.fork(fb)) // introduce parallelism with Task#fork
override def product[A, B](fa: Task[A], fb: Task[B]): Task[(A, B)] =
Task.zip2(Task.fork(fa), Task.fork(fb)) // introduce parallelism with Task#fork

def pure[A](x: A): Task[A] =
Task.now(x)
def pure[A](x: A): Task[A] =
Task.now(x)

def handleErrorWith[A](fa: Task[A])(f: FetchException => Task[A]): Task[A] =
fa.onErrorHandleWith({
case ex: FetchException => f(ex)
})
def handleErrorWith[A](fa: Task[A])(f: FetchException => Task[A]): Task[A] =
fa.onErrorHandleWith({
case ex: FetchException => f(ex)
})

def raiseError[A](e: FetchException): Task[A] =
Task.raiseError(e)
def raiseError[A](e: FetchException): Task[A] =
Task.raiseError(e)

def flatMap[A, B](fa: Task[A])(f: A => Task[B]): Task[B] =
fa.flatMap(f)
def flatMap[A, B](fa: Task[A])(f: A => Task[B]): Task[B] =
fa.flatMap(f)

override def runQuery[A](q: Query[A]): Task[A] = queryToTask(q)
}
override def runQuery[A](q: Query[A]): Task[A] = queryToTask(q)
}

val scheduler = Scheduler.Implicits.global

Expand Down
8 changes: 6 additions & 2 deletions src/main/scala/fetchlib/ErrorHandlingSection.scala
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-fetch
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package fetchlib

import cats.data.NonEmptyList
Expand Down Expand Up @@ -30,9 +35,8 @@ object ErrorHandlingSection extends FlatSpec with Matchers with Section {
* val fetchError: Fetch[User] = (new Exception("Oh noes")).fetch
* }}}
*/
def failedFetch(res0: Boolean) = {
def failedFetch(res0: Boolean) =
Try(fetchError.runA[Id]).isFailure should be(res0)
}

/**
* Since `Id` runs the fetch eagerly, the only way to recover from errors is to capture the exception.
Expand Down
13 changes: 9 additions & 4 deletions src/main/scala/fetchlib/FetchLibrary.scala
@@ -1,15 +1,20 @@
/*
* scala-exercises - exercises-fetch
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package fetchlib

import org.scalaexercises.definitions._

/** Fetch is a library for making access to data both simple & efficient.
*
* @param name fetch
*/
*
* @param name fetch
*/
object FetchLibrary extends Library {
override def logoPath = "fetch"

override def owner = "scala-exercises"
override def owner = "scala-exercises"
override def repository = "exercises-fetch"

override def color = Some("#2F2859")
Expand Down

0 comments on commit 25554d2

Please sign in to comment.