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

Commit f3bcc6a

Browse files
committed
Add logs to the gui package task and fix some smaller things
1 parent 2c8c678 commit f3bcc6a

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

project/BuildUtility.scala

+20-7
Original file line numberDiff line numberDiff line change
@@ -214,25 +214,38 @@ class BuildUtility(logger: ManagedLogger) {
214214
def packageGUITask(guiProjectPath: String, scalaMajorVersion: String, crossTargetDir: File): Unit = {
215215
val dir = new File(guiProjectPath, "dist")
216216
if (!dir.exists()) {
217+
logger info "GUI hasn't been compiled. Won't create a jar for it."
217218
return
218219
}
219220

220221
val files = recursiveFileListing(dir)
221222

222223
// contains tuples with the actual file as the first value and the name with directory in the jar as the second value
223-
val jarEntries = files.map(file => (file, "/chatoverflow-gui/" + dir.toURI.relativize(file.toURI)))
224+
val jarEntries = files.map(file => file -> s"/chatoverflow-gui/${dir.toURI.relativize(file.toURI).toString}")
224225

225-
val guiVersion = getGUIVersion(guiProjectPath)
226+
val guiVersion = getGUIVersion(guiProjectPath).getOrElse("unknown")
226227

227228
sbt.IO.jar(jarEntries, new File(crossTargetDir, s"chatoverflow-gui_$scalaMajorVersion-$guiVersion.jar"), new Manifest())
228229
}
229230

230-
private def getGUIVersion(guiProjectPath: String): String = {
231-
val packageJson = Source.fromFile(s"$guiProjectPath/package.json")
232-
val version = new ObjectMapper().reader().readTree(packageJson.mkString).get("version").asText()
231+
private def getGUIVersion(guiProjectPath: String): Option[String] = {
232+
val packageJson = new File(s"$guiProjectPath/package.json")
233+
if (!packageJson.exists()) {
234+
logger error "The package.json file of the GUI doesn't exist. Have you cloned the GUI in the correct directory?"
235+
return None
236+
}
237+
238+
val content = Source.fromFile(packageJson)
239+
val version = new ObjectMapper().reader().readTree(content.mkString).get("version").asText()
240+
241+
content.close()
233242

234-
packageJson.close()
235-
version
243+
if (version.isEmpty) {
244+
logger warn "The GUI version couldn't be loaded from the package.json."
245+
None
246+
} else {
247+
Option(version)
248+
}
236249
}
237250

238251
/**

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
22

3-
// JSON Lib (Jackson)
3+
// JSON lib (Jackson) used for parsing the GUI version in the package.json file
44
libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.5.2"

src/main/scala/org/codeoverflow/chatoverflow/ui/web/GUIServlet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GUIServlet extends ScalatraServlet with WithLogger {
2424
// directory couldn't be found
2525
if (res == null) {
2626
logger error "GUI couldn't be found on the classpath! Has the GUI been built?"
27-
null
27+
None
2828
} else {
2929
// remove the path inside the jar and only keep the file path to the jar file
3030
val jarPath = res.getFile.split("!").head

0 commit comments

Comments
 (0)