Set default extension and classifier of artifact type test-jar

Fixes https://github.com/alexarchambault/coursier/issues/298
This commit is contained in:
Alexandre Archambault 2016-07-23 18:28:32 +02:00
parent 658d451561
commit 5ac4efc661
No known key found for this signature in database
GPG Key ID: 14640A6839C263A9
8 changed files with 105 additions and 5 deletions

View File

@ -48,7 +48,12 @@ object MavenRepository {
val defaultPackaging = "jar"
def defaultPublications(moduleName: String, packaging: String) = Seq(
"compile" -> Publication(moduleName, packaging, MavenSource.typeExtension(packaging), ""),
"compile" -> Publication(
moduleName,
packaging,
MavenSource.typeExtension(packaging),
MavenSource.typeDefaultClassifier(packaging)
),
"docs" -> Publication(moduleName, "doc", "jar", "javadoc"),
"sources" -> Publication(moduleName, "src", "jar", "sources")
)

View File

@ -136,12 +136,20 @@ case class MavenSource(
if (publications.isEmpty) {
val type0 = if (dependency.attributes.`type`.isEmpty) "jar" else dependency.attributes.`type`
val extension = MavenSource.typeExtension(type0)
val classifier =
if (dependency.attributes.classifier.isEmpty)
MavenSource.typeDefaultClassifier(type0)
else
dependency.attributes.classifier
Seq(
Publication(
dependency.module.name,
type0,
MavenSource.typeExtension(type0),
dependency.attributes.classifier
extension,
classifier
)
)
} else
@ -163,10 +171,27 @@ object MavenSource {
"jar" -> "jar",
"bundle" -> "jar",
"doc" -> "jar",
"src" -> "jar"
"src" -> "jar",
"test-jar" -> "jar",
"ejb-client" -> "jar"
)
def typeExtension(`type`: String): String =
typeExtensions.getOrElse(`type`, `type`)
// see https://github.com/apache/maven/blob/c023e58104b71e27def0caa034d39ab0fa0373b6/maven-core/src/main/resources/META-INF/plexus/artifact-handlers.xml
// discussed in https://github.com/alexarchambault/coursier/issues/298
val typeDefaultClassifiers: Map[String, String] = Map(
"test-jar" -> "tests",
"javadoc" -> "javadoc",
"java-source" -> "sources",
"ejb-client" -> "client"
)
def typeDefaultClassifierOpt(`type`: String): Option[String] =
typeDefaultClassifiers.get(`type`)
def typeDefaultClassifier(`type`: String): String =
typeDefaultClassifierOpt(`type`).getOrElse("")
}

View File

@ -23,7 +23,9 @@ object ToSbt {
// FIXME Get these two from publications
artifact.attributes.`type`,
MavenSource.typeExtension(artifact.attributes.`type`),
Some(artifact.attributes.classifier).filter(_.nonEmpty),
Some(artifact.attributes.classifier)
.filter(_.nonEmpty)
.orElse(MavenSource.typeDefaultClassifierOpt(artifact.attributes.`type`)),
Nil,
Some(url(artifact.url)),
Map.empty

View File

@ -0,0 +1,10 @@
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.hadoop" % "hadoop-yarn-server-resourcemanager" % "2.7.1"
coursierCachePolicies := {
if (sys.props("os.name").startsWith("Windows"))
coursierCachePolicies.value
else
Seq(coursier.CachePolicy.ForceDownload)
}

View File

@ -0,0 +1,11 @@
{
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
)
addSbtPlugin("io.get-coursier" % "sbt-coursier" % pluginVersion)
}

View File

@ -0,0 +1,8 @@
import java.io.File
import java.nio.file.Files
import org.apache.zookeeper.ZooKeeper
object Main extends App {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
}

View File

@ -0,0 +1,3 @@
$ delete output
> run
$ exists output

View File

@ -355,6 +355,42 @@ object CentralTests extends TestSuite {
assert(nonUnique.isEmpty)
}
}
'testJarType - {
// dependencies with type "test-jar" should be given the classifier "tests" by default
async {
val deps = Set(
Dependency(
Module("org.apache.hadoop", "hadoop-yarn-server-resourcemanager"),
"2.7.1"
)
)
val res = await(resolve(deps))
assert(res.errors.isEmpty)
assert(res.conflicts.isEmpty)
assert(res.isDone)
val dependencyArtifacts = res.dependencyArtifacts
val zookeeperTestArtifacts = dependencyArtifacts.collect {
case (dep, artifact)
if dep.module == Module("org.apache.zookeeper", "zookeeper") &&
dep.attributes.`type` == "test-jar" =>
artifact
}
assert(zookeeperTestArtifacts.length == 1)
val zookeeperTestArtifact = zookeeperTestArtifacts.head
assert(zookeeperTestArtifact.attributes.`type` == "test-jar")
assert(zookeeperTestArtifact.attributes.classifier == "tests")
zookeeperTestArtifact.url.endsWith("-tests.jar")
}
}
}
}