Merge pull request #508 from smarter/fix-snapshot-no-versioning

Fix #506: Support Maven snapshots without `snapshotVersions`
This commit is contained in:
Alexandre Archambault 2017-04-22 14:27:26 +02:00 committed by GitHub
commit 6637ec772b
9 changed files with 100 additions and 2 deletions

View File

@ -34,7 +34,10 @@ object MavenRepository {
): Option[String] =
snapshotVersioning
.snapshotVersions
.find(v => v.classifier == classifier && v.extension == extension)
.find(v =>
(v.classifier == classifier || v.classifier == "*") &&
(v.extension == extension || v.extension == "*")
)
.map(_.value)
.filter(_.nonEmpty)

View File

@ -322,6 +322,19 @@ object Pom {
))
}
/** If `snapshotVersion` is missing, guess it based on
* `version`, `timestamp` and `buildNumber`, as is done in:
* https://github.com/sbt/ivy/blob/2.3.x-sbt/src/java/org/apache/ivy/plugins/resolver/IBiblioResolver.java
*/
def guessedSnapshotVersion(
version: String,
timestamp: String,
buildNumber: Int
): SnapshotVersion = {
val value = s"${version.dropRight("SNAPSHOT".length)}$timestamp-$buildNumber"
SnapshotVersion("*", "*", value, None)
}
def snapshotVersioning(node: Node): String \/ SnapshotVersioning = {
import Scalaz._
@ -392,7 +405,10 @@ object Pom {
buildNumber,
localCopy,
lastUpdatedOpt,
snapshotVersions
if (!snapshotVersions.isEmpty)
snapshotVersions
else
buildNumber.map(bn => guessedSnapshotVersion(version, timestamp, bn)).toList
)
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.abc</groupId>
<artifactId>test-snapshot-special</artifactId>
<version>0.1.0-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20170421.034426</timestamp>
<buildNumber>82</buildNumber>
</snapshot>
<lastUpdated>20170421034426</lastUpdated>
</versioning>
</metadata>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc</groupId>
<artifactId>test-snapshot-special</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>Test</name>
<url>test.com</url>
</project>

View File

@ -0,0 +1,53 @@
package coursier.test
import coursier.{ Attributes, Dependency, Module }
import coursier.maven.MavenRepository
import utest._
object MavenTests extends TestSuite {
// only tested on the JVM for lack of support of XML attributes in the platform-dependent XML stubs
val tests = TestSuite {
'testSnapshotNoVersioning - {
val dep = Dependency(
Module("com.abc", "test-snapshot-special"),
"0.1.0-SNAPSHOT",
transitive = false,
attributes = Attributes()
)
val repoBase = getClass.getResource("/test-repo/http/abc.com").toString.stripSuffix("/") + "/"
val repo = MavenRepository(repoBase)
val mainJarUrl = repoBase + "com/abc/test-snapshot-special/0.1.0-SNAPSHOT/test-snapshot-special-0.1.0-20170421.034426-82.jar"
val sourcesJarUrl = repoBase + "com/abc/test-snapshot-special/0.1.0-SNAPSHOT/test-snapshot-special-0.1.0-20170421.034426-82-sources.jar"
* - CentralTests.withArtifacts(
dep = dep,
artifactType = "jar",
extraRepo = Some(repo),
classifierOpt = None
) {
case Seq(artifact) =>
assert(artifact.url == mainJarUrl)
case other =>
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
}
* - CentralTests.withArtifacts(
dep = dep,
artifactType = "jar",
extraRepo = Some(repo),
classifierOpt = Some("sources")
) {
case Seq(artifact) =>
assert(artifact.url == sourcesJarUrl)
case other =>
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
}
}
}
}