Use uri instead of url

This commit is contained in:
Eugene Yokota 2017-09-18 23:07:29 -04:00
parent c5bfc67750
commit 8a8215cf1b
7 changed files with 33 additions and 33 deletions

View File

@ -90,7 +90,7 @@ private[sbt] final class CommandExchange {
case Some(x) => // do nothing
case _ =>
val portfile = (new File(".")).getAbsoluteFile / "project" / "target" / "active.json"
val h = Hash.halfHashString(portfile.toURL.toString)
val h = Hash.halfHashString(portfile.toURI.toString)
val tokenfile = BuildPaths.getGlobalBase(s) / "server" / h / "token.json"
val x = Server.start("127.0.0.1", port, onIncomingSocket, portfile, tokenfile, s.log)
Await.ready(x.ready, Duration("10s"))

View File

@ -9,27 +9,27 @@ package sbt.internal.protocol
* It can be used to find out the transport protocol (port number etc).
*/
final class PortFile private (
/** URL of the sbt server. */
val url: String,
/** URI of the sbt server. */
val uri: String,
val tokenfile: Option[String]) extends Serializable {
override def equals(o: Any): Boolean = o match {
case x: PortFile => (this.url == x.url) && (this.tokenfile == x.tokenfile)
case x: PortFile => (this.uri == x.uri) && (this.tokenfile == x.tokenfile)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (17 + "sbt.internal.protocol.PortFile".##) + url.##) + tokenfile.##)
37 * (37 * (37 * (17 + "sbt.internal.protocol.PortFile".##) + uri.##) + tokenfile.##)
}
override def toString: String = {
"PortFile(" + url + ", " + tokenfile + ")"
"PortFile(" + uri + ", " + tokenfile + ")"
}
protected[this] def copy(url: String = url, tokenfile: Option[String] = tokenfile): PortFile = {
new PortFile(url, tokenfile)
protected[this] def copy(uri: String = uri, tokenfile: Option[String] = tokenfile): PortFile = {
new PortFile(uri, tokenfile)
}
def withUrl(url: String): PortFile = {
copy(url = url)
def withUri(uri: String): PortFile = {
copy(uri = uri)
}
def withTokenfile(tokenfile: Option[String]): PortFile = {
copy(tokenfile = tokenfile)
@ -40,6 +40,6 @@ final class PortFile private (
}
object PortFile {
def apply(url: String, tokenfile: Option[String]): PortFile = new PortFile(url, tokenfile)
def apply(url: String, tokenfile: String): PortFile = new PortFile(url, Option(tokenfile))
def apply(uri: String, tokenfile: Option[String]): PortFile = new PortFile(uri, tokenfile)
def apply(uri: String, tokenfile: String): PortFile = new PortFile(uri, Option(tokenfile))
}

View File

@ -5,26 +5,26 @@
// DO NOT EDIT MANUALLY
package sbt.internal.protocol
final class TokenFile private (
val url: String,
val uri: String,
val token: String) extends Serializable {
override def equals(o: Any): Boolean = o match {
case x: TokenFile => (this.url == x.url) && (this.token == x.token)
case x: TokenFile => (this.uri == x.uri) && (this.token == x.token)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (17 + "sbt.internal.protocol.TokenFile".##) + url.##) + token.##)
37 * (37 * (37 * (17 + "sbt.internal.protocol.TokenFile".##) + uri.##) + token.##)
}
override def toString: String = {
"TokenFile(" + url + ", " + token + ")"
"TokenFile(" + uri + ", " + token + ")"
}
protected[this] def copy(url: String = url, token: String = token): TokenFile = {
new TokenFile(url, token)
protected[this] def copy(uri: String = uri, token: String = token): TokenFile = {
new TokenFile(uri, token)
}
def withUrl(url: String): TokenFile = {
copy(url = url)
def withUri(uri: String): TokenFile = {
copy(uri = uri)
}
def withToken(token: String): TokenFile = {
copy(token = token)
@ -32,5 +32,5 @@ final class TokenFile private (
}
object TokenFile {
def apply(url: String, token: String): TokenFile = new TokenFile(url, token)
def apply(uri: String, token: String): TokenFile = new TokenFile(uri, token)
}

View File

@ -11,17 +11,17 @@ implicit lazy val PortFileFormat: JsonFormat[sbt.internal.protocol.PortFile] = n
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val url = unbuilder.readField[String]("url")
val uri = unbuilder.readField[String]("uri")
val tokenfile = unbuilder.readField[Option[String]]("tokenfile")
unbuilder.endObject()
sbt.internal.protocol.PortFile(url, tokenfile)
sbt.internal.protocol.PortFile(uri, tokenfile)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.internal.protocol.PortFile, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("url", obj.url)
builder.addField("uri", obj.uri)
builder.addField("tokenfile", obj.tokenfile)
builder.endObject()
}

View File

@ -11,17 +11,17 @@ implicit lazy val TokenFileFormat: JsonFormat[sbt.internal.protocol.TokenFile] =
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val url = unbuilder.readField[String]("url")
val uri = unbuilder.readField[String]("uri")
val token = unbuilder.readField[String]("token")
unbuilder.endObject()
sbt.internal.protocol.TokenFile(url, token)
sbt.internal.protocol.TokenFile(uri, token)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.internal.protocol.TokenFile, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("url", obj.url)
builder.addField("uri", obj.uri)
builder.addField("token", obj.token)
builder.endObject()
}

View File

@ -5,12 +5,12 @@ package sbt.internal.protocol
## This file should exist throughout the lifetime of the server.
## It can be used to find out the transport protocol (port number etc).
type PortFile {
## URL of the sbt server.
url: String!
## URI of the sbt server.
uri: String!
tokenfile: String
}
type TokenFile {
url: String!
uri: String!
token: String!
}

View File

@ -30,14 +30,14 @@ object Client extends App {
val json: JValue = Parser.parseFromFile(portfile).get
json match {
case JObject(fields) =>
(fields find { _.field == "url" } map { _.value }) match {
(fields find { _.field == "uri" } map { _.value }) match {
case Some(JString(value)) =>
val u = new URI(value)
u.getPort
case _ =>
sys.error("json doesn't url field that is JString")
sys.error("json doesn't uri field that is JString")
}
case _ => sys.error("json doesn't have url field")
case _ => sys.error("json doesn't have uri field")
}
}