aboutsummaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
Diffstat (limited to 'stage2')
-rw-r--r--stage2/Lib.scala17
-rw-r--r--stage2/PublishBuild.scala17
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 )
}