mirror of https://github.com/sbt/sbt.git
Add back support for some checksum format
This commit is contained in:
parent
af5275c014
commit
dee115c1b6
|
|
@ -444,18 +444,28 @@ object Cache {
|
||||||
Nondeterminism[Task].gather(tasks)
|
Nondeterminism[Task].gather(tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def parseChecksum(content: String): Option[BigInteger] = {
|
||||||
|
val lines = content
|
||||||
|
.linesIterator
|
||||||
|
.toVector
|
||||||
|
|
||||||
|
parseChecksumLine(lines) orElse parseChecksumAlternative(lines)
|
||||||
|
}
|
||||||
|
|
||||||
// matches md5 or sha1
|
// matches md5 or sha1
|
||||||
private val checksumPattern = Pattern.compile("^[0-9a-f]{32}([0-9a-f]{8})?")
|
private val checksumPattern = Pattern.compile("^[0-9a-f]{32}([0-9a-f]{8})?")
|
||||||
|
|
||||||
def parseChecksum(content: String): Option[BigInteger] =
|
private def findChecksum(elems: Seq[String]): Option[BigInteger] =
|
||||||
content
|
elems.collectFirst {
|
||||||
.linesIterator
|
case rawSum if checksumPattern.matcher(rawSum).matches() =>
|
||||||
.toStream
|
new BigInteger(rawSum, 16)
|
||||||
.map(_.toLowerCase.replaceAll("\\s", ""))
|
}
|
||||||
.collectFirst {
|
|
||||||
case rawSum if checksumPattern.matcher(rawSum).matches() =>
|
private def parseChecksumLine(lines: Seq[String]): Option[BigInteger] =
|
||||||
new BigInteger(rawSum, 16)
|
findChecksum(lines.map(_.toLowerCase.replaceAll("\\s", "")))
|
||||||
}
|
|
||||||
|
private def parseChecksumAlternative(lines: Seq[String]): Option[BigInteger] =
|
||||||
|
findChecksum(lines.flatMap(_.toLowerCase.split("\\s+")))
|
||||||
|
|
||||||
def validateChecksum(
|
def validateChecksum(
|
||||||
artifact: Artifact,
|
artifact: Artifact,
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,37 @@ object ChecksumTests extends TestSuite {
|
||||||
val tests = TestSuite {
|
val tests = TestSuite {
|
||||||
|
|
||||||
'parse - {
|
'parse - {
|
||||||
// https://repo1.maven.org/maven2/org/apache/spark/spark-core_2.11/1.2.0/spark-core_2.11-1.2.0.pom.sha1
|
|
||||||
// as of 2016-03-02
|
|
||||||
val junkSha1 =
|
|
||||||
"./spark-core_2.11/1.2.0/spark-core_2.11-1.2.0.pom:\n" +
|
|
||||||
"5630 42A5 4B97 E31A F452 9EA0 DB79 BA2C 4C2B B6CC"
|
|
||||||
|
|
||||||
val cleanSha1 = "563042a54b97e31af4529ea0db79ba2c4c2bb6cc"
|
def sha1ParseTest(clean: String, others: String*): Unit = {
|
||||||
|
val expected = Some(new BigInteger(clean, 16))
|
||||||
|
|
||||||
val checksum = Some(new BigInteger(cleanSha1, 16))
|
assert(Cache.parseChecksum(clean) == expected)
|
||||||
|
for (other <- others)
|
||||||
'junk - {
|
assert(Cache.parseChecksum(other) == expected)
|
||||||
assert(Cache.parseChecksum(junkSha1) == checksum)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
'clean - {
|
* - {
|
||||||
assert(Cache.parseChecksum(cleanSha1) == checksum)
|
// https://repo1.maven.org/maven2/org/apache/spark/spark-core_2.11/1.2.0/spark-core_2.11-1.2.0.pom.sha1
|
||||||
|
// as of 2016-03-02
|
||||||
|
val junkSha1 =
|
||||||
|
"./spark-core_2.11/1.2.0/spark-core_2.11-1.2.0.pom:\n" +
|
||||||
|
"5630 42A5 4B97 E31A F452 9EA0 DB79 BA2C 4C2B B6CC"
|
||||||
|
|
||||||
|
val cleanSha1 = "563042a54b97e31af4529ea0db79ba2c4c2bb6cc"
|
||||||
|
|
||||||
|
sha1ParseTest(cleanSha1, junkSha1)
|
||||||
|
}
|
||||||
|
|
||||||
|
* - {
|
||||||
|
// https://repo1.maven.org/maven2/org/json/json/20080701/json-20080701.pom.sha1
|
||||||
|
// as of 2016-03-05
|
||||||
|
val dirtySha1 =
|
||||||
|
"4bf5daa95eb5c12d753a359a3e00621fdc73d187 " + // no CR here
|
||||||
|
"/home/maven/repository-staging/to-ibiblio/maven2/org/json/json/20080701/json-20080701.pom"
|
||||||
|
|
||||||
|
val cleanSha1 = "4bf5daa95eb5c12d753a359a3e00621fdc73d187"
|
||||||
|
|
||||||
|
sha1ParseTest(cleanSha1, dirtySha1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue