Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit ea53193

Browse files
committed
Added more startup options and flags.
1 parent c17b66b commit ea53193

File tree

10 files changed

+56
-27
lines changed

10 files changed

+56
-27
lines changed

src/main/scala/org/codeoverflow/chatoverflow/ChatOverflow.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import org.codeoverflow.chatoverflow.registry.TypeRegistry
2020
*/
2121
class ChatOverflow(val pluginFolderPath: String,
2222
val configFolderPath: String,
23-
val requirementPackage: String)
23+
val requirementPackage: String,
24+
val requirePasswordOnStartup: Boolean,
25+
val logOutputOnConsole: Boolean)
2426
extends WithLogger {
2527

2628
val pluginFramework = new PluginFramework(pluginFolderPath)
27-
val pluginInstanceRegistry = new PluginInstanceRegistry
29+
val pluginInstanceRegistry = new PluginInstanceRegistry(logOutputOnConsole)
2830
val typeRegistry = new TypeRegistry(requirementPackage)
2931
val credentialsService = new CredentialsService(s"$configFolderPath/credentials")
3032
val configService = new ConfigurationService(s"$configFolderPath/config.xml")
@@ -52,11 +54,12 @@ class ChatOverflow(val pluginFolderPath: String,
5254
ConnectorRegistry.setTypeRegistry(typeRegistry)
5355
logger debug "Finished updating type registry."
5456

55-
logger debug "Loading configs and credentials."
56-
// TODO: Add flag for asking for the password on the console prior to the gui
57-
//askForPassword()
58-
//load()
59-
logger debug "Finished loading configs and credentials."
57+
if (requirePasswordOnStartup) {
58+
logger debug "Loading configs and credentials."
59+
askForPassword()
60+
load()
61+
logger debug "Finished loading configs and credentials."
62+
}
6063

6164
logger debug "Finished initialization."
6265
}

src/main/scala/org/codeoverflow/chatoverflow/Launcher.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,37 @@ import org.codeoverflow.chatoverflow.ui.web.Server
1111
object Launcher extends WithLogger {
1212

1313
var server: Option[Server] = None
14+
var pluginDataPath: String = "data"
1415

1516
/**
1617
* Software entry point.
1718
*/
1819
def main(args: Array[String]): Unit = {
1920
parse(args) { config =>
2021

22+
this.pluginDataPath = config.pluginDataPath
23+
2124
// The complete project visible trough one single instance
2225
val chatOverflow = new ChatOverflow(config.pluginFolderPath,
23-
config.configFolderPath, config.requirementPackage)
26+
config.configFolderPath, config.requirementPackage, config.requirePasswordOnStartup, config.pluginLogOutputOnConsole)
2427

2528
chatOverflow.init()
2629

2730
// Launch UI
2831
config.ui match {
2932
case UI.GUI =>
30-
startServer(chatOverflow)
33+
startServer(chatOverflow, config.webServerPort)
3134
case UI.REPL =>
3235
startREPL(chatOverflow)
3336
case UI.BOTH =>
34-
startServer(chatOverflow)
37+
startServer(chatOverflow, config.webServerPort)
3538
startREPL(chatOverflow)
3639
}
3740
}
3841
}
3942

40-
private def startServer(chatOverflow: ChatOverflow): Unit = {
43+
private def startServer(chatOverflow: ChatOverflow, port: Int): Unit = {
4144
if (server.isEmpty) {
42-
// TODO: Enable custom port support
4345
server = Some(new Server(chatOverflow, 2400))
4446
server.get.startAsync()
4547
}

src/main/scala/org/codeoverflow/chatoverflow/configuration/CredentialsService.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scala.collection.mutable
1313
* @param credentialsFilePath the file path of the credentials file
1414
*/
1515
class CredentialsService(val credentialsFilePath: String) extends WithLogger {
16-
private var password = Array[Char]()
16+
private[this] var password = Array[Char]()
1717

1818
/**
1919
* Sets the password. Needed to load or save credentials.
@@ -22,6 +22,11 @@ class CredentialsService(val credentialsFilePath: String) extends WithLogger {
2222
*/
2323
def setPassword(password: Array[Char]): Unit = this.password = password
2424

25+
/**
26+
* Returns true, if a password is set. Note that this says nothing about the correctness of it.
27+
*
28+
* @return true, if the password length is greater than zero
29+
*/
2530
def isLoggedIn: Boolean = {
2631
password.length > 0
2732
}

src/main/scala/org/codeoverflow/chatoverflow/connector/actor/FileSystemActor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.io.{File, PrintWriter}
44
import java.nio.file.Paths
55

66
import akka.actor.Actor
7+
import org.codeoverflow.chatoverflow.Launcher
78
import org.codeoverflow.chatoverflow.connector.actor.FileSystemActor.{CreateDirectory, LoadFile, SaveFile}
89

910
import scala.io.Source
@@ -13,8 +14,7 @@ import scala.io.Source
1314
*/
1415
class FileSystemActor extends Actor {
1516

16-
// TODO: Should be an startup option in the CLI
17-
private val dataFilePath = "data"
17+
private val dataFilePath = Launcher.pluginDataPath
1818

1919
// Create data folder if non existent
2020
private val dataFolder = new File(dataFilePath)

src/main/scala/org/codeoverflow/chatoverflow/framework/manager/PluginManagerImpl.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scala.collection.mutable.ListBuffer
1313
*
1414
* @param pluginInstanceName the name of the plugin instance
1515
*/
16-
class PluginManagerImpl(pluginInstanceName: String) extends PluginManager with WithLogger {
16+
class PluginManagerImpl(pluginInstanceName: String, logOutputOnConsole: Boolean) extends PluginManager with WithLogger {
1717

1818
private val logMessages = new ListBuffer[String]
1919

@@ -24,8 +24,10 @@ class PluginManagerImpl(pluginInstanceName: String) extends PluginManager with W
2424
*/
2525
override def log(message: String): Unit = {
2626
logMessages += message
27-
// TODO: Add disabling plugin messages by flag
28-
logger info s"[$pluginInstanceName] $message"
27+
28+
if (logOutputOnConsole) {
29+
logger info s"[$pluginInstanceName] $message"
30+
}
2931
}
3032

3133
/**

src/main/scala/org/codeoverflow/chatoverflow/instance/PluginInstance.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ class PluginInstance(val instanceName: String, pluginType: PluginType) extends W
231231
* Creates a new plugin instance with the default manager implementation.
232232
* Note: This is instance-private, because non-instantiatable plugins should be not added in the registry
233233
*/
234-
private[instance] def createPluginInstanceWithDefaultManager: Boolean = {
235-
createPluginInstance(new PluginManagerImpl(instanceName))
234+
private[instance] def createPluginInstanceWithDefaultManager(logOutputOnConsole: Boolean): Boolean = {
235+
createPluginInstance(new PluginManagerImpl(instanceName, logOutputOnConsole))
236236
}
237237

238238
/**

src/main/scala/org/codeoverflow/chatoverflow/instance/PluginInstanceRegistry.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.collection.mutable
88
/**
99
* The plugin instance registry does hold all running and not-running instances of plugins.
1010
*/
11-
class PluginInstanceRegistry extends WithLogger {
11+
class PluginInstanceRegistry(logOutputOnConsole: Boolean) extends WithLogger {
1212
private val pluginInstances = mutable.Map[String, PluginInstance]()
1313

1414
/**
@@ -31,7 +31,7 @@ class PluginInstanceRegistry extends WithLogger {
3131
// The plugin instance is created here. Why: A plugin, which could not be created
3232
// e.g. due to version issues or code failures has no reason to be in the list of plugin instances
3333
val instance = new PluginInstance(instanceName, pluginType)
34-
if (instance.createPluginInstanceWithDefaultManager) {
34+
if (instance.createPluginInstanceWithDefaultManager(logOutputOnConsole)) {
3535
pluginInstances += instanceName -> instance
3636
logger info s"Successfully instantiated and added plugin instance '$instanceName' of type '${pluginType.getName}'."
3737
true

src/main/scala/org/codeoverflow/chatoverflow/ui/CLI.scala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ object CLI {
3030
opt[String]('r', "requirementPackage").action((x, c) =>
3131
c.copy(requirementPackage = x)).text("path to the package where all requirements are defined")
3232

33+
// Subject of change. After GUI will be -l (for requireLogin)
34+
opt[Unit]('n', "noPassword").action((_, c) =>
35+
c.copy(requirePasswordOnStartup = false)).text("set this flag to disable password checking on framework startup")
36+
37+
opt[String]('d', "pluginDataFolder").action((x, c) =>
38+
c.copy(pluginDataPath = x)).text("path to the data folder, accessible from within plugins")
39+
40+
opt[Int]('w', "webServerPort").action((x, c) =>
41+
c.copy(webServerPort = x)).text("default web server port, used eg. for the rest api")
42+
43+
// Subject of change. After GUI will be -o (enablePluginOutput)
44+
opt[Unit]('z', "disableLogOutputOnConsole").action((_, c) =>
45+
c.copy(pluginLogOutputOnConsole = false)).text("set this flag to disable plugin log output on console")
46+
3347
help("help").hidden().text("prints this usage text")
3448

3549
note("\nFor more information, please visit http://codeoverflow.org/")
@@ -55,7 +69,11 @@ object CLI {
5569
case class Config(pluginFolderPath: String = "plugins/",
5670
configFolderPath: String = "config/",
5771
requirementPackage: String = "org.codeoverflow.chatoverflow.requirement",
58-
ui: UI = UI.BOTH)
72+
ui: UI = UI.BOTH,
73+
requirePasswordOnStartup: Boolean = true,
74+
pluginDataPath: String = "data",
75+
webServerPort: Int = 2400,
76+
pluginLogOutputOnConsole: Boolean = true)
5977

6078
object UI extends Enumeration {
6179
type UI = Value

src/main/scala/org/codeoverflow/chatoverflow/ui/web/rest/DTOs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object DTOs {
88
case class PluginInstance(instanceName: String, pluginName: String, pluginAuthor: String, isRunning: Boolean, requirementIDs: Seq[String])
99

1010
case class ConfigInfo(name: String, apiMajorVersion: Int, apiMinorVersion: Int, pluginFolderPath: String,
11-
configFolderPath: String, requirementPackage: String)
11+
configFolderPath: String, requirementPackage: String, pluginDataPath: String)
1212

1313
case class Requirement(uniqueRequirementId: String, name: String, isOptional: Boolean, isSet: Boolean, value: String, targetType: String)
1414

src/main/scala/org/codeoverflow/chatoverflow/ui/web/rest/config/ConfigController.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.codeoverflow.chatoverflow.ui.web.rest.config
22

3+
import org.codeoverflow.chatoverflow.Launcher
34
import org.codeoverflow.chatoverflow.api.APIVersion
45
import org.codeoverflow.chatoverflow.ui.web.JsonServlet
56
import org.codeoverflow.chatoverflow.ui.web.rest.DTOs.{ConfigInfo, Password, ResultMessage}
@@ -10,7 +11,7 @@ class ConfigController(implicit val swagger: Swagger) extends JsonServlet with C
1011
get("/", operation(getConfig)) {
1112
ConfigInfo("Chat Overflow", APIVersion.MAJOR_VERSION,
1213
APIVersion.MINOR_VERSION, chatOverflow.pluginFolderPath,
13-
chatOverflow.configFolderPath, chatOverflow.requirementPackage)
14+
chatOverflow.configFolderPath, chatOverflow.requirementPackage, Launcher.pluginDataPath)
1415
}
1516

1617
post("/save", operation(postSave)) {
@@ -36,6 +37,4 @@ class ConfigController(implicit val swagger: Swagger) extends JsonServlet with C
3637
}
3738

3839
// TODO: Handle first time login / Creation of the config files (same as postLogin above...?)
39-
40-
// TODO: After this: Add the flags (pw, log output, data folder) and update the ConfigInfo
4140
}

0 commit comments

Comments
 (0)