From 9194853749651bb67302b57e1b3e2759f19236bd Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Sat, 18 Mar 2017 16:37:51 +0100 Subject: [PATCH] More loose main class detection Makes it find the main class of scalafmt --- .../main/scala-2.11/coursier/cli/Helper.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cli/src/main/scala-2.11/coursier/cli/Helper.scala b/cli/src/main/scala-2.11/coursier/cli/Helper.scala index 435ea6357..f59f2431d 100644 --- a/cli/src/main/scala-2.11/coursier/cli/Helper.scala +++ b/cli/src/main/scala-2.11/coursier/cli/Helper.scala @@ -763,6 +763,10 @@ class Helper( val (_, mainClass) = mainClasses.head mainClass } else { + + // TODO Move main class detection code to the coursier-extra module to come, add non regression tests for it + // In particular, check the main class for scalafmt, scalafix, ammonite, ... + // Trying to get the main class of the first artifact val mainClassOpt = for { (module, _, _) <- allModuleVersionConfigs.headOption @@ -776,7 +780,17 @@ class Helper( } } yield mainClass - mainClassOpt.getOrElse { + def sameOrgOnlyMainClassOpt = for { + (module, _, _) <- allModuleVersionConfigs.headOption + orgMainClasses = mainClasses.collect { + case ((org, name), mainClass) + if org == module.organization => + mainClass + }.toSet + if orgMainClasses.size == 1 + } yield orgMainClasses.head + + mainClassOpt.orElse(sameOrgOnlyMainClassOpt).getOrElse { Helper.errPrintln(s"Cannot find default main class. Specify one with -M or --main.") sys.exit(255) }