This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
/
Launcher.scala
82 lines (68 loc) · 2.35 KB
/
Launcher.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package org.codeoverflow.chatoverflow
import org.codeoverflow.chatoverflow.ui.CLI.{UI, parse}
import org.codeoverflow.chatoverflow.ui.repl.REPL
import org.codeoverflow.chatoverflow.ui.web.Server
/**
* The launcher object is the entry point to the chat overflow framework.
* All UI and framework related tasks are started here.
*/
object Launcher extends WithLogger {
var server: Option[Server] = None
var pluginDataPath: String = "data"
/**
* Software entry point.
*/
def main(args: Array[String]): Unit = {
parse(args) { config =>
// Set globally available plugin data path
this.pluginDataPath = config.pluginDataPath
// The complete project visible trough one single instance
val chatOverflow = new ChatOverflow(config.pluginFolderPath,
config.configFolderPath, config.requirementPackage, config.requirePasswordOnStartup, config.pluginLogOutputOnConsole)
// Initialize chat overflow
chatOverflow.init()
// Login if a password is specified
if (config.loginPassword.nonEmpty && !chatOverflow.isLoaded) {
chatOverflow.credentialsService.setPassword(config.loginPassword)
chatOverflow.load()
}
// Start plugins if specified
if (chatOverflow.isLoaded && config.startupPlugins.nonEmpty) {
for (instanceName <- config.startupPlugins) {
val instance = chatOverflow.pluginInstanceRegistry.getPluginInstance(instanceName)
if (instance.isEmpty) {
println(s"No plugin instance named '$instanceName' was registered.")
} else {
instance.get.start()
}
}
}
// Launch UI
config.ui match {
case UI.GUI =>
startServer(chatOverflow, config.webServerPort)
case UI.REPL =>
startREPL(chatOverflow)
case UI.BOTH =>
startServer(chatOverflow, config.webServerPort)
startREPL(chatOverflow)
}
}
}
private def startServer(chatOverflow: ChatOverflow, port: Int): Unit = {
if (server.isEmpty) {
server = Some(new Server(chatOverflow, port))
server.get.startAsync()
}
}
private def startREPL(chatOverflow: ChatOverflow): Unit = {
new REPL(chatOverflow).run()
}
/**
* Shuts down the framework.
*/
def exit(): Unit = {
logger info "Shutting down Chat Overflow."
System.exit(0)
}
}