diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-27 09:32:35 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-28 13:34:01 -0400 |
commit | 63d1076783f3d39876c829108c335661948010b5 (patch) | |
tree | e57c64729dffaa752403d57ddf90dc7c2a3ddd26 /stage2 | |
parent | a8b87e23767f6fc7022152eb3b6784d42c93a33b (diff) | |
download | cbt-63d1076783f3d39876c829108c335661948010b5.tar.gz cbt-63d1076783f3d39876c829108c335661948010b5.tar.bz2 cbt-63d1076783f3d39876c829108c335661948010b5.zip |
Make sonatype credentials customizable from Build class rather than hard coded
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/Lib.scala | 17 | ||||
-rw-r--r-- | stage2/PublishBuild.scala | 17 |
2 files changed, 23 insertions, 11 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index cebdb92..6894073 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -340,14 +340,14 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ else items.map(projection) } - def publishSnapshot( sourceFiles: Seq[File], artifacts: Seq[File], url: URL ): Unit = { + def publishSnapshot( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: String ): Unit = { if(sourceFiles.nonEmpty){ val files = artifacts.map(nameAndContents) - uploadAll(url, files) + uploadAll(url, files, credentials) } } - def publishSigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL ): Unit = { + def publishSigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: String ): Unit = { // TODO: make concurrency configurable here if(sourceFiles.nonEmpty){ val files = (artifacts ++ artifacts.map(sign)).map(nameAndContents) @@ -358,15 +358,15 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ ) } val all = (files ++ checksums) - uploadAll(url, all) + uploadAll(url, all, credentials) } } - def uploadAll(url: URL, nameAndContents: Seq[(String, Array[Byte])]): Unit = - nameAndContents.map{ case(name, content) => upload(name, content, url) } + def uploadAll(url: URL, nameAndContents: Seq[(String, Array[Byte])], credentials: String ): Unit = + nameAndContents.map{ case(name, content) => upload(name, content, url, credentials: String ) } - def upload(fileName: String, fileContents: Array[Byte], baseUrl: URL): Unit = { + def upload(fileName: String, fileContents: Array[Byte], baseUrl: URL, credentials: String): Unit = { import java.net._ import java.io._ logger.task("uploading "++fileName) @@ -374,8 +374,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ val httpCon = url.openConnection.asInstanceOf[HttpURLConnection] httpCon.setDoOutput(true) httpCon.setRequestMethod("PUT") - val userPassword = new String(readAllBytes(sonatypeLogin.toPath)).trim - val encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes) + val encoding = new sun.misc.BASE64Encoder().encode(credentials.getBytes) httpCon.setRequestProperty("Authorization", "Basic " ++ encoding) httpCon.setRequestProperty("Content-Type", "application/binary") httpCon.getOutputStream.write( diff --git a/stage2/PublishBuild.scala b/stage2/PublishBuild.scala index 6b85b22..cc4f5e5 100644 --- a/stage2/PublishBuild.scala +++ b/stage2/PublishBuild.scala @@ -1,6 +1,7 @@ package cbt import java.io.File import java.net.URL +import java.nio.file.Files.readAllBytes import scala.collection.immutable.Seq abstract class PublishBuild(context: Context) extends PackageBuild(context){ @@ -37,10 +38,22 @@ abstract class PublishBuild(context: Context) extends PackageBuild(context){ def snapshotUrl = new URL("https://oss.sonatype.org/content/repositories/snapshots") def releaseUrl = new URL("https://oss.sonatype.org/service/local/staging/deploy/maven2") override def copy(context: Context) = super.copy(context).asInstanceOf[PublishBuild] + + protected def sonatypeCredentials = { + // FIXME: this should probably not use cbtHome, but some reference to the system's host cbt + new String(readAllBytes((context.cbtHome ++ "/sonatype.login").toPath)).trim + } + def publishSnapshot: Unit = { val snapshotBuild = copy( context.copy(version = Some(version+"-SNAPSHOT")) ) val files = snapshotBuild.pom +: snapshotBuild.`package` - lib.publishSnapshot(sourceFiles, files, snapshotUrl ++ releaseFolder ) + lib.publishSnapshot( + sourceFiles, files, snapshotUrl ++ releaseFolder, sonatypeCredentials + ) + } + def publishSigned: Unit = { + lib.publishSigned( + sourceFiles, pom +: `package`, releaseUrl ++ releaseFolder, sonatypeCredentials + ) } - def publishSigned: Unit = lib.publishSigned(sourceFiles, pom +: `package`, releaseUrl ++ releaseFolder ) } |