Merge pull request #899 from coursier/topic/no-directory-listing

Don't rely on directory listings anymore
This commit is contained in:
Alexandre Archambault 2018-09-20 16:16:58 +02:00 committed by GitHub
commit 08d0375f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 193 additions and 572 deletions

View File

@ -71,7 +71,8 @@ lazy val `proxy-tests` = project
coursierPrefix,
libs ++= Seq(
Deps.dockerClient,
Deps.scalaAsync.value
Deps.scalaAsync.value,
Deps.slf4JNop
),
utest,
sharedTestResources

View File

@ -73,18 +73,19 @@ final case class Attributes(
`type`: String,
classifier: String
) {
def packaging: String = if (`type`.isEmpty)
def packaging: String =
if (`type`.isEmpty)
"jar"
else
`type`
def packagingAndClassifier: String = if (isEmpty) {
def packagingAndClassifier: String =
if (isEmpty)
""
} else if (classifier.isEmpty) {
else if (classifier.isEmpty)
packaging
} else {
else
s"$packaging:$classifier"
}
def publication(name: String, ext: String): Publication =
Publication(name, `type`, ext, classifier)

View File

@ -1,8 +1,8 @@
package coursier.core
import coursier.Fetch
import coursier.core.compatibility.encodeURIComponent
import coursier.maven.MavenSource
import coursier.util.{EitherT, Monad}
trait Repository extends Product with Serializable {
@ -24,19 +24,28 @@ object Repository {
"SHA-1" -> (underlying.url + ".sha1"),
"SHA-256" -> (underlying.url + ".sha256")
))
def withDefaultSignature: Artifact =
def withDefaultSignature: Artifact = {
val underlyingExt =
if (underlying.attributes.`type`.isEmpty)
"jar"
else
// TODO move MavenSource.typeExtension elsewhere
MavenSource.typeExtension(underlying.attributes.`type`)
underlying.copy(extra = underlying.extra ++ Seq(
"sig" ->
Artifact(
underlying.url + ".asc",
Map.empty,
Map.empty,
Attributes("asc", ""),
Attributes(s"$underlyingExt.asc", ""),
changing = underlying.changing,
authentication = underlying.authentication
)
.withDefaultChecksums
))
}
}
}

View File

@ -79,9 +79,12 @@ final case class IvyRepository(
}
else if (dependency.attributes.`type`.nonEmpty)
project.publications.collect {
case (_, p)
if p.classifier.isEmpty && (
p.`type` == dependency.attributes.`type` ||
case (conf, p)
if (conf == "*" ||
conf == dependency.configuration ||
project.allConfigurations.getOrElse(dependency.configuration, Set.empty).contains(conf)) &&
(
p.`type` == dependency.attributes.`type` ||
(p.ext == dependency.attributes.`type` && project.packagingOpt.toSeq.contains(p.`type`)) // wow
) =>
p

View File

@ -316,110 +316,21 @@ final case class MavenRepository(
proj <- Pom.project(xml, relocationAsDependency = true).right
} yield proj
def isArtifact(fileName: String, prefix: String): Option[(String, String)] =
// TODO There should be a regex for that...
if (fileName.startsWith(prefix)) {
val end = fileName.stripPrefix(prefix)
val idx = end.indexOf('.')
if (idx >= 0) {
val ext = end.drop(idx + 1)
val rem = end.take(idx)
if (rem.isEmpty)
Some(("", ext))
else if (rem.startsWith("-"))
Some((rem.drop(1), ext))
else
None
} else
None
} else
None
val projectArtifact0 = projectArtifact(module, version, versioningValue)
val listFilesUrl = urlFor(moduleVersionPath(module, version)) + "/"
val changing0 = changing.getOrElse(isSnapshot(version))
val listFilesArtifact =
Artifact(
listFilesUrl,
Map.empty,
Map(
"metadata" -> projectArtifact0
),
Attributes("", ""),
changing = changing0,
authentication
)
val requiringDirListingProjectArtifact = projectArtifact0
.copy(
extra = projectArtifact0.extra + (
// In LocalUpdate and LocalUpdateChanging mode, makes getting the POM fail if the POM
// is in cache, but no info about the directory listing is (directory listing not in cache and no kept error
// for it).
"required" -> listFilesArtifact
)
)
for {
str <- fetch(requiringDirListingProjectArtifact)
rawListFilesPageOpt <- EitherT(F.map(fetch(artifactFor(listFilesUrl, changing0)).run) {
e => Right(e.right.toOption): Either[String, Option[String]]
})
str <- fetch(projectArtifact0)
proj0 <- EitherT(F.point[Either[String, Project]](parseRawPom(str)))
} yield {
val foundPublications =
rawListFilesPageOpt match {
case Some(rawListFilesPage) =>
val files = WebPage.listFiles(listFilesUrl, rawListFilesPage)
val prefix = s"${module.name}-${versioningValue.getOrElse(version)}"
val packagingTpeMap = proj0.packagingOpt
.filter(_ != Pom.relocatedPackaging)
.map { packaging =>
(MavenSource.typeDefaultClassifier(packaging), MavenSource.typeExtension(packaging)) -> packaging
}
.toMap
files
.flatMap(isArtifact(_, prefix))
.map {
case (classifier, ext) =>
val tpe = packagingTpeMap.getOrElse(
(classifier, ext),
MavenSource.classifierExtensionDefaultTypeOpt(classifier, ext).getOrElse(ext)
)
val config = MavenSource.typeDefaultConfig(tpe).getOrElse("compile")
config -> Publication(
module.name,
tpe,
ext,
classifier
)
}
case None =>
// Publications can't be listed - MavenSource then handles that
Nil
}
val proj = Pom.addOptionalDependenciesInConfig(
proj0.copy(configurations = defaultConfigurations),
} yield
Pom.addOptionalDependenciesInConfig(
proj0.copy(
actualVersionOpt = Some(version),
configurations = defaultConfigurations
),
Set("", "default"),
"optional"
)
proj.copy(
actualVersionOpt = Some(version),
publications = foundPublications
)
}
}
def find[F[_]](

View File

@ -32,7 +32,11 @@ final case class MavenSource(
val versioning = project
.snapshotVersioning
.flatMap(versioning =>
mavenVersioning(versioning, publication.classifier, publication.`type`)
mavenVersioning(
versioning,
publication.classifier,
MavenSource.typeExtension(publication.`type`)
)
)
val path = dependency.module.organization.split('.').toSeq ++ Seq(
@ -42,21 +46,17 @@ final case class MavenSource(
)
val changing0 = changing.getOrElse(isSnapshot(project.actualVersion))
var artifact =
Artifact(
root + path.mkString("/"),
Map.empty,
Map.empty,
publication.attributes,
changing = changing0,
authentication = authentication
)
.withDefaultChecksums
if (publication.ext == "jar")
artifact = artifact.withDefaultSignature
artifact
Artifact(
root + path.mkString("/"),
Map.empty,
Map.empty,
publication.attributes,
changing = changing0,
authentication = authentication
)
.withDefaultChecksums
.withDefaultSignature
}
val metadataArtifact = artifactOf(Publication(dependency.module.name, "pom", "pom", ""))
@ -133,142 +133,6 @@ final case class MavenSource(
.map(artifactWithExtra)
}
private val types = Map("sha1" -> "SHA-1", "sha256" -> "SHA-256", "md5" -> "MD5", "asc" -> "sig")
private def artifactsKnownPublications(
dependency: Dependency,
project: Project,
overrideClassifiers: Option[Seq[String]]
): Seq[Artifact] = {
final case class EnrichedPublication(
publication: Publication,
extra: Map[String, EnrichedPublication]
) {
def artifact: Artifact =
artifact(publication.`type`)
def artifact(versioningType: String): Artifact = {
val versioningExtension = MavenSource.typeExtensions.getOrElse(versioningType, versioningType)
val versioning = project
.snapshotVersioning
.flatMap(versioning =>
mavenVersioning(versioning, publication.classifier, versioningExtension)
)
val path = dependency.module.organization.split('.').toSeq ++ Seq(
MavenRepository.dirModuleName(dependency.module, sbtAttrStub),
project.actualVersion,
s"${dependency.module.name}-${versioning getOrElse project.actualVersion}${Some(publication.classifier).filter(_.nonEmpty).map("-" + _).mkString}.${publication.ext}"
)
val changing0 = changing.getOrElse(isSnapshot(project.actualVersion))
val extra0 = extra.mapValues(_.artifact(versioningType)).iterator.toMap
Artifact(
root + path.mkString("/"),
extra0.filterKeys(MavenSource.checksumTypes).mapValues(_.url).iterator.toMap,
extra0,
publication.attributes,
changing = changing0,
authentication = authentication
)
}
}
def groupedEnrichedPublications(publications: Seq[Publication]): Seq[EnrichedPublication] = {
def helper(publications: Seq[Publication]): Seq[EnrichedPublication] = {
var publications0 = publications
.map { pub =>
pub.ext -> EnrichedPublication(pub, Map())
}
.toMap
val byLength = publications0.toVector.sortBy(-_._1.length)
for {
(ext, _) <- byLength
idx = ext.lastIndexOf('.')
if idx >= 0
subExt = ext.substring(idx + 1)
baseExt = ext.substring(0, idx)
tpe <- types.get(subExt)
mainPub <- publications0.get(baseExt)
} {
val pub = publications0(ext)
publications0 += baseExt -> mainPub.copy(
extra = mainPub.extra + (tpe -> pub)
)
publications0 -= ext
}
publications0.values.toVector
}
publications
.groupBy(p => (p.name, p.classifier))
.mapValues(helper)
.values
.toVector
.flatten
}
val enrichedPublications = groupedEnrichedPublications(project.publications.map(_._2))
val metadataArtifactOpt = enrichedPublications.collectFirst {
case pub if pub.publication.name == dependency.module.name &&
pub.publication.ext == "pom" &&
pub.publication.classifier.isEmpty =>
pub.artifact
}
def withMetadataExtra(artifact: Artifact) =
metadataArtifactOpt.fold(artifact) { metadataArtifact =>
artifact.copy(
extra = artifact.extra + ("metadata" -> metadataArtifact)
)
}
val res = overrideClassifiers match {
case Some(classifiers) =>
val classifiersSet = classifiers.toSet
enrichedPublications.collect {
case p if classifiersSet(p.publication.classifier) =>
p.artifact
}
case None =>
if (dependency.attributes.classifier.nonEmpty)
// FIXME We're ignoring dependency.attributes.`type` in this case
enrichedPublications.collect {
case p if p.publication.classifier == dependency.attributes.classifier =>
p.artifact
}
else if (dependency.attributes.`type`.nonEmpty)
enrichedPublications.collect {
case p
if (p.publication.classifier.isEmpty || p.publication.classifier == MavenSource.typeDefaultClassifier(dependency.attributes.`type`)) && (
p.publication.`type` == dependency.attributes.`type` ||
(p.publication.ext == dependency.attributes.`type` && project.packagingOpt.toSeq.contains(p.publication.`type`)) // wow
) =>
p.artifact
}
else
enrichedPublications.collect {
case p if p.publication.classifier.isEmpty =>
p.artifact
}
}
res.map(withMetadataExtra)
}
private val dummyArtifact = Artifact("", Map(), Map(), Attributes("", ""), changing = false, None)
def artifacts(
@ -285,52 +149,13 @@ final case class MavenSource(
extra = a.extra.mapValues(makeOptional).iterator.toMap + (Artifact.optionalKey -> dummyArtifact)
)
def merge(a: Artifact, other: Artifact): Artifact = {
assert(a.url == other.url, s"Merging artifacts with different URLs (${a.url}, ${other.url})")
val extra =
a.extra.map {
case (k, v) =>
k -> other.extra.get(k).fold(v)(merge(v, _))
} ++
other.extra
.filterKeys(k => !a.extra.contains(k) && k != Artifact.optionalKey)
a.copy(
checksumUrls = other.checksumUrls ++ a.checksumUrls,
extra = extra
)
}
val defaultPublications = artifactsUnknownPublications(dependency, project, overrideClassifiers)
artifactsUnknownPublications(dependency, project, overrideClassifiers)
.map(makeOptional)
if (project.publications.isEmpty)
defaultPublications
else {
val listedPublications = artifactsKnownPublications(dependency, project, overrideClassifiers)
val listedUrls = listedPublications.map(_.url).toSet
val defaultPublicationsMap = defaultPublications
.map(a => a.url -> a)
.toMap
val listedPublications0 = listedPublications.map { a =>
defaultPublicationsMap
.get(a.url)
.fold(a)(merge(a, _))
}
val extraPublications = defaultPublications
.filter(a => !listedUrls(a.url))
listedPublications0 ++ extraPublications
}
}
}
object MavenSource {
private val checksumTypes = Set("MD5", "SHA-1", "SHA-256")
val typeExtensions: Map[String, String] = Map(
"eclipse-plugin" -> "jar",
"maven-plugin" -> "jar",
@ -373,12 +198,4 @@ object MavenSource {
def classifierExtensionDefaultTypeOpt(classifier: String, ext: String): Option[String] =
classifierExtensionDefaultTypes.get((classifier, ext))
val typeDefaultConfigs: Map[String, String] = Map(
"doc" -> "docs",
"src" -> "sources"
)
def typeDefaultConfig(`type`: String): Option[String] =
typeDefaultConfigs.get(`type`)
}

View File

@ -45,4 +45,6 @@ object Deps {
def scalaNativeNir = "org.scala-native" %% "nir" % SharedVersions.scalaNative
def scalaNativeTools = "org.scala-native" %% "tools" % SharedVersions.scalaNative
def scalaNativeUtil = "org.scala-native" %% "util" % SharedVersions.scalaNative
def slf4JNop = "org.slf4j" % "slf4j-nop" % "1.7.25"
}

View File

@ -16,7 +16,6 @@ check := {
sys.error("No configuration report found for configuration 'compile'")
}
val moduleReports = configReport.modules
val artifacts = moduleReports.flatMap(_.artifacts.map(_._1))
val signatures = moduleReports
.flatMap(_.artifacts)
.filter(_._1.extension == "jar.asc")

View File

@ -9,62 +9,35 @@ object DirectoryListingTests extends TestSuite {
val user = "user"
val password = "pass"
val withListingRepo = MavenRepository(
val repo = MavenRepository(
"http://localhost:8080",
authentication = Some(Authentication(user, password))
)
val withoutListingRepo = MavenRepository(
"http://localhost:8081",
authentication = Some(Authentication(user, password))
)
val module = Module("com.abc", "test")
val version = "0.1"
val tests = Tests {
'withListing - {
'jar - CentralTests.withArtifacts(
module,
version,
"jar",
extraRepos = Seq(withListingRepo)
) {
artifacts =>
assert(artifacts.length == 1)
}
'jarFoo - CentralTests.withArtifacts(
module,
version,
"jar-foo",
extraRepos = Seq(withListingRepo)
) {
artifacts =>
assert(artifacts.length == 1)
}
'jar - CentralTests.withArtifacts(
module,
version,
attributes = Attributes("jar"),
extraRepos = Seq(repo)
) {
artifacts =>
assert(artifacts.length == 1)
assert(artifacts.headOption.exists(_.url.endsWith(".jar")))
}
'withoutListing - {
'jar - CentralTests.withArtifacts(
module,
version,
"jar",
extraRepos = Seq(withoutListingRepo)
) {
artifacts =>
assert(artifacts.length == 1)
}
'jarFoo - CentralTests.withArtifacts(
module,
version,
"jar-foo",
extraRepos = Seq(withoutListingRepo)
) {
artifacts =>
assert(artifacts.length == 0)
}
'jarFoo - CentralTests.withArtifacts(
module,
version,
attributes = Attributes("jar-foo"),
extraRepos = Seq(repo)
) {
artifacts =>
assert(artifacts.length == 1)
assert(artifacts.headOption.exists(_.url.endsWith(".jar-foo")))
}
}

View File

@ -46,8 +46,8 @@ object IvyTests extends TestSuite {
extraRepos = Seq(sbtRepo)
)
* - CentralTests.withArtifact(mod, ver, "jar", extraRepos = Seq(sbtRepo)) { artifact =>
assert(artifact.url == expectedArtifactUrl)
* - CentralTests.withArtifacts(mod, ver, Attributes("jar"), extraRepos = Seq(sbtRepo)) { artifacts =>
assert(artifacts.exists(_.url == expectedArtifactUrl))
}
}
@ -71,11 +71,9 @@ object IvyTests extends TestSuite {
val testJarUrl = repoBase + "com.example/a_2.11/0.1.0-SNAPSHOT/jars/a_2.11-tests.jar"
"no conf or classifier" - CentralTests.withArtifacts(
dep = dep,
artifactType = "jar",
dep = dep.copy(attributes = Attributes("jar")),
extraRepos = Seq(repo),
classifierOpt = None,
optional = true
classifierOpt = None
) {
case Seq(artifact) =>
assert(artifact.url == mainJarUrl)
@ -83,21 +81,26 @@ object IvyTests extends TestSuite {
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
}
"test conf" - CentralTests.withArtifacts(
dep = dep.copy(configuration = "test"),
artifactType = "jar",
extraRepos = Seq(repo),
classifierOpt = None,
optional = true
) {
case Seq(artifact1, artifact2) =>
val urls = Set(
artifact1.url,
artifact2.url
)
assert(urls == Set(mainJarUrl, testJarUrl))
case other =>
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
"test conf" - {
"no attributes" - CentralTests.withArtifacts(
dep = dep.copy(configuration = "test"),
extraRepos = Seq(repo),
classifierOpt = None
) { artifacts =>
val urls = artifacts.map(_.url).toSet
assert(urls(mainJarUrl))
assert(urls(testJarUrl))
}
"attributes" - CentralTests.withArtifacts(
dep = dep.copy(configuration = "test", attributes = Attributes("jar")),
extraRepos = Seq(repo),
classifierOpt = None
) { artifacts =>
val urls = artifacts.map(_.url).toSet
assert(urls(mainJarUrl))
assert(urls(testJarUrl))
}
}
"tests classifier" - {
@ -105,27 +108,18 @@ object IvyTests extends TestSuite {
* - CentralTests.withArtifacts(
deps = Set(dep, testsDep),
artifactType = "jar",
extraRepos = Seq(repo),
classifierOpt = None,
optional = true
) {
case Seq(artifact1, artifact2) =>
val urls = Set(
artifact1.url,
artifact2.url
)
assert(urls == Set(mainJarUrl, testJarUrl))
case other =>
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
classifierOpt = None
) { artifacts =>
val urls = artifacts.map(_.url).toSet
assert(urls(mainJarUrl))
assert(urls(testJarUrl))
}
* - CentralTests.withArtifacts(
dep = testsDep,
artifactType = "jar",
extraRepos = Seq(repo),
classifierOpt = None,
optional = true
classifierOpt = None
) {
case Seq(artifact) =>
assert(artifact.url == testJarUrl)

View File

@ -26,11 +26,9 @@ object MavenTests extends TestSuite {
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",
dep = dep.copy(attributes = Attributes("jar")),
extraRepos = Seq(repo),
classifierOpt = None,
optional = true
classifierOpt = None
) {
case Seq(artifact) =>
assert(artifact.url == mainJarUrl)
@ -39,11 +37,9 @@ object MavenTests extends TestSuite {
}
* - CentralTests.withArtifacts(
dep = dep,
artifactType = "src",
dep = dep.copy(attributes = Attributes("src")),
extraRepos = Seq(repo),
classifierOpt = Some("sources"),
optional = true
classifierOpt = Some("sources")
) {
case Seq(artifact) =>
assert(artifact.url == sourcesJarUrl)

@ -1 +1 @@
Subproject commit ed446075ace7914af71a39ac7b00f17fa5d9190b
Subproject commit cdad75ba739422d2f110e0e70093e21c4cb0e6d6

View File

@ -126,58 +126,33 @@ abstract class CentralTests extends TestSuite {
assert(result == expected)
}
def withArtifact[T](
module: Module,
version: String,
artifactType: String,
attributes: Attributes = Attributes(),
extraRepos: Seq[Repository] = Nil
)(
f: Artifact => T
): Future[T] =
withArtifacts(module, version, artifactType, attributes, extraRepos) {
case Seq(artifact) =>
f(artifact)
case other =>
throw new Exception(
s"Unexpected artifact list size: ${other.size}\n" +
"Artifacts:\n" + other.map(" " + _).mkString("\n")
)
}
def withArtifacts[T](
module: Module,
version: String,
artifactType: String,
attributes: Attributes = Attributes(),
extraRepos: Seq[Repository] = Nil,
classifierOpt: Option[String] = None,
transitive: Boolean = false,
optional: Boolean = true
transitive: Boolean = false
)(
f: Seq[Artifact] => T
): Future[T] = {
val dep = Dependency(module, version, transitive = transitive, attributes = attributes)
withArtifacts(dep, artifactType, extraRepos, classifierOpt, optional)(f)
withArtifacts(dep, extraRepos, classifierOpt)(f)
}
def withArtifacts[T](
dep: Dependency,
artifactType: String,
extraRepos: Seq[Repository],
classifierOpt: Option[String],
optional: Boolean
classifierOpt: Option[String]
)(
f: Seq[Artifact] => T
): Future[T] =
withArtifacts(Set(dep), artifactType, extraRepos, classifierOpt, optional)(f)
withArtifacts(Set(dep), extraRepos, classifierOpt)(f)
def withArtifacts[T](
deps: Set[Dependency],
artifactType: String,
extraRepos: Seq[Repository],
classifierOpt: Option[String],
optional: Boolean
classifierOpt: Option[String]
)(
f: Seq[Artifact] => T
): Future[T] = async {
@ -191,13 +166,8 @@ abstract class CentralTests extends TestSuite {
assert(isDone)
val artifacts = classifierOpt
.fold(res.dependencyArtifacts(withOptional = optional))(c => res.dependencyClassifiersArtifacts(Seq(c)))
.fold(res.dependencyArtifacts(withOptional = true))(c => res.dependencyClassifiersArtifacts(Seq(c)))
.map(_._2)
.filter {
if (artifactType == "*") _ => true
else
_.`type` == artifactType
}
f(artifacts)
}
@ -205,13 +175,12 @@ abstract class CentralTests extends TestSuite {
def ensureHasArtifactWithExtension(
module: Module,
version: String,
artifactType: String,
extension: String,
attributes: Attributes = Attributes(),
extraRepos: Seq[Repository] = Nil
): Future[Unit] =
withArtifact(module, version, artifactType, attributes = attributes, extraRepos = extraRepos) { artifact =>
assert(artifact.url.endsWith("." + extension))
withArtifacts(module, version, attributes = attributes, extraRepos = extraRepos) { artifacts =>
assert(artifacts.exists(_.url.endsWith("." + extension)))
}
val tests = Tests {
@ -305,7 +274,7 @@ abstract class CentralTests extends TestSuite {
mod,
version,
"jar",
"jar",
Attributes("jar"),
extraRepos = Seq(extraRepo)
)
}
@ -372,6 +341,8 @@ abstract class CentralTests extends TestSuite {
'versionInterval - {
if (isActualCentral)
// that one involves version intervals, thus changing versions, so only
// running it against our cached Central stuff
resolutionCheck(
Module("org.webjars.bower", "malihu-custom-scrollbar-plugin"),
"3.1.5"
@ -409,8 +380,8 @@ abstract class CentralTests extends TestSuite {
* - resolutionCheck(mod, version)
* - withArtifact(mod, version, "jar") { artifact =>
assert(artifact.url == expectedArtifactUrl)
* - withArtifacts(mod, version, Attributes("jar")) { artifacts =>
assert(artifacts.exists(_.url == expectedArtifactUrl))
}
}
@ -438,7 +409,8 @@ abstract class CentralTests extends TestSuite {
Dependency(
Module("org.scala-lang", "scala-compiler"), "2.11.8",
configuration = config,
transitive = false
transitive = false,
attributes = Attributes("jar")
)
withArtifacts(
@ -446,10 +418,8 @@ abstract class CentralTests extends TestSuite {
intransitiveCompiler("default"),
intransitiveCompiler("optional")
),
"jar",
extraRepos = Nil,
classifierOpt = None,
optional = true
classifierOpt = None
) {
case Seq() =>
throw new Exception("Expected one JAR")
@ -471,19 +441,14 @@ abstract class CentralTests extends TestSuite {
module,
version,
tpe,
tpe,
attributes = Attributes(tpe)
)
* - {
if (isActualCentral)
ensureHasArtifactWithExtension(
module,
version,
tpe,
tpe
)
}
* - ensureHasArtifactWithExtension(
module,
version,
tpe
)
}
'bundle - {
@ -491,7 +456,6 @@ abstract class CentralTests extends TestSuite {
* - ensureHasArtifactWithExtension(
Module("com.google.guava", "guava"),
"17.0",
"bundle",
"jar"
)
@ -500,7 +464,6 @@ abstract class CentralTests extends TestSuite {
* - ensureHasArtifactWithExtension(
Module("com.google.guava", "guava"),
"17.0",
"bundle",
"jar",
attributes = Attributes("jar")
)
@ -511,17 +474,14 @@ abstract class CentralTests extends TestSuite {
ensureHasArtifactWithExtension(
Module("org.bytedeco", "javacpp"),
"1.1",
"maven-plugin",
"jar"
"jar",
Attributes("maven-plugin")
)
}
}
'classifier - {
// Adding extra repo so it's agnostic from nexus which only has the poms
val extraRepo = MavenRepository("https://repo1.maven.org/maven2")
'vanilla - {
async {
val deps = Set(
@ -529,8 +489,8 @@ abstract class CentralTests extends TestSuite {
Module("org.apache.avro", "avro"), "1.8.1"
)
)
val res = await(resolve(deps, extraRepos = Seq(extraRepo)))
val filenames: Set[String] = res.artifacts.map(_.url.split("/").last).toSet
val res = await(resolve(deps))
val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet
assert(filenames.contains("avro-1.8.1.jar"))
assert(!filenames.contains("avro-1.8.1-tests.jar"))
}
@ -543,8 +503,8 @@ abstract class CentralTests extends TestSuite {
Module("org.apache.avro", "avro"), "1.8.1", attributes = Attributes("", "tests")
)
)
val res = await(resolve(deps, extraRepos = Seq(extraRepo)))
val filenames: Set[String] = res.artifacts.map(_.url.split("/").last).toSet
val res = await(resolve(deps))
val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet
assert(!filenames.contains("avro-1.8.1.jar"))
assert(filenames.contains("avro-1.8.1-tests.jar"))
}
@ -560,8 +520,8 @@ abstract class CentralTests extends TestSuite {
Module("org.apache.avro", "avro"), "1.8.1", attributes = Attributes("", "tests")
)
)
val res = await(resolve(deps, extraRepos = Seq(extraRepo)))
val filenames: Set[String] = res.artifacts.map(_.url.split("/").last).toSet
val res = await(resolve(deps))
val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet
assert(filenames.contains("avro-1.8.1.jar"))
assert(filenames.contains("avro-1.8.1-tests.jar"))
}
@ -589,7 +549,7 @@ abstract class CentralTests extends TestSuite {
assert(conflicts.isEmpty)
assert(isDone)
val artifacts = res.artifacts
val artifacts = res.artifacts(withOptional = true)
val map = artifacts.groupBy(a => a)
@ -640,7 +600,6 @@ abstract class CentralTests extends TestSuite {
val zookeeperTestArtifact = zookeeperTestArtifacts.head
assert(!isActualCentral || !zookeeperTestArtifact.isOptional)
assert(zookeeperTestArtifact.attributes.`type` == "test-jar")
assert(zookeeperTestArtifact.attributes.classifier == "tests")
zookeeperTestArtifact.url.endsWith("-tests.jar")
@ -703,30 +662,18 @@ abstract class CentralTests extends TestSuite {
* - resolutionCheck(mod, version)
val mainTarGzUrl = s"$centralBase/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.tar.gz"
val expectedTarGzArtifactUrls = Set(
mainTarGzUrl,
s"$centralBase/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-bin.tar.gz"
)
val mainZipUrl = s"$centralBase/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip"
val expectedZipArtifactUrls = Set(
mainZipUrl,
s"$centralBase/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-bin.zip"
)
'tarGz - {
* - {
if (isActualCentral)
withArtifacts(mod, version, "tar.gz", classifierOpt = Some("bin"), transitive = true) { artifacts =>
assert(artifacts.length == 2)
val urls = artifacts.map(_.url).toSet
assert(urls == expectedTarGzArtifactUrls)
}
else
Future.successful(())
withArtifacts(mod, version, attributes = Attributes("tar.gz", "bin"), transitive = true) { artifacts =>
assert(artifacts.nonEmpty)
val urls = artifacts.map(_.url).toSet
assert(urls.contains(mainTarGzUrl))
}
}
* - {
withArtifacts(mod, version, "tar.gz", attributes = Attributes("tar.gz", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts =>
withArtifacts(mod, version, attributes = Attributes("tar.gz", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts =>
assert(artifacts.nonEmpty)
val urls = artifacts.map(_.url).toSet
assert(urls.contains(mainTarGzUrl))
@ -736,17 +683,14 @@ abstract class CentralTests extends TestSuite {
'zip - {
* - {
if (isActualCentral)
withArtifacts(mod, version, "zip", classifierOpt = Some("bin"), transitive = true) { artifacts =>
assert(artifacts.length == 2)
val urls = artifacts.map(_.url).toSet
assert(urls == expectedZipArtifactUrls)
}
else
Future.successful(())
withArtifacts(mod, version, attributes = Attributes("zip", "bin"), transitive = true) { artifacts =>
assert(artifacts.nonEmpty)
val urls = artifacts.map(_.url).toSet
assert(urls.contains(mainZipUrl))
}
}
* - {
withArtifacts(mod, version, "zip", attributes = Attributes("zip", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts =>
withArtifacts(mod, version, attributes = Attributes("zip", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts =>
assert(artifacts.nonEmpty)
val urls = artifacts.map(_.url).toSet
assert(urls.contains(mainZipUrl))
@ -776,9 +720,8 @@ abstract class CentralTests extends TestSuite {
* - resolutionCheck(mod, ver)
* - withArtifacts(mod, ver, "jar", transitive = true) { artifacts =>
assert(artifacts.length == 1)
assert(artifacts.head.url == expectedUrl)
* - withArtifacts(mod, ver, transitive = true) { artifacts =>
assert(artifacts.exists(_.url == expectedUrl))
}
}
}
@ -812,33 +755,27 @@ abstract class CentralTests extends TestSuite {
def hasSha1(a: Artifact) = a.checksumUrls.contains("SHA-1")
def hasMd5(a: Artifact) = a.checksumUrls.contains("MD5")
def hasSig(a: Artifact) = a.extra.contains("sig")
def sigHasSig(a: Artifact) = a.extra.get("sig").exists(hasSig)
* - resolutionCheck(mod, ver)
* - withArtifacts(mod, ver, "*") { artifacts =>
* - withArtifacts(mod, ver, Attributes("bundle")) { artifacts =>
val jarOpt = artifacts.find(_.`type` == "bundle").orElse(artifacts.find(_.`type` == "jar"))
val pomOpt = artifacts.find(_.`type` == "pom")
assert(jarOpt.nonEmpty)
assert(jarOpt.forall(hasSha1))
assert(jarOpt.forall(hasMd5))
assert(jarOpt.forall(hasSig))
}
if (isActualCentral) {
if (artifacts.length != 2 || jarOpt.isEmpty || pomOpt.isEmpty)
artifacts.foreach(println)
* - withArtifacts(mod, ver, Attributes("pom")) { artifacts =>
assert(jarOpt.forall(_.`type` == "bundle"))
assert(artifacts.length == 2)
assert(pomOpt.nonEmpty)
assert(pomOpt.forall(hasSha1))
assert(pomOpt.forall(hasMd5))
assert(pomOpt.forall(hasSig))
assert(jarOpt.forall(sigHasSig))
assert(pomOpt.forall(sigHasSig))
}
val pomOpt = artifacts.find(_.`type` == "pom")
assert(pomOpt.nonEmpty)
assert(pomOpt.forall(hasSha1))
assert(pomOpt.forall(hasMd5))
assert(pomOpt.forall(hasSig))
}
}
@ -877,43 +814,26 @@ abstract class CentralTests extends TestSuite {
val mod = Module("io.monix", "monix_2.12")
val ver = "2.3.0"
val mainUrl = "https://repo1.maven.org/maven2/io/monix/monix_2.12/2.3.0/monix_2.12-2.3.0.jar"
val mainUrl = s"$centralBase/io/monix/monix_2.12/2.3.0/monix_2.12-2.3.0.jar"
* - resolutionCheck(mod, ver)
* - {
if (isActualCentral)
withArtifacts(mod, ver, "jar") { artifacts =>
val mainArtifactOpt = artifacts.find(_.url == mainUrl)
assert(mainArtifactOpt.nonEmpty)
assert(mainArtifactOpt.forall(_.isOptional))
}
else
Future.successful(())
}
* - withArtifacts(mod, ver, "jar", optional = false) { artifacts =>
* - withArtifacts(mod, ver, Attributes("jar")) { artifacts =>
val mainArtifactOpt = artifacts.find(_.url == mainUrl)
assert(mainArtifactOpt.isEmpty)
assert(mainArtifactOpt.nonEmpty)
assert(mainArtifactOpt.forall(_.isOptional))
}
* - {
if (isActualCentral)
withArtifacts(Module("com.lihaoyi", "scalatags_2.12"), "0.6.2", "jar", transitive = true, optional = false) { artifacts =>
* - withArtifacts(Module("com.lihaoyi", "scalatags_2.12"), "0.6.2", Attributes("jar"), transitive = true) { artifacts =>
assert(artifacts.forall(!_.isOptional))
val urls = artifacts.map(_.url).toSet
val urls = artifacts.map(_.url).toSet
val expectedUrls = Set(
"https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.0/scala-library-2.12.0.jar",
"https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3.jar",
"https://repo1.maven.org/maven2/com/lihaoyi/scalatags_2.12/0.6.2/scalatags_2.12-0.6.2.jar"
)
assert(urls == expectedUrls)
}
else
Future.successful(())
val expectedUrls = Seq(
s"$centralBase/org/scala-lang/scala-library/2.12.0/scala-library-2.12.0.jar",
s"$centralBase/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3.jar",
s"$centralBase/com/lihaoyi/scalatags_2.12/0.6.2/scalatags_2.12-0.6.2.jar"
)
assert(expectedUrls.forall(urls))
}
}
@ -925,7 +845,7 @@ abstract class CentralTests extends TestSuite {
* - resolutionCheck(mod, ver, extraRepos = Seq(extraRepo))
* - withArtifacts(mod, ver, "*", extraRepos = Seq(extraRepo), transitive = true) { artifacts =>
* - withArtifacts(mod, ver, Attributes("aar"), extraRepos = Seq(extraRepo), transitive = true) { artifacts =>
val urls = artifacts.map(_.url).toSet
val expectedUrls = Set(
"https://maven.google.com/com/android/support/support-fragment/25.3.1/support-fragment-25.3.1.aar",
@ -962,34 +882,29 @@ abstract class CentralTests extends TestSuite {
* - resolutionCheck(mod, ver, extraRepos = extraRepos)
* - {
if (isActualCentral)
withArtifacts(mod, ver, "*", extraRepos = extraRepos, transitive = true) { artifacts =>
val urls = artifacts.map(_.url).toSet
val expectedUrls = Set(
"https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/com/cedarsoftware/json-io/4.9.9-TALEND/json-io-4.9.9-TALEND.jar",
"https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceSnapshot/org/talend/daikon/daikon/0.19.0-SNAPSHOT/daikon-0.19.0-20171201.100416-43.jar",
"https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.5.3/jackson-annotations-2.5.3.jar",
"https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.5.3/jackson-core-2.5.3.jar",
"https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.5.3/jackson-databind-2.5.3.jar",
"https://repo1.maven.org/maven2/com/thoughtworks/paranamer/paranamer/2.7/paranamer-2.7.jar",
"https://repo1.maven.org/maven2/commons-codec/commons-codec/1.6/commons-codec-1.6.jar",
"https://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar",
"https://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar",
"https://repo1.maven.org/maven2/org/apache/avro/avro/1.8.1/avro-1.8.1.jar",
"https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar",
"https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar",
"https://repo1.maven.org/maven2/org/codehaus/jackson/jackson-core-asl/1.9.13/jackson-core-asl-1.9.13.jar",
"https://repo1.maven.org/maven2/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar",
"https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar",
"https://repo1.maven.org/maven2/org/tukaani/xz/1.5/xz-1.5.jar",
"https://repo1.maven.org/maven2/org/xerial/snappy/snappy-java/1.1.1.3/snappy-java-1.1.1.3.jar"
)
* - withArtifacts(mod, ver, Attributes("jar"), extraRepos = extraRepos, transitive = true) { artifacts =>
val urls = artifacts.map(_.url).toSet
val expectedUrls = Set(
"https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/com/cedarsoftware/json-io/4.9.9-TALEND/json-io-4.9.9-TALEND.jar",
"https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceSnapshot/org/talend/daikon/daikon/0.19.0-SNAPSHOT/daikon-0.19.0-20171201.100416-43.jar",
s"$centralBase/com/fasterxml/jackson/core/jackson-annotations/2.5.3/jackson-annotations-2.5.3.jar",
s"$centralBase/com/fasterxml/jackson/core/jackson-core/2.5.3/jackson-core-2.5.3.jar",
s"$centralBase/com/fasterxml/jackson/core/jackson-databind/2.5.3/jackson-databind-2.5.3.jar",
s"$centralBase/com/thoughtworks/paranamer/paranamer/2.7/paranamer-2.7.jar",
s"$centralBase/commons-codec/commons-codec/1.6/commons-codec-1.6.jar",
s"$centralBase/javax/inject/javax.inject/1/javax.inject-1.jar",
s"$centralBase/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar",
s"$centralBase/org/apache/avro/avro/1.8.1/avro-1.8.1.jar",
s"$centralBase/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar",
s"$centralBase/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar",
s"$centralBase/org/codehaus/jackson/jackson-core-asl/1.9.13/jackson-core-asl-1.9.13.jar",
s"$centralBase/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar",
s"$centralBase/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar",
s"$centralBase/org/tukaani/xz/1.5/xz-1.5.jar",
s"$centralBase/org/xerial/snappy/snappy-java/1.1.1.3/snappy-java-1.1.1.3.jar"
)
assert(expectedUrls.forall(urls))
}
else
Future.successful(())
assert(expectedUrls.forall(urls))
}
}
}