aboutsummaryrefslogtreecommitdiff
path: root/stage2/Publish.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-06-14 22:15:52 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-06-15 01:24:46 -0400
commitee439cdc67034d35762d54a6d87d51844fcf6dde (patch)
treec6aa1a4663c63f13638b16f263105a6e72f2cf6e /stage2/Publish.scala
parent8794d3ce0ca7f92df24c317c9a9b7025aa0e3dee (diff)
downloadcbt-ee439cdc67034d35762d54a6d87d51844fcf6dde.tar.gz
cbt-ee439cdc67034d35762d54a6d87d51844fcf6dde.tar.bz2
cbt-ee439cdc67034d35762d54a6d87d51844fcf6dde.zip
turn Build base classes into traits for less verbosity and uniform usage with any other plugin
Diffstat (limited to 'stage2/Publish.scala')
-rw-r--r--stage2/Publish.scala64
1 files changed, 64 insertions, 0 deletions
diff --git a/stage2/Publish.scala b/stage2/Publish.scala
new file mode 100644
index 0000000..2f7d2fe
--- /dev/null
+++ b/stage2/Publish.scala
@@ -0,0 +1,64 @@
+package cbt
+import java.io.File
+import java.net.URL
+import java.nio.file.Files.readAllBytes
+import scala.collection.immutable.Seq
+
+trait Publish extends PackageJars{
+ def description: String
+ def url: URL
+ def developers: Seq[Developer]
+ def licenses: Seq[License]
+ def scmUrl: String
+ def scmConnection: String
+ def inceptionYear: Int
+ def organization: Option[Organization]
+
+ // ========== package ==========
+
+ /** put additional xml that should go into the POM file in here */
+ def pom: File = lib.pom(
+ groupId = groupId,
+ artifactId = artifactId,
+ version = version,
+ scalaMajorVersion = scalaMajorVersion,
+ name = name,
+ description = description,
+ url = url,
+ developers = developers,
+ licenses = licenses,
+ scmUrl = scmUrl,
+ scmConnection = scmConnection,
+ inceptionYear,
+ organization,
+ dependencies = dependencies,
+ jarTarget = jarTarget
+ )
+
+ // ========== publish ==========
+ final protected def releaseFolder = s"/${groupId.replace(".","/")}/${artifactId}_$scalaMajorVersion/$version/"
+ private def snapshotUrl = new URL("https://oss.sonatype.org/content/repositories/snapshots")
+ private def releaseUrl = new URL("https://oss.sonatype.org/service/local/staging/deploy/maven2")
+ def publishUrl = if(version.endsWith("-SNAPSHOT")) snapshotUrl else releaseUrl
+ override def copy(context: Context) = super.copy(context).asInstanceOf[Publish]
+
+ protected def sonatypeCredentials = {
+ // FIXME: this should probably not use cbtHome, but some reference to the system's host cbt
+ new String(readAllBytes((context.cbtRootHome ++ "/sonatype.login").toPath)).trim
+ }
+
+ def publishSnapshot: Unit = {
+ copy( context.copy(version = Some(version+"-SNAPSHOT")) ).publishUnsigned
+ }
+
+ def publishUnsigned: Unit = {
+ lib.publishUnsigned(
+ sourceFiles, `package` :+ pom, publishUrl ++ releaseFolder, sonatypeCredentials
+ )
+ }
+ def publishSigned: Unit = {
+ lib.publishSigned(
+ sourceFiles, `package` :+ pom, publishUrl ++ releaseFolder, sonatypeCredentials
+ )
+ }
+}