mirror of https://github.com/sbt/sbt.git
Reference token file using URI and full file path
Node didn't seem to like read URI out of the box, and I am not sure if File -> URI -> File conversion is universally accepted. Ref sbt/sbt#3088
This commit is contained in:
parent
252e803de8
commit
d5e24979bf
|
|
@ -138,12 +138,14 @@ private[sbt] object Server {
|
|||
import JsonProtocol._
|
||||
|
||||
val uri = s"tcp://$host:$port"
|
||||
val tokenRef =
|
||||
if (auth(ServerAuthentication.Token)) {
|
||||
writeTokenfile()
|
||||
Some(tokenfile.toURI.toString)
|
||||
} else None
|
||||
val p = PortFile(uri, tokenRef)
|
||||
val p =
|
||||
auth match {
|
||||
case _ if auth(ServerAuthentication.Token) =>
|
||||
writeTokenfile()
|
||||
PortFile(uri, Option(tokenfile.toString), Option(tokenfile.toURI.toString))
|
||||
case _ =>
|
||||
PortFile(uri, None, None)
|
||||
}
|
||||
val json = Converter.toJson(p).get
|
||||
IO.write(portfile, CompactPrinter(json))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,35 +11,42 @@ package sbt.internal.protocol
|
|||
final class PortFile private (
|
||||
/** URI of the sbt server. */
|
||||
val uri: String,
|
||||
val tokenfile: Option[String]) extends Serializable {
|
||||
val tokenfilePath: Option[String],
|
||||
val tokenfileUri: Option[String]) extends Serializable {
|
||||
|
||||
|
||||
|
||||
override def equals(o: Any): Boolean = o match {
|
||||
case x: PortFile => (this.uri == x.uri) && (this.tokenfile == x.tokenfile)
|
||||
case x: PortFile => (this.uri == x.uri) && (this.tokenfilePath == x.tokenfilePath) && (this.tokenfileUri == x.tokenfileUri)
|
||||
case _ => false
|
||||
}
|
||||
override def hashCode: Int = {
|
||||
37 * (37 * (37 * (17 + "sbt.internal.protocol.PortFile".##) + uri.##) + tokenfile.##)
|
||||
37 * (37 * (37 * (37 * (17 + "sbt.internal.protocol.PortFile".##) + uri.##) + tokenfilePath.##) + tokenfileUri.##)
|
||||
}
|
||||
override def toString: String = {
|
||||
"PortFile(" + uri + ", " + tokenfile + ")"
|
||||
"PortFile(" + uri + ", " + tokenfilePath + ", " + tokenfileUri + ")"
|
||||
}
|
||||
protected[this] def copy(uri: String = uri, tokenfile: Option[String] = tokenfile): PortFile = {
|
||||
new PortFile(uri, tokenfile)
|
||||
protected[this] def copy(uri: String = uri, tokenfilePath: Option[String] = tokenfilePath, tokenfileUri: Option[String] = tokenfileUri): PortFile = {
|
||||
new PortFile(uri, tokenfilePath, tokenfileUri)
|
||||
}
|
||||
def withUri(uri: String): PortFile = {
|
||||
copy(uri = uri)
|
||||
}
|
||||
def withTokenfile(tokenfile: Option[String]): PortFile = {
|
||||
copy(tokenfile = tokenfile)
|
||||
def withTokenfilePath(tokenfilePath: Option[String]): PortFile = {
|
||||
copy(tokenfilePath = tokenfilePath)
|
||||
}
|
||||
def withTokenfile(tokenfile: String): PortFile = {
|
||||
copy(tokenfile = Option(tokenfile))
|
||||
def withTokenfilePath(tokenfilePath: String): PortFile = {
|
||||
copy(tokenfilePath = Option(tokenfilePath))
|
||||
}
|
||||
def withTokenfileUri(tokenfileUri: Option[String]): PortFile = {
|
||||
copy(tokenfileUri = tokenfileUri)
|
||||
}
|
||||
def withTokenfileUri(tokenfileUri: String): PortFile = {
|
||||
copy(tokenfileUri = Option(tokenfileUri))
|
||||
}
|
||||
}
|
||||
object PortFile {
|
||||
|
||||
def apply(uri: String, tokenfile: Option[String]): PortFile = new PortFile(uri, tokenfile)
|
||||
def apply(uri: String, tokenfile: String): PortFile = new PortFile(uri, Option(tokenfile))
|
||||
def apply(uri: String, tokenfilePath: Option[String], tokenfileUri: Option[String]): PortFile = new PortFile(uri, tokenfilePath, tokenfileUri)
|
||||
def apply(uri: String, tokenfilePath: String, tokenfileUri: String): PortFile = new PortFile(uri, Option(tokenfilePath), Option(tokenfileUri))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ implicit lazy val PortFileFormat: JsonFormat[sbt.internal.protocol.PortFile] = n
|
|||
case Some(js) =>
|
||||
unbuilder.beginObject(js)
|
||||
val uri = unbuilder.readField[String]("uri")
|
||||
val tokenfile = unbuilder.readField[Option[String]]("tokenfile")
|
||||
val tokenfilePath = unbuilder.readField[Option[String]]("tokenfilePath")
|
||||
val tokenfileUri = unbuilder.readField[Option[String]]("tokenfileUri")
|
||||
unbuilder.endObject()
|
||||
sbt.internal.protocol.PortFile(uri, tokenfile)
|
||||
sbt.internal.protocol.PortFile(uri, tokenfilePath, tokenfileUri)
|
||||
case None =>
|
||||
deserializationError("Expected JsObject but found None")
|
||||
}
|
||||
|
|
@ -22,7 +23,8 @@ implicit lazy val PortFileFormat: JsonFormat[sbt.internal.protocol.PortFile] = n
|
|||
override def write[J](obj: sbt.internal.protocol.PortFile, builder: Builder[J]): Unit = {
|
||||
builder.beginObject()
|
||||
builder.addField("uri", obj.uri)
|
||||
builder.addField("tokenfile", obj.tokenfile)
|
||||
builder.addField("tokenfilePath", obj.tokenfilePath)
|
||||
builder.addField("tokenfileUri", obj.tokenfileUri)
|
||||
builder.endObject()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ package sbt.internal.protocol
|
|||
type PortFile {
|
||||
## URI of the sbt server.
|
||||
uri: String!
|
||||
tokenfile: String
|
||||
tokenfilePath: String
|
||||
tokenfileUri: String
|
||||
}
|
||||
|
||||
type TokenFile {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ object Client extends App {
|
|||
IO.write(baseDirectory / "ok.txt", "ok")
|
||||
|
||||
def getToken: String = {
|
||||
val tokenfile = new File(getTokenFile)
|
||||
val tokenfile = new File(getTokenFileUri)
|
||||
val json: JValue = Parser.parseFromFile(tokenfile).get
|
||||
json match {
|
||||
case JObject(fields) =>
|
||||
|
|
@ -43,12 +43,12 @@ object Client extends App {
|
|||
}
|
||||
}
|
||||
|
||||
def getTokenFile: URI = {
|
||||
def getTokenFileUri: URI = {
|
||||
val portfile = baseDirectory / "project" / "target" / "active.json"
|
||||
val json: JValue = Parser.parseFromFile(portfile).get
|
||||
json match {
|
||||
case JObject(fields) =>
|
||||
(fields find { _.field == "tokenfile" } map { _.value }) match {
|
||||
(fields find { _.field == "tokenfileUri" } map { _.value }) match {
|
||||
case Some(JString(value)) => new URI(value)
|
||||
case _ =>
|
||||
sys.error("json doesn't tokenfile field that is JString")
|
||||
|
|
|
|||
Loading…
Reference in New Issue