summaryrefslogtreecommitdiff
path: root/core
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 /core
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
Diffstat (limited to 'core')
-rw-r--r--core/src/mill/main/Resolve.scala12
-rw-r--r--core/src/mill/modules/Jvm.scala48
2 files changed, 33 insertions, 27 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)
}