├── project ├── build.properties ├── plugins.sbt └── Publishing.scala ├── engine └── src │ ├── test │ └── scala │ │ └── com │ │ └── outworkers │ │ └── diesel │ │ └── engine │ │ └── query │ │ ├── MergeListTest.scala │ │ └── AbstractQueryTest.scala │ └── main │ └── scala │ └── com │ └── outworkers │ └── diesel │ └── engine │ ├── syntax │ └── Syntax.scala │ └── query │ ├── multiparts │ └── Parts.scala │ └── AbstractQuery.scala ├── .gitignore ├── reflection └── src │ ├── main │ └── scala │ │ └── com │ │ └── outworkers │ │ └── diesel │ │ └── reflection │ │ └── EarlyInit.scala │ └── test │ └── scala │ └── com │ └── outworkers │ └── diesel │ └── reflection │ └── ReflectionTests.scala ├── README.md └── .travis.yml /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.8 2 | -------------------------------------------------------------------------------- /engine/src/test/scala/com/outworkers/diesel/engine/query/MergeListTest.scala: -------------------------------------------------------------------------------- 1 | package com.outworkers.diesel.engine.query 2 | 3 | import org.scalatest.{FlatSpec, Matchers} 4 | 5 | class MergeListTest extends FlatSpec with Matchers { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | *.jar 4 | *.jar.old 5 | 6 | atlassian-ide-plugin.xml 7 | 8 | 9 | # Eclipse specific 10 | .classpath 11 | .project 12 | .settings/ 13 | .metadata 14 | 15 | # Project statistics 16 | stats 17 | 18 | # Java heap dump files 19 | java_pid* 20 | 21 | 22 | # InteliJ IDEA 23 | *.iml 24 | 25 | # sbt specific 26 | dist/* 27 | target/ 28 | lib_managed/ 29 | src_managed/ 30 | project/boot/ 31 | project/plugins/project/ 32 | 33 | # Scala-IDE specific 34 | .scala_dependencies 35 | 36 | # MacOS X specific 37 | .DS_Store 38 | 39 | #InteliJ 40 | .idea_modules/ 41 | .idea/ 42 | -------------------------------------------------------------------------------- /engine/src/main/scala/com/outworkers/diesel/engine/syntax/Syntax.scala: -------------------------------------------------------------------------------- 1 | package com.outworkers.diesel.engine.syntax 2 | 3 | sealed abstract class Symbols { 4 | val `*` = "*" 5 | val `{` = "{" 6 | val `}` = "}" 7 | val `[` = "[" 8 | val `]` = "]" 9 | 10 | val `.` = "." 11 | val `:` = ":" 12 | val `;` = ";" 13 | val `(` = "(" 14 | val `)` = ")" 15 | val `,` = "," 16 | val `<` = "<" 17 | val `>` = ">" 18 | val `=` = "=" 19 | val + = "+" 20 | val - = "-" 21 | } 22 | 23 | class Syntax { 24 | object Symbols extends Symbols 25 | } 26 | 27 | object DefaultSyntax extends Syntax -------------------------------------------------------------------------------- /engine/src/test/scala/com/outworkers/diesel/engine/query/AbstractQueryTest.scala: -------------------------------------------------------------------------------- 1 | package com.outworkers.diesel.engine.query 2 | 3 | import org.scalatest.{FlatSpec, Matchers} 4 | 5 | case class DummyQuery(override val queryString: String) extends AbstractQuery[DummyQuery](queryString) { 6 | override def create(st: String): DummyQuery = DummyQuery(st) 7 | } 8 | 9 | object DummyQuery { 10 | def empty: DummyQuery = DummyQuery("") 11 | } 12 | 13 | class AbstractQueryTest extends FlatSpec with Matchers { 14 | 15 | it should "create an empty CQL query using the empty method on the companion object" in { 16 | DummyQuery.empty.queryString shouldEqual "" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers ++= Seq( 2 | Classpaths.typesafeReleases, 3 | Resolver.sonatypeRepo("releases"), 4 | Resolver.jcenterRepo, 5 | "jgit-repo" at "http://download.eclipse.org/jgit/maven", 6 | "Twitter Repo" at "http://maven.twttr.com/" 7 | ) 8 | 9 | addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2") 10 | 11 | addSbtPlugin("com.websudos" %% "sbt-package-dist" % "1.2.0") 12 | 13 | addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.5") 14 | 15 | addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.7.0") 16 | 17 | addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.0.4") 18 | 19 | addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.5.0") 20 | 21 | addSbtPlugin("org.scoverage" %% "sbt-coveralls" % "1.1.0") 22 | 23 | addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.10") 24 | 25 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") 26 | 27 | addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0") 28 | 29 | addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") -------------------------------------------------------------------------------- /reflection/src/main/scala/com/outworkers/diesel/reflection/EarlyInit.scala: -------------------------------------------------------------------------------- 1 | package com.outworkers.diesel.reflection 2 | 3 | import scala.reflect.runtime.universe.TypeTag 4 | import scala.reflect.runtime.{currentMirror => cm, universe => ru} 5 | 6 | private object Lock 7 | 8 | trait EarlyInit[T] { 9 | 10 | private[this] val instanceMirror = cm.reflect(this) 11 | 12 | def initialize()(implicit typeTag: TypeTag[T]): Seq[T] = { 13 | Lock.synchronized { 14 | val selfType = instanceMirror.symbol.toType 15 | 16 | val members: Seq[ru.Symbol] = (for { 17 | baseClass <- selfType.baseClasses.reverse 18 | symbol <- baseClass.typeSignature.members.sorted 19 | if symbol.typeSignature <:< ru.typeOf[T] 20 | } yield symbol)(collection.breakOut) 21 | 22 | for { 23 | symbol <- members.distinct 24 | field = if (symbol.isModule) { 25 | instanceMirror.reflectModule(symbol.asModule).instance 26 | } else if (symbol.isTerm && symbol.asTerm.isVal) { 27 | instanceMirror.reflectField(symbol.asTerm).get 28 | } 29 | } yield field.asInstanceOf[T] 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /reflection/src/test/scala/com/outworkers/diesel/reflection/ReflectionTests.scala: -------------------------------------------------------------------------------- 1 | package com.outworkers.diesel.reflection 2 | 3 | import org.scalatest.{FlatSpec, Matchers} 4 | 5 | import scala.reflect.runtime.{currentMirror => cm} 6 | 7 | class ColumnHolder[V] { 8 | lazy val name: String = { 9 | cm.reflect(this).symbol.name.toTypeName.decodedName.toString 10 | } 11 | } 12 | 13 | class TypeHolder[T <: TypeHolder[T, R], R] extends EarlyInit[ColumnHolder[_]] 14 | 15 | class Holder extends TypeHolder[Holder, String] { 16 | object test extends ColumnHolder[String] 17 | object test2 extends ColumnHolder[Int] 18 | } 19 | 20 | class Holder2 extends TypeHolder[Holder2, String] { 21 | object test extends ColumnHolder[String] 22 | object test2 extends ColumnHolder[Int] 23 | object test3 extends ColumnHolder[String] 24 | object test4 extends ColumnHolder[Int] 25 | object test5 extends ColumnHolder[String] 26 | } 27 | 28 | class ReflectionTests extends FlatSpec with Matchers { 29 | 30 | it should "initialise the members of a companion object and emit a TypeTag automatically" in { 31 | val holder = new Holder 32 | val initList = holder.initialize() 33 | 34 | initList.size shouldEqual 2 35 | } 36 | 37 | it should "initialise all five members of the companion object using the emitted typetag" in { 38 | val holder = new Holder2 39 | val initList = holder.initialize() 40 | 41 | initList.size shouldEqual 5 42 | } 43 | 44 | 45 | it should "capture the names as they appear written by the user using the TypeTag" in { 46 | val holder = new Holder 47 | val initList = holder.initialize() 48 | 49 | initList.map(_.name).toList shouldEqual List("test", "test2") 50 | } 51 | 52 | it should "capture the names as they appear written by the user using the TypeTag from the larger object" in { 53 | val holder = new Holder2 54 | val initList = holder.initialize() 55 | 56 | initList.map(_.name).toList shouldEqual List("test", "test2", "test3", "test4", "test5") 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /engine/src/main/scala/com/outworkers/diesel/engine/query/multiparts/Parts.scala: -------------------------------------------------------------------------------- 1 | package com.outworkers.diesel.engine.query.multiparts 2 | 3 | import com.outworkers.diesel.engine.query.AbstractQuery 4 | 5 | abstract class QueryPart[T <: QueryPart[T, QT], QT <: AbstractQuery[QT]](val list: List[QT] = Nil) { 6 | 7 | def instance(l: List[QT]): T 8 | 9 | def nonEmpty: Boolean = list.nonEmpty 10 | 11 | def qb: QT 12 | 13 | def build(init: QT): QT = if (init.nonEmpty) { 14 | qb.bpad.prepend(init) 15 | } else { 16 | qb.prepend(init) 17 | } 18 | 19 | def append(q: QT): T = instance(list ::: (q :: Nil)) 20 | 21 | def append(q: QT*): T = instance(q.toList ::: list) 22 | 23 | def append(q: List[QT]): T = instance(q ::: list) 24 | 25 | def mergeList(list: List[QT]): MergedQueryList[QT] 26 | 27 | def merge[X <: QueryPart[X, QT]](part: X): MergedQueryList[QT] = { 28 | val list = if (part.qb.nonEmpty) List(qb, part.qb) else List(qb) 29 | 30 | mergeList(list) 31 | } 32 | } 33 | 34 | 35 | abstract class MergedQueryList[QT <: AbstractQuery[QT]](val list: List[QT]) { 36 | 37 | def this(query: QT) = this(List(query)) 38 | 39 | def apply(list: List[QT]): MergedQueryList[QT] 40 | 41 | def apply(str: String): QT 42 | 43 | def build: QT = apply(list.map(_.queryString).mkString(" ")) 44 | 45 | /** 46 | * This will build a merge list into a final executable query. 47 | * It will also prepend the CQL query passed as a parameter to the final string. 48 | * 49 | * If the current list has only empty queries to merge, the init string is return instead. 50 | * Alternatively, the init string is prepended after a single space. 51 | * 52 | * @param init The initialisation query of the part merge. 53 | * @return A final, executable CQL query with all the parts merged. 54 | */ 55 | def build(init: QT): QT = if (list.exists(_.nonEmpty)) { 56 | build.bpad.prepend(init.queryString) 57 | } else { 58 | init 59 | } 60 | 61 | def merge[X <: QueryPart[X, QT]](part: X, init: QT = apply("")): MergedQueryList[QT] = { 62 | val appendable = part build init 63 | 64 | if (appendable.nonEmpty) { 65 | apply(list ::: List(appendable)) 66 | } else { 67 | this 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | diesel [![Build Status](https://travis-ci.org/outworkers/diesel.svg?branch=develop)](https://travis-ci.org/outworkers/diesel) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/1f2485923ecf446c856fa0e3e31b0b99)](https://www.codacy.com/app/flavian/diesel?utm_source=github.com&utm_medium=referral&utm_content=outworkers/diesel&utm_campaign=Badge_Grade) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.outworkers/diesel-engine_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.outworkers/diesel-engine-2.11) [![Bintray](https://api.bintray.com/packages/outworkers/oss-releases/diesel-engine/images/download.svg) ](https://bintray.com/outworkers/oss-releases/diesel-engine/_latestVersion) [![ScalaDoc](http://javadoc-badge.appspot.com/com.outworkers/diesel-engine_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/com.outworkers/diesel-engine_2.11) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/outworkers/diesel?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 2 | ====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================== 3 | 4 | Mini query engine used to power our various DSL frameworks. 5 | 6 | #### Scala versions 7 | 8 | As of 0.5.x, Diesel engine publishes artefacts for Scala 2.10, 2.11 and 2.12 respecitvely. 9 | -------------------------------------------------------------------------------- /engine/src/main/scala/com/outworkers/diesel/engine/query/AbstractQuery.scala: -------------------------------------------------------------------------------- 1 | package com.outworkers.diesel.engine.query 2 | 3 | import com.outworkers.diesel.engine.syntax.DefaultSyntax._ 4 | 5 | abstract class AbstractQuery[QT <: AbstractQuery[QT]](val queryString: String) { 6 | 7 | def create(st: String): QT 8 | 9 | def copy: QT = create(queryString) 10 | 11 | def nonEmpty: Boolean = queryString.nonEmpty 12 | 13 | def append(st: String): QT = create(queryString + st) 14 | def append(st: QT): QT = append(st.queryString) 15 | def append[T](list: T, sep: String = ", ")(implicit ev1: T => TraversableOnce[String]): QT = { 16 | create(queryString + list.mkString(sep)) 17 | } 18 | 19 | def appendEscape(st: String): QT = append(escape(st)) 20 | def appendEscape(st: QT): QT = appendEscape(st.queryString) 21 | 22 | def terminate(): QT = appendIfAbsent(";") 23 | 24 | def appendSingleQuote(st: String): QT = append(singleQuote(st)) 25 | def appendSingleQuote(st: QT): QT = append(singleQuote(st.queryString)) 26 | 27 | def appendIfAbsent(st: String): QT = if (queryString.endsWith(st)) create(queryString) else append(st) 28 | def appendIfAbsent(st: QT): QT = appendIfAbsent(st.queryString) 29 | 30 | def prepend(st: String): QT = create(st + queryString) 31 | def prepend(st: QT): QT = prepend(st.queryString) 32 | 33 | def prependIfAbsent(st: String): QT = if (queryString.startsWith(st)) create(queryString) else prepend(st) 34 | def prependIfAbsent(st: QT): QT = prependIfAbsent(st.queryString) 35 | 36 | def escape(st: String): String = "`" + st + "`" 37 | def singleQuote(st: String): String = "'" + st.replaceAll("'", "''") + "'" 38 | 39 | def spaced: Boolean = queryString.endsWith(" ") 40 | def pad: QT = if (spaced) copy else create(queryString + " ") 41 | def bpad: QT = prependIfAbsent(" ") 42 | 43 | def forcePad: QT = create(queryString + " ") 44 | def trim: QT = create(queryString.trim) 45 | 46 | def wrapn(str: String): QT = append(Symbols.`(`).append(str).append(Symbols.`)`) 47 | def wrapn(query: QT): QT = wrapn(query.queryString) 48 | def wrap(str: String): QT = pad.append(Symbols.`(`).append(str).append(Symbols.`)`) 49 | def wrap(query: QT): QT = wrap(query.queryString) 50 | 51 | def wrapn[T](list: T)(implicit ev1: T => TraversableOnce[String]): QT = wrapn(list.mkString(", ")) 52 | def wrap[T](list: T)(implicit ev1: T => TraversableOnce[String]): QT = wrap(list.mkString(", ")) 53 | def wrapEscape(list: List[String]): QT = wrap(list.map(escape).mkString(", ")) 54 | 55 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | 3 | scala: 4 | - 2.10.6 5 | - 2.11.8 6 | 7 | sudo: false 8 | 9 | 10 | jdk: 11 | - openjdk7 12 | - oraclejdk7 13 | - oraclejdk8 14 | 15 | notifications: 16 | slack: 17 | - websudos:P9QNXx1ZGFnDHp3v3jUqtB8k 18 | email: 19 | - false 20 | 21 | branches: 22 | only: 23 | - master 24 | - develop 25 | 26 | matrix: 27 | include: 28 | - scala: 2.12.0 29 | jdk: oraclejdk8 30 | 31 | env: 32 | global: 33 | - GH_REF: github.com/outworkers/diesel.git 34 | - secure: lfylvCgZoY/rqfLhheKAxZRWHJyDFqV48KNS9xo8LZn6kMD0KGW7uXCIlzfUmt8V3SZaMriySA6aVGfbj+QPzFA3XARZUs1qQMjw+9/WGI21htrF6w8PRK3Sln4qAsshiVjGXYNqMiJr7PbDbtKA2iL815QAptSu/kODBvVW5Lul0KdsPtUVQhYVeVvzkHXnwuH/C9ah6qe0zyvtdfpUm2UeVqSCSNGcnkPBSYHpy+uYxN+tNXJImDD/xGCj7VO8mJRDTaAko0Wn9BGgDCc3s5oJ3CFbdOT6BN8UoNRbQ7CnJJlTjruHFYIt55hapy0f04DBk2F5xMatZBRdpqnMb58aMtyckqOMIiCiWdiir8G/iSwZp3c3Y07GlR6ynzny0pK7znqCZPoGt4ULDO+Mgn8ledBV0FV5gaATsqZbhlw2mI/bng8AUZe8GxasKXXz5aALuRZJKHTdrIZvvEODbRD3GivQj3+9V0E4+xkHE2WUJD2b3Uz0DXRM41VTeM4OEoTL70ZPNTf4SuhzSpKgjynqMRTSLDxW9ai+IVLZc9QDa6lu5yz0Ty1zXObMA/MrFP1IYwgdZBnrUeHXL6DuoPP18SEprogher46fOgaDtpqox3tagOdEXB8fTPyXaoohJaz+Abw3azGF4q45nRyNdancNe1+0S/Ik3rC7NRSmc= 35 | - secure: vOa6eYYPnokSIOMjgNQWT5HMupvMHenHkPBOWRT1+2j5xL89s5bQ5ACWb1XF5fUqk5zRmMKMIIkHysaQFpSj8Zo17IWx5R/2MA+nQcvHmDNS4tCNL+g6Xig+wvQbA5b5dWAHNzlUhQTXl4DF3HMBAk2LoHRyjhDSoms01T2KPsoMI/k2NyBPb3o+ZdFvlenJ0NlkYSgdiV3SZYSIlEqTP362OMkplpOUCk/PWqjDlevhXl9pajFBy9bG7JgIJW3OA18ndoe+qa0vwL91DFTA5YGon4GlfHi2Uh++eWZ+rWVHDotUPohbcwR1l0xGzeSeCMTYpCBXnQc3OuSb9DCPDpP6sC2TKqv0dgb8LiA3l1qs3PbJY0fWCjdoORD8gUWLidZ2s7ryCQgHUEZ75bPH3YEr61HephCVi0YTqFkzNxnVEmeE6AcUtvUIvII7YF6B6qEYFQ5ybuYP7yFfLFjLi3UCOvAbpUlED2kAEzGCW5iEc1RH72gjQ96G3pW7NqaWCpi4ir5HAT2eK48+gQ/Au4NtMwYQ55zn5zg020YKSL0DMD0YKFBbBHVJVnMunCaW+YlVCKFzIoDK9S1yxNsn9V8pDkb2IV+D8ch7IBfXtI3/ljIJp0r5IqyQFNxPf7cubyNEi+xM3btyPJ0KeQ5RYdJIhh19dCmcsm+9KKE2B/k= 36 | - secure: fpsCdaJc3Aa543A3a3HsuZpBhsTtsqK4ANnxtczOe9XbLtDobPEMOkD+u7Fh7CgxfcdflZcbYNysyqRcNBZNAZ2Ndr5NKxump5QfMVnuA185mBG9F6G6qahpMZNJ81WAdU/VXV6FAdoIOVXGqMD+YKb44/3X3eZvyLN1AzRmPRye5GBWzwFwXlkPWBpmWy39qaQBj1nmQyGhfRg/e/o3BFvqMXGZv7nfbuViZ5An8/9m0bd7I0OQRfZnmsCsSiyuTmt/88jh3ckJ3X0QSnBtdB1Ok/GGUWzyFo6YtXfa5ewpmSUbWgdYFleXVBt39LA+dD0sLDPgEvw/yPwFXHQVC1aSF4beGNRCaz9zcBDQI5gfGw8ZdpmSjnHPdTemmwQ+EL9T/3xDfPm6yncZT96frFTtvkWWA8aKMOnLYXXO2vDtnlBfyST/s2RLcCfvXkP4U66uyTVw8CTkDny/6LYYJ8rPSObkFVfYKH5uGj6QJ2AXtYWJDNI4hwIrvlaIb7+YtwwYpxq8M1i+/Qq87cyI9FFgCFrEVfK95WdZYedgm5x4qycXdmVoCI6oddNVcwhsqG925P/XussRuErvUXsY9bbdAsF4ef7WaEK1Ds+9OIvn6/hfOy/Y2kdnYdnuzaQsMZR3C+KOJdpYKv5AqCmgbIQmuKjTBCNEvD41VWfcwRE= 37 | - secure: vpRG9zCAXG9C/2fqk9QjxpwNOPFCeM+gXc9sPYUaHm/4ODBuhRrhcW7R+6lo8Et1XFGFpCZRxHvqK6AL6xRqWet1A90IC030i1VNIKgax0P8IZYnTy5NgmReLM5TCRC8X0aXlx9c+HPypKUrOaYVJnB4PmP3Nfs+hZd/C37917VXzBYOPE91xeQOAECYubvlfRxbkMMFHT9/UAroljUWISE1sFgZSepOCqDd8IAYYRaNVIwKnVVoHzYDf2Ehf91yaE48FYvHm6oUsVNQhsvWiESEpZmWwRTepSc2ceJ+8gtwL1I4sUToB2k/E6KzwDZMKjYKFDgugdtanysm1Fw6AyWfwDrfQJjEYoisgNzcX5vm/ovPVqxy/7pRVhTohHhT1M1X8okJnAb8AmptP3rqUNZV/dFeieb5Xg8FqTWYCOGr+WHHMjnMLlZNhm7cMSgYkXQdnEPI3EQrN+eggetkIip5KD8FNfMvUDt8w4T8obk/d8vP1cgJ7PpQDrdO48pOayj9Sn8VeG13SgueKKAZ30IiCo3usdMPxp9K5q8360kiulDTsQB0qtIw0W/KCJlfrZWQ7+W4sw6FVdy4gpDR2U+6QHlgJ9jy0fQiJA1sen10eBlYtZhfk6b+YL2tJKFoDNc4tvGSQlEg3Hlso1jq3uRf54zNAvvxkmroXkfAuaw= 38 | 39 | 40 | before_script: 41 | - travis_retry sbt ++$TRAVIS_SCALA_VERSION update 42 | 43 | cache: 44 | directories: 45 | - $HOME/.sbt/0.13/dependency 46 | - $HOME/.sbt/boot/scala* 47 | - $HOME/.sbt/launchers 48 | - $HOME/.ivy2/cache 49 | - $HOME/.nvm 50 | 51 | before_cache: 52 | - du -h -d 1 $HOME/.ivy2/cache 53 | - du -h -d 2 $HOME/.sbt/ 54 | - find $HOME/.sbt -name "*.lock" -type f -delete 55 | - find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete 56 | 57 | script: "./build/run_tests.sh" 58 | 59 | after_success: 60 | - "./build/publish_develop.sh" 61 | -------------------------------------------------------------------------------- /project/Publishing.scala: -------------------------------------------------------------------------------- 1 | import bintray.BintrayPlugin.autoImport._ 2 | import sbt.Keys._ 3 | import sbt.{Credentials, Def, Path, ProjectReference, _} 4 | 5 | import scala.util.Properties 6 | import com.typesafe.sbt.pgp.PgpKeys._ 7 | 8 | object Publishing { 9 | 10 | val runningUnderCi = sys.env.contains("CI") || sys.env.contains("TRAVIS") 11 | 12 | lazy val defaultCredentials: Seq[Credentials] = { 13 | if (!runningUnderCi) { 14 | Seq( 15 | Credentials(Path.userHome / ".bintray" / ".credentials"), 16 | Credentials(Path.userHome / ".ivy2" / ".credentials") 17 | ) 18 | } else { 19 | Seq( 20 | Credentials( 21 | realm = "Bintray", 22 | host = "dl.bintray.com", 23 | userName = System.getenv("bintray_user"), 24 | passwd = System.getenv("bintray_password") 25 | ), 26 | Credentials( 27 | realm = "Sonatype OSS Repository Manager", 28 | host = "oss.sonatype.org", 29 | userName = System.getenv("maven_user"), 30 | passwd = System.getenv("maven_password") 31 | ), 32 | Credentials( 33 | realm = "Bintray API Realm", 34 | host = "api.bintray.com", 35 | userName = System.getenv("bintray_user"), 36 | passwd = System.getenv("bintray_password") 37 | ) 38 | ) 39 | } 40 | } 41 | 42 | val defaultPublishingSettings = Seq( 43 | version := "0.5.0", 44 | credentials ++= defaultCredentials 45 | ) 46 | 47 | lazy val pgpPass = Properties.envOrNone("pgp_passphrase").map(_.toCharArray) 48 | 49 | lazy val mavenSettings: Seq[Def.Setting[_]] = Seq( 50 | credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"), 51 | publishMavenStyle := true, 52 | pgpPassphrase in ThisBuild := { 53 | if (runningUnderCi && pgpPass.isDefined) { 54 | println("Running under CI and PGP password specified under settings.") 55 | println(s"Password longer than five characters: ${pgpPass.exists(_.length > 5)}") 56 | pgpPass 57 | } else { 58 | println("Could not find settings for a PGP passphrase.") 59 | println(s"pgpPass defined in environemnt: ${pgpPass.isDefined}") 60 | println(s"Running under CI: $runningUnderCi") 61 | None 62 | } 63 | }, 64 | publishTo <<= version.apply { 65 | v => 66 | val nexus = "https://oss.sonatype.org/" 67 | if (v.trim.endsWith("SNAPSHOT")) { 68 | Some("snapshots" at nexus + "content/repositories/snapshots") 69 | } else { 70 | Some("releases" at nexus + "service/local/staging/deploy/maven2") 71 | } 72 | }, 73 | externalResolvers <<= resolvers map { rs => 74 | Resolver.withDefaultResolvers(rs, mavenCentral = true) 75 | }, 76 | licenses += ("Outworkers License", url("https://github.com/outworkers/diesel/blob/develop/LICENSE.txt")), 77 | publishArtifact in Test := false, 78 | pomIncludeRepository := { _ => true }, 79 | pomExtra := 80 | https://github.com/outworkers/diesel 81 | 82 | git@github.com:outworkers/diesel.git 83 | scm:git:git@github.com:outworkers/diesel.git 84 | 85 | 86 | 87 | alexflav 88 | Flavian Alexandru 89 | http://github.com/alexflav23 90 | 91 | 92 | ) 93 | 94 | val bintraySettings : Seq[Def.Setting[_]] = Seq( 95 | publishMavenStyle := true, 96 | bintrayReleaseOnPublish in ThisBuild := true, 97 | bintrayOrganization := Some("outworkers"), 98 | bintrayRepository := "oss-releases", 99 | publishArtifact in Test := false, 100 | pomIncludeRepository := { _ => true}, 101 | licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")) 102 | ) 103 | 104 | def isJdk8: Boolean = sys.props("java.specification.version") == "1.8" 105 | 106 | def addOnCondition(condition: Boolean, projectReference: ProjectReference): Seq[ProjectReference] = 107 | if (condition) projectReference :: Nil else Nil 108 | 109 | def jdk8Only(ref: ProjectReference): Seq[ProjectReference] = addOnCondition(isJdk8, ref) 110 | 111 | def effectiveSettings: Seq[Def.Setting[_]] = { 112 | val base = if (!sys.env.contains("MAVEN_PUBLISH")) mavenSettings else bintraySettings 113 | base ++ defaultPublishingSettings 114 | } 115 | } 116 | --------------------------------------------------------------------------------