More loose main class detection

Makes it find the main class of scalafmt
This commit is contained in:
Alexandre Archambault 2017-03-18 16:37:51 +01:00
parent 62d3ed307a
commit 9194853749
1 changed files with 15 additions and 1 deletions

View File

@ -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)
}