Skip to content

Commit

Permalink
Merge pull request #318 from eed3si9n/wip/http
Browse files Browse the repository at this point in the history
Deprecate HTTP resolvers (take 2)
  • Loading branch information
eed3si9n committed Aug 28, 2019
2 parents 60b4356 + 3377168 commit 4b4087a
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 84 deletions.
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ lazy val lmCore = (project in file("core"))
exclude[DirectMissingMethodProblem](
"sbt.librarymanagement.ResolverFunctions.useSecureResolvers"
),
exclude[ReversedMissingMethodProblem](
"sbt.librarymanagement.MavenRepository.allowInsecureProtocol"
)
),
)
.configure(addSbtIO, addSbtUtilLogging, addSbtUtilPosition, addSbtUtilCache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ final class Artifact private (
val configurations: Vector[sbt.librarymanagement.ConfigRef],
val url: Option[java.net.URL],
val extraAttributes: Map[String, String],
val checksum: Option[sbt.librarymanagement.Checksum]) extends sbt.librarymanagement.ArtifactExtra with Serializable {

private def this(name: String) = this(name, Artifact.DefaultType, Artifact.DefaultExtension, None, Vector.empty, None, Map.empty, None)
val checksum: Option[sbt.librarymanagement.Checksum],
val allowInsecureProtocol: Boolean) extends sbt.librarymanagement.ArtifactExtra with Serializable {
private[sbt] def validateProtocol(logger: sbt.util.Logger): Unit = 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, `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)

override def equals(o: Any): Boolean = 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)
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 _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + "sbt.librarymanagement.Artifact".##) + name.##) + `type`.##) + extension.##) + classifier.##) + configurations.##) + url.##) + extraAttributes.##) + checksum.##)
37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + "sbt.librarymanagement.Artifact".##) + name.##) + `type`.##) + extension.##) + classifier.##) + configurations.##) + url.##) + extraAttributes.##) + checksum.##) + allowInsecureProtocol.##)
}
override def toString: String = {
"Artifact(" + name + ", " + `type` + ", " + extension + ", " + classifier + ", " + configurations + ", " + url + ", " + extraAttributes + ", " + checksum + ")"
"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): Artifact = {
new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum)
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 = {
new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, allowInsecureProtocol)
}
def withName(name: String): Artifact = {
copy(name = name)
Expand All @@ -53,9 +55,13 @@ final class Artifact private (
def withChecksum(checksum: Option[sbt.librarymanagement.Checksum]): Artifact = {
copy(checksum = checksum)
}
def withAllowInsecureProtocol(allowInsecureProtocol: Boolean): Artifact = {
copy(allowInsecureProtocol = allowInsecureProtocol)
}
}
object Artifact extends sbt.librarymanagement.ArtifactFunctions {

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.URL], extraAttributes: Map[String, String], checksum: Option[sbt.librarymanagement.Checksum], allowInsecureProtocol: Boolean): Artifact = new Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, allowInsecureProtocol)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ implicit lazy val ArtifactFormat: JsonFormat[sbt.librarymanagement.Artifact] = n
val url = unbuilder.readField[Option[java.net.URL]]("url")
val extraAttributes = unbuilder.readField[Map[String, String]]("extraAttributes")
val checksum = unbuilder.readField[Option[sbt.librarymanagement.Checksum]]("checksum")
val allowInsecureProtocol = unbuilder.readField[Boolean]("allowInsecureProtocol")
unbuilder.endObject()
sbt.librarymanagement.Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum)
sbt.librarymanagement.Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes, checksum, allowInsecureProtocol)
case None =>
deserializationError("Expected JsObject but found None")
}
Expand All @@ -35,6 +36,7 @@ implicit lazy val ArtifactFormat: JsonFormat[sbt.librarymanagement.Artifact] = n
builder.addField("url", obj.url)
builder.addField("extraAttributes", obj.extraAttributes)
builder.addField("checksum", obj.checksum)
builder.addField("allowInsecureProtocol", obj.allowInsecureProtocol)
builder.endObject()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package sbt.librarymanagement
final class ChainedResolver private (
name: String,
val resolvers: Vector[sbt.librarymanagement.Resolver]) extends sbt.librarymanagement.Resolver(name) with Serializable {

private[sbt] override def validateProtocol(logger: sbt.util.Logger): Unit = resolvers.foreach(_.validateProtocol(logger))


override def equals(o: Any): Boolean = o match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ final class MavenCache private (
localIfFile: Boolean,
val rootFile: java.io.File) extends sbt.librarymanagement.MavenRepository(name, root, localIfFile) with Serializable {
def this(name: String, rootFile: java.io.File) = this(name, rootFile.toURI.toURL.toString, true, rootFile)
def isCache: Boolean = true
override def isCache: Boolean = true
override def allowInsecureProtocol: Boolean = false
private def this(name: String, root: String, rootFile: java.io.File) = this(name, root, true, rootFile)

override def equals(o: Any): Boolean = o match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
/** This is the internal implementation of actual Maven Repository (as opposed to a file cache). */
final class MavenRepo private (
name: String,
root: String,
localIfFile: Boolean) extends sbt.librarymanagement.MavenRepository(name, root, localIfFile) with Serializable {
def isCache: Boolean = false
private def this(name: String, root: String) = this(name, root, true)
localIfFile: Boolean,
val _allowInsecureProtocol: Boolean) extends sbt.librarymanagement.MavenRepository(name, root, localIfFile) with Serializable {
override def isCache: Boolean = false
override def allowInsecureProtocol: Boolean = _allowInsecureProtocol
private[sbt] override def validateProtocol(logger: sbt.util.Logger): Unit = Resolver.validateMavenRepo(this, logger)
private def this(name: String, root: String) = this(name, root, true, false)
private def this(name: String, root: String, localIfFile: Boolean) = this(name, root, localIfFile, false)

override def equals(o: Any): Boolean = o match {
case x: MavenRepo => (this.name == x.name) && (this.root == x.root) && (this.localIfFile == x.localIfFile)
case x: MavenRepo => (this.name == x.name) && (this.root == x.root) && (this.localIfFile == x.localIfFile) && (this._allowInsecureProtocol == x._allowInsecureProtocol)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (37 * (17 + "sbt.librarymanagement.MavenRepo".##) + name.##) + root.##) + localIfFile.##)
37 * (37 * (37 * (37 * (37 * (17 + "sbt.librarymanagement.MavenRepo".##) + name.##) + root.##) + localIfFile.##) + _allowInsecureProtocol.##)
}
override def toString: String = {
s"$name: $root"
}
private[this] def copy(name: String = name, root: String = root, localIfFile: Boolean = localIfFile): MavenRepo = {
new MavenRepo(name, root, localIfFile)
private[this] def copy(name: String = name, root: String = root, localIfFile: Boolean = localIfFile, _allowInsecureProtocol: Boolean = _allowInsecureProtocol): MavenRepo = {
new MavenRepo(name, root, localIfFile, _allowInsecureProtocol)
}
def withName(name: String): MavenRepo = {
copy(name = name)
Expand All @@ -33,9 +38,13 @@ final class MavenRepo private (
def withLocalIfFile(localIfFile: Boolean): MavenRepo = {
copy(localIfFile = localIfFile)
}
def with_allowInsecureProtocol(_allowInsecureProtocol: Boolean): MavenRepo = {
copy(_allowInsecureProtocol = _allowInsecureProtocol)
}
}
object MavenRepo {

def apply(name: String, root: String): MavenRepo = new MavenRepo(name, root)
def apply(name: String, root: String, localIfFile: Boolean): MavenRepo = new MavenRepo(name, root, localIfFile)
def apply(name: String, root: String, localIfFile: Boolean, _allowInsecureProtocol: Boolean): MavenRepo = new MavenRepo(name, root, localIfFile, _allowInsecureProtocol)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ implicit lazy val MavenRepoFormat: JsonFormat[sbt.librarymanagement.MavenRepo] =
val name = unbuilder.readField[String]("name")
val root = unbuilder.readField[String]("root")
val localIfFile = unbuilder.readField[Boolean]("localIfFile")
val _allowInsecureProtocol = unbuilder.readField[Boolean]("_allowInsecureProtocol")
unbuilder.endObject()
sbt.librarymanagement.MavenRepo(name, root, localIfFile)
sbt.librarymanagement.MavenRepo(name, root, localIfFile, _allowInsecureProtocol)
case None =>
deserializationError("Expected JsObject but found None")
}
Expand All @@ -25,6 +26,7 @@ implicit lazy val MavenRepoFormat: JsonFormat[sbt.librarymanagement.MavenRepo] =
builder.addField("name", obj.name)
builder.addField("root", obj.root)
builder.addField("localIfFile", obj.localIfFile)
builder.addField("_allowInsecureProtocol", obj._allowInsecureProtocol)
builder.endObject()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ abstract class MavenRepository(
val root: String,
val localIfFile: Boolean) extends sbt.librarymanagement.Resolver(name) with Serializable {
def isCache: Boolean
def allowInsecureProtocol: Boolean
def withAllowInsecureProtocol(allowInsecureProtocol: Boolean): MavenRepository =
this match {
case x: MavenRepo => x.with_allowInsecureProtocol(allowInsecureProtocol)
case x: MavenCache => x
}
def this(name: String, root: String) = this(name, root, true)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
package sbt.librarymanagement
abstract class Resolver(
val name: String) extends Serializable {

/** check for HTTP */
private[sbt] def validateProtocol(logger: sbt.util.Logger): Unit = ()



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@
package sbt.librarymanagement
final class URLRepository private (
name: String,
patterns: sbt.librarymanagement.Patterns) extends sbt.librarymanagement.PatternsBasedRepository(name, patterns) with Serializable {
Resolver.validatePatterns(patterns)

patterns: sbt.librarymanagement.Patterns,
val allowInsecureProtocol: Boolean) extends sbt.librarymanagement.PatternsBasedRepository(name, patterns) with Serializable {
private[sbt] override def validateProtocol(logger: sbt.util.Logger): Unit = Resolver.validateURLRepository(this, logger)
private def this(name: String, patterns: sbt.librarymanagement.Patterns) = this(name, patterns, false)

override def equals(o: Any): Boolean = o match {
case x: URLRepository => (this.name == x.name) && (this.patterns == x.patterns)
case x: URLRepository => (this.name == x.name) && (this.patterns == x.patterns) && (this.allowInsecureProtocol == x.allowInsecureProtocol)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (17 + "sbt.librarymanagement.URLRepository".##) + name.##) + patterns.##)
37 * (37 * (37 * (37 * (17 + "sbt.librarymanagement.URLRepository".##) + name.##) + patterns.##) + allowInsecureProtocol.##)
}
override def toString: String = {
"URLRepository(" + name + ", " + patterns + ")"
"URLRepository(" + name + ", " + patterns + ", " + allowInsecureProtocol + ")"
}
private[this] def copy(name: String = name, patterns: sbt.librarymanagement.Patterns = patterns): URLRepository = {
new URLRepository(name, patterns)
private[this] def copy(name: String = name, patterns: sbt.librarymanagement.Patterns = patterns, allowInsecureProtocol: Boolean = allowInsecureProtocol): URLRepository = {
new URLRepository(name, patterns, allowInsecureProtocol)
}
def withName(name: String): URLRepository = {
copy(name = name)
}
def withPatterns(patterns: sbt.librarymanagement.Patterns): URLRepository = {
copy(patterns = patterns)
}
def withAllowInsecureProtocol(allowInsecureProtocol: Boolean): URLRepository = {
copy(allowInsecureProtocol = allowInsecureProtocol)
}
}
object URLRepository {

def apply(name: String, patterns: sbt.librarymanagement.Patterns): URLRepository = new URLRepository(name, patterns)
def apply(name: String, patterns: sbt.librarymanagement.Patterns, allowInsecureProtocol: Boolean): URLRepository = new URLRepository(name, patterns, allowInsecureProtocol)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ implicit lazy val URLRepositoryFormat: JsonFormat[sbt.librarymanagement.URLRepos
unbuilder.beginObject(js)
val name = unbuilder.readField[String]("name")
val patterns = unbuilder.readField[sbt.librarymanagement.Patterns]("patterns")
val allowInsecureProtocol = unbuilder.readField[Boolean]("allowInsecureProtocol")
unbuilder.endObject()
sbt.librarymanagement.URLRepository(name, patterns)
sbt.librarymanagement.URLRepository(name, patterns, allowInsecureProtocol)
case None =>
deserializationError("Expected JsObject but found None")
}
Expand All @@ -23,6 +24,7 @@ implicit lazy val URLRepositoryFormat: JsonFormat[sbt.librarymanagement.URLRepos
builder.beginObject()
builder.addField("name", obj.name)
builder.addField("patterns", obj.patterns)
builder.addField("allowInsecureProtocol", obj.allowInsecureProtocol)
builder.endObject()
}
}
Expand Down
43 changes: 38 additions & 5 deletions core/src/main/contraband/librarymanagement.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@
{ "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": "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" }
],
"extra": [
"private[sbt] def validateProtocol(logger: sbt.util.Logger): Unit = Resolver.validateArtifact(this, logger)"
],
"parentsCompanion": "sbt.librarymanagement.ArtifactFunctions"
},
Expand Down Expand Up @@ -557,6 +561,10 @@
"fields": [
{ "name": "name", "type": "String" }
],
"extra": [
"/** check for HTTP */",
"private[sbt] def validateProtocol(logger: sbt.util.Logger): Unit = ()"
],
"types": [
{
"name": "ChainedResolver",
Expand All @@ -565,6 +573,9 @@
"type": "record",
"fields": [
{ "name": "resolvers", "type": "sbt.librarymanagement.Resolver*" }
],
"extra": [
"private[sbt] override def validateProtocol(logger: sbt.util.Logger): Unit = resolvers.foreach(_.validateProtocol(logger))"
]
},
{
Expand All @@ -583,7 +594,17 @@
"namespace": "sbt.librarymanagement",
"target": "Scala",
"type": "record",
"extra": "def isCache: Boolean = false",
"doc": [
"This is the internal implementation of actual Maven Repository (as opposed to a file cache)."
],
"fields": [
{ "name": "_allowInsecureProtocol", "type": "Boolean", "default": "false", "since": "1.3.0" }
],
"extra": [
"override def isCache: Boolean = false",
"override def allowInsecureProtocol: Boolean = _allowInsecureProtocol",
"private[sbt] override def validateProtocol(logger: sbt.util.Logger): Unit = Resolver.validateMavenRepo(this, logger)"
],
"toString": "s\"$name: $root\""
},
{
Expand All @@ -600,13 +621,22 @@
],
"extra": [
"def this(name: String, rootFile: java.io.File) = this(name, rootFile.toURI.toURL.toString, true, rootFile)",
"def isCache: Boolean = true"
"override def isCache: Boolean = true",
"override def allowInsecureProtocol: Boolean = false"
],
"toString": "s\"cache:$name: ${rootFile.getAbsolutePath}\"",
"extraCompanion": "def apply(name: String, rootFile: java.io.File): MavenCache = new MavenCache(name, rootFile)"
}
],
"extra": "def isCache: Boolean",
"extra": [
"def isCache: Boolean",
"def allowInsecureProtocol: Boolean",
"def withAllowInsecureProtocol(allowInsecureProtocol: Boolean): MavenRepository =",
" this match {",
" case x: MavenRepo => x.with_allowInsecureProtocol(allowInsecureProtocol)",
" case x: MavenCache => x",
" }"
],
"parentsCompanion": "sbt.librarymanagement.MavenRepositoryFunctions"
},
{
Expand Down Expand Up @@ -642,8 +672,11 @@
"namespace": "sbt.librarymanagement",
"target": "Scala",
"type": "record",
"fields": [
{ "name": "allowInsecureProtocol", "type": "boolean", "default": "false", "since": "1.3.0" }
],
"extra": [
"Resolver.validatePatterns(patterns)"
"private[sbt] override def validateProtocol(logger: sbt.util.Logger): Unit = Resolver.validateURLRepository(this, logger)"
]
},
{
Expand Down
Loading

0 comments on commit 4b4087a

Please sign in to comment.