Move ModuleID toString out

This commit is contained in:
Eugene Yokota 2017-01-03 23:35:40 -05:00 committed by Dale Wijnand
parent 4ca5b5ae0a
commit a87ed10dc7
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
2 changed files with 27 additions and 3 deletions

View File

@ -257,9 +257,7 @@
{ "name": "branchName", "type": "Option[String]", "default": "None", "since": "0.0.1" }
],
"toString": [
"organization + \":\" + name + \":\" + revision +",
" (configurations match { case Some(s) => \":\" + s; case None => \"\" }) +",
" (if (extraAttributes.isEmpty) \"\" else \" \" + extraString)"
"this.toStringImpl"
],
"parentsCompanion": "sbt.librarymanagement.ModuleIDFunctions"
},

View File

@ -6,6 +6,7 @@ package sbt.librarymanagement
import java.net.URL
import sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties
import scala.collection.mutable.ListBuffer
abstract class ModuleIDExtra {
def organization: String
@ -38,6 +39,31 @@ abstract class ModuleIDExtra {
branchName: Option[String] = branchName
): ModuleID
protected def toStringImpl: String =
s"""$organization:$name:$revision""" +
(configurations match { case Some(s) => ":" + s; case None => "" }) +
{
val attr = attributeString
if (attr == "") ""
else " " + attr
} +
(if (extraAttributes.isEmpty) "" else " " + extraString)
protected def attributeString: String =
{
val buffer = ListBuffer.empty[String]
if (isChanging) {
buffer += "changing"
}
if (!isTransitive) {
buffer += "intransitive"
}
if (isForce) {
buffer += "force"
}
buffer.toList.mkString(";")
}
/** String representation of the extra attributes, excluding any information only attributes. */
def extraString: String = extraDependencyAttributes.map { case (k, v) => k + "=" + v } mkString ("(", ", ", ")")