summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-01-21 13:41:46 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-21 13:41:56 -0800
commitf9f413d82bf81864dafd24d86400646b089bc410 (patch)
tree0e99ab9adfa8f732bf2290a0ffc047dfa9266163
parent0b80a077168293dec684e2cdfe365b3163c76585 (diff)
downloadmill-f9f413d82bf81864dafd24d86400646b089bc410.tar.gz
mill-f9f413d82bf81864dafd24d86400646b089bc410.tar.bz2
mill-f9f413d82bf81864dafd24d86400646b089bc410.zip
- Make `docsJar` and `sourcesJar` more robust against empty inputs
- `sourcesJar` now de-dupes items by default, rather than crashing - Resolving commands now works properly within cross-builds
-rw-r--r--core/src/mill/main/Resolve.scala12
-rw-r--r--core/src/mill/modules/Jvm.scala48
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala24
3 files changed, 45 insertions, 39 deletions
diff --git a/core/src/mill/main/Resolve.scala b/core/src/mill/main/Resolve.scala
index ed4c4f80..3d9c0409 100644
--- a/core/src/mill/main/Resolve.scala
+++ b/core/src/mill/main/Resolve.scala
@@ -24,8 +24,12 @@ object Resolve {
.map(Right(_))
def invokeCommand[V](target: mill.Module, name: String) = {
- for(cmd <- discover.value.get(target.getClass).toSeq.flatten.find(_.name == name))
- yield cmd.asInstanceOf[EntryPoint[mill.Module]].invoke(target, ammonite.main.Scripts.groupArgs(rest.toList)) match {
+
+ for{
+ (cls, entryPoints) <- discover.value.filterKeys(_.isAssignableFrom(target.getClass))
+ ep <- entryPoints
+ if ep.name == name
+ } yield ep.asInstanceOf[EntryPoint[mill.Module]].invoke(target, ammonite.main.Scripts.groupArgs(rest.toList)) match {
case Router.Result.Success(v) => Right(v)
case _ => Left(s"Command failed $last")
}
@@ -35,12 +39,12 @@ object Resolve {
child <- obj.millInternal.reflectNestedObjects[mill.Module]
if child.millOuterCtx.segment == Segment.Label(last)
res <- child match{
- case taskMod: TaskModule => Some(invokeCommand(child, taskMod.defaultCommandName()))
+ case taskMod: TaskModule => Some(invokeCommand(child, taskMod.defaultCommandName()).headOption)
case _ => None
}
} yield res
- val command = invokeCommand(obj, last)
+ val command = invokeCommand(obj, last).headOption
command orElse target orElse runDefault.headOption.flatten match{
case None => Left("Cannot resolve task " +
diff --git a/core/src/mill/modules/Jvm.scala b/core/src/mill/modules/Jvm.scala
index 888a687b..fdd928d7 100644
--- a/core/src/mill/modules/Jvm.scala
+++ b/core/src/mill/modules/Jvm.scala
@@ -162,33 +162,35 @@ object Jvm {
(implicit ctx: Ctx.DestCtx): PathRef = {
val outputPath = ctx.dest
rm(outputPath)
- if(inputPaths.nonEmpty) {
- mkdir(outputPath/up)
+ mkdir(outputPath/up)
- val jar = new JarOutputStream(
- new FileOutputStream(outputPath.toIO),
- createManifest(mainClass)
- )
+ val seen = mutable.Set.empty[RelPath]
+ seen.add("META-INF" / "MANIFEST.MF")
+ val jar = new JarOutputStream(
+ new FileOutputStream(outputPath.toIO),
+ createManifest(mainClass)
+ )
- try{
- assert(inputPaths.forall(exists(_)))
- for{
- p <- inputPaths
- (file, mapping) <-
- if (p.isFile) Iterator(p -> empty/p.last)
- else ls.rec(p).filter(_.isFile).map(sub => sub -> sub.relativeTo(p))
- } {
- val entry = new JarEntry(mapping.toString)
- entry.setTime(file.mtime.toMillis)
- jar.putNextEntry(entry)
- jar.write(read.bytes(file))
- jar.closeEntry()
- }
- } finally {
- jar.close()
+ try{
+ assert(inputPaths.forall(exists(_)))
+ for{
+ p <- inputPaths
+ (file, mapping) <-
+ if (p.isFile) Iterator(p -> empty/p.last)
+ else ls.rec(p).filter(_.isFile).map(sub => sub -> sub.relativeTo(p))
+ if !seen(mapping)
+ } {
+ seen.add(mapping)
+ val entry = new JarEntry(mapping.toString)
+ entry.setTime(file.mtime.toMillis)
+ jar.putNextEntry(entry)
+ jar.write(read.bytes(file))
+ jar.closeEntry()
}
-
+ } finally {
+ jar.close()
}
+
PathRef(outputPath)
}
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index 1b2bd28d..975a5972 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -192,27 +192,27 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
val javadocDir = outDir / 'javadoc
mkdir(javadocDir)
- val options = {
-
- val files = for{
- ref <- sources()
- p <- ls.rec(ref.path)
- if p.isFile
- } yield p.toNIO.toString
- files ++ Seq("-d", javadocDir.toNIO.toString, "-usejavacp")
- }
+ val files = for{
+ ref <- sources()
+ if exists(ref.path)
+ p <- ls.rec(ref.path)
+ if p.isFile
+ } yield p.toNIO.toString
- subprocess(
+
+ val options = Seq("-d", javadocDir.toNIO.toString, "-usejavacp")
+
+ if (files.nonEmpty) subprocess(
"scala.tools.nsc.ScalaDoc",
compileDepClasspath().filter(_.path.ext != "pom").map(_.path),
- options = options.toSeq
+ options = (files ++ options).toSeq
)
createJar(Agg(javadocDir))(outDir / "javadoc.jar")
}
def sourcesJar = T {
- createJar((sources() ++ resources()).map(_.path).filter(exists))(T.ctx().dest / "sources.jar")
+ createJar((allSources() ++ resources()).map(_.path).filter(exists))(T.ctx().dest / "sources.jar")
}
def forkArgs = T{ Seq.empty[String] }