Add null check

This commit is contained in:
Naoki Takezoe
2017-07-25 12:35:41 +09:00
parent 5b245978d4
commit 2a83c1b9ba

View File

@@ -134,23 +134,25 @@ class InitializeListener extends ServletContextListener with SystemSettingsServi
val cl = Thread.currentThread.getContextClassLoader val cl = Thread.currentThread.getContextClassLoader
try { try {
using(cl.getResourceAsStream("plugins/plugins.json")){ pluginsFile => using(cl.getResourceAsStream("plugins/plugins.json")){ pluginsFile =>
val pluginsJson = IOUtils.toString(pluginsFile, "UTF-8") if(pluginsFile != null){
val pluginsJson = IOUtils.toString(pluginsFile, "UTF-8")
FileUtils.forceMkdir(PluginRepository.LocalRepositoryDir) FileUtils.forceMkdir(PluginRepository.LocalRepositoryDir)
FileUtils.write(PluginRepository.LocalRepositoryIndexFile, pluginsJson, "UTF-8") FileUtils.write(PluginRepository.LocalRepositoryIndexFile, pluginsJson, "UTF-8")
val plugins = PluginRepository.parsePluginJson(pluginsJson) val plugins = PluginRepository.parsePluginJson(pluginsJson)
plugins.foreach { plugin => plugins.foreach { plugin =>
plugin.versions.sortBy { x => Semver.valueOf(x.version) }.reverse.zipWithIndex.foreach { case (version, i) => plugin.versions.sortBy { x => Semver.valueOf(x.version) }.reverse.zipWithIndex.foreach { case (version, i) =>
val file = new File(PluginRepository.LocalRepositoryDir, version.file) val file = new File(PluginRepository.LocalRepositoryDir, version.file)
if(!file.exists) { if(!file.exists) {
logger.info(s"Copy ${plugin} to ${file.getAbsolutePath}") logger.info(s"Copy ${plugin} to ${file.getAbsolutePath}")
FileUtils.forceMkdirParent(file) FileUtils.forceMkdirParent(file)
using(cl.getResourceAsStream("plugins/" + version.file), new FileOutputStream(file)){ case (in, out) => IOUtils.copy(in, out) } using(cl.getResourceAsStream("plugins/" + version.file), new FileOutputStream(file)){ case (in, out) => IOUtils.copy(in, out) }
if(plugin.default && i == 0){ if(plugin.default && i == 0){
logger.info(s"Enable ${file.getName} in default") logger.info(s"Enable ${file.getName} in default")
FileUtils.copyFile(file, new File(PluginHome, version.file)) FileUtils.copyFile(file, new File(PluginHome, version.file))
}
} }
} }
} }