Merge pull request #42 from alexarchambault/develop

Switch to coursier-based sbt-launcher
This commit is contained in:
Alexandre Archambault 2019-03-06 13:37:54 +01:00 committed by GitHub
commit c24e8dd4e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 161 additions and 59 deletions

View File

@ -1,11 +1,15 @@
language: scala
scala: 2.12.7
language: java
os: linux
jdk: oraclejdk8
jdk: openjdk8
git:
depth: false # https://stackoverflow.com/a/51727114/3714539
before_install:
- git fetch --tags
script:
- scripts/travis.sh
- mkdir .bin
- curl -Lo .bin/sbt https://raw.githubusercontent.com/coursier/sbt-extras/77c93346a2b52cf35cc72382125cfdbb25a00197/sbt
- chmod +x .bin/sbt
- export PATH="$(pwd)/.bin:$PATH"
- export TRAVIS_SCALA_VERSION=2.12.8
script: scripts/travis.sh
stages:
- name: test
- name: release

View File

@ -2,18 +2,12 @@
version: '{build}'
os: Windows Server 2012
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\sbt" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://dl.bintray.com/sbt/native-packages/sbt/0.13.8/sbt-0.13.8.zip',
'C:\sbt-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sbt-bin.zip", "C:\sbt")
}
- cmd: mkdir C:\sbt
- cmd: curl -Lo C:\sbt\sbt https://github.com/coursier/sbt-launcher/releases/download/v1.2.5/csbt
- cmd: curl -Lo C:\sbt\sbt.bat https://github.com/coursier/sbt-launcher/releases/download/v1.2.5/csbt.bat
- cmd: SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0
- cmd: SET PATH=C:\sbt\sbt\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET SBT_OPTS=-Xmx4g -Xss2m
- cmd: SET PATH=C:\sbt;%JAVA_HOME%\bin;%PATH%
- cmd: SET JAVA_OPTS=-Xmx4g -Xss2m
- git submodule update --init --recursive
environment:
TEST_REPOSITORY_HOST: localhost
@ -22,6 +16,7 @@ environment:
TEST_REPOSITORY_PASSWORD: pass
TEST_REPOSITORY: http://localhost:8080
build_script:
- cmd: .\metadata\coursier fetch io.get-coursier:http-server_2.12:1.0.0
- ps: Start-Job -filepath .\metadata\scripts\start-it-auth-server.ps1 -ArgumentList $pwd\metadata, $env:TEST_REPOSITORY_HOST, $env:TEST_REPOSITORY_PORT, $env:TEST_REPOSITORY_USER, $env:TEST_REPOSITORY_PASSWORD
test_script:
- sbt ++2.12.7 "sbt-lm-coursier/scripted shared-2/simple" sbt-coursier/scripted sbt-shading/scripted

View File

@ -15,16 +15,13 @@ inThisBuild(List(
)
))
val coursierVersion = "1.1.0-M12"
lazy val `lm-coursier` = project
.in(file("modules/lm-coursier"))
.enablePlugins(ContrabandPlugin)
.settings(
shared,
libraryDependencies ++= Seq(
"io.get-coursier" %% "coursier" % coursierVersion,
"io.get-coursier" %% "coursier-extra" % coursierVersion,
"io.get-coursier" %% "coursier" % "1.1.0-M13",
// We depend on librarymanagement-ivy rather than just
// librarymanagement-core to handle the ModuleDescriptor passed
// to DependencyResolutionInterface.update, which is an

@ -1 +1 @@
Subproject commit a0752761c58fddd917f8b0c4bc8e69c8111ea606
Subproject commit eb8d9e382fe9640dd4bea86ecf5d4ba99c8995a0

View File

@ -6,7 +6,7 @@ import coursier.cache.FileCache
import coursier.Artifact
import coursier.cache.loggers.{ProgressBarRefreshDisplay, RefreshLogger}
import coursier.core.Type
import coursier.util.Schedulable
import coursier.util.Sync
import sbt.util.Logger
object ArtifactsRun {
@ -29,7 +29,7 @@ object ArtifactsRun {
else
""
Schedulable.withFixedThreadPool(params.cacheParams.parallel) { pool =>
Sync.withFixedThreadPool(params.cacheParams.parallel) { pool =>
coursier.Artifacts()
.withResolutions(params.resolutions)

View File

@ -4,9 +4,9 @@ import java.io.File
import _root_.coursier.{Artifact, Organization, Resolution, organizationString}
import _root_.coursier.core.{Classifier, Configuration, ModuleName}
import _root_.coursier.extra.Typelevel
import _root_.coursier.lmcoursier.Inputs.withAuthenticationByHost
import coursier.cache.{CacheDefaults, CachePolicy}
import coursier.internal.Typelevel
import coursier.params.CacheParams
import sbt.internal.librarymanagement.IvySbt
import sbt.librarymanagement._
@ -108,9 +108,9 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
val dependencies = module0
.dependencies
.flatMap { d =>
// crossVersion already taken into account, wiping it here
val d0 = d.withCrossVersion(CrossVersion.Disabled())
FromSbt.dependencies(d0, sv, sbv)
// crossVersion sometimes already taken into account (when called via the update task), sometimes not
// (e.g. sbt-dotty 0.13.0-RC1)
FromSbt.dependencies(d, sv, sbv, optionalCrossVer = true)
}
.map {
case (config, dep) =>

View File

@ -2,7 +2,7 @@ package coursier.lmcoursier
import coursier.ivy.IvyRepository
import coursier.ivy.IvyXml.{mappings => ivyXmlMappings}
import java.net.{MalformedURLException, URL}
import java.net.MalformedURLException
import coursier.cache.CacheUrl
import coursier.{Attributes, Dependency, Module}
@ -17,9 +17,21 @@ object FromSbt {
def sbtModuleIdName(
moduleId: ModuleID,
scalaVersion: => String,
scalaBinaryVersion: => String
): String =
sbtCrossVersionName(moduleId.name, moduleId.crossVersion, scalaVersion, scalaBinaryVersion)
scalaBinaryVersion: => String,
optionalCrossVer: Boolean = false
): String = {
val name0 = moduleId.name
val updatedName = sbtCrossVersionName(name0, moduleId.crossVersion, scalaVersion, scalaBinaryVersion)
if (!optionalCrossVer || updatedName.length <= name0.length)
updatedName
else {
val suffix = updatedName.substring(name0.length)
if (name0.endsWith(suffix))
name0
else
updatedName
}
}
def sbtCrossVersionName(
name: String,
@ -40,10 +52,11 @@ object FromSbt {
def moduleVersion(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String
scalaBinaryVersion: String,
optionalCrossVer: Boolean = false
): (Module, String) = {
val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion)
val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion, optionalCrossVer)
val module0 = Module(Organization(module.organization), ModuleName(fullName), FromSbt.attributes(module.extraDependencyAttributes))
val version = module.revision
@ -54,12 +67,13 @@ object FromSbt {
def dependencies(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String
scalaBinaryVersion: String,
optionalCrossVer: Boolean = false
): Seq[(Configuration, Dependency)] = {
// TODO Warn about unsupported properties in `module`
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion)
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer)
val dep = Dependency(
module0,

View File

@ -3,8 +3,9 @@ package coursier.lmcoursier
import java.io.File
import coursier.cache.CacheLogger
import coursier.{FallbackDependenciesRepository, ProjectCache}
import coursier.ProjectCache
import coursier.core._
import coursier.util.InMemoryRepository
import sbt.librarymanagement.{Resolver, URLRepository}
final case class ResolutionParams(
@ -33,7 +34,7 @@ final case class ResolutionParams(
}.toMap
Seq(
FallbackDependenciesRepository(map)
InMemoryRepository(map)
)
}

View File

@ -6,7 +6,7 @@ import coursier.cache.loggers.{ProgressBarRefreshDisplay, RefreshLogger}
import coursier.core._
import coursier.ivy.IvyRepository
import coursier.maven.MavenRepository
import coursier.util.Schedulable
import coursier.util.Sync
import sbt.util.Logger
object ResolutionRun {
@ -64,7 +64,7 @@ object ResolutionRun {
if (verbosityLevel >= 2)
log.info(initialMessage)
Schedulable.withFixedThreadPool(params.cacheParams.parallel) { pool =>
Sync.withFixedThreadPool(params.cacheParams.parallel) { pool =>
Resolve()
.withDependencies(

View File

@ -218,7 +218,11 @@ object ToSbt {
val configReports = configs.map {
case (config, extends0) =>
val configDeps = extends0.toSeq.sortBy(_.value).flatMap(configDependencies.getOrElse(_, Nil))
val configDeps = extends0
.toSeq
.sortBy(_.value)
.flatMap(configDependencies.getOrElse(_, Nil))
.distinct
val subRes = resolutions(config).subset(configDeps)
val reports = ToSbt.moduleReports(

View File

@ -2,7 +2,7 @@ package coursier.sbtcoursier
import coursier.ProjectCache
import coursier.core._
import coursier.extra.Typelevel
import coursier.internal.Typelevel
import coursier.lmcoursier._
import coursier.lmcoursier.Inputs.withAuthenticationByHost
import coursier.sbtcoursier.Keys._
@ -85,7 +85,7 @@ object ResolutionTasks {
val (currentProject, fallbackDependencies, configGraphs) = currentProjectTask.value
val autoScalaLib = autoScalaLibrary.value
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
val resolvers = resolversTask.value

View File

@ -1,3 +1,4 @@
> clean
> checkEmpty
> update
> checkNotEmpty

View File

@ -0,0 +1,25 @@
Copyright (c) 2015 The dotty-example-project contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1 @@
Cut-n-pasted from https://github.com/lampepfl/dotty-example-project/tree/a753b14e281bbaa6c69f26298913ad6feba969c7

View File

@ -0,0 +1 @@
scalaVersion := "0.13.0-RC1"

View File

@ -0,0 +1,3 @@
# sbt-coursier scripted tests: required, as we default to sbt 1.0.3,
# but sbt-dotty requires sbt >= 1.2.7
sbt.version=1.2.7

View File

@ -0,0 +1,2 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.0")
addSbtCoursier

View File

@ -0,0 +1,13 @@
addSbtPlugin {
val name = sys.props.getOrElse(
"plugin.name",
sys.error("plugin.name Java property not set")
)
val version = sys.props.getOrElse(
"plugin.version",
sys.error("plugin.version Java property not set")
)
"io.get-coursier" % name % version
}

View File

@ -0,0 +1,16 @@
object Main {
def main(args: Array[String]): Unit = {
runExample("Trait Params")(TraitParams.test)
}
private def runExample(name: String)(f: => Unit) = {
println(Console.MAGENTA + s"$name example:" + Console.RESET)
f
println()
}
}

View File

@ -0,0 +1,21 @@
/**
* Trait Parameters: https://dotty.epfl.ch/docs/reference/other-new-features/trait-parameters.html
*/
object TraitParams {
trait Base(val msg: String)
class A extends Base("Hello")
class B extends Base("Dotty!")
// Union types only exist in Dotty, so there's no chance that this will accidentally be compiled with Scala 2
private def printMessages(msgs: (A | B)*) = println(msgs.map(_.msg).mkString(" "))
def test: Unit = {
printMessages(new A, new B)
// Sanity check the classpath: this won't run if the dotty jar is not present.
val x: Int => Int = z => z
x(1)
}
}

View File

@ -0,0 +1 @@
> run

View File

@ -7,7 +7,7 @@ coursierCache := baseDirectory.value / "cache"
logFile := baseDirectory.value / "log"
coursierLogger := {
val logStream = new java.io.PrintStream(logFile.value)
var logStream: java.io.PrintStream = null
def log(msg: String): Unit = {
println(msg)
logStream.println(msg)
@ -16,6 +16,9 @@ coursierLogger := {
val logger = new coursier.cache.CacheLogger {
override def init(sizeHint: Option[Int]): Unit = {
logStream = new java.io.PrintStream(
new java.io.FileOutputStream(logFile.value, true)
)
log("init")
}
override def foundLocally(url: String): Unit = {
@ -29,6 +32,9 @@ coursierLogger := {
}
override def stop(): Unit = {
log("stop")
logStream.flush()
logStream.close()
logStream = null
}
}

View File

@ -2,5 +2,6 @@ $ delete cache
> update
> checkDownloaded
> reload
> clean
> update
> checkFound

View File

@ -26,7 +26,10 @@ object Main extends App {
"sbt.global.base",
sys.props("user.home") + "/.sbt"
))
val prefix = new File(sbtBase, "boot").getAbsolutePath
val prefixes = Seq(new File(sbtBase, "boot").getAbsolutePath) ++
Seq("coursier.sbt-launcher.dirs.scala-jars", "coursier.sbt-launcher.dirs.base")
.flatMap(sys.props.get(_))
.map(new File(_).getAbsolutePath)
def fromBootAndUnique(name: String): Unit = {
val jars = cp.filter(_.getName.startsWith(name)).distinct
@ -34,7 +37,7 @@ object Main extends App {
val Seq(jar) = jars
assert(jar.getAbsolutePath.startsWith(prefix), s"JAR for $name ($jar) not under $prefix")
assert(prefixes.exists(jar.getAbsolutePath.startsWith), s"JAR for $name ($jar) not under any of ${prefixes.mkString(", ")}")
}
val props = Thread.currentThread()

View File

@ -7,7 +7,7 @@ import coursier.sbtcoursiershared.SbtCoursierShared
import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey}
import sbt.Project.inTask
import sbt.KeyRanks.DTask
import sbt.Keys.{appConfiguration, autoScalaLibrary, classpathTypes, dependencyResolution, excludeDependencies, scalaBinaryVersion, scalaOrganization, scalaVersion, streams, updateClassifiers, updateSbtClassifiers}
import sbt.Keys.{appConfiguration, autoScalaLibrary, classpathTypes, dependencyResolution, excludeDependencies, scalaBinaryVersion, scalaModuleInfo, scalaOrganization, scalaVersion, streams, updateClassifiers, updateSbtClassifiers}
import sbt.librarymanagement.DependencyResolution
object LmCoursierPlugin extends AutoPlugin {
@ -84,7 +84,7 @@ object LmCoursierPlugin extends AutoPlugin {
streams.value.log
)
val fallbackDeps = coursierFallbackDependencies.value
val autoScalaLib = autoScalaLibrary.value
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
val profiles = mavenProfiles.value
val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication)

View File

@ -8,7 +8,7 @@ import com.tonicsystems.jarjar.classpath.ClassPath
import com.tonicsystems.jarjar.transform.JarTransformer
import com.tonicsystems.jarjar.transform.config.ClassRename
import com.tonicsystems.jarjar.transform.jar.DefaultJarProcessor
import coursier.core.{Configuration, Orders, Type}
import coursier.core.{Configuration, Orders}
import sbt.file
object Shading {

View File

@ -2,7 +2,7 @@ package coursier
import java.io.File
import coursier.core.{Configuration, Type}
import coursier.core.Configuration
import coursier.ivy.IvyXml.{mappings => ivyXmlMappings}
import coursier.sbtcoursier.{CoursierPlugin, InputsTasks, Keys}
import coursier.sbtcoursiershared.{IvyXml, SbtCoursierShared}

View File

@ -42,7 +42,8 @@ object Settings {
"-Xmx1024M",
"-Dplugin.name=" + name.value,
"-Dplugin.version=" + version.value,
"-Dsbttest.base=" + (sourceDirectory.value / "sbt-test").getAbsolutePath
"-Dsbttest.base=" + (sourceDirectory.value / "sbt-test").getAbsolutePath,
"-Dcoursier.sbt-launcher.add-plugin=false"
),
scriptedBufferLog := false,
sbtPlugin := true,

View File

@ -1,12 +1,6 @@
#!/usr/bin/env bash
set -euvx
downloadInstallSbtExtras() {
mkdir -p bin
curl -L -o bin/sbt https://github.com/paulp/sbt-extras/raw/9ade5fa54914ca8aded44105bf4b9a60966f3ccd/sbt
chmod +x bin/sbt
}
lmCoursier() {
[ "${LM_COURSIER:-""}" = 1 ]
}
@ -55,8 +49,6 @@ addPgpKeys() {
}
downloadInstallSbtExtras
if sbtShading; then
runSbtShadingTests
elif sbtPgpCoursier; then