mirror of https://github.com/sbt/sbt.git
Artifact
This commit is contained in:
parent
02fc0d9d89
commit
d078dc4772
|
|
@ -10,13 +10,13 @@ final class Artifact private (
|
||||||
val extension: String,
|
val extension: String,
|
||||||
val classifier: Option[String],
|
val classifier: Option[String],
|
||||||
val configurations: Vector[sbt.librarymanagement.ConfigRef],
|
val configurations: Vector[sbt.librarymanagement.ConfigRef],
|
||||||
val url: Option[java.net.URL],
|
val url: Option[java.net.URI],
|
||||||
val extraAttributes: Map[String, String],
|
val extraAttributes: Map[String, String],
|
||||||
val checksum: Option[sbt.librarymanagement.Checksum],
|
val checksum: Option[sbt.librarymanagement.Checksum],
|
||||||
val allowInsecureProtocol: Boolean) extends sbt.librarymanagement.ArtifactExtra with Serializable {
|
val allowInsecureProtocol: Boolean) extends sbt.librarymanagement.ArtifactExtra with Serializable {
|
||||||
private[sbt] def validateProtocol(logger: sbt.util.Logger): Boolean = Resolver.validateArtifact(this, logger)
|
private[sbt] def validateProtocol(logger: sbt.util.Logger): Boolean = Resolver.validateArtifact(this, logger)
|
||||||
private def this(name: String) = this(name, Artifact.DefaultType, Artifact.DefaultExtension, None, Vector.empty, None, Map.empty, None, false)
|
private def this(name: String) = this(name, Artifact.DefaultType, Artifact.DefaultExtension, None, Vector.empty, None, Map.empty, None, false)
|
||||||
private def this(name: String, `type`: String, extension: String, classifier: Option[String], configurations: Vector[sbt.librarymanagement.ConfigRef], url: Option[java.net.URL], extraAttributes: Map[String, String], checksum: Option[sbt.librarymanagement.Checksum]) = this(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, false)
|
private def this(name: String, `type`: String, extension: String, classifier: Option[String], configurations: Vector[sbt.librarymanagement.ConfigRef], url: Option[java.net.URI], extraAttributes: Map[String, String], checksum: Option[sbt.librarymanagement.Checksum]) = this(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, false)
|
||||||
|
|
||||||
override def equals(o: Any): Boolean = this.eq(o.asInstanceOf[AnyRef]) || (o match {
|
override def equals(o: Any): Boolean = this.eq(o.asInstanceOf[AnyRef]) || (o match {
|
||||||
case x: Artifact => (this.name == x.name) && (this.`type` == x.`type`) && (this.extension == x.extension) && (this.classifier == x.classifier) && (this.configurations == x.configurations) && (this.url == x.url) && (this.extraAttributes == x.extraAttributes) && (this.checksum == x.checksum) && (this.allowInsecureProtocol == x.allowInsecureProtocol)
|
case x: Artifact => (this.name == x.name) && (this.`type` == x.`type`) && (this.extension == x.extension) && (this.classifier == x.classifier) && (this.configurations == x.configurations) && (this.url == x.url) && (this.extraAttributes == x.extraAttributes) && (this.checksum == x.checksum) && (this.allowInsecureProtocol == x.allowInsecureProtocol)
|
||||||
|
|
@ -28,7 +28,7 @@ final class Artifact private (
|
||||||
override def toString: String = {
|
override def toString: String = {
|
||||||
"Artifact(" + name + ", " + `type` + ", " + extension + ", " + classifier + ", " + configurations + ", " + url + ", " + extraAttributes + ", " + checksum + ", " + allowInsecureProtocol + ")"
|
"Artifact(" + name + ", " + `type` + ", " + extension + ", " + classifier + ", " + configurations + ", " + url + ", " + extraAttributes + ", " + checksum + ", " + allowInsecureProtocol + ")"
|
||||||
}
|
}
|
||||||
private[this] def copy(name: String = name, `type`: String = `type`, extension: String = extension, classifier: Option[String] = classifier, configurations: Vector[sbt.librarymanagement.ConfigRef] = configurations, url: Option[java.net.URL] = url, extraAttributes: Map[String, String] = extraAttributes, checksum: Option[sbt.librarymanagement.Checksum] = checksum, allowInsecureProtocol: Boolean = allowInsecureProtocol): Artifact = {
|
private[this] def copy(name: String = name, `type`: String = `type`, extension: String = extension, classifier: Option[String] = classifier, configurations: Vector[sbt.librarymanagement.ConfigRef] = configurations, url: Option[java.net.URI] = url, extraAttributes: Map[String, String] = extraAttributes, checksum: Option[sbt.librarymanagement.Checksum] = checksum, allowInsecureProtocol: Boolean = allowInsecureProtocol): Artifact = {
|
||||||
new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, allowInsecureProtocol)
|
new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, allowInsecureProtocol)
|
||||||
}
|
}
|
||||||
def withName(name: String): Artifact = {
|
def withName(name: String): Artifact = {
|
||||||
|
|
@ -46,7 +46,7 @@ final class Artifact private (
|
||||||
def withConfigurations(configurations: Vector[sbt.librarymanagement.ConfigRef]): Artifact = {
|
def withConfigurations(configurations: Vector[sbt.librarymanagement.ConfigRef]): Artifact = {
|
||||||
copy(configurations = configurations)
|
copy(configurations = configurations)
|
||||||
}
|
}
|
||||||
def withUrl(url: Option[java.net.URL]): Artifact = {
|
def withUrl(url: Option[java.net.URI]): Artifact = {
|
||||||
copy(url = url)
|
copy(url = url)
|
||||||
}
|
}
|
||||||
def withExtraAttributes(extraAttributes: Map[String, String]): Artifact = {
|
def withExtraAttributes(extraAttributes: Map[String, String]): Artifact = {
|
||||||
|
|
@ -62,6 +62,6 @@ final class Artifact private (
|
||||||
object Artifact extends sbt.librarymanagement.ArtifactFunctions {
|
object Artifact extends sbt.librarymanagement.ArtifactFunctions {
|
||||||
|
|
||||||
def apply(name: String): Artifact = new Artifact(name)
|
def apply(name: String): Artifact = new Artifact(name)
|
||||||
def apply(name: String, `type`: String, extension: String, classifier: Option[String], configurations: Vector[sbt.librarymanagement.ConfigRef], url: Option[java.net.URL], extraAttributes: Map[String, String], checksum: Option[sbt.librarymanagement.Checksum]): Artifact = new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum)
|
def apply(name: String, `type`: String, extension: String, classifier: Option[String], configurations: Vector[sbt.librarymanagement.ConfigRef], url: Option[java.net.URI], extraAttributes: Map[String, String], checksum: Option[sbt.librarymanagement.Checksum]): Artifact = new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum)
|
||||||
def apply(name: String, `type`: String, extension: String, classifier: Option[String], configurations: Vector[sbt.librarymanagement.ConfigRef], url: Option[java.net.URL], extraAttributes: Map[String, String], checksum: Option[sbt.librarymanagement.Checksum], allowInsecureProtocol: Boolean): Artifact = new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, allowInsecureProtocol)
|
def apply(name: String, `type`: String, extension: String, classifier: Option[String], configurations: Vector[sbt.librarymanagement.ConfigRef], url: Option[java.net.URI], extraAttributes: Map[String, String], checksum: Option[sbt.librarymanagement.Checksum], allowInsecureProtocol: Boolean): Artifact = new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, allowInsecureProtocol)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ implicit lazy val ArtifactFormat: JsonFormat[sbt.librarymanagement.Artifact] = n
|
||||||
val extension = unbuilder.readField[String]("extension")
|
val extension = unbuilder.readField[String]("extension")
|
||||||
val classifier = unbuilder.readField[Option[String]]("classifier")
|
val classifier = unbuilder.readField[Option[String]]("classifier")
|
||||||
val configurations = unbuilder.readField[Vector[sbt.librarymanagement.ConfigRef]]("configurations")
|
val configurations = unbuilder.readField[Vector[sbt.librarymanagement.ConfigRef]]("configurations")
|
||||||
val url = unbuilder.readField[Option[java.net.URL]]("url")
|
val url = unbuilder.readField[Option[java.net.URI]]("url")
|
||||||
val extraAttributes = unbuilder.readField[Map[String, String]]("extraAttributes")
|
val extraAttributes = unbuilder.readField[Map[String, String]]("extraAttributes")
|
||||||
val checksum = unbuilder.readField[Option[sbt.librarymanagement.Checksum]]("checksum")
|
val checksum = unbuilder.readField[Option[sbt.librarymanagement.Checksum]]("checksum")
|
||||||
val allowInsecureProtocol = unbuilder.readField[Boolean]("allowInsecureProtocol")
|
val allowInsecureProtocol = unbuilder.readField[Boolean]("allowInsecureProtocol")
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@
|
||||||
{ "name": "extension", "type": "String", "default": "Artifact.DefaultExtension", "since": "0.0.1" },
|
{ "name": "extension", "type": "String", "default": "Artifact.DefaultExtension", "since": "0.0.1" },
|
||||||
{ "name": "classifier", "type": "Option[String]", "default": "None", "since": "0.0.1" },
|
{ "name": "classifier", "type": "Option[String]", "default": "None", "since": "0.0.1" },
|
||||||
{ "name": "configurations", "type": "sbt.librarymanagement.ConfigRef*", "default": "Vector.empty", "since": "0.0.1" },
|
{ "name": "configurations", "type": "sbt.librarymanagement.ConfigRef*", "default": "Vector.empty", "since": "0.0.1" },
|
||||||
{ "name": "url", "type": "Option[java.net.URL]", "default": "None", "since": "0.0.1" },
|
{ "name": "url", "type": "Option[java.net.URI]", "default": "None", "since": "0.0.1" },
|
||||||
{ "name": "extraAttributes", "type": "Map[String, String]", "default": "Map.empty", "since": "0.0.1" },
|
{ "name": "extraAttributes", "type": "Map[String, String]", "default": "Map.empty", "since": "0.0.1" },
|
||||||
{ "name": "checksum", "type": "Option[sbt.librarymanagement.Checksum]", "default": "None", "since": "0.0.1" },
|
{ "name": "checksum", "type": "Option[sbt.librarymanagement.Checksum]", "default": "None", "since": "0.0.1" },
|
||||||
{ "name": "allowInsecureProtocol", "type": "Boolean", "default": "false", "since": "1.3.0" }
|
{ "name": "allowInsecureProtocol", "type": "Boolean", "default": "false", "since": "1.3.0" }
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
package sbt.librarymanagement
|
package sbt.librarymanagement
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URI
|
||||||
|
|
||||||
private[librarymanagement] abstract class ArtifactExtra {
|
private[librarymanagement] abstract class ArtifactExtra {
|
||||||
def extraAttributes: Map[String, String]
|
def extraAttributes: Map[String, String]
|
||||||
|
|
@ -26,15 +26,15 @@ private[librarymanagement] abstract class ArtifactFunctions {
|
||||||
Artifact(name, `type`, extension, None, Vector.empty, None)
|
Artifact(name, `type`, extension, None, Vector.empty, None)
|
||||||
def apply(name: String, `type`: String, extension: String, classifier: String): Artifact =
|
def apply(name: String, `type`: String, extension: String, classifier: String): Artifact =
|
||||||
Artifact(name, `type`, extension, Some(classifier), Vector.empty, None)
|
Artifact(name, `type`, extension, Some(classifier), Vector.empty, None)
|
||||||
def apply(name: String, url: URL): Artifact = Artifact(name, url, false)
|
def apply(name: String, uri: URI): Artifact = Artifact(name, uri, false)
|
||||||
def apply(name: String, url: URL, allowInsecureProtocol: Boolean): Artifact =
|
def apply(name: String, uri: URI, allowInsecureProtocol: Boolean): Artifact =
|
||||||
Artifact(
|
Artifact(
|
||||||
name,
|
name,
|
||||||
extract(url, DefaultType),
|
extract(uri, DefaultType),
|
||||||
extract(url, DefaultExtension),
|
extract(uri, DefaultExtension),
|
||||||
None,
|
None,
|
||||||
Vector.empty,
|
Vector.empty,
|
||||||
Some(url),
|
Some(uri),
|
||||||
Map.empty,
|
Map.empty,
|
||||||
None,
|
None,
|
||||||
allowInsecureProtocol
|
allowInsecureProtocol
|
||||||
|
|
@ -47,8 +47,9 @@ private[librarymanagement] abstract class ArtifactFunctions {
|
||||||
extension: String,
|
extension: String,
|
||||||
classifier: Option[String],
|
classifier: Option[String],
|
||||||
configurations: Vector[ConfigRef],
|
configurations: Vector[ConfigRef],
|
||||||
url: Option[URL]
|
uri: Option[URI]
|
||||||
): Artifact = Artifact(name, `type`, extension, classifier, configurations, url, empty, None)
|
): Artifact =
|
||||||
|
Artifact(name, `type`, extension, classifier, configurations, uri, empty, None)
|
||||||
|
|
||||||
val DefaultExtension = "jar"
|
val DefaultExtension = "jar"
|
||||||
val DefaultType = "jar"
|
val DefaultType = "jar"
|
||||||
|
|
@ -78,7 +79,7 @@ private[librarymanagement] abstract class ArtifactFunctions {
|
||||||
assert(DefaultDocTypes contains DocType)
|
assert(DefaultDocTypes contains DocType)
|
||||||
assert(DefaultSourceTypes contains SourceType)
|
assert(DefaultSourceTypes contains SourceType)
|
||||||
|
|
||||||
def extract(url: URL, default: String): String = extract(url.toString, default)
|
def extract(uri: URI, default: String): String = extract(uri.toString, default)
|
||||||
def extract(name: String, default: String): String = {
|
def extract(name: String, default: String): String = {
|
||||||
val i = name.lastIndexOf('.')
|
val i = name.lastIndexOf('.')
|
||||||
if (i >= 0)
|
if (i >= 0)
|
||||||
|
|
@ -96,7 +97,7 @@ private[librarymanagement] abstract class ArtifactFunctions {
|
||||||
extract(name, DefaultExtension),
|
extract(name, DefaultExtension),
|
||||||
None,
|
None,
|
||||||
Vector.empty,
|
Vector.empty,
|
||||||
Some(file.toURI.toURL)
|
Some(file.toURI)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
def artifactName(scalaVersion: ScalaVersion, module: ModuleID, artifact: Artifact): String = {
|
def artifactName(scalaVersion: ScalaVersion, module: ModuleID, artifact: Artifact): String = {
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ private[librarymanagement] abstract class ModuleIDExtra {
|
||||||
* It is not included in published metadata.
|
* It is not included in published metadata.
|
||||||
*/
|
*/
|
||||||
def from(url: String, allowInsecureProtocol: Boolean): ModuleID =
|
def from(url: String, allowInsecureProtocol: Boolean): ModuleID =
|
||||||
artifacts(Artifact(name, new URI(url).toURL, allowInsecureProtocol))
|
artifacts(Artifact(name, new URI(url), allowInsecureProtocol))
|
||||||
|
|
||||||
/** Adds a dependency on the artifact for this module with classifier `c`. */
|
/** Adds a dependency on the artifact for this module with classifier `c`. */
|
||||||
def classifier(c: String): ModuleID = artifacts(Artifact(name, c))
|
def classifier(c: String): ModuleID = artifacts(Artifact(name, c))
|
||||||
|
|
|
||||||
|
|
@ -1000,7 +1000,7 @@ private[sbt] object IvySbt {
|
||||||
name,
|
name,
|
||||||
`type`,
|
`type`,
|
||||||
extension,
|
extension,
|
||||||
url.orNull,
|
url.map(_.toURL).orNull,
|
||||||
extraMap
|
extraMap
|
||||||
)
|
)
|
||||||
copyConfigurations(artifact, (ref: ConfigRef) => { ivyArtifact.addConfiguration(ref.name) })
|
copyConfigurations(artifact, (ref: ConfigRef) => { ivyArtifact.addConfiguration(ref.name) })
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ object IvyRetrieve {
|
||||||
getConfigurations.toVector map { (c: String) =>
|
getConfigurations.toVector map { (c: String) =>
|
||||||
ConfigRef(c)
|
ConfigRef(c)
|
||||||
},
|
},
|
||||||
Option(getUrl)
|
Option(getUrl).map(_.toURI)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ object DMSerializationSpec extends BasicTestSuite {
|
||||||
}
|
}
|
||||||
|
|
||||||
test("""Artifact("foo", url("http://example.com/")) should roundtrip""") {
|
test("""Artifact("foo", url("http://example.com/")) should roundtrip""") {
|
||||||
roundtrip(Artifact("foo", new URI("http://example.com/").toURL))
|
roundtrip(Artifact("foo", new URI("http://example.com/")))
|
||||||
}
|
}
|
||||||
|
|
||||||
test("""Artifact("foo").extra(("key", "value")) should roundtrip""") {
|
test("""Artifact("foo").extra(("key", "value")) should roundtrip""") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue