mirror of https://github.com/sbt/sbt.git
Merge pull request #508 from smarter/fix-snapshot-no-versioning
Fix #506: Support Maven snapshots without `snapshotVersions`
This commit is contained in:
commit
6637ec772b
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -0,0 +1 @@
|
|||
nothing here
|
||||
|
|
@ -0,0 +1 @@
|
|||
nothing here
|
||||
|
|
@ -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>
|
||||
|
|
@ -0,0 +1 @@
|
|||
16e31f3b60344230b62f1c6a9367edde
|
||||
|
|
@ -0,0 +1 @@
|
|||
563042a54b97e31af4529ea0db79ba2c4c2bb6cc
|
||||
|
|
@ -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")}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue