diff options
48 files changed, 1193 insertions, 530 deletions
@@ -1,7 +1,7 @@ import $file.ci.shared import $file.ci.upload import java.nio.file.attribute.PosixFilePermission - +import $ivy.`org.scalaj::scalaj-http:2.4.1` import ammonite.ops._ import coursier.maven.MavenRepository import mill._ @@ -93,7 +93,7 @@ object main extends MillModule { def ivyDeps = Agg( // Keep synchronized with ammonite in Versions.scala - ivy"com.lihaoyi:::ammonite:1.6.0", + ivy"com.lihaoyi:::ammonite:1.6.7", // Necessary so we can share the JNA classes throughout the build process ivy"net.java.dev.jna:jna:4.5.0", ivy"net.java.dev.jna:jna-platform:4.5.0" @@ -214,6 +214,7 @@ object scalajslib extends MillModule { object api extends MillApiModule{ def moduleDeps = Seq(main.core) + def ivyDeps = Agg(ivy"org.scala-sbt:test-interface:1.0") } object worker extends Cross[WorkerModule]("0.6", "1.0") class WorkerModule(scalajsBinary: String) extends MillApiModule{ @@ -307,6 +308,15 @@ object contrib extends MillModule { def moduleDeps = Seq(scalalib) def ivyDeps = Agg(ivy"org.flywaydb:flyway-core:5.2.4") } + + object bloop extends MillModule { + def moduleDeps = Seq(scalalib) + def ivyDeps = Agg( + ivy"ch.epfl.scala::bloop-config:1.2.5", + ivy"com.lihaoyi::ujson-circe:0.7.4" + ) + } + } @@ -329,6 +339,7 @@ object scalanativelib extends MillModule { } object api extends MillApiModule{ def moduleDeps = Seq(main.core) + def ivyDeps = Agg(ivy"org.scala-sbt:test-interface:1.0") } object worker extends Cross[WorkerModule]("0.3") class WorkerModule(scalaNativeBinary: String) extends MillApiModule { diff --git a/ci/shared.sc b/ci/shared.sc index a496fd1f..89e504fe 100644 --- a/ci/shared.sc +++ b/ci/shared.sc @@ -4,6 +4,7 @@ * via import $file */ +import $ivy.`org.scalaj::scalaj-http:2.4.1` import ammonite.ops.{write, Path, mkdir, RelPath, up} def argNames(n: Int) = { diff --git a/contrib/bloop/src/mill.contrib.bloop/BloopImpl.scala b/contrib/bloop/src/mill.contrib.bloop/BloopImpl.scala new file mode 100644 index 00000000..03af2465 --- /dev/null +++ b/contrib/bloop/src/mill.contrib.bloop/BloopImpl.scala @@ -0,0 +1,359 @@ +package mill.contrib.bloop + +import ammonite.ops._ +import bloop.config.ConfigEncoderDecoders._ +import bloop.config.{Config => BloopConfig} +import mill._ +import mill.api.Loose +import mill.define.{Module => MillModule, _} +import mill.eval.Evaluator +import mill.scalalib._ +import os.pwd + +/** + * Implementation of the Bloop related tasks. Inherited by the + * `mill.contrib.Bloop` object, and usable in tests by passing + * a custom evaluator. + */ +class BloopImpl(ev: () => Evaluator, wd: Path) extends ExternalModule { outer => + + /** + * Generates bloop configuration files reflecting the build, + * under pwd/.bloop. + */ + def install = T { + Task.traverse(computeModules)(_.bloop.writeConfig) + } + + /** + * Trait that can be mixed-in to quickly access the bloop config + * of the module. + * + * {{{ + * object myModule extends ScalaModule with Bloop.Module { + * ... + * } + * }}} + */ + trait Module extends MillModule with CirceCompat { self: JavaModule => + + object bloop extends MillModule { + def config = T { + new BloopOps(self).bloop.config() + } + } + } + + /** + * Extension class used to ensure that the config related tasks are + * cached alongside their respective modules, without requesting the user + * to extend a specific trait. + * + * This also ensures that we're not duplicating work between the global + * "install" task that traverse all modules in the build, and "local" tasks + * that traverse only their transitive dependencies. + */ + private implicit class BloopOps(jm: JavaModule) + extends MillModule + with CirceCompat { + override def millOuterCtx = jm.millOuterCtx + + object bloop extends MillModule { + def config = T { outer.bloopConfig(jm) } + + def writeConfig: Target[(String, PathRef)] = T { + mkdir(bloopDir) + val path = bloopConfigPath(jm) + _root_.bloop.config.write(config(), path.toNIO) + T.ctx().log.info(s"Wrote $path") + name(jm) -> PathRef(path) + } + + def writeTransitiveConfig = T { + Task.traverse(jm.transitiveModuleDeps)(_.bloop.writeConfig) + } + } + } + + private val bloopDir = wd / ".bloop" + + private def computeModules: Seq[JavaModule] = { + val eval = ev() + if (eval != null) { + val rootModule = eval.rootModule + rootModule.millInternal.segmentsToModules.values.collect { + case m: scalalib.JavaModule => m + }.toSeq + } else Seq() + } + + /** + * Computes sources files paths for the whole project. Cached in a way + * that does not get invalidated upon sourcefile change. Mainly called + * from module#sources in bloopInstall + */ + def moduleSourceMap: Target[Map[String, Seq[Path]]] = T { + val sources = Task.traverse(computeModules) { m => + m.allSources.map { paths => + m.millModuleSegments.render -> paths.map(_.path) + } + }() + sources.toMap + } + + protected def name(m: JavaModule) = m.millModuleSegments.render + + protected def bloopConfigPath(module: JavaModule): Path = + bloopDir / s"${name(module)}.json" + + ////////////////////////////////////////////////////////////////////////////// + // SemanticDB related configuration + ////////////////////////////////////////////////////////////////////////////// + + // Version of the semanticDB plugin. + def semanticDBVersion: String = "4.1.4" + + // Scala versions supported by semantic db. Needs to be updated when + // bumping semanticDBVersion. + // See [https://github.com/scalameta/metals/blob/333ab6fc00fb3542bcabd0dac51b91b72798768a/build.sbt#L121] + def semanticDBSupported = Set( + "2.12.8", + "2.12.7", + "2.12.6", + "2.12.5", + "2.12.4", + "2.11.12", + "2.11.11", + "2.11.10", + "2.11.9" + ) + + // Recommended for metals usage. + def semanticDBOptions = List( + s"-P:semanticdb:sourceroot:$pwd", + "-P:semanticdb:synthetics:on", + "-P:semanticdb:failures:warning" + ) + + ////////////////////////////////////////////////////////////////////////////// + // Computation of the bloop configuration for a specific module + ////////////////////////////////////////////////////////////////////////////// + + def bloopConfig(module: JavaModule): Task[BloopConfig.File] = { + import _root_.bloop.config.Config + def out(m: JavaModule) = bloopDir / "out" / m.millModuleSegments.render + def classes(m: JavaModule) = out(m) / "classes" + + val javaConfig = + module.javacOptions.map(opts => Some(Config.Java(options = opts.toList))) + + //////////////////////////////////////////////////////////////////////////// + // Scalac + //////////////////////////////////////////////////////////////////////////// + + val scalaConfig = module match { + case s: ScalaModule => + val semanticDb = s.resolveDeps(s.scalaVersion.map { + case scalaV if semanticDBSupported(scalaV) => + Agg(ivy"org.scalameta:semanticdb-scalac_$scalaV:$semanticDBVersion") + case _ => Agg() + }) + + T.task { + val pluginCp = semanticDb() ++ s.scalacPluginClasspath() + val pluginOptions = pluginCp.map { pathRef => + s"-Xplugin:${pathRef.path}" + } + + val allScalacOptions = + (s.scalacOptions() ++ pluginOptions ++ semanticDBOptions).toList + Some( + BloopConfig.Scala( + organization = "org.scala-lang", + name = "scala-compiler", + version = s.scalaVersion(), + options = allScalacOptions, + jars = s.scalaCompilerClasspath().map(_.path.toNIO).toList, + analysis = None, + setup = None + ) + ) + } + case _ => T.task(None) + } + + //////////////////////////////////////////////////////////////////////////// + // Platform (Jvm/Js/Native) + //////////////////////////////////////////////////////////////////////////// + + val platform = T.task { + BloopConfig.Platform.Jvm( + BloopConfig.JvmConfig( + home = T.ctx().env.get("JAVA_HOME").map(s => Path(s).toNIO), + options = module.forkArgs().toList + ), + mainClass = module.mainClass() + ) + } + + //////////////////////////////////////////////////////////////////////////// + // Tests + //////////////////////////////////////////////////////////////////////////// + + val testConfig = module match { + case m: TestModule => + T.task { + Some( + BloopConfig.Test( + frameworks = m + .testFrameworks() + .map(f => Config.TestFramework(List(f))) + .toList, + options = Config.TestOptions( + excludes = List(), + arguments = List() + ) + ) + ) + } + case _ => T.task(None) + } + + //////////////////////////////////////////////////////////////////////////// + // Ivy dependencies + sources + //////////////////////////////////////////////////////////////////////////// + + val scalaLibraryIvyDeps = module match { + case x: ScalaModule => x.scalaLibraryIvyDeps + case _ => T.task { Loose.Agg.empty[Dep] } + } + + /** + * Resolves artifacts using coursier and creates the corresponding + * bloop config. + */ + def artifacts(repos: Seq[coursier.Repository], + deps: Seq[coursier.Dependency]): List[BloopConfig.Module] = { + import coursier._ + import coursier.util._ + + def source(r: Resolution) = Resolution( + r.dependencies + .map(d => + d.copy(attributes = d.attributes.copy(classifier = coursier.Classifier("sources"))) + ) + .toSeq + ) + + import scala.concurrent.ExecutionContext.Implicits.global + val unresolved = Resolution(deps) + val fetch = ResolutionProcess.fetch(repos, coursier.cache.Cache.default.fetch) + val gatherTask = for { + resolved <- unresolved.process.run(fetch) + resolvedSources <- source(resolved).process.run(fetch) + all = resolved.dependencyArtifacts ++ resolvedSources.dependencyArtifacts + gathered <- Gather[Task].gather(all.distinct.map { + case (dep, art) => coursier.cache.Cache.default.file(art).run.map(dep -> _) + }) + } yield + gathered + .collect { + case (dep, Right(file)) if Path(file).ext == "jar" => + (dep.module.organization, + dep.module.name, + dep.version, + Option(dep.attributes.classifier).filter(_.nonEmpty), + file) + } + .groupBy { + case (org, mod, version, _, _) => (org, mod, version) + } + .mapValues { + _.map { + case (_, mod, _, classifier, file) => + BloopConfig.Artifact(mod.value, classifier.map(_.value), None, file.toPath) + }.toList + } + .map { + case ((org, mod, version), artifacts) => + BloopConfig.Module( + organization = org.value, + name = mod.value, + version = version, + configurations = None, + artifacts = artifacts + ) + } + + gatherTask.unsafeRun().toList + } + + val bloopResolution: Task[BloopConfig.Resolution] = T.task { + val repos = module.repositories + val allIvyDeps = module + .transitiveIvyDeps() ++ scalaLibraryIvyDeps() ++ module.compileIvyDeps() + val coursierDeps = + allIvyDeps.map(module.resolveCoursierDependency()).toList + BloopConfig.Resolution(artifacts(repos, coursierDeps)) + } + + //////////////////////////////////////////////////////////////////////////// + // Classpath + //////////////////////////////////////////////////////////////////////////// + + val ivyDepsClasspath = + module + .resolveDeps(T.task { + module.compileIvyDeps() ++ module.transitiveIvyDeps() + }) + .map(_.map(_.path).toSeq) + + def transitiveClasspath(m: JavaModule): Task[Seq[Path]] = T.task { + m.moduleDeps.map(classes) ++ + m.unmanagedClasspath().map(_.path) ++ + Task.traverse(m.moduleDeps)(transitiveClasspath)().flatten + } + + val classpath = T.task(transitiveClasspath(module)() ++ ivyDepsClasspath()) + val resources = T.task(module.resources().map(_.path.toNIO).toList) + + //////////////////////////////////////////////////////////////////////////// + // Tying up + //////////////////////////////////////////////////////////////////////////// + + val project = T.task { + val mSources = moduleSourceMap() + .get(name(module)) + .toSeq + .flatten + .map(_.toNIO) + .toList + + BloopConfig.Project( + name = name(module), + directory = module.millSourcePath.toNIO, + sources = mSources, + dependencies = module.moduleDeps.map(name).toList, + classpath = classpath().map(_.toNIO).toList, + out = out(module).toNIO, + classesDir = classes(module).toNIO, + resources = Some(resources()), + `scala` = scalaConfig(), + java = javaConfig(), + sbt = None, + test = testConfig(), + platform = Some(platform()), + resolution = Some(bloopResolution()) + ) + } + + T.task { + BloopConfig.File( + version = BloopConfig.File.LatestVersion, + project = project() + ) + } + } + + lazy val millDiscover = Discover[this.type] +} diff --git a/contrib/bloop/src/mill.contrib.bloop/CirceCompat.scala b/contrib/bloop/src/mill.contrib.bloop/CirceCompat.scala new file mode 100644 index 00000000..bfd88e07 --- /dev/null +++ b/contrib/bloop/src/mill.contrib.bloop/CirceCompat.scala @@ -0,0 +1,23 @@ +package mill.contrib.bloop + +import io.circe.{Decoder, Encoder, Json} +import upickle.core.Visitor +import upickle.default + +trait CirceCompat { + + // Converts from a Circe encoder to a uPickle one + implicit def circeWriter[T: Encoder]: default.Writer[T] = + new default.Writer[T] { + override def write0[V](out: Visitor[_, V], v: T) = + ujson.circe.CirceJson.transform(Encoder[T].apply(v), out) + } + + // Converts from a Circe decoder to a uPickle one + implicit def circeReader[T: Decoder]: default.Reader[T] = + new default.Reader.Delegate[Json, T]( + ujson.circe.CirceJson.map(Decoder[T].decodeJson).map(_.right.get)) + +} + +object CirceCompat extends CirceCompat diff --git a/contrib/bloop/src/mill/contrib/Bloop.scala b/contrib/bloop/src/mill/contrib/Bloop.scala new file mode 100644 index 00000000..9c85a308 --- /dev/null +++ b/contrib/bloop/src/mill/contrib/Bloop.scala @@ -0,0 +1,10 @@ +package mill.contrib + +import mill.eval.Evaluator +import os.pwd +import mill.contrib.bloop.BloopImpl + +/** + * Usage : `mill mill.contrib.Bloop/install` + */ +object Bloop extends BloopImpl(Evaluator.currentEvaluator.get, pwd) diff --git a/contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala b/contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala new file mode 100644 index 00000000..dfbb346d --- /dev/null +++ b/contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala @@ -0,0 +1,103 @@ +package mill.contrib.bloop + +import bloop.config.Config.{File => BloopFile} +import bloop.config.ConfigEncoderDecoders._ +import mill._ +import mill.contrib.bloop.CirceCompat._ +import mill.scalalib._ +import mill.util.{TestEvaluator, TestUtil} +import os.Path +import upickle.default._ +import utest._ + +object BloopTests extends TestSuite { + + val workdir = os.pwd / 'target / 'workspace / "bloop" + val testEvaluator = TestEvaluator.static(build) + val testBloop = new BloopImpl(() => testEvaluator.evaluator, workdir) + + object build extends TestUtil.BaseModule { + + override def millSourcePath = BloopTests.workdir + + object scalaModule extends scalalib.ScalaModule with testBloop.Module { + def scalaVersion = "2.12.8" + val bloopVersion = "1.2.5" + override def mainClass = Some("foo.bar.Main") + + override def ivyDeps = Agg( + ivy"ch.epfl.scala::bloop-config:$bloopVersion" + ) + override def scalacOptions = Seq( + "-language:higherKinds" + ) + + object test extends super.Tests { + def testFrameworks = Seq("utest.runner.Framework") + } + } + + } + + def readBloopConf(jsonFile: String) = + read[BloopFile](os.read(workdir / ".bloop" / jsonFile)) + + def tests: Tests = Tests { + 'genBloopTests - { + + testEvaluator(testBloop.install) + val scalaModuleConfig = readBloopConf("scalaModule.json") + val testModuleConfig = readBloopConf("scalaModule.test.json") + + 'scalaModule - { + val p = scalaModuleConfig.project + val name = p.name + val sources = p.sources.map(Path(_)) + val options = p.scala.get.options + val version = p.scala.get.version + val classpath = p.classpath.map(_.toString) + val platform = p.platform.get.name + val mainCLass = p.platform.get.mainClass.get + val resolution = p.resolution.get.modules + val sdb = testBloop.semanticDBVersion + val sdbOpts = testBloop.semanticDBOptions + + assert(name == "scalaModule") + assert(sources == List(workdir / "scalaModule" / "src")) + assert(options.contains("-language:higherKinds")) + assert(options.exists(_.contains(s"semanticdb-scalac_2.12.8-$sdb.jar"))) + assert(sdbOpts.forall(options.contains)) + assert(version == "2.12.8") + assert(classpath.exists(_.contains("bloop-config_2.12-1.2.5.jar"))) + assert(platform == "jvm") + assert(mainCLass == "foo.bar.Main") + + val bloopConfigDep = resolution.find(_.name == "bloop-config_2.12").get + val artifacts = bloopConfigDep.artifacts + assert(bloopConfigDep.version == build.scalaModule.bloopVersion) + assert(bloopConfigDep.organization == "ch.epfl.scala") + assert(artifacts.map(_.name).distinct == List("bloop-config_2.12")) + assert(artifacts.flatMap(_.classifier).contains("sources")) + } + 'scalaModuleTest - { + val p = testModuleConfig.project + val name = p.name + val sources = p.sources.map(Path(_)) + val framework = p.test.get.frameworks.head.names.head + val dep = p.dependencies.head + val mainModuleClasspath = scalaModuleConfig.project.classpath + assert(name == "scalaModule.test") + assert(sources == List(workdir / "scalaModule" / "test" / "src")) + assert(framework == "utest.runner.Framework") + assert(dep == "scalaModule") + assert(mainModuleClasspath.forall(p.classpath.contains)) + } + 'configAccessTest - { + val (accessedConfig, _) = + testEvaluator(build.scalaModule.bloop.config).asSuccess.get.value.right.get + assert(accessedConfig == scalaModuleConfig) + } + } + } + +} diff --git a/contrib/playlib/src/mill/playlib/RouterModule.scala b/contrib/playlib/src/mill/playlib/RouterModule.scala index abf3082b..5af87839 100644 --- a/contrib/playlib/src/mill/playlib/RouterModule.scala +++ b/contrib/playlib/src/mill/playlib/RouterModule.scala @@ -1,7 +1,7 @@ package mill package playlib -import coursier.{Cache, MavenRepository} +import coursier.MavenRepository import mill.eval.PathRef import mill.playlib.api.RouteCompilerType import mill.scalalib.Lib.resolveDependencies @@ -49,7 +49,7 @@ trait RouterModule extends ScalaModule with Version { def routerClasspath: T[Agg[PathRef]] = T { resolveDependencies( Seq( - Cache.ivy2Local, + coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2") ), Lib.depToDependency(_, scalaVersion()), diff --git a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala index f6313589..e862249d 100644 --- a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala @@ -69,7 +69,7 @@ object PlayModuleTests extends TestSuite { "play-logback", "play-ahc-ws" ) - val outputModules = deps.map(_.dep.module.name) + val outputModules = deps.map(_.dep.module.name.value) assert( outputModules.forall(expectedModules.contains), evalCount > 0 diff --git a/contrib/scalapblib/src/ScalaPBModule.scala b/contrib/scalapblib/src/ScalaPBModule.scala index 57bfdd40..00b977ce 100644 --- a/contrib/scalapblib/src/ScalaPBModule.scala +++ b/contrib/scalapblib/src/ScalaPBModule.scala @@ -1,7 +1,7 @@ package mill package contrib.scalapblib -import coursier.{Cache, MavenRepository} +import coursier.MavenRepository import coursier.core.Version import mill.define.Sources import mill.api.PathRef @@ -51,7 +51,7 @@ trait ScalaPBModule extends ScalaModule { def scalaPBClasspath: T[Loose.Agg[PathRef]] = T { resolveDependencies( Seq( - Cache.ivy2Local, + coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2") ), Lib.depToDependency(_, "2.12.4"), diff --git a/contrib/twirllib/src/TwirlModule.scala b/contrib/twirllib/src/TwirlModule.scala index 22e4a43a..72887019 100644 --- a/contrib/twirllib/src/TwirlModule.scala +++ b/contrib/twirllib/src/TwirlModule.scala @@ -1,7 +1,7 @@ package mill package twirllib -import coursier.{Cache, MavenRepository} +import coursier.MavenRepository import mill.define.Sources import mill.api.PathRef import mill.scalalib.Lib.resolveDependencies @@ -22,7 +22,7 @@ trait TwirlModule extends mill.Module { def twirlClasspath: T[Loose.Agg[PathRef]] = T { resolveDependencies( Seq( - Cache.ivy2Local, + coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2") ), Lib.depToDependency(_, "2.12.4"), diff --git a/docs/pages/1 - Intro to Mill.md b/docs/pages/1 - Intro to Mill.md index 61608ba5..00d60a80 100644 --- a/docs/pages/1 - Intro to Mill.md +++ b/docs/pages/1 - Intro to Mill.md @@ -44,7 +44,7 @@ pkg install mill ### Windows To get started, download Mill from: -https://github.com/lihaoyi/mill/releases/download/0.3.6/0.3.6, and save it as +https://github.com/lihaoyi/mill/releases/download/0.3.8/0.3.8, and save it as `mill.bat`. If you're using [Scoop](https://scoop.sh) you can install Mill via @@ -81,7 +81,7 @@ To get started, download Mill and install it into your system via the following `curl`/`chmod` command: ```bash -sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/lihaoyi/mill/releases/download/0.3.6/0.3.6) > /usr/local/bin/mill && chmod +x /usr/local/bin/mill' +sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/lihaoyi/mill/releases/download/0.3.8/0.3.8) > /usr/local/bin/mill && chmod +x /usr/local/bin/mill' ``` ### Development Releases diff --git a/docs/pages/10 - Thirdparty Modules.md b/docs/pages/10 - Thirdparty Modules.md new file mode 100644 index 00000000..b98b9f67 --- /dev/null +++ b/docs/pages/10 - Thirdparty Modules.md @@ -0,0 +1,250 @@ + +The modules (aka plugins) in this section are developed/maintained outside the mill git tree. + +Besides the documentation provided here, we urge you to consult the respective linked plugin documentation pages. +The usage examples given here are most probably incomplete and sometimes outdated. + +If you develop or maintain a mill plugin, please create a [pull request](https://github.com/lihaoyi/mill/pulls) to get your plugin listed here. + +[comment]: # (Please keep list of plugins in alphabetical order) + +## DGraph + +Show transitive dependencies of your build in your browser. + +Project home: https://github.com/ajrnz/mill-dgraph + +### Quickstart + +```scala +import $ivy.`com.github.ajrnz::mill-dgraph:0.2.0` +``` + +```sh +sh> mill plugin.dgraph.browseDeps(proj)() +``` + +## Ensime + +Create an [.ensime](http://ensime.github.io/ "ensime") file for your build. + +Project home: https://github.com/yyadavalli/mill-ensime + +### Quickstart + +```scala +import $ivy.`fun.valycorp::mill-ensime:0.0.1` +``` + +```sh +sh> mill fun.valycorp.mill.GenEnsime/ensimeConfig +``` + +## Integration Testing Mill Plugins + +Integration testing for mill plugins. + +### Quickstart + +We assume, you have a mill plugin named `mill-demo` + +```scala +// build.sc +import mill._, mill.scalalib._ +object demo extends ScalaModule with PublishModule { + // ... +} +``` + +Add an new test sub-project, e.g. `it`. + +```scala +import $ivy.`de.tototec::de.tobiasroeser.mill.integrationtest:0.1.0` +import de.tobiasroeser.mill.integrationtest._ + +object it extends MillIntegrationTest { + + def millTestVersion = "{exampleMillVersion}" + + def pluginsUnderTest = Seq(demo) + +} +``` + +Your project should now look similar to this: + +```text +. ++-- demo/ +| +-- src/ +| ++-- it/ + +-- src/ + +-- 01-first-test/ + | +-- build.sc + | +-- src/ + | + +-- 02-second-test/ + +-- build.sc +``` + +As the buildfiles `build.sc` in your test cases typically want to access the locally built plugin(s), +the plugins publishes all plugins referenced under `pluginsUnderTest` to a temporary ivy repository, just before the test is executed. +The mill version used in the integration test then used that temporary ivy repository. + +Instead of referring to your plugin with `import $ivy.'your::plugin:version'`, +you can use the following line instead, which ensures you will use the correct locally build plugins. + +```scala +// build.sc +import $exec.plugins +``` + +Effectively, at execution time, this line gets replaced by the content of `plugins.sc`, a file which was generated just before the test started to execute. + +### Configuration and Targets + +The mill-integrationtest plugin provides the following targets. + +#### Mandatory configuration + +* `def millTestVersion: T[String]` + The mill version used for executing the test cases. + Used by `downloadMillTestVersion` to automatically download. + +* `def pluginsUnderTest: Seq[PublishModule]` - + The plugins used in the integration test. + You should at least add your plugin under test here. + You can also add additional libraries, e.g. those that assist you in the test result validation (e.g. a local test support project). + The defined modules will be published into a temporary ivy repository before the tests are executed. + In your test `build.sc` file, instead of the typical `import $ivy.` line, + you should use `import $exec.plugins` to include all plugins that are defined here. + +#### Optional configuration + +* `def sources: Sources` - + Locations where integration tests are located. + Each integration test is a sub-directory, containing a complete test mill project. + +* `def testCases: T[Seq[PathRef]]` - + The directories each representing a mill test case. + Derived from `sources`. + +* `def testTargets: T[Seq[String]]` - + The targets which are called to test the project. + Defaults to `verify`, which should implement test result validation. + +* `def downloadMillTestVersion: T[PathRef]` - + Download the mill version as defined by `millTestVersion`. + Override this, if you need to use a custom built mill version. + Returns the `PathRef` to the mill executable (must have the executable flag). + +#### Commands + +* `def test(): Command[Unit]` - + Run the integration tests. + + +## JBake + +Create static sites/blogs with JBake. + +Plugin home: https://github.com/lefou/mill-jbake + +JBake home: https://jbake.org + +### Quickstart + +```scala +// build.sc +import mill._ +import $ivy.`de.tototec::de.tobiasroeser.mill.jbake:0.1.0` +import de.tobiasroeser.mill.jbake._ + +object site extends JBakeModule { + + def jbakeVersion = "2.6.4" + +} +``` + +Generate the site: + +```sh +bash> mill site.jbake +``` + +Start a local Web-Server on Port 8820 with the generated site: + +```sh +bash> mill site.jbakeServe +``` + + +## OSGi + +Produce OSGi Bundles with mill. + +Project home: https://github.com/lefou/mill-osgi + +### Quickstart + +```scala +import mill._, mill.scalalib._ +import $ivy.`de.tototec::de.tobiasroeser.mill.osgi:0.0.5` +import de.tobiasroeser.mill.osgi._ + +object project extends ScalaModule with OsgiBundleModule { + + def bundleSymbolicName = "com.example.project" + + def osgiHeaders = T{ super.osgiHeaders().copy( + `Export-Package` = Seq("com.example.api"), + `Bundle-Activator` = Some("com.example.internal.Activator") + )} + + // other settings ... + +} +``` + + +## PublishM2 + +Mill plugin to publish artifacts into a local Maven repository. + +Project home: https://github.com/lefou/mill-publishM2 + +### Quickstart + +Just mix-in the `PublishM2Module` into your project. +`PublishM2Module` already extends mill's built-in `PublishModule`. + +File: `build.sc` +```scala +import mill._, scalalib._, publish._ + +import $ivy.`de.tototec::de.tobiasroeser.mill.publishM2:0.0.1` +import de.tobiasroeser.mill.publishM2._ + +object project extends PublishModule with PublishM2Module { + // ... +} +``` + +Publishing to default local Maven repository + +```bash +> mill project.publishM2Local +[40/40] project.publishM2Local +Publishing to /home/user/.m2/repository +``` + +Publishing to custom local Maven repository + +```bash +> mill project.publishM2Local /tmp/m2repo +[40/40] project.publishM2Local +Publishing to /tmp/m2repo +``` + diff --git a/docs/pages/9 - Contrib Modules.md b/docs/pages/9 - Contrib Modules.md index 1b9b55fa..eca61be3 100644 --- a/docs/pages/9 - Contrib Modules.md +++ b/docs/pages/9 - Contrib Modules.md @@ -1,8 +1,69 @@ -## Contrib Modules The plugins in this section are developed/maintained in the mill git tree. -### BuildInfo +When using one of these, you should make sure to use the versions that matches your mill version. + +[comment]: # (Please keep list of plugins in alphabetical order) + +## Bloop + +This plugin generates [bloop](https://scalacenter.github.io/bloop/) configuration +from your build file, which lets you use the bloop CLI for compiling, and makes +your scala code editable in [Metals](https://scalameta.org/metals/) + + +### Quickstart +```scala +// build.sc (or any other .sc file it depends on, including predef) +// Don't forget to replace VERSION +import $ivy.`com.lihaoyi::mill-contrib-bloop:VERSION` +``` + +Then in your terminal : + +``` +> mill mill.contrib.Bloop/install +``` + +### Mix-in + +You can mix-in the `Bloop.Module` trait with any JavaModule to quickly access +the deserialised configuration for that particular module: + +```scala +// build.sc +import mill._ +import mill.scalalib._ +import mill.contrib.Bloop + +object MyModule extends ScalaModule with Bloop.Module { + def myTask = T { bloop.config() } +} +``` + +### Note regarding metals + +Generating the bloop config should be enough for metals to pick it up and for +features to start working in vscode (or the bunch of other editors metals supports). +However, note that this applies only to your project sources. Your mill/ammonite related +`.sc` files are not yet supported by metals. + +The generated bloop config references the semanticDB compiler plugin required by +metals to function. If need be, the version of semanticDB can be overriden by +extending `mill.contrib.bloop.BloopImpl` in your own space. + +### Note regarding current mill support in bloop + +The mill-bloop integration currently present in the [bloop codebase](https://github.com/scalacenter/bloop/blob/master/integrations/mill-bloop/src/main/scala/bloop/integrations/mill/MillBloop.scala#L10) +will be deprecated in favour of this implementation. + +### Caveats + +At this time, only Java/ScalaModule are processed correctly. ScalaJS/ScalaNative integration will +be added in a near future. + + +## BuildInfo Generate scala code from your buildfile. This plugin generates a single object containing information from your build. @@ -27,7 +88,7 @@ object project extends BuildInfo { } ``` -#### Configuration options +### Configuration options * `def buildInfoMembers: T[Map[String, String]]` The map containing all member names and values for the generated info object. @@ -39,7 +100,7 @@ object project extends BuildInfo { The package name of the object. -### Flyway +## Flyway Enables you to configure and run [Flyway](https://flywaydb.org/) commands from your mill build file. The flyway module currently supports the most common flyway use cases with file based migrations. @@ -83,7 +144,7 @@ mill foo.flywayMigrate > You should write some code to populate the settings for flyway instead. > For example `def flywayPassword = T.input(T.ctx().env("FLYWAY_PASSWORD"))` -### Play Framework +## Play Framework This module adds basic Play Framework support to mill: @@ -96,7 +157,7 @@ This module adds basic Play Framework support to mill: There is no specific Play Java support, building a Play Java application will require a bit of customization (mostly adding the proper dependencies). -#### Using the plugin +### Using the plugin There are 2 base modules and 2 helper traits in this plugin, all of which can be found in `mill.playlib`. @@ -118,7 +179,7 @@ directories at the top level alongside the `build.sc` file. This trait takes car * `RouterModule` allows you to use the Play router without the rest of the configuration (see [Using the router module directly](#using-the-router-module-directly).) -#### Using `PlayModule` +### Using `PlayModule` In order to use the `PlayModule` for your application, you need to provide the scala, Play and Twirl versions. You also need to define your own test object which extends the provided @@ -185,7 +246,7 @@ In order to have a working `start` command the following runtime dependency is a ivy"com.typesafe.play::play-akka-http-server:${playVersion()}" ``` -#### Using `PlayApiModule` +### Using `PlayApiModule` The `PlayApiModule` trait behaves the same as the `PlayModule` trait but it won't process .scala .html files and you don't need to define the `twirlVersion: @@ -206,12 +267,12 @@ object core extends PlayApiModule { } ``` -#### Play configuration options +### Play configuration options The Play modules themselves don't have specific configuration options at this point but the [router module configuration options](#router-configuration-options) and the [Twirl module configuration options](#twirl-configuration-options) are applicable. -#### Additional play libraries +### Additional play libraries The following helpers are available to provide additional Play Framework dependencies: @@ -246,7 +307,7 @@ object core extends PlayApiModule { } ``` -#### Commands equivalence +### Commands equivalence Mill commands are targets on a named build. For example if your build is called `core`: @@ -262,7 +323,7 @@ starts a server in *PROD* mode which: command to get a runnable fat jar of the project. The packaging is slightly different but should be find for a production deployment. -#### Using `SingleModule` +### Using `SingleModule` The `SingleModule` trait allows you to have the build descriptor at the same level as the source code on the filesystem. You can move from there to a multi-module build either by refactoring @@ -350,7 +411,7 @@ the layout becomes: └── controllers ``` -##### Using the router module directly +#### Using the router module directly If you want to use the router module in a project which doesn't use the default Play layout, you can mix-in the `mill.playlib.routesModule` trait directly when defining your module. Your app must @@ -369,7 +430,7 @@ object app extends ScalaModule with RouterModule { } ``` -###### Router Configuration options +##### Router Configuration options * `def playVersion: T[String]` (mandatory) - The version of Play to use to compile the routes file. * `def scalaVersion: T[String]` - The scalaVersion in use in your project. @@ -382,7 +443,7 @@ object app extends ScalaModule with RouterModule { * `def generatorType: RouteCompilerType = RouteCompilerType.InjectedGenerator` - The routes compiler type, one of RouteCompilerType.InjectedGenerator or RouteCompilerType.StaticGenerator -###### Details +##### Details The following filesystem layout is expected by default: @@ -423,7 +484,7 @@ object app extends ScalaModule with RouterModule { ``` -### ScalaPB +## ScalaPB This module allows [ScalaPB](https://scalapb.github.io) to be used in Mill builds. ScalaPB is a [Protocol Buffers](https://developers.google.com/protocol-buffers/) compiler plugin that generates Scala case classes, encoders and decoders for protobuf messages. @@ -454,7 +515,7 @@ example/ resources/ ``` -#### Configuration options +### Configuration options * scalaPBVersion (mandatory) - The ScalaPB version `String` e.g. `"0.7.4"` @@ -482,7 +543,7 @@ object example extends ScalaPBModule { } ``` -### TestNG +## TestNG Provides support for [TestNG](https://testng.org/doc/index.html). @@ -499,7 +560,7 @@ object project extends ScalaModule { } ``` -### Tut +## Tut This module allows [Tut](https://tpolecat.github.io/tut) to be used in Mill builds. Tut is a documentation tool which compiles and evaluates Scala code in documentation files and provides various options for configuring how the results will be displayed in the compiled documentation. @@ -538,7 +599,7 @@ In order to compile documentation we can execute the `tut` task in the module: sh> mill example.tut ``` -#### Configuration options +### Configuration options * tutSourceDirectory - This task determines where documentation files must be placed in order to be compiled with Tut. By default this is the `tut` folder at the root of the module. @@ -558,7 +619,7 @@ sh> mill example.tut * tutPluginJars - A task which performs the dependency resolution for the scalac plugins to be used with Tut. -### Twirl +## Twirl Twirl templates support. @@ -577,7 +638,7 @@ object app extends ScalaModule with TwirlModule { } ``` -#### Twirl configuration options +### Twirl configuration options * `def twirlVersion: T[String]` (mandatory) - the version of the twirl compiler to use, like "1.3.15" * `def twirlAdditionalImports: Seq[String] = Nil` - the additional imports that will be added by twirl compiler to the top of all templates @@ -585,7 +646,7 @@ object app extends ScalaModule with TwirlModule { * `def twirlCodec = Codec(Properties.sourceEncoding)` - the codec used to generate the files (the default is the same sbt plugin uses) * `def twirlInclusiveDot: Boolean = false` -#### Details +### Details The following filesystem layout is expected: @@ -659,256 +720,6 @@ Seq( These imports will always be added to every template. You don't need to list them if you override `twirlAdditionalImports`. -#### Example +### Example There's an [example project](https://github.com/lihaoyi/cask/tree/master/example/twirl) - - -## Thirdparty Mill Plugins - -The plugins in this section are developed/maintained outside the mill git tree. - -Besides the documentation provided here, we urge you to consult the respective linked plugin documentation pages. -The usage examples given here are most probably outdated and incomplete. - -If you develop or maintain a mill plugin, please create a [pull request](https://github.com/lihaoyi/mill/pulls) to get your plugin listed here. - -### DGraph - -Show transitive dependencies of your build in your browser. - -Project home: https://github.com/ajrnz/mill-dgraph - -#### Quickstart - -```scala -import $ivy.`com.github.ajrnz::mill-dgraph:0.2.0` -``` - -```sh -sh> mill plugin.dgraph.browseDeps(proj)() -``` - -### Ensime - -Create an [.ensime](http://ensime.github.io/ "ensime") file for your build. - -Project home: https://github.com/yyadavalli/mill-ensime - -#### Quickstart - -```scala -import $ivy.`fun.valycorp::mill-ensime:0.0.1` -``` - -```sh -sh> mill fun.valycorp.mill.GenEnsime/ensimeConfig -``` - -### Integration Testing Mill Plugins - -Integration testing for mill plugins. - -#### Quickstart - -We assume, you have a mill plugin named `mill-demo` - -```scala -// build.sc -import mill._, mill.scalalib._ -object demo extends ScalaModule with PublishModule { - // ... -} -``` - -Add an new test sub-project, e.g. `it`. - -```scala -import $ivy.`de.tototec::de.tobiasroeser.mill.integrationtest:0.1.0` -import de.tobiasroeser.mill.integrationtest._ - -object it extends MillIntegrationTest { - - def millTestVersion = "{exampleMillVersion}" - - def pluginsUnderTest = Seq(demo) - -} -``` - -Your project should now look similar to this: - -```text -. -+-- demo/ -| +-- src/ -| -+-- it/ - +-- src/ - +-- 01-first-test/ - | +-- build.sc - | +-- src/ - | - +-- 02-second-test/ - +-- build.sc -``` - -As the buildfiles `build.sc` in your test cases typically want to access the locally built plugin(s), -the plugins publishes all plugins referenced under `pluginsUnderTest` to a temporary ivy repository, just before the test is executed. -The mill version used in the integration test then used that temporary ivy repository. - -Instead of referring to your plugin with `import $ivy.'your::plugin:version'`, -you can use the following line instead, which ensures you will use the correct locally build plugins. - -```scala -// build.sc -import $exec.plugins -``` - -Effectively, at execution time, this line gets replaced by the content of `plugins.sc`, a file which was generated just before the test started to execute. - -#### Configuration and Targets - -The mill-integrationtest plugin provides the following targets. - -##### Mandatory configuration - -* `def millTestVersion: T[String]` - The mill version used for executing the test cases. - Used by `downloadMillTestVersion` to automatically download. - -* `def pluginsUnderTest: Seq[PublishModule]` - - The plugins used in the integration test. - You should at least add your plugin under test here. - You can also add additional libraries, e.g. those that assist you in the test result validation (e.g. a local test support project). - The defined modules will be published into a temporary ivy repository before the tests are executed. - In your test `build.sc` file, instead of the typical `import $ivy.` line, - you should use `import $exec.plugins` to include all plugins that are defined here. - -##### Optional configuration - -* `def sources: Sources` - - Locations where integration tests are located. - Each integration test is a sub-directory, containing a complete test mill project. - -* `def testCases: T[Seq[PathRef]]` - - The directories each representing a mill test case. - Derived from `sources`. - -* `def testTargets: T[Seq[String]]` - - The targets which are called to test the project. - Defaults to `verify`, which should implement test result validation. - -* `def downloadMillTestVersion: T[PathRef]` - - Download the mill version as defined by `millTestVersion`. - Override this, if you need to use a custom built mill version. - Returns the `PathRef` to the mill executable (must have the executable flag). - -##### Commands - -* `def test(): Command[Unit]` - - Run the integration tests. - - -### JBake - -Create static sites/blogs with JBake. - -Plugin home: https://github.com/lefou/mill-jbake - -JBake home: https://jbake.org - -#### Quickstart - -```scala -// build.sc -import mill._ -import $ivy.`de.tototec::de.tobiasroeser.mill.jbake:0.1.0` -import de.tobiasroeser.mill.jbake._ - -object site extends JBakeModule { - - def jbakeVersion = "2.6.4" - -} -``` - -Generate the site: - -```sh -bash> mill site.jbake -``` - -Start a local Web-Server on Port 8820 with the generated site: - -```sh -bash> mill site.jbakeServe -``` - - -### OSGi - -Produce OSGi Bundles with mill. - -Project home: https://github.com/lefou/mill-osgi - -#### Quickstart - -```scala -import mill._, mill.scalalib._ -import $ivy.`de.tototec::de.tobiasroeser.mill.osgi:0.0.5` -import de.tobiasroeser.mill.osgi._ - -object project extends ScalaModule with OsgiBundleModule { - - def bundleSymbolicName = "com.example.project" - - def osgiHeaders = T{ super.osgiHeaders().copy( - `Export-Package` = Seq("com.example.api"), - `Bundle-Activator` = Some("com.example.internal.Activator") - )} - - // other settings ... - -} -``` - - -### PublishM2 - -Mill plugin to publish artifacts into a local Maven repository. - -Project home: https://github.com/lefou/mill-publishM2 - -#### Quickstart - -Just mix-in the `PublishM2Module` into your project. -`PublishM2Module` already extends mill's built-in `PublishModule`. - -File: `build.sc` -```scala -import mill._, scalalib._, publish._ - -import $ivy.`de.tototec::de.tobiasroeser.mill.publishM2:0.0.1` -import de.tobiasroeser.mill.publishM2._ - -object project extends PublishModule with PublishM2Module { - // ... -} -``` - -Publishing to default local Maven repository - -```bash -> mill project.publishM2Local -[40/40] project.publishM2Local -Publishing to /home/user/.m2/repository -``` - -Publishing to custom local Maven repository - -```bash -> mill project.publishM2Local /tmp/m2repo -[40/40] project.publishM2Local -Publishing to /tmp/m2repo -``` diff --git a/main/core/src/eval/Evaluator.scala b/main/core/src/eval/Evaluator.scala index ebb00ef1..f4ec8ff9 100644 --- a/main/core/src/eval/Evaluator.scala +++ b/main/core/src/eval/Evaluator.scala @@ -32,7 +32,7 @@ case class Evaluator(home: os.Path, externalOutPath: os.Path, rootModule: mill.define.BaseModule, log: Logger, - classLoaderSig: Seq[(Either[String, os.Path], Long)] = Evaluator.classLoaderSig, + classLoaderSig: Seq[(Either[String, java.net.URL], Long)] = Evaluator.classLoaderSig, workerCache: mutable.Map[Segments, (Int, Any)] = mutable.Map.empty, env : Map[String, String] = Evaluator.defaultEnv, failFast: Boolean = true @@ -374,7 +374,7 @@ object Evaluator{ implicit val rw: upickle.default.ReadWriter[Cached] = upickle.default.macroRW } case class State(rootModule: mill.define.BaseModule, - classLoaderSig: Seq[(Either[String, os.Path], Long)], + classLoaderSig: Seq[(Either[String, java.net.URL], Long)], workerCache: mutable.Map[Segments, (Int, Any)], watched: Seq[(os.Path, Long)]) // This needs to be a ThreadLocal because we need to pass it into the body of diff --git a/main/core/src/util/JsonFormatters.scala b/main/core/src/util/JsonFormatters.scala index 830782c6..c1dd18f0 100644 --- a/main/core/src/util/JsonFormatters.scala +++ b/main/core/src/util/JsonFormatters.scala @@ -6,5 +6,10 @@ trait JsonFormatters extends mill.api.JsonFormatters{ implicit lazy val modFormat: RW[coursier.Module] = upickle.default.macroRW implicit lazy val depFormat: RW[coursier.Dependency]= upickle.default.macroRW implicit lazy val attrFormat: RW[coursier.Attributes] = upickle.default.macroRW + implicit lazy val orgFormat: RW[coursier.Organization] = upickle.default.macroRW + implicit lazy val modNameFormat: RW[coursier.ModuleName] = upickle.default.macroRW + implicit lazy val configurationFormat: RW[coursier.core.Configuration] = upickle.default.macroRW + implicit lazy val typeFormat: RW[coursier.core.Type] = upickle.default.macroRW + implicit lazy val classifierFormat: RW[coursier.core.Classifier] = upickle.default.macroRW } object JsonFormatters extends JsonFormatters diff --git a/main/src/MillMain.scala b/main/src/MillMain.scala index f1a7a9e7..ca4af87d 100644 --- a/main/src/MillMain.scala +++ b/main/src/MillMain.scala @@ -23,54 +23,57 @@ object MillMain { System.out, System.err, System.getenv().asScala.toMap, - b => () + b => (), + initialSystemProperties = Map() ) - System.exit(if(result) 0 else 1) + System.exit(if (result) 0 else 1) } - def main0(args: Array[String], - stateCache: Option[Evaluator.State], - mainInteractive: Boolean, - stdin: InputStream, - stdout: PrintStream, - stderr: PrintStream, - env: Map[String, String], - setIdle: Boolean => Unit): (Boolean, Option[Evaluator.State]) = { + def main0( + args: Array[String], + stateCache: Option[Evaluator.State], + mainInteractive: Boolean, + stdin: InputStream, + stdout: PrintStream, + stderr: PrintStream, + env: Map[String, String], + setIdle: Boolean => Unit, + initialSystemProperties: Map[String, String] + ): (Boolean, Option[Evaluator.State]) = { import ammonite.main.Cli - + val millHome = mill.api.Ctx.defaultHome val removed = Set("predef-code", "no-home-predef") + var interactive = false val interactiveSignature = Arg[Config, Unit]( "interactive", Some('i'), "Run Mill in interactive mode, suitable for opening REPLs and taking user input. In this mode, no mill server will be used.", - (c, v) =>{ + (c, v) => { interactive = true c } ) - - var disableTicker = false val disableTickerSignature = Arg[Config, Unit]( - "disable-ticker", None, - "Disable ticker log (e.g. short-lived prints of stages and progress bars)", - (c, v) =>{ - disableTicker = true - c - } + name = "disable-ticker", shortName = None, + doc = "Disable ticker log (e.g. short-lived prints of stages and progress bars)", + action = (c, v) => { + disableTicker = true + c + } ) var debugLog = false val debugLogSignature = Arg[Config, Unit]( name = "debug", shortName = Some('d'), doc = "Show debug output on STDOUT", - (c, v) => { - debugLog = true - c - } + action = (c, v) => { + debugLog = true + c + } ) var keepGoing = false @@ -82,27 +85,46 @@ object MillMain { } ) + var extraSystemProperties = Map[String, String]() + val extraSystemPropertiesSignature = Arg[Config, String]( + name = "define", shortName = Some('D'), + doc = "Define (or overwrite) a system property", + action = { (c, v) => + extraSystemProperties += (v.split("[=]", 2) match { + case Array(k, v) => k -> v + case Array(k) => k -> "" + }) + c + } + ) + val millArgSignature = Cli.genericSignature.filter(a => !removed(a.name)) ++ - Seq(interactiveSignature, disableTickerSignature, debugLogSignature, keepGoingSignature) + Seq( + interactiveSignature, + disableTickerSignature, + debugLogSignature, + keepGoingSignature, + extraSystemPropertiesSignature + ) Cli.groupArgs( args.toList, millArgSignature, Cli.Config(home = millHome, remoteLogging = false) - ) match{ - case _ if interactive => - stderr.println("-i/--interactive must be passed in as the first argument") - (false, None) - case Left(msg) => - stderr.println(msg) - (false, None) - case Right((cliConfig, _)) if cliConfig.help => - val leftMargin = millArgSignature.map(ammonite.main.Cli.showArg(_).length).max + 2 - stdout.println( - s"""Mill Build Tool - |usage: mill [mill-options] [target [target-options]] - | + ) match { + case _ if interactive => + stderr.println("-i/--interactive must be passed in as the first argument") + (false, None) + case Left(msg) => + stderr.println(msg) + (false, None) + case Right((cliConfig, _)) if cliConfig.help => + val leftMargin = millArgSignature.map(ammonite.main.Cli.showArg(_).length).max + 2 + stdout.println( + s"""Mill Build Tool + |usage: mill [mill-options] [target [target-options]] + | |${formatBlock(millArgSignature, leftMargin).mkString(ammonite.util.Util.newLine)}""".stripMargin ) (true, None) @@ -113,6 +135,8 @@ object MillMain { stderr.println("Build repl needs to be run with the -i/--interactive flag") (false, stateCache) }else{ + val systemProps = initialSystemProperties ++ extraSystemProperties + val config = if(!repl) cliConfig else cliConfig.copy( @@ -125,43 +149,45 @@ object MillMain { | repl.pprinter(), | build.millSelf.get, | build.millDiscover, - | $debugLog, - | keepGoing = $keepGoing + | debugLog = $debugLog, + | keepGoing = $keepGoing, + | systemProperties = ${systemProps} |) |repl.pprinter() = replApplyHandler.pprinter |import replApplyHandler.generatedEval._ | """.stripMargin, - welcomeBanner = None + welcomeBanner = None + ) + + val runner = new mill.main.MainRunner( + config.copy(colored = config.colored orElse Option(mainInteractive)), + disableTicker, + stdout, stderr, stdin, + stateCache, + env, + setIdle, + debugLog = debugLog, + keepGoing = keepGoing, + systemProperties = systemProps ) - val runner = new mill.main.MainRunner( - config.copy(colored = config.colored orElse Option(mainInteractive)), - disableTicker, - stdout, stderr, stdin, - stateCache, - env, - setIdle, - debugLog, - keepGoing = keepGoing - ) - - if (mill.main.client.Util.isJava9OrAbove) { - val rt = cliConfig.home / Export.rtJarName - if (!os.exists(rt)) { - runner.printInfo(s"Preparing Java ${System.getProperty("java.version")} runtime; this may take a minute or two ...") - Export.rtTo(rt.toIO, false) + if (mill.main.client.Util.isJava9OrAbove) { + val rt = cliConfig.home / Export.rtJarName + if (!os.exists(rt)) { + runner.printInfo(s"Preparing Java ${System.getProperty("java.version")} runtime; this may take a minute or two ...") + Export.rtTo(rt.toIO, false) + } } - } - if (repl){ - runner.printInfo("Loading...") - (runner.watchLoop(isRepl = true, printing = false, _.run()), runner.stateCache) - } else { - (runner.runScript(os.pwd / "build.sc", leftoverArgs), runner.stateCache) + if (repl) { + runner.printInfo("Loading...") + (runner.watchLoop(isRepl = true, printing = false, _.run()), runner.stateCache) + } else { + (runner.runScript(os.pwd / "build.sc", leftoverArgs), runner.stateCache) + } } - } - } + } } } diff --git a/main/src/main/MainRunner.scala b/main/src/main/MainRunner.scala index e08905a6..6705a4b3 100644 --- a/main/src/main/MainRunner.scala +++ b/main/src/main/MainRunner.scala @@ -25,7 +25,8 @@ class MainRunner(val config: ammonite.main.Cli.Config, env : Map[String, String], setIdle: Boolean => Unit, debugLog: Boolean, - keepGoing: Boolean) + keepGoing: Boolean, + systemProperties: Map[String, String]) extends ammonite.MainRunner( config, outprintStream, errPrintStream, stdIn, outprintStream, errPrintStream @@ -85,7 +86,8 @@ class MainRunner(val config: ammonite.main.Cli.Config, debugEnabled = debugLog ), env, - keepGoing = keepGoing + keepGoing = keepGoing, + systemProperties ) result match{ @@ -126,7 +128,7 @@ class MainRunner(val config: ammonite.main.Cli.Config, ) } - object CustomCodeWrapper extends Preprocessor.CodeWrapper { + object CustomCodeWrapper extends ammonite.interp.CodeWrapper { def apply(code: String, source: CodeSource, imports: ammonite.util.Imports, diff --git a/main/src/main/MillServerMain.scala b/main/src/main/MillServerMain.scala index 862daaf7..500c3e8f 100644 --- a/main/src/main/MillServerMain.scala +++ b/main/src/main/MillServerMain.scala @@ -21,7 +21,8 @@ trait MillServerMain[T]{ stdout: PrintStream, stderr: PrintStream, env : Map[String, String], - setIdle: Boolean => Unit): (Boolean, Option[T]) + setIdle: Boolean => Unit, + systemProperties: Map[String, String]): (Boolean, Option[T]) } object MillServerMain extends mill.main.MillServerMain[Evaluator.State]{ @@ -44,6 +45,7 @@ object MillServerMain extends mill.main.MillServerMain[Evaluator.State]{ mill.main.client.Locks.files(args0(0)) ).run() } + def main0(args: Array[String], stateCache: Option[Evaluator.State], mainInteractive: Boolean, @@ -51,7 +53,8 @@ object MillServerMain extends mill.main.MillServerMain[Evaluator.State]{ stdout: PrintStream, stderr: PrintStream, env : Map[String, String], - setIdle: Boolean => Unit) = { + setIdle: Boolean => Unit, + systemProperties: Map[String, String]) = { MillMain.main0( args, stateCache, @@ -60,7 +63,8 @@ object MillServerMain extends mill.main.MillServerMain[Evaluator.State]{ stdout, stderr, env, - setIdle = setIdle + setIdle = setIdle, + systemProperties ) } } @@ -132,6 +136,7 @@ class Server[T](lockBase: String, } val args = Util.parseArgs(argStream) val env = Util.parseMap(argStream) + val systemProperties = Util.parseMap(argStream) argStream.close() @volatile var done = false @@ -147,6 +152,7 @@ class Server[T](lockBase: String, stderr, env.asScala.toMap, idle = _, + systemProperties.asScala.toMap ) sm.stateCache = newStateCache diff --git a/main/src/main/ReplApplyHandler.scala b/main/src/main/ReplApplyHandler.scala index 6f1e060d..7f959929 100644 --- a/main/src/main/ReplApplyHandler.scala +++ b/main/src/main/ReplApplyHandler.scala @@ -1,14 +1,13 @@ package mill.main +import scala.collection.mutable +import mill.api.Strict.Agg import mill.define.Applicative.ApplyHandler import mill.define.Segment.Label import mill.define._ import mill.eval.{Evaluator, Result} -import mill.api.Strict.Agg - -import scala.collection.mutable object ReplApplyHandler{ def apply[T](home: os.Path, disableTicker: Boolean, @@ -17,7 +16,8 @@ object ReplApplyHandler{ rootModule: mill.define.BaseModule, discover: Discover[_], debugLog: Boolean, - keepGoing: Boolean) = { + keepGoing: Boolean, + systemProperties: Map[String, String]): ReplApplyHandler = { new ReplApplyHandler( pprinter0, new Evaluator( @@ -36,7 +36,8 @@ object ReplApplyHandler{ debugEnabled = debugLog ), failFast = !keepGoing - ) + ), + systemProperties ) } def pprintCross(c: mill.define.Cross[_], evaluator: Evaluator) = { @@ -113,8 +114,15 @@ object ReplApplyHandler{ } } + class ReplApplyHandler(pprinter0: pprint.PPrinter, - val evaluator: Evaluator) extends ApplyHandler[Task] { + val evaluator: Evaluator, + systemProperties: Map[String, String]) extends ApplyHandler[Task] { + + systemProperties.foreach {case (k,v) => + System.setProperty(k,v) + } + // Evaluate classLoaderSig only once in the REPL to avoid busting caches // as the user enters more REPL commands and changes the classpath val classLoaderSig = Evaluator.classLoaderSig diff --git a/main/src/main/RunScript.scala b/main/src/main/RunScript.scala index ea8e554f..ab53aa1a 100644 --- a/main/src/main/RunScript.scala +++ b/main/src/main/RunScript.scala @@ -30,9 +30,14 @@ object RunScript{ stateCache: Option[Evaluator.State], log: Logger, env : Map[String, String], - keepGoing: Boolean) + keepGoing: Boolean, + systemProperties: Map[String, String]) : (Res[(Evaluator, Seq[PathRef], Either[String, Seq[ujson.Value]])], Seq[(os.Path, Long)]) = { + systemProperties.foreach {case (k,v) => + System.setProperty(k, v) + } + val (evalState, interpWatched) = stateCache match{ case Some(s) if watchedSigUnchanged(s.watched) => Res.Success(s) -> s.watched case _ => diff --git a/main/src/main/VisualizeModule.scala b/main/src/main/VisualizeModule.scala index e950973f..b3d59509 100644 --- a/main/src/main/VisualizeModule.scala +++ b/main/src/main/VisualizeModule.scala @@ -2,7 +2,7 @@ package mill.main import java.util.concurrent.LinkedBlockingQueue -import coursier.Cache +import coursier.LocalRepositories import coursier.core.Repository import coursier.maven.MavenRepository import mill.T @@ -11,7 +11,7 @@ import mill.eval.{PathRef, Result} object VisualizeModule extends ExternalModule with VisualizeModule { def repositories = Seq( - Cache.ivy2Local, + LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2"), MavenRepository("https://oss.sonatype.org/content/repositories/releases") ) diff --git a/main/src/modules/Jvm.scala b/main/src/modules/Jvm.scala index 555fabae..c1f07a9b 100644 --- a/main/src/modules/Jvm.scala +++ b/main/src/modules/Jvm.scala @@ -8,7 +8,7 @@ import java.nio.file.attribute.PosixFilePermission import java.util.Collections import java.util.jar.{JarEntry, JarFile, JarOutputStream} -import coursier.{Cache, Dependency, Fetch, Repository, Resolution, CachePolicy} +import coursier.{Dependency, Fetch, Repository, Resolution} import coursier.util.{Gather, Task} import geny.Generator import mill.main.client.InputPumper @@ -37,7 +37,7 @@ object Jvm { val commandArgs = Vector("java") ++ jvmArgs ++ - Vector("-cp", classPath.mkString(File.pathSeparator), mainClass) ++ + Vector("-cp", classPath.mkString(java.io.File.pathSeparator), mainClass) ++ mainArgs val workingDir1 = Option(workingDir).getOrElse(ctx.dest) @@ -60,7 +60,7 @@ object Jvm { val args = Vector("java") ++ jvmArgs ++ - Vector("-cp", classPath.mkString(File.pathSeparator), mainClass) ++ + Vector("-cp", classPath.mkString(java.io.File.pathSeparator), mainClass) ++ mainArgs if (background) spawnSubprocess(args, envArgs, workingDir) @@ -84,7 +84,7 @@ object Jvm { process.waitFor() if (process.exitCode() == 0) () - else throw new Exception("Interactive Subprocess Failed") + else throw new Exception("Interactive Subprocess Failed (exit code " + process.exitCode() + ")") } /** @@ -289,9 +289,7 @@ object Jvm { writeEntry(path, concatenated, append = true) case (mapping, WriteOnceEntry(entry)) => val path = zipFs.getPath(mapping).toAbsolutePath - if (Files.notExists(path)) { - writeEntry(path, entry.inputStream, append = false) - } + writeEntry(path, entry.inputStream, append = false) } zipFs.close() @@ -409,6 +407,7 @@ object Jvm { repositories, deps, force, mapDependencies, ctx ) val errs = resolution.metadataErrors + if(errs.nonEmpty) { val header = s"""| @@ -424,13 +423,11 @@ object Jvm { } else { def load(artifacts: Seq[coursier.Artifact]) = { - val logger = None import scala.concurrent.ExecutionContext.Implicits.global val loadedArtifacts = Gather[Task].gather( for (a <- artifacts) - yield coursier.Cache.file[Task](a, logger = logger).run - .map(a.isOptional -> _) + yield coursier.cache.Cache.default.file(a).run.map(a.optional -> _) ).unsafeRun val errors = loadedArtifacts.collect { @@ -442,8 +439,13 @@ object Jvm { } val sourceOrJar = - if (sources) resolution.classifiersArtifacts(Seq("sources")) - else resolution.artifacts(true) + if (sources) { + resolution.artifacts( + types = Set(coursier.Type.source, coursier.Type.javaSource), + classifiers = Some(Seq(coursier.Classifier("sources"))) + ) + } + else resolution.artifacts() val (errors, successes) = load(sourceOrJar) if(errors.isEmpty){ mill.Agg.from( @@ -463,7 +465,7 @@ object Jvm { mapDependencies: Option[Dependency => Dependency] = None, ctx: Option[mill.util.Ctx.Log] = None) = { - val cachePolicies = CachePolicy.default + val cachePolicies = coursier.cache.CacheDefaults.cachePolicies val forceVersions = force .map(mapDependencies.getOrElse(identity[Dependency](_))) @@ -471,20 +473,23 @@ object Jvm { .toMap val start = Resolution( - deps.map(mapDependencies.getOrElse(identity[Dependency](_))).toSet, + deps.map(mapDependencies.getOrElse(identity[Dependency](_))).toSeq, forceVersions = forceVersions, mapDependencies = mapDependencies ) val resolutionLogger = ctx.map(c => new TickerResolutionLogger(c)) - val fetches = cachePolicies.map { p => - Cache.fetch[Task]( - logger = resolutionLogger, - cachePolicy = p - ) + val cache = resolutionLogger match { + case None => coursier.cache.FileCache[Task].withCachePolicies(cachePolicies) + case Some(l) => + coursier.cache.FileCache[Task] + .withCachePolicies(cachePolicies) + .withLogger(l) } - val fetch = Fetch.from(repositories, fetches.head, fetches.tail: _*) + val fetches = cache.fetchs + + val fetch = coursier.core.ResolutionProcess.fetch(repositories, fetches.head, fetches.tail: _*) import scala.concurrent.ExecutionContext.Implicits.global val resolution = start.process.run(fetch).unsafeRun() @@ -498,7 +503,7 @@ object Jvm { * In practice, this ticker output gets prefixed with the current target for which * dependencies are being resolved, using a [[mill.util.ProxyLogger]] subclass. */ - class TickerResolutionLogger(ctx: mill.util.Ctx.Log) extends Cache.Logger { + class TickerResolutionLogger(ctx: mill.util.Ctx.Log) extends coursier.cache.CacheLogger { case class DownloadState(var current: Long, var total: Long) var downloads = new mutable.TreeMap[String,DownloadState]() var totalDownloadCount = 0 @@ -518,7 +523,7 @@ object Jvm { ctx.log.ticker(s"Downloading [${downloads.size + finishedCount}/$totalDownloadCount] artifacts (~${sums.current}/${sums.total} bytes)") } - override def downloadingArtifact(url: String, file: File): Unit = synchronized { + override def downloadingArtifact(url: String): Unit = synchronized { totalDownloadCount += 1 downloads += url -> DownloadState(0,0) updateTicker() diff --git a/main/src/modules/Util.scala b/main/src/modules/Util.scala index 20f06d8f..8cb72e61 100644 --- a/main/src/modules/Util.scala +++ b/main/src/modules/Util.scala @@ -65,7 +65,7 @@ object Util { repositories, Seq( coursier.Dependency( - coursier.Module("com.lihaoyi", artifact + artifactSuffix), + coursier.Module(coursier.Organization("com.lihaoyi"), coursier.ModuleName(artifact + artifactSuffix)), sys.props("MILL_VERSION") ) ), diff --git a/main/test/src/main/ClientServerTests.scala b/main/test/src/main/ClientServerTests.scala index 05238a5f..6d918b30 100644 --- a/main/test/src/main/ClientServerTests.scala +++ b/main/test/src/main/ClientServerTests.scala @@ -13,7 +13,8 @@ class EchoServer extends MillServerMain[Int]{ stdout: PrintStream, stderr: PrintStream, env: Map[String, String], - setIdle: Boolean => Unit) = { + setIdle: Boolean => Unit, + systemProperties: Map[String, String]) = { val reader = new BufferedReader(new InputStreamReader(stdin)) val str = reader.readLine() @@ -23,6 +24,9 @@ class EchoServer extends MillServerMain[Int]{ env.toSeq.sortBy(_._1).foreach{ case (key, value) => stdout.println(s"$key=$value") } + systemProperties.toSeq.sortBy(_._1).foreach{ + case (key, value) => stdout.println(s"$key=$value") + } stdout.flush() if (args.nonEmpty){ stderr.println(str.toUpperCase + args(0)) diff --git a/main/test/src/util/ScriptTestSuite.scala b/main/test/src/util/ScriptTestSuite.scala index 92f57c4f..b15541f3 100644 --- a/main/test/src/util/ScriptTestSuite.scala +++ b/main/test/src/util/ScriptTestSuite.scala @@ -16,10 +16,19 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{ val disableTicker = false val debugLog = false val keepGoing = false + val systemProperties = Map[String, String]() lazy val runner = new mill.main.MainRunner( - ammonite.main.Cli.Config(wd = wd), disableTicker, - stdOutErr, stdOutErr, stdIn, None, Map.empty, - b => (), debugLog, keepGoing = keepGoing + config = ammonite.main.Cli.Config(wd = wd), + disableTicker = disableTicker, + outprintStream = stdOutErr, + errPrintStream = stdOutErr, + stdIn = stdIn, + stateCache0 = None, + env = Map.empty, + setIdle = b => (), + debugLog = debugLog, + keepGoing = keepGoing, + systemProperties = systemProperties ) def eval(s: String*) = { if (!fork) runner.runScript(workspacePath / buildPath , s.toList) diff --git a/main/test/src/util/TestEvaluator.scala b/main/test/src/util/TestEvaluator.scala index 97be20be..45bc41d9 100644 --- a/main/test/src/util/TestEvaluator.scala +++ b/main/test/src/util/TestEvaluator.scala @@ -12,12 +12,12 @@ object TestEvaluator{ val externalOutPath = os.pwd / 'target / 'external - def static(module: TestUtil.BaseModule)(implicit fullName: sourcecode.FullName) = { + def static(module: => TestUtil.BaseModule)(implicit fullName: sourcecode.FullName) = { new TestEvaluator(module)(fullName, TestPath(Nil)) } } -class TestEvaluator(module: TestUtil.BaseModule, failFast: Boolean = false) +class TestEvaluator(module: => TestUtil.BaseModule, failFast: Boolean = false) (implicit fullName: sourcecode.FullName, tp: TestPath){ val outPath = TestUtil.getOutPath() @@ -155,9 +155,24 @@ optimizer without classpath conflicts. ## Changelog -### {master} +### 0.3.8 -- Publish compileIvyDeps as provided scope +- Publish `compileIvyDeps` as provided scope + ([535](https://github.com/lihaoyi/mill/issues/535)) + +- Added contrib modules to integrate + [Bloop](http://www.lihaoyi.com/mill/page/contrib-modules.html#bloop), + [Flyway](http://www.lihaoyi.com/mill/page/contrib-modules.html#flyway), + [Play Framework](http://www.lihaoyi.com/mill/page/contrib-modules.html#play-framework) + +- Allow configuration of GPG key names when publishing + ([530](https://github.com/lihaoyi/mill/pull/530)) + +- Bump Ammonite version to 1.6.7, making + [Requests-Scala](https://github.com/lihaoyi/requests-scala) available to use + in your `build.sc` + +- Support for Scala 2.13.0-RC2 ### 0.3.6 diff --git a/scalajslib/src/ScalaJSModule.scala b/scalajslib/src/ScalaJSModule.scala index 230a3e5c..51b04e6a 100644 --- a/scalajslib/src/ScalaJSModule.scala +++ b/scalajslib/src/ScalaJSModule.scala @@ -1,7 +1,6 @@ package mill package scalajslib -import coursier.Cache import coursier.maven.MavenRepository import mill.eval.{PathRef, Result} import mill.api.Result.Success diff --git a/scalalib/api/src/ZincWorkerApi.scala b/scalalib/api/src/ZincWorkerApi.scala index 70128e8d..790ea274 100644 --- a/scalalib/api/src/ZincWorkerApi.scala +++ b/scalalib/api/src/ZincWorkerApi.scala @@ -60,7 +60,7 @@ object Util{ classPath .find(p => p.toString.endsWith(mavenStylePath) || p.toString.endsWith(ivyStylePath)) - .getOrElse(throw new Exception(s"Cannot find $mavenStylePath or $ivyStylePath")) + .getOrElse(throw new Exception(s"Cannot find $mavenStylePath or $ivyStylePath in ${classPath.mkString("[", ", ", "]")}")) } private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r diff --git a/scalalib/src/Dep.scala b/scalalib/src/Dep.scala index 714fa21e..59c3be5e 100644 --- a/scalalib/src/Dep.scala +++ b/scalalib/src/Dep.scala @@ -9,16 +9,28 @@ case class Dep(dep: coursier.Dependency, cross: CrossVersion, force: Boolean) { def artifactName(binaryVersion: String, fullVersion: String, platformSuffix: String) = { val suffix = cross.suffixString(binaryVersion, fullVersion, platformSuffix) - dep.module.name + suffix + dep.module.name.value + suffix } def configure(attributes: coursier.Attributes): Dep = copy(dep = dep.copy(attributes = attributes)) def forceVersion(): Dep = copy(force = true) - def exclude(exclusions: (String, String)*) = copy(dep = dep.copy(exclusions = dep.exclusions ++ exclusions)) + def exclude(exclusions: (String, String)*) = copy( + dep = dep.copy( + exclusions = + dep.exclusions ++ + exclusions.map{case (k, v) => (coursier.Organization(k), coursier.ModuleName(v))} + ) + ) def excludeOrg(organizations: String*): Dep = exclude(organizations.map(_ -> "*"): _*) def excludeName(names: String*): Dep = exclude(names.map("*" -> _): _*) def toDependency(binaryVersion: String, fullVersion: String, platformSuffix: String) = - dep.copy(module = dep.module.copy(name = artifactName(binaryVersion, fullVersion, platformSuffix))) - def withConfiguration(configuration: String): Dep = copy(dep = dep.copy(configuration = configuration)) + dep.copy( + module = dep.module.copy( + name = coursier.ModuleName(artifactName(binaryVersion, fullVersion, platformSuffix)) + ) + ) + def withConfiguration(configuration: String): Dep = copy( + dep = dep.copy(configuration = coursier.core.Configuration(configuration)) + ) /** * If scalaVersion is a Dotty version, replace the cross-version suffix @@ -49,14 +61,14 @@ case class Dep(dep: coursier.Dependency, cross: CrossVersion, force: Boolean) { object Dep { - val DefaultConfiguration = "default(compile)" + val DefaultConfiguration = coursier.core.Configuration("default(compile)") implicit def parse(signature: String): Dep = { val parts = signature.split(';') val module = parts.head val attributes = parts.tail.foldLeft(coursier.Attributes()) { (as, s) => s.split('=') match { - case Array("classifier", v) => as.copy(classifier = v) + case Array("classifier", v) => as.copy(classifier = coursier.Classifier(v)) case Array(k, v) => throw new Exception(s"Unrecognized attribute: [$s]") case _ => throw new Exception(s"Unable to parse attribute specifier: [$s]") } @@ -72,7 +84,15 @@ object Dep { }).configure(attributes = attributes) } def apply(org: String, name: String, version: String, cross: CrossVersion, force: Boolean = false): Dep = { - apply(coursier.Dependency(coursier.Module(org, name), version, DefaultConfiguration), cross, force) + apply( + coursier.Dependency( + coursier.Module(coursier.Organization(org), coursier.ModuleName(name)), + version, + DefaultConfiguration + ), + cross, + force + ) } implicit def rw: RW[Dep] = macroRW } diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 379ce30b..404a0235 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -1,7 +1,7 @@ package mill.scalalib import ammonite.runtime.SpecialClassLoader -import coursier.{Cache, CoursierPaths, Repository} +import coursier.Repository import mill.define._ import mill.eval.{Evaluator, PathRef, Result} import mill.api.Ctx.{Home, Log} @@ -204,7 +204,7 @@ object GenIdeaImpl { // Tries to group jars with their poms and sources. def toResolvedJar(path : os.Path) : Option[ResolvedLibrary] = { - val inCoursierCache = path.startsWith(os.Path(CoursierPaths.cacheDirectory())) + val inCoursierCache = path.startsWith(os.Path(coursier.paths.CoursierPaths.cacheDirectory())) val isSource = path.last.endsWith("sources.jar") val isPom = path.ext == "pom" if (inCoursierCache && (isSource || isPom)) { diff --git a/scalalib/src/JavaModule.scala b/scalalib/src/JavaModule.scala index 75a0339d..7b373650 100644 --- a/scalalib/src/JavaModule.scala +++ b/scalalib/src/JavaModule.scala @@ -163,7 +163,6 @@ trait JavaModule extends mill.Module with TaskModule { outer => finalMainClassOpt().toOption match{ case None => "" case Some(cls) => - val isWin = scala.util.Properties.isWin mill.modules.Jvm.launcherUniversalScript( cls, Agg("$0"), Agg("%~dpnx0"), @@ -384,8 +383,14 @@ trait JavaModule extends mill.Module with TaskModule { outer => Some(mapDependencies()) ) - println(coursier.util.Print.dependencyTree(flattened, resolution, - printExclusions = false, reverse = inverse)) + println( + coursier.util.Print.dependencyTree( + roots = flattened, + resolution = resolution, + printExclusions = false, + reverse = inverse + ) + ) Result.Success() } diff --git a/scalalib/src/Lib.scala b/scalalib/src/Lib.scala index 2706850e..da133d94 100644 --- a/scalalib/src/Lib.scala +++ b/scalalib/src/Lib.scala @@ -8,7 +8,7 @@ import java.util.zip.ZipInputStream import javax.tools.ToolProvider import ammonite.util.Util -import coursier.{Cache, Dependency, Fetch, Repository, Resolution} +import coursier.{Dependency, Fetch, Repository, Resolution} import mill.scalalib.api.Util.isDotty import mill.Agg import mill.eval.{PathRef, Result} diff --git a/scalalib/src/PublishModule.scala b/scalalib/src/PublishModule.scala index 0fd862b3..9a4374f2 100644 --- a/scalalib/src/PublishModule.scala +++ b/scalalib/src/PublishModule.scala @@ -106,9 +106,9 @@ object PublishModule extends ExternalModule { def publishAll(sonatypeCreds: String, gpgPassphrase: String = null, - gpgKeyName: String = null, publishArtifacts: mill.main.Tasks[PublishModule.PublishData], release: Boolean = false, + gpgKeyName: String = null, sonatypeUri: String = "https://oss.sonatype.org/service/local", sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots", signed: Boolean = true) = T.command { diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index 5fad1664..f45a7e98 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -48,8 +48,13 @@ trait ScalaModule extends JavaModule { outer => Set("dotty-library", "dotty-compiler") else Set("scala-library", "scala-compiler", "scala-reflect") - if (!artifacts(d.module.name)) d - else d.copy(module = d.module.copy(organization = scalaOrganization()), version = scalaVersion()) + if (!artifacts(d.module.name.value)) d + else d.copy( + module = d.module.copy( + organization = coursier.Organization(scalaOrganization()) + ), + version = scalaVersion() + ) } override def resolveCoursierDependency: Task[Dep => coursier.Dependency] = T.task{ diff --git a/scalalib/src/Versions.scala b/scalalib/src/Versions.scala index 231eb86b..973b05ed 100644 --- a/scalalib/src/Versions.scala +++ b/scalalib/src/Versions.scala @@ -2,7 +2,7 @@ package mill.scalalib object Versions { // Keep synchronized with ammonite dependency in core in build.sc - val ammonite = "1.6.0" + val ammonite = "1.6.7" // Keep synchronized with zinc dependency in scalalib.worker in build.sc val zinc = "1.2.5" } diff --git a/scalalib/src/ZincWorkerModule.scala b/scalalib/src/ZincWorkerModule.scala index 50d37611..4c94102c 100644 --- a/scalalib/src/ZincWorkerModule.scala +++ b/scalalib/src/ZincWorkerModule.scala @@ -1,6 +1,6 @@ package mill.scalalib -import coursier.Cache + import coursier.maven.MavenRepository import mill.Agg import mill.T @@ -17,7 +17,7 @@ object ZincWorkerModule extends mill.define.ExternalModule with ZincWorkerModule } trait ZincWorkerModule extends mill.Module{ def repositories = Seq( - Cache.ivy2Local, + coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2"), MavenRepository("https://oss.sonatype.org/content/repositories/releases") ) @@ -69,11 +69,10 @@ trait ZincWorkerModule extends mill.Module{ instance.asInstanceOf[mill.scalalib.api.ZincWorkerApi] } - private val Milestone213 = raw"""2.13.(\d+)-M(\d+)""".r def scalaCompilerBridgeSourceJar(scalaVersion: String, scalaOrganization: String) = { val (scalaVersion0, scalaBinaryVersion0) = scalaVersion match { - case Milestone213(_, _) => ("2.13.0-M2", "2.13.0-M2") + case s if s.startsWith("2.13.") => ("2.13.0-M2", "2.13.0-M2") case _ => (scalaVersion, mill.scalalib.api.Util.scalaBinaryVersion(scalaVersion)) } diff --git a/scalalib/src/dependency/metadata/MavenMetadataLoader.scala b/scalalib/src/dependency/metadata/MavenMetadataLoader.scala index 491911bf..e40337fc 100644 --- a/scalalib/src/dependency/metadata/MavenMetadataLoader.scala +++ b/scalalib/src/dependency/metadata/MavenMetadataLoader.scala @@ -1,6 +1,5 @@ package mill.scalalib.dependency.metadata -import coursier.Cache import coursier.maven.MavenRepository import coursier.util.Task import mill.scalalib.dependency.versions.Version @@ -8,14 +7,14 @@ import mill.scalalib.dependency.versions.Version private[dependency] final case class MavenMetadataLoader(mavenRepo: MavenRepository) extends MetadataLoader { - private val fetch = Cache.fetch[Task]() + private val fetch = coursier.cache.FileCache[Task].fetch override def getVersions(module: coursier.Module): List[Version] = { import scala.concurrent.ExecutionContext.Implicits.global // TODO fallback to 'versionsFromListing' if 'versions' doesn't work? (needs to be made public in coursier first) val allVersions = mavenRepo.versions(module, fetch).run.unsafeRun allVersions - .map(_.available.map(Version(_))) + .map(_._1.available.map(Version(_))) .getOrElse(List.empty) } } diff --git a/scalalib/src/publish/SonatypeHttpApi.scala b/scalalib/src/publish/SonatypeHttpApi.scala index 12defa93..217d556e 100644 --- a/scalalib/src/publish/SonatypeHttpApi.scala +++ b/scalalib/src/publish/SonatypeHttpApi.scala @@ -5,18 +5,10 @@ import java.util.Base64 import scala.concurrent.duration._ -import scalaj.http.{BaseHttp, HttpOptions, HttpRequest, HttpResponse} - -object PatientHttp - extends BaseHttp( - options = Seq( - HttpOptions.connTimeout(5.seconds.toMillis.toInt), - HttpOptions.readTimeout(1.minute.toMillis.toInt), - HttpOptions.followRedirects(false) - ) - ) + class SonatypeHttpApi(uri: String, credentials: String) { + val http = requests.Session(connectTimeout = 5000, readTimeout = 1000, maxRedirects = 0) private val base64Creds = base64(credentials) @@ -29,12 +21,19 @@ class SonatypeHttpApi(uri: String, credentials: String) { // https://oss.sonatype.org/nexus-staging-plugin/default/docs/path__staging_profiles.html def getStagingProfileUri(groupId: String): String = { val response = withRetry( - PatientHttp(s"$uri/staging/profiles").headers(commonHeaders)) - .throwError + http.get( + s"$uri/staging/profiles", + headers = commonHeaders + ) + ) + + if (!response.is2xx) { + throw new Exception(s"$uri/staging/profiles returned ${response.statusCode}") + } val resourceUri = ujson - .read(response.body)("data") + .read(response.data.text)("data") .arr .find(profile => groupId.split('.').startsWith(profile("name").str.split('.'))) @@ -47,79 +46,84 @@ class SonatypeHttpApi(uri: String, credentials: String) { } def getStagingRepoState(stagingRepoId: String): String = { - val response = PatientHttp(s"${uri}/staging/repository/${stagingRepoId}") - .option(HttpOptions.readTimeout(60000)) - .headers(commonHeaders) - .asString - .throwError - - ujson.read(response.body)("type").str.toString + val response = http.get( + s"${uri}/staging/repository/${stagingRepoId}", + readTimeout = 60000, + headers = commonHeaders + ) + ujson.read(response.data.text)("type").str.toString } // https://oss.sonatype.org/nexus-staging-plugin/default/docs/path__staging_profiles_-profileIdKey-_start.html def createStagingRepo(profileUri: String, groupId: String): String = { - val response = withRetry(PatientHttp(s"${profileUri}/start") - .headers(commonHeaders) - .postData( - s"""{"data": {"description": "fresh staging profile for ${groupId}"}}""")) - .throwError + val response = http.post( + s"${profileUri}/start", + headers = commonHeaders, + data = s"""{"data": {"description": "fresh staging profile for ${groupId}"}}""" + ) - ujson.read(response.body)("data")("stagedRepositoryId").str.toString + if (!response.is2xx) { + throw new Exception(s"$uri/staging/profiles returned ${response.statusCode}") + } + + ujson.read(response.data.text)("data")("stagedRepositoryId").str.toString } // https://oss.sonatype.org/nexus-staging-plugin/default/docs/path__staging_profiles_-profileIdKey-_finish.html def closeStagingRepo(profileUri: String, repositoryId: String): Boolean = { val response = withRetry( - PatientHttp(s"${profileUri}/finish") - .headers(commonHeaders) - .postData( - s"""{"data": {"stagedRepositoryId": "${repositoryId}", "description": "closing staging repository"}}""" - )) + http.post( + s"${profileUri}/finish", + headers = commonHeaders, + data = s"""{"data": {"stagedRepositoryId": "${repositoryId}", "description": "closing staging repository"}}""" + ) + ) - response.code == 201 + response.statusCode == 201 } // https://oss.sonatype.org/nexus-staging-plugin/default/docs/path__staging_profiles_-profileIdKey-_promote.html def promoteStagingRepo(profileUri: String, repositoryId: String): Boolean = { val response = withRetry( - PatientHttp(s"${profileUri}/promote") - .headers(commonHeaders) - .postData( - s"""{"data": {"stagedRepositoryId": "${repositoryId}", "description": "promote staging repository"}}""" - )) + http.post( + s"${profileUri}/promote", + headers = commonHeaders, + data = s"""{"data": {"stagedRepositoryId": "${repositoryId}", "description": "promote staging repository"}}""" + ) + ) - response.code == 201 + response.statusCode == 201 } // https://oss.sonatype.org/nexus-staging-plugin/default/docs/path__staging_profiles_-profileIdKey-_drop.html def dropStagingRepo(profileUri: String, repositoryId: String): Boolean = { val response = withRetry( - PatientHttp(s"${profileUri}/drop") - .headers(commonHeaders) - .postData( - s"""{"data": {"stagedRepositoryId": "${repositoryId}", "description": "drop staging repository"}}""" - )) - - response.code == 201 + http.post( + s"${profileUri}/drop", + headers = commonHeaders, + data = s"""{"data": {"stagedRepositoryId": "${repositoryId}", "description": "drop staging repository"}}""" + ) + ) + response.statusCode == 201 } private val uploadTimeout = 5.minutes.toMillis.toInt - def upload(uri: String, data: Array[Byte]): HttpResponse[String] = { - PatientHttp(uri) - .option(HttpOptions.readTimeout(uploadTimeout)) - .method("PUT") - .headers( + def upload(uri: String, data: Array[Byte]): requests.Response = { + http.put( + uri, + readTimeout = uploadTimeout, + headers = Seq( "Content-Type" -> "application/binary", "Authorization" -> s"Basic ${base64Creds}" - ) - .put(data) - .asString + ), + data = data + ) } - private def withRetry(request: HttpRequest, - retries: Int = 10): HttpResponse[String] = { - val resp = request.asString + private def withRetry(request: => requests.Response, + retries: Int = 10): requests.Response = { + val resp = request if (resp.is5xx && retries > 0) { Thread.sleep(500) withRetry(request, retries - 1) diff --git a/scalalib/src/publish/SonatypePublisher.scala b/scalalib/src/publish/SonatypePublisher.scala index 6dcadd5b..5ca8f5c1 100644 --- a/scalalib/src/publish/SonatypePublisher.scala +++ b/scalalib/src/publish/SonatypePublisher.scala @@ -5,7 +5,6 @@ import java.security.MessageDigest import mill.api.Logger import os.Shellable -import scalaj.http.HttpResponse class SonatypePublisher(uri: String, snapshotUri: String, @@ -105,13 +104,13 @@ class SonatypePublisher(uri: String, } } - private def reportPublishResults(publishResults: Seq[HttpResponse[String]], + private def reportPublishResults(publishResults: Seq[requests.Response], artifacts: Seq[Artifact]) = { if (publishResults.forall(_.is2xx)) { log.info(s"Published ${artifacts.map(_.id).mkString(", ")} to Sonatype") } else { val errors = publishResults.filterNot(_.is2xx).map { response => - s"Code: ${response.code}, message: ${response.body}" + s"Code: ${response.statusCode}, message: ${response.data.text}" } throw new RuntimeException( s"Failed to publish ${artifacts.map(_.id).mkString(", ")} to Sonatype. Errors: \n${errors.mkString("\n")}" diff --git a/scalalib/src/publish/settings.scala b/scalalib/src/publish/settings.scala index bca81cf0..d2801752 100644 --- a/scalalib/src/publish/settings.scala +++ b/scalalib/src/publish/settings.scala @@ -23,13 +23,13 @@ object Artifact { ) Dependency( Artifact( - dep.dep.module.organization, + dep.dep.module.organization.value, name, dep.dep.version ), Scope.Compile, - if (dep.dep.configuration == "") None else Some(dep.dep.configuration), - dep.dep.exclusions.toList + if (dep.dep.configuration == "") None else Some(dep.dep.configuration.value), + dep.dep.exclusions.toList.map{case (a, b) => (a.value, b.value)} ) } } diff --git a/scalalib/test/src/GenIdeaTests.scala b/scalalib/test/src/GenIdeaTests.scala index f8d9a0ed..60c9f9a8 100644 --- a/scalalib/test/src/GenIdeaTests.scala +++ b/scalalib/test/src/GenIdeaTests.scala @@ -1,6 +1,5 @@ package mill.scalalib -import coursier.Cache import mill._ import mill.util.{TestEvaluator, TestUtil} import utest._ @@ -57,6 +56,6 @@ object GenIdeaTests extends TestSuite { private def normaliseLibraryPaths(in: String): String = { - in.replaceAll(Cache.default.toPath.toAbsolutePath.toString, "COURSIER_HOME") + in.replaceAll(coursier.paths.CoursierPaths.cacheDirectory().toString, "COURSIER_HOME") } } diff --git a/scalalib/test/src/HelloWorldTests.scala b/scalalib/test/src/HelloWorldTests.scala index da08f056..57750991 100644 --- a/scalalib/test/src/HelloWorldTests.scala +++ b/scalalib/test/src/HelloWorldTests.scala @@ -766,7 +766,7 @@ object HelloWorldTests extends TestSuite { resourcePath = helloWorldMultiResourcePath ) - 'writeFirstWhenNoRule - { + 'writeDownstreamWhenNoRule - { 'withDeps - workspaceTest(HelloWorldAkkaHttpNoRules) { eval => val Right((result, _)) = eval.apply(HelloWorldAkkaHttpNoRules.core.assembly) @@ -802,11 +802,11 @@ object HelloWorldTests extends TestSuite { val referenceContent = readFileFromJar(jarFile, "reference.conf") assert( - referenceContent.contains("Model Reference Config File"), - referenceContent.contains("foo.bar=2"), + !referenceContent.contains("Model Reference Config File"), + !referenceContent.contains("foo.bar=2"), - !referenceContent.contains("Core Reference Config File"), - !referenceContent.contains("bar.baz=hello") + referenceContent.contains("Core Reference Config File"), + referenceContent.contains("bar.baz=hello") ) } } diff --git a/scalalib/test/src/ResolveDepsTests.scala b/scalalib/test/src/ResolveDepsTests.scala index ce905907..94b8adb9 100644 --- a/scalalib/test/src/ResolveDepsTests.scala +++ b/scalalib/test/src/ResolveDepsTests.scala @@ -1,6 +1,5 @@ package mill.scalalib -import coursier.Cache import coursier.maven.MavenRepository import mill.api.Result.{Failure, Success} import mill.eval.{PathRef, Result} @@ -8,7 +7,7 @@ import mill.api.Loose.Agg import utest._ object ResolveDepsTests extends TestSuite { - val repos = Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")) + val repos = Seq(coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")) def evalDeps(deps: Agg[Dep]): Result[Agg[PathRef]] = Lib.resolveDependencies( repos, diff --git a/scalalib/test/src/dependency/metadata/MetadataLoaderFactoryTests.scala b/scalalib/test/src/dependency/metadata/MetadataLoaderFactoryTests.scala index 4c2206b8..af2ea617 100644 --- a/scalalib/test/src/dependency/metadata/MetadataLoaderFactoryTests.scala +++ b/scalalib/test/src/dependency/metadata/MetadataLoaderFactoryTests.scala @@ -28,8 +28,8 @@ */ package mill.scalalib.dependency.metadata -import coursier.Fetch.Content -import coursier.core.{Artifact, Module, Project, Repository} +import coursier.Fetch +import coursier.core.{Artifact, Classifier, Dependency, Module, Project, Repository} import coursier.ivy.IvyRepository import coursier.maven.MavenRepository import coursier.util.{EitherT, Monad} @@ -57,8 +57,12 @@ object MetadataLoaderFactoryTests extends TestSuite { } case class CustomRepository() extends Repository { - override def find[F[_]](module: Module, version: String, fetch: Content[F])( - implicit F: Monad[F]): EitherT[F, String, (Artifact.Source, Project)] = + override def find[F[_]](module: Module, version: String, fetch: coursier.Repository.Fetch[F]) + (implicit F: Monad[F]): EitherT[F, String, (Artifact.Source, Project)] = ??? + + override def artifacts(dependency: Dependency, + project: Project, + overrideClassifiers: Option[Seq[Classifier]]) = ??? } } diff --git a/scalalib/test/src/dependency/updates/UpdatesFinderTests.scala b/scalalib/test/src/dependency/updates/UpdatesFinderTests.scala index 7b6e6e36..3b613bcb 100644 --- a/scalalib/test/src/dependency/updates/UpdatesFinderTests.scala +++ b/scalalib/test/src/dependency/updates/UpdatesFinderTests.scala @@ -37,7 +37,10 @@ object UpdatesFinderTests extends TestSuite { available: Seq[String], allowPreRelease: Boolean) = { val dependency = coursier.Dependency( - coursier.Module("com.example.organization", "example-artifact"), + coursier.Module( + coursier.Organization("com.example.organization"), + coursier.ModuleName("example-artifact") + ), current) val currentVersion = Version(current) val allVersions = available.map(Version(_)).toSet diff --git a/scalanativelib/src/ScalaNativeModule.scala b/scalanativelib/src/ScalaNativeModule.scala index 38525032..b04b00a1 100644 --- a/scalanativelib/src/ScalaNativeModule.scala +++ b/scalanativelib/src/ScalaNativeModule.scala @@ -3,7 +3,6 @@ package scalanativelib import java.net.URLClassLoader -import coursier.Cache import coursier.maven.MavenRepository import mill.define.{Target, Task} import mill.api.Result @@ -50,7 +49,7 @@ trait ScalaNativeModule extends ScalaModule { outer => Result.Success(Agg(workerPath.split(',').map(p => PathRef(os.Path(p), quick = true)): _*)) else Lib.resolveDependencies( - Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), + Seq(coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), Lib.depToDependency(_, "2.12.4", ""), Seq(ivy"com.lihaoyi::mill-scalanativelib-worker-${scalaNativeBinaryVersion()}:${sys.props("MILL_VERSION")}"), ctx = Some(implicitly[mill.util.Ctx.Log]) @@ -82,7 +81,7 @@ trait ScalaNativeModule extends ScalaModule { outer => def bridgeFullClassPath = T { Lib.resolveDependencies( - Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), + Seq(coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), Lib.depToDependency(_, scalaVersion(), platformSuffix()), toolsIvyDeps(), ctx = Some(implicitly[mill.util.Ctx.Log]) @@ -202,7 +201,7 @@ trait TestScalaNativeModule extends ScalaNativeModule with TestModule { testOute Lib.resolveDependencies( repositories, Lib.depToDependency(_, scalaVersion(), ""), - transitiveIvyDeps().filter(d => d.cross.isBinary && supportedTestFrameworks(d.dep.module.name)), + transitiveIvyDeps().filter(d => d.cross.isBinary && supportedTestFrameworks(d.dep.module.name.value)), ctx = Some(implicitly[mill.util.Ctx.Log]) ) } diff --git a/scratch/build.sc b/scratch/build.sc index 0a33c86e..d9271f2d 100644 --- a/scratch/build.sc +++ b/scratch/build.sc @@ -1,31 +1,7 @@ import mill.Agg import mill.scalalib._ -trait JUnitTests extends TestModule{ - def testFrameworks = Seq("com.novocode.junit.JUnitFramework") - - /** - * Overriden ivyDeps Docs!!! - */ - def ivyDeps = Agg(ivy"com.novocode:junit-interface:0.11") - def task = T{ - "???" - } -} - -/** - * The Core Module Docz! - */ -object core extends JavaModule{ - object test extends Tests with JUnitTests - - /** - * Core Task Docz! - */ - def task = T{ - import collection.JavaConverters._ - println(this.getClass.getClassLoader.getResources("scalac-plugin.xml").asScala.toList) - "Hello!" - } +object core extends ScalaModule{ + def scalaVersion = "2.13.0-RC2" } |