Merge pull request #135 from alexarchambault/topic/foo

Fix minor glitches
This commit is contained in:
Alexandre Archambault 2016-02-12 00:43:50 +01:00
commit 76b0fc4945
3 changed files with 40 additions and 53 deletions

View File

@ -13,6 +13,7 @@ import coursier.util.Parse
import scala.annotation.tailrec
import scala.language.reflectiveCalls
import scala.util.Try
case class CommonOptions(
@Help("Keep optional dependencies (Maven)")
@ -50,6 +51,9 @@ case class CommonOptions(
@Help("Maximum number of parallel downloads (default: 6)")
@Short("n")
parallel: Int = 6,
@Help("Checksums")
@Value("checksum1,checksum2,... - end with none to allow for no checksum validation if none are available")
checksum: List[String],
@Recurse
cacheOptions: CacheOptions
) {
@ -225,18 +229,23 @@ case class Launch(
val contextLoader = Thread.currentThread().getContextClassLoader
val parentLoader0: ClassLoader = Launch.mainClassLoader(contextLoader)
.flatMap(cl => Option(cl.getParent))
.getOrElse {
if (common.verbose0 >= 0)
Console.err.println(
"Warning: cannot find the main ClassLoader that launched coursier. " +
"Was coursier launched by its main launcher? " +
"The ClassLoader of the application that is about to be launched will be intertwined " +
"with the one of coursier, which may be a problem if their dependencies conflict."
)
val parentLoader0: ClassLoader =
if (Try(contextLoader.loadClass("coursier.Launch")).isSuccess)
Launch.mainClassLoader(contextLoader)
.flatMap(cl => Option(cl.getParent))
.getOrElse {
if (common.verbose0 >= 0)
Console.err.println(
"Warning: cannot find the main ClassLoader that launched coursier. " +
"Was coursier launched by its main launcher? " +
"The ClassLoader of the application that is about to be launched will be intertwined " +
"with the one of coursier, which may be a problem if their dependencies conflict."
)
contextLoader
}
else
// proguarded -> no risk of conflicts, no need to find a specific ClassLoader
contextLoader
}
val (parentLoader, filteredFiles) =
if (isolated.isolated.isEmpty)

View File

@ -173,6 +173,18 @@ class Helper(
)
}
val checksums = {
val splitChecksumArgs = checksum.flatMap(_.split(',')).filter(_.nonEmpty)
if (splitChecksumArgs.isEmpty)
Cache.defaultChecksums
else
splitChecksumArgs.map {
case none if none.toLowerCase == "none" => None
case sumType => Some(sumType)
}
}
val startRes = Resolution(
dependencies.toSet,
forceVersions = forceVersions,
@ -186,7 +198,7 @@ class Helper(
None
val fetchs = cachePolicies.map(p =>
Cache.fetch(caches, p, logger = logger, pool = pool)
Cache.fetch(caches, p, checksums = checksums, logger = logger, pool = pool)
)
val fetchQuiet = coursier.Fetch.from(
repositories,
@ -261,7 +273,7 @@ class Helper(
subset: Set[Dependency] = null
): Seq[File] = {
if (verbose0 >= 0) {
if (subset == null && verbose0 >= 0) {
val msg = cachePolicies match {
case Seq(CachePolicy.LocalOnly) =>
" Checking artifacts"
@ -296,8 +308,8 @@ class Helper(
println(s" Found ${artifacts.length} artifacts")
val tasks = artifacts.map(artifact =>
(Cache.file(artifact, caches, cachePolicies.head, logger = logger, pool = pool) /: cachePolicies.tail)(
_ orElse Cache.file(artifact, caches, _, logger = logger, pool = pool)
(Cache.file(artifact, caches, cachePolicies.head, checksums = checksums, logger = logger, pool = pool) /: cachePolicies.tail)(
_ orElse Cache.file(artifact, caches, _, checksums = checksums, logger = logger, pool = pool)
).run.map(artifact.->)
)

View File

@ -3,48 +3,14 @@ set -e
cd "$(dirname "$0")/.."
if [ ! -d cli/target/pack/lib ]; then
echo "Compiling coursier-cli..." 1>&2
sbt cli/pack
if [ ! -e cli/target/scala-2.11/proguard/coursier-standalone.jar ]; then
echo "Generating proguarded JAR..." 1>&2
sbt cli/proguard:proguard
fi
echo -n > coursier.pro
for i in cli/target/pack/lib/*.jar; do
echo "-injars $i" >> coursier.pro
done
cat >> coursier.pro << EOF
-outjars coursier-standalone.jar
-libraryjars <java.home>/lib/rt.jar
-dontwarn
-keep class coursier.cli.Coursier {
public static void main(java.lang.String[]);
}
-keep class coursier.cli.IsolatedClassLoader {
public java.lang.String[] getIsolationTargets();
}
EOF
# -noverify added in launcher below because of errors like
# http://sourceforge.net/p/proguard/bugs/567/
# These options don't fix it:
# -dontshrink
# -dontoptimize
# -dontobfuscate
./coursier launch \
net.sf.proguard:proguard-base:5.2.1 -M proguard.ProGuard -- -- \
@coursier.pro
cat > coursier-standalone << EOF
#!/bin/sh
exec java -noverify -cp "\$0" coursier.cli.Coursier "\$@"
EOF
cat coursier-standalone.jar >> coursier-standalone
cat cli/target/scala-2.11/proguard/coursier-standalone.jar >> coursier-standalone
chmod +x coursier-standalone
rm -f coursier-standalone.jar
rm -f coursier.pro