|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
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 |
17 | 22 | import sbt.Keys._
|
18 |
| -import sbt.Def.Initialize |
19 |
| -import scala.xml.NodeBuffer |
| 23 | +import sbt._ |
20 | 24 |
|
21 | 25 | object Publish {
|
22 | 26 |
|
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" |
32 | 34 |
|
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 := { |
35 | 57 | val nexus = "https://oss.sonatype.org/"
|
36 |
| - if (v.trim.endsWith("SNAPSHOT")) |
| 58 | + if (isSnapshot.value) |
37 | 59 | Some("snapshots" at nexus + "content/repositories/snapshots")
|
38 | 60 | else
|
39 | 61 | 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 | + ) |
42 | 95 |
|
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 { } |
63 | 100 | }
|
64 | 101 |
|
65 | 102 | }
|
0 commit comments