Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to fetch artifact with a given url #774

Merged
merged 36 commits into from Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d562a12
changes
dotordogh Feb 5, 2018
2c6f12f
changes to Attributes
dotordogh Feb 5, 2018
362b170
make changes
dotordogh Feb 8, 2018
b590fda
fix merge conflicts
dotordogh Feb 8, 2018
fd2b355
add test and fix bug
dotordogh Feb 9, 2018
6a91c1f
add more tests
dotordogh Feb 10, 2018
e70a73f
Merge branch 'master' into dotordogh/exp-w-cli-I
dotordogh Feb 10, 2018
d3a1337
fix failing tests
dotordogh Feb 10, 2018
7e9775a
fix parentheses
dotordogh Feb 10, 2018
b46b1be
remove comments I added and add test that's guarenteed not to exist i…
dotordogh Feb 12, 2018
60cebe8
remove Attributes third parameter and refactor Parse's moduleVersionC…
dotordogh Feb 13, 2018
d04f46d
update some return types and methods in the Helper class
dotordogh Feb 14, 2018
aa583b8
Merge branch 'master' into dotordogh/issue-710-refactor
dotordogh Feb 14, 2018
d5b189b
return FallbackDependenciesRepository back to original state
dotordogh Feb 14, 2018
92b185d
refactor helper
dotordogh Feb 15, 2018
4912757
remove url from attributes
dotordogh Feb 15, 2018
3fe0507
fix tests and add cache to extra in build.sbt
dotordogh Feb 15, 2018
684f055
remove FallbackDepsRepo from sbt-coursier
dotordogh Feb 15, 2018
4245f11
add variable for url and call encode in tests
dotordogh Feb 15, 2018
b8bddb3
update tests and helper to have proper behavior
dotordogh Feb 15, 2018
0a0c930
remove setting deps to intransitive when url is present and add two t…
dotordogh Feb 16, 2018
53d9851
add more tests, implement @wisechengyi's comments
dotordogh Feb 16, 2018
56cbf2e
fix nits
dotordogh Feb 16, 2018
935bacc
update ParseTests because some failed
dotordogh Feb 16, 2018
3b33d07
fix tests
dotordogh Feb 16, 2018
7333f0f
incorporate feedback from @alexarchambault and @wisechengyi
dotordogh Feb 21, 2018
fb6ba3f
update ParseTests to check for returned error vs thrown error
dotordogh Feb 21, 2018
dcaa484
remove one test that is covered in ParseTests
dotordogh Feb 21, 2018
3d8d3b5
fix nits
dotordogh Feb 21, 2018
d5c5e6a
add back deleted brackets
dotordogh Feb 21, 2018
f72ba7c
return errors in Left without using return statement
dotordogh Feb 21, 2018
e27a6de
revert change because it's broken
dotordogh Feb 21, 2018
080fcbf
fix some positional things
dotordogh Feb 21, 2018
b19a407
add return statement or else error won't be processed
dotordogh Feb 21, 2018
f647943
fix nits. thanks @wisechengyi
dotordogh Feb 22, 2018
e0bd15b
Remove return statements
alexarchambault Feb 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Expand Up @@ -118,7 +118,7 @@ lazy val bootstrap = project
lazy val extra = project
.disablePlugins(ScriptedPlugin)
.enablePlugins(ShadingPlugin)
.dependsOn(coreJvm)
.dependsOn(coreJvm, cache)
.settings(
shared,
coursierPrefix,
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/scala-2.12/BUILD
Expand Up @@ -5,6 +5,7 @@ scala_library(
"3rdparty/jvm:caseapp",
"cache/src/main/scala:cache",
"core:core",
"extra/src/main/scala/coursier:fallback-deps-repo",
"extra/src/main/scala/coursier/extra:extra",
"extra/src/main/scala-2.12/coursier/extra:native",
":util",
Expand Down
45 changes: 35 additions & 10 deletions cli/src/main/scala-2.12/coursier/cli/Helper.scala
Expand Up @@ -2,7 +2,7 @@ package coursier
package cli

import java.io.{File, OutputStreamWriter, PrintWriter}
import java.net.{URL, URLClassLoader}
import java.net.{URL, URLClassLoader, URLDecoder}
import java.util.concurrent.Executors
import java.util.jar.{Manifest => JManifest}

Expand Down Expand Up @@ -116,7 +116,7 @@ class Helper(
repos
}

val repositories = repositoriesValidation match {
val standardRepositories = repositoriesValidation match {
case Success(repos) =>
repos
case Failure(errors) =>
Expand All @@ -125,14 +125,13 @@ class Helper(
)
}


val loggerFallbackMode =
!progress && TermDisplay.defaultFallbackMode

val (scaladexRawDependencies, otherRawDependencies) =
rawDependencies.partition(s => s.contains("/") || !s.contains(":"))

val scaladexDeps: List[Dependency] =
val scaladexDepsWithExtraParams: List[(Dependency, Map[String, String])] =
if (scaladexRawDependencies.isEmpty)
Nil
else {
Expand Down Expand Up @@ -192,7 +191,7 @@ class Helper(
res
.collect { case \/-(l) => l }
.flatten
.map { case (mod, ver) => Dependency(mod, ver) }
.map { case (mod, ver) => (Dependency(mod, ver), Map[String, String]()) }
}

val (forceVersionErrors, forceVersions0) = Parse.moduleVersions(forceVersion, scalaVersion)
Expand Down Expand Up @@ -258,10 +257,10 @@ class Helper(

val moduleReq = ModuleRequirements(globalExcludes, localExcludeMap, defaultConfiguration)

val (modVerCfgErrors: Seq[String], normalDeps: Seq[Dependency]) =
val (modVerCfgErrors: Seq[String], normalDepsWithExtraParams: Seq[(Dependency, Map[String, String])]) =
Parse.moduleVersionConfigs(otherRawDependencies, moduleReq, transitive=true, scalaVersion)

val (intransitiveModVerCfgErrors: Seq[String], intransitiveDeps: Seq[Dependency]) =
val (intransitiveModVerCfgErrors: Seq[String], intransitiveDepsWithExtraParams: Seq[(Dependency, Map[String, String])]) =
Parse.moduleVersionConfigs(intransitive, moduleReq, transitive=false, scalaVersion)

prematureExitIf(modVerCfgErrors.nonEmpty) {
Expand All @@ -273,11 +272,37 @@ class Helper(
intransitiveModVerCfgErrors.map(" "+_).mkString("\n")
}

val transitiveDeps: Seq[Dependency] =
val transitiveDepsWithExtraParams: Seq[(Dependency, Map[String, String])] =
// FIXME Order of the dependencies is not respected here (scaladex ones go first)
scaladexDeps ++ normalDeps
scaladexDepsWithExtraParams ++ normalDepsWithExtraParams

val transitiveDeps: Seq[Dependency] = transitiveDepsWithExtraParams.map(dep => dep._1)

val allDependenciesWithExtraParams: Seq[(Dependency, Map[String, String])] =
transitiveDepsWithExtraParams ++ intransitiveDepsWithExtraParams

val allDependencies: Seq[Dependency] = allDependenciesWithExtraParams.map(dep => dep._1)

// Any dependencies with URIs should not be resolved with a pom so this is a
// hack to add all the deps with URIs to the FallbackDependenciesRepository
// which will be used during the resolve
val depsWithUrls: Map[(Module, String), (URL, Boolean)] = allDependenciesWithExtraParams
.flatMap {
case (dep, extraParams) =>
extraParams.get("url").map { url =>
dep.moduleVersion -> (new URL(URLDecoder.decode(url, "UTF-8")), true)
}
}.toMap

val depsWithUrlRepo: Seq[FallbackDependenciesRepository] = Seq(FallbackDependenciesRepository(depsWithUrls))

// Prepend FallbackDependenciesRepository to the repository list
// so that dependencies with URIs are resolved against this repo
val repositories: Seq[Repository] = depsWithUrlRepo ++ standardRepositories
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe more clear with the following

val depsWithUrlRepo = FallbackDependenciesRepository(depsWithUrls)

val repositories: Seq[Repository] = Seq(depsWithUrlRepo) ++ standardRepositories


val allDependencies: Seq[Dependency] = transitiveDeps ++ intransitiveDeps
for (((mod, version), _) <- depsWithUrls if forceVersions.get(mod).exists(_ != version))
throw new Exception(s"Cannot force a version that is different from the one specified " +
s"for the module ${mod}:${version} with url")

val checksums = {
val splitChecksumArgs = checksum.flatMap(_.split(',')).filter(_.nonEmpty)
Expand Down