Skip to content

Commit

Permalink
add available main classes to the usage notes in bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
frosforever authored and muuki88 committed Sep 4, 2017
1 parent 366dcfb commit 8e8ead4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Usage: $script_name [options]
In the case of duplicated or conflicting options, basically the order above
shows precedence: JAVA_OPTS lowest, command line options highest except "--".
${{available_main_classes}}
EOM
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ object BashStartScriptPlugin extends AutoPlugin {
log.warn("You have no main class in your project. No start script will be generated.")
Seq.empty
case SingleMain(main) =>
Seq(MainScript(main, config, targetDir) -> s"$scriptTargetFolder/${config.executableScriptName}")
Seq(MainScript(main, config, targetDir, Seq(main)) -> s"$scriptTargetFolder/${config.executableScriptName}")
case MultipleMains(mains) =>
generateMainScripts(discoveredMainClasses, config, targetDir)
generateMainScripts(mains, config, targetDir)
case ExplicitMainWithAdditional(main, additional) =>
(MainScript(main, config, targetDir) -> s"$scriptTargetFolder/${config.executableScriptName}") +:
(MainScript(main, config, targetDir, discoveredMainClasses) -> s"$scriptTargetFolder/${config.executableScriptName}") +:
ForwarderScripts(config.executableScriptName, additional, targetDir)
}

Expand All @@ -135,7 +135,7 @@ object BashStartScriptPlugin extends AutoPlugin {
discoveredMainClasses.map { qualifiedClassName =>
val bashConfig =
config.copy(executableScriptName = makeScriptName(qualifiedClassName))
MainScript(qualifiedClassName, bashConfig, targetDir) -> s"$scriptTargetFolder/${bashConfig.executableScriptName}"
MainScript(qualifiedClassName, bashConfig, targetDir, discoveredMainClasses) -> s"$scriptTargetFolder/${bashConfig.executableScriptName}"
}

private[this] def makeScriptName(qualifiedClassName: String): String = {
Expand Down Expand Up @@ -193,9 +193,12 @@ object BashStartScriptPlugin extends AutoPlugin {
* @param targetDir - Target directory for this script
* @return File pointing to the created main script
*/
def apply(mainClass: String, config: BashScriptConfig, targetDir: File): File = {
def apply(mainClass: String, config: BashScriptConfig, targetDir: File, mainClasses: Seq[String]): File = {
val template = resolveTemplate(config.bashScriptTemplateLocation)
val replacements = Seq("app_mainclass" -> mainClassReplacement(mainClass)) ++ config.bashScriptReplacements
val replacements = Seq(
"app_mainclass" -> mainClassReplacement(mainClass),
"available_main_classes" -> usageMainClassReplacement(mainClasses)
) ++ config.bashScriptReplacements

val scriptContent = TemplateWriter.generateScript(template, replacements)
val script = targetDir / "scripts" / config.executableScriptName
Expand All @@ -214,6 +217,12 @@ object BashStartScriptPlugin extends AutoPlugin {
args.map(s => "\"" + s + "\"").mkString(" ")
}

private[this] def usageMainClassReplacement(mainClasses: Seq[String]): String =
if (mainClasses.nonEmpty)
mainClasses.mkString("Available main classes:\n\t", "\n\t", "")
else
""

private[this] def resolveTemplate(defaultTemplateLocation: File): URL =
if (defaultTemplateLocation.exists) defaultTemplateLocation.toURI.toURL
else getClass.getResource(defaultTemplateLocation.getName)
Expand Down

0 comments on commit 8e8ead4

Please sign in to comment.