forked from akka/akka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPublish.scala
99 lines (82 loc) · 3.13 KB
/
Publish.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package akka
import sbt._
import sbt.Keys._
import sbt.Project.Initialize
import java.io.File
object Publish {
final val Snapshot = "-SNAPSHOT"
val defaultPublishTo = SettingKey[File]("default-publish-to")
lazy val settings = Seq(
crossPaths := false,
pomExtra := akkaPomExtra,
publishTo <<= akkaPublishTo,
credentials ++= akkaCredentials,
organizationName := "Typesafe Inc.",
organizationHomepage := Some(url("http://www.typesafe.com")),
publishMavenStyle := true,
// Maven central cannot allow other repos.
// TODO - Make sure all artifacts are on central.
pomIncludeRepository := { x => false }
)
lazy val versionSettings = Seq(
commands += stampVersion
)
def akkaPomExtra = {
(<inceptionYear>2009</inceptionYear>
<scm>
<url>git://github.com/akka/akka.git</url>
<connection>scm:git:[email protected]:akka/akka.git</connection>
</scm>) ++ makeDevelopersXml(Map(
"jboner" -> "Jonas Boner",
"viktorklang" -> "Viktor Klang",
"rkuhn" -> "Roland Kuhn",
"pvlugter" -> "Peter Vlugter"
// TODO - More than the names in the last 10 commits
))
}
private[this] def makeDevelopersXml(users: Map[String,String]) =
<developers>
{
for((id, user) <- users)
yield <developer><id>{id}</id><name>{user}</name></developer>
}
</developers>
def sonatypePublishTo: Initialize[Option[Resolver]] = {
version { v: String =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
}
def akkaPublishTo: Initialize[Option[Resolver]] = {
(defaultPublishTo, version) { (defaultPT, v) =>
akkaPublishRepository orElse
sonatypeRepo(v) orElse
Some(Resolver.file("Default Local Repository", defaultPT))
}
}
def sonatypeRepo(version: String): Option[Resolver] = {
Option(sys.props("publish.maven.central")) filter (_.toLowerCase == "true") map { _ =>
val nexus = "https://oss.sonatype.org/"
if(version endsWith "-SNAPSHOT") ("snapshots" at nexus + "content/repositories/snapshots")
else ("releases" at nexus + "service/local/staging/deploy/maven2")
}
}
def akkaPublishRepository: Option[Resolver] =
Option(System.getProperty("akka.publish.repository", null)) map { "Akka Publish Repository" at _ }
def akkaCredentials: Seq[Credentials] =
Option(System.getProperty("akka.publish.credentials", null)) map (f => Credentials(new File(f))) toSeq
// timestamped versions
def stampVersion = Command.command("stamp-version") { state =>
val extracted = Project.extract(state)
extracted.append(List(version in ThisBuild ~= stamp), state)
}
def stamp(version: String): String = {
if (version endsWith Snapshot) (version stripSuffix Snapshot) + "-" + timestamp(System.currentTimeMillis)
else version
}
def timestamp(time: Long): String = {
val format = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss")
format.format(new java.util.Date(time))
}
}