Skip to content

Commit

Permalink
Merge pull request #717 from tindzk/issue/716-external-main-classes
Browse files Browse the repository at this point in the history
Interpreter: Allow to run externally-defined main classes
  • Loading branch information
jvican authored Nov 14, 2018
2 parents f635679 + 9b1579c commit f36ae3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
10 changes: 4 additions & 6 deletions frontend/src/main/scala/bloop/engine/Feedback.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ object Feedback {
private final val eol = System.lineSeparator
def listMainClasses(mainClasses: List[String]): String =
s"Use the following main classes:\n${mainClasses.mkString(" * ", s"$eol * ", "")}"
def missingMainClass(project: Project, mainClass: String = ""): String =
s"Missing main class $mainClass in project '${project.name}'"
def missingDefaultMainClass(project: Project, mainClass: String): String =
s"Missing default main class $mainClass in project '${project.name}'"
def expectedMainClass(project: Project): String =
s"Expected a main class via command-line or in the configuration of project '${project.name}'"
def missingMainClass(project: Project): String =
s"No main classes defined in project '${project.name}'"
def expectedDefaultMainClass(project: Project): String =
s"Multiple main classes found. Expected a default main class via command-line or in the configuration of project '${project.name}'"

def missingScalaInstance(project: Project): String =
s"Failed to compile project '${project.name}': found Scala sources but project is missing Scala configuration."
Expand Down
33 changes: 15 additions & 18 deletions frontend/src/main/scala/bloop/engine/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -391,27 +391,24 @@ object Interpreter {
project: Project,
cliMainClass: Option[String]
): Either[State, String] = {
Tasks.findMainClasses(state, project) match {
case Nil => Left(state.withError(Feedback.missingMainClass(project)))
case List(main) => Right(main)
case mainClasses =>
def withS(msg: String): String = msg.suggest(Feedback.listMainClasses(mainClasses))
val configMainClass = project.platform.userMainClass
cliMainClass match {
case Some(userMainClass) if mainClasses.contains(userMainClass) => Right(userMainClass)
case Some(userMainClass) =>
Left(state.withError(withS(Feedback.missingMainClass(project, userMainClass))))
cliMainClass match {
case Some(userMainClass) => Right(userMainClass)
case None =>
project.platform.userMainClass match {
case Some(configMainClass) => Right(configMainClass)
case None =>
configMainClass match {
case Some(configMainClass) if mainClasses.contains(configMainClass) =>
Right(configMainClass)
case Some(configMainClass) =>
val msg = withS(Feedback.missingDefaultMainClass(project, configMainClass))
Left(state.withError(msg))
case None =>
val msg = withS(Feedback.expectedMainClass(project))
Tasks.findMainClasses(state, project) match {
case Nil =>
val msg = Feedback.missingMainClass(project)
Left(state.withError(msg, ExitStatus.InvalidCommandLineOption))
case List(mainClass) => Right(mainClass)
case mainClasses =>
val msg = Feedback
.expectedDefaultMainClass(project)
.suggest(Feedback.listMainClasses(mainClasses))
Left(state.withError(msg, ExitStatus.InvalidCommandLineOption))
}

}
}
}
Expand Down

0 comments on commit f36ae3d

Please sign in to comment.