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

Commit 471dc4d

Browse files
committed
Check if json is valid before parsing to get GUI and Rest api version
1 parent 2613b1d commit 471dc4d

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

build/src/main/scala/org/codeoverflow/chatoverflow/build/GUIUtility.scala

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class GUIUtility(logger: ManagedLogger) {
102102

103103
// contains tuples with the actual file as the first value and the name with directory in the jar as the second value
104104
val jarEntries = files.map(file => file -> s"/chatoverflow-gui/${dir.toURI.relativize(file.toURI).toString}") ++
105-
getVersionFiles(guiProjectPath).map(file => file -> s"/${file.getName}")
105+
getVersionFiles(guiProjectPath).map(file => file -> s"/${file.getName}")
106106

107107
sbt.IO.jar(jarEntries, getGUIJarFile(guiProjectPath, crossTargetDir), new Manifest())
108108
}
@@ -132,24 +132,32 @@ class GUIUtility(logger: ManagedLogger) {
132132
}.getOrElse(None)
133133

134134
private def getGUIVersion(packageJson: JsonNode): Option[String] = {
135-
val version = packageJson.get("version").asText()
135+
if (packageJson.has("version")) {
136+
val version = packageJson.get("version").asText()
136137

137-
if (version.isEmpty) {
138-
logger warn "The GUI version couldn't be loaded from the package.json."
139-
None
138+
if (version.isEmpty) {
139+
logger warn "The GUI version couldn't be loaded from the package.json."
140+
None
141+
} else {
142+
Option(version)
143+
}
140144
} else {
141-
Option(version)
145+
None
142146
}
143147
}
144148

145149
private def getRestVersion(packageJson: JsonNode): Option[String] = {
146-
val version = packageJson.get("dependencies").get("@codeoverflow-org/chatoverflow").asText()
150+
if (packageJson.has("dependencies") && packageJson.get("dependencies").hasNonNull("@codeoverflow-org/chatoverflow")) {
151+
val version = packageJson.get("dependencies").get("@codeoverflow-org/chatoverflow").asText()
147152

148-
if (version.isEmpty) {
149-
logger warn "The used REST api version couldn't be loaded from the package.json."
150-
None
153+
if (version.isEmpty) {
154+
logger warn "The used REST api version couldn't be loaded from the package.json."
155+
None
156+
} else {
157+
Option(version)
158+
}
151159
} else {
152-
Option(version)
160+
None
153161
}
154162
}
155163

@@ -159,12 +167,12 @@ class GUIUtility(logger: ManagedLogger) {
159167
val files = ListBuffer[File]()
160168
val tempDir = sbt.IO.createTemporaryDirectory
161169

162-
getGUIVersion(json.get).foreach {ver =>
170+
getGUIVersion(json.get).foreach { ver =>
163171
val f = new File(tempDir, "version_gui.txt")
164172
sbt.IO.write(f, ver)
165173
files += f
166174
}
167-
getRestVersion(json.get).foreach {ver =>
175+
getRestVersion(json.get).foreach { ver =>
168176
val f = new File(tempDir, "version_gui_rest.txt")
169177
sbt.IO.write(f, ver)
170178
files += f

0 commit comments

Comments
 (0)