diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-07-05 11:37:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-05 11:37:54 -0400 |
commit | bc2231720d3620b5e0459fa12c467bf675fcfdf5 (patch) | |
tree | 6c37b019c3c23cbc7a03484bec003c7266c99e4b /stage2 | |
parent | b1b2195b13300d9b3057b96deebf24d9353a7344 (diff) | |
parent | 11342ecc8c6bd92e73b8ad9a2791f8d9462043a6 (diff) | |
download | cbt-bc2231720d3620b5e0459fa12c467bf675fcfdf5.tar.gz cbt-bc2231720d3620b5e0459fa12c467bf675fcfdf5.tar.bz2 cbt-bc2231720d3620b5e0459fa12c467bf675fcfdf5.zip |
Merge pull request #196 from benjaminfrank/fix/publish_anonymous
Allow empty credentials for publishing.
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/Lib.scala | 18 | ||||
-rw-r--r-- | stage2/Publish.scala | 4 |
2 files changed, 13 insertions, 9 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 620c009..a060ac6 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -361,20 +361,20 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ else items.map(projection) } - def publishUnsigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: String ): Unit = { + def publishUnsigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: Option[String] = None ): Unit = { if(sourceFiles.nonEmpty){ publish( artifacts, url, credentials ) } } - def publishSigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: String ): Unit = { + def publishSigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: Option[String] = None ): Unit = { // TODO: make concurrency configurable here if(sourceFiles.nonEmpty){ publish( artifacts ++ artifacts.map(sign), url, credentials ) } } - private def publish(artifacts: Seq[File], url: URL, credentials: String): Unit = { + private def publish(artifacts: Seq[File], url: URL, credentials: Option[String]): Unit = { val files = artifacts.map(nameAndContents) lazy val checksums = files.flatMap{ case (name, content) => Seq( @@ -386,10 +386,10 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ uploadAll(url, all, credentials) } - def uploadAll(url: URL, nameAndContents: Seq[(String, Array[Byte])], credentials: String ): Unit = + def uploadAll(url: URL, nameAndContents: Seq[(String, Array[Byte])], credentials: Option[String] = None ): Unit = nameAndContents.map{ case(name, content) => upload(name, content, url, credentials ) } - def upload(fileName: String, fileContents: Array[Byte], baseUrl: URL, credentials: String): Unit = { + def upload(fileName: String, fileContents: Array[Byte], baseUrl: URL, credentials: Option[String] = None): Unit = { import java.net._ import java.io._ val url = baseUrl ++ fileName @@ -397,8 +397,12 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ val httpCon = url.openConnection.asInstanceOf[HttpURLConnection] httpCon.setDoOutput(true) httpCon.setRequestMethod("PUT") - val encoding = new sun.misc.BASE64Encoder().encode(credentials.getBytes) - httpCon.setRequestProperty("Authorization", "Basic " ++ encoding) + credentials.foreach( + c => { + val encoding = new sun.misc.BASE64Encoder().encode(c.getBytes) + httpCon.setRequestProperty("Authorization", "Basic " ++ encoding) + } + ) httpCon.setRequestProperty("Content-Type", "application/binary") httpCon.getOutputStream.write( fileContents diff --git a/stage2/Publish.scala b/stage2/Publish.scala index 8cdb65b..1cc3b70 100644 --- a/stage2/Publish.scala +++ b/stage2/Publish.scala @@ -41,9 +41,9 @@ trait Publish extends PackageJars{ def publishUrl = if(version.endsWith("-SNAPSHOT")) snapshotUrl else releaseUrl override def copy(context: Context) = super.copy(context).asInstanceOf[Publish] - protected def sonatypeCredentials = { + protected def sonatypeCredentials: Option[String] = { // FIXME: this should probably not use cbtHome, but some reference to the system's host cbt - new String(readAllBytes((context.cbtRootHome ++ "/sonatype.login").toPath)).trim + Some(new String(readAllBytes((context.cbtRootHome ++ "/sonatype.login").toPath)).trim) } def publishSnapshot: Unit = { |