Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit d341402

Browse files
committed
Updated publishing settings
Added publishSnapshot task SCALA-155
1 parent bb642f2 commit d341402

File tree

3 files changed

+77
-38
lines changed

3 files changed

+77
-38
lines changed

project/MongoScalaBuild.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object MongoScalaBuild extends Build {
100100

101101

102102
lazy val driver = Project(
103-
id = "driver",
103+
id = "mongo-scala-driver",
104104
base = file("driver")
105105
).configs(IntTest)
106106
.configs(UnitTest)

project/Publish.scala

+74-37
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,90 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import sbt._
16+
17+
import java.io.FileInputStream
18+
import java.util.Properties
19+
20+
import com.typesafe.sbt.SbtPgp
21+
import com.typesafe.sbt.pgp.PgpKeys
1722
import sbt.Keys._
18-
import sbt.Def.Initialize
19-
import scala.xml.NodeBuffer
23+
import sbt._
2024

2125
object Publish {
2226

23-
lazy val settings = Seq(
24-
crossPaths := true,
25-
pomExtra := driverPomExtra,
26-
publishTo <<= sonatypePublishTo,
27-
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
28-
pomIncludeRepository := { x => false },
29-
publishMavenStyle := true,
30-
publishArtifact in Test := false
31-
)
27+
val propFile = new File(Path.userHome / ".gradle", "gradle.properties")
28+
29+
val username = "nexusUsername"
30+
val password = "nexusPassword"
31+
val keyId = "signing.keyId"
32+
val secretKeyRing = "signing.secretKeyRingFile"
33+
val keyPassword = "signing.password"
3234

33-
def sonatypePublishTo: Initialize[Option[Resolver]] = {
34-
version { v: String =>
35+
lazy val settings: Seq[Def.Setting[_]] = {
36+
if (!propFile.exists) Seq.empty
37+
else {
38+
val props = new Properties
39+
val input = new FileInputStream(propFile)
40+
try props.load(input) finally input.close()
41+
42+
mavenSettings ++ SbtPgp.settings ++ Seq(
43+
SbtPgp.pgpPassphrase := Some(props.getProperty(keyPassword).toArray),
44+
SbtPgp.pgpSecretRing := file(props.getProperty(secretKeyRing)),
45+
credentials += Credentials(
46+
"Sonatype Nexus Repository Manager",
47+
"oss.sonatype.org",
48+
props.getProperty(username),
49+
props.getProperty(password)),
50+
publishSnapshot <<= publishSnapshotTask
51+
)
52+
}
53+
}
54+
55+
lazy val mavenSettings = Seq(
56+
publishTo := {
3557
val nexus = "https://oss.sonatype.org/"
36-
if (v.trim.endsWith("SNAPSHOT"))
58+
if (isSnapshot.value)
3759
Some("snapshots" at nexus + "content/repositories/snapshots")
3860
else
3961
Some("releases" at nexus + "service/local/staging/deploy/maven2")
40-
}
41-
}
62+
},
63+
publishMavenStyle := true,
64+
publishArtifact in Test := false,
65+
pomIncludeRepository := { _ => false },
66+
pomExtra := (
67+
<url>http://mongodb.github.io/mongo-scala-driver</url>
68+
<licenses>
69+
<license>
70+
<name>Apache 2</name>
71+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
72+
<distribution>repo</distribution>
73+
</license>
74+
</licenses>
75+
<scm>
76+
<url>git@github.com:mongodb/mongo-scala-driver.git</url>
77+
<connection>scm:git:git@github.com:mongodb/mongo-scala-driver.git</connection>
78+
</scm>
79+
<developers>
80+
<developer>
81+
<id>ross</id>
82+
<name>Ross Lawley</name>
83+
<url>http://rosslawley.co.uk</url>
84+
</developer>
85+
</developers>
86+
)
87+
)
88+
89+
lazy val noPublishing = Seq(
90+
publish :=(),
91+
publishLocal :=(),
92+
publishTo := None,
93+
publishSnapshot := None
94+
)
4295

43-
def driverPomExtra: NodeBuffer = {
44-
<url>http://github.com/mongodb/mongo-scala-driver</url>
45-
<licenses>
46-
<license>
47-
<name>Apache 2</name>
48-
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
49-
<distribution>repo</distribution>
50-
</license>
51-
</licenses>
52-
<scm>
53-
<url>git@github.com:mongodb/mongo-scala-driver.git</url>
54-
<connection>scm:git:git@github.com:mongodb/mongo-scala-driver.git</connection>
55-
</scm>
56-
<developers>
57-
<developer>
58-
<id>ross</id>
59-
<name>Ross Lawley</name>
60-
<url>http://rosslawley.co.uk</url>
61-
</developer>
62-
</developers>
96+
lazy val publishSnapshot: TaskKey[Unit] = TaskKey[Unit]("publish-snapshot", "publishes a snapshot")
97+
val publishSnapshotTask = Def.taskDyn {
98+
// Only publish if snapshot
99+
if(isSnapshot.value) Def.task { PgpKeys.publishSigned.value } else Def.task { }
63100
}
64101

65102
}

project/plugins.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.6.0")
66
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0")
77

88
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.1.0")
9+
10+
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")

0 commit comments

Comments
 (0)