Skip to content

Commit

Permalink
Merge branch 'zowe-release/v2.0.2' into zowe-release/v2.1.0
Browse files Browse the repository at this point in the history
Signed-off-by: Uladzislau <[email protected]>
  • Loading branch information
KUGDev committed Nov 14, 2024
2 parents 0d11bfc + b4f91e6 commit 0871dae
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to the Zowe Explorer plug-in for IntelliJ IDEA will be docum

### Bugfixes

* Bugfix: Fixed IDE error in case of invalid Zowe config ([71b495c4](https://github.com/zowe/zowe-explorer-intellij/commit/71b495c4))
* Bugfix: Fixed FileNotFoundException for Zowe config ([d4665459](https://github.com/zowe/zowe-explorer-intellij/commit/d4665459))
* Bugfix: Fixed NullPointerException during a sort action ([42c9ee5a](https://github.com/zowe/zowe-explorer-intellij/commit/42c9ee5a))
* Bugfix: Fixed issue with purge that won't trigger a refresh ([b93118b7](https://github.com/zowe/zowe-explorer-intellij/commit/b93118b7))
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ val plugins = listOf(
jvmTargetVersion = JavaVersion.VERSION_21,
since = "243.12818",
getUntil = { provider { null } },
sdkVersion = "243-EAP-SNAPSHOT",
sdkVersion = "2024.3",
sourceFolder = "IC-243"
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package org.zowe.explorer.config.connect.ui.zosmf

import com.google.gson.JsonSyntaxException
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.options.BoundSearchableConfigurable
Expand All @@ -35,6 +38,7 @@ import org.zowe.explorer.config.connect.Credentials
import org.zowe.explorer.config.ws.FilesWorkingSetConfig
import org.zowe.explorer.config.ws.JesWorkingSetConfig
import org.zowe.explorer.config.ws.WorkingSetConfig
import org.zowe.explorer.telemetry.NotificationsService
import org.zowe.explorer.utils.crudable.getAll
import org.zowe.explorer.utils.isThe
import org.zowe.explorer.utils.runWriteActionInEdtAndWait
Expand Down Expand Up @@ -110,7 +114,16 @@ class ZOSMFConnectionConfigurable : BoundSearchableConfigurable("z/OSMF Connecti
return
}

val zoweConfig = parseConfigJson(configFile.inputStream)
val zoweConfig = try {
parseConfigJson(configFile.inputStream)
} catch (e: JsonSyntaxException) {
NotificationsService.errorNotification(
e,
project = DataManager.getInstance().getDataContext(panel).getData(PlatformDataKeys.PROJECT),
custTitle = "Error with Zowe config file"
)
return
}
zoweConfig.extractSecureProperties(configFile.path.split("/").toTypedArray())
kotlin.runCatching {
zoweConfig.updateFromState(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.zowe.explorer.zowe.actions

import com.intellij.icons.AllIcons
import com.google.gson.JsonSyntaxException
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
Expand Down Expand Up @@ -85,12 +86,17 @@ class UpdateZoweConfigAction : DumbAwareAction() {
zoweConfigService.localZoweConfig
else
zoweConfigService.globalZoweConfig
if (type == ZoweConfigType.LOCAL) {
zoweConfigService.localZoweConfig = parseConfigJson(editor.document.text)
zoweConfigService.localZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray())
} else {
zoweConfigService.globalZoweConfig = parseConfigJson(editor.document.text)
zoweConfigService.globalZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray())
try {
if (type == ZoweConfigType.LOCAL) {
zoweConfigService.localZoweConfig = parseConfigJson(editor.document.text)
zoweConfigService.localZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray())
} else {
zoweConfigService.globalZoweConfig = parseConfigJson(editor.document.text)
zoweConfigService.globalZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray())
}
} catch (ex: JsonSyntaxException) {
e.presentation.isEnabledAndVisible = false
return
}
val zoweState = zoweConfigService.getZoweConfigState(false, type = type)
if (zoweState == ZoweConfigState.NEED_TO_ADD) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
}
}
} catch (e: Exception) {
throw Exception("Cannot parse $type Zowe config file")
NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file")
return null
}
}

Expand Down Expand Up @@ -283,7 +284,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
}
}
} catch (e: Exception) {
NotificationsService.getService().notifyError(e)
NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file")
}
}

Expand Down Expand Up @@ -362,7 +363,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
}

} catch (e: Exception) {
NotificationsService.getService().notifyError(e)
NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file")
}
}

Expand Down Expand Up @@ -470,11 +471,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
*/
override fun getZoweConfigState(scanProject: Boolean, type: ZoweConfigType): ZoweConfigState {
if (scanProject) {
try {
scanForZoweConfig(type)
} catch (e: Exception) {
NotificationsService.getService().notifyError(e)
}
scanForZoweConfig(type)
}
val zoweConfig = if (type == ZoweConfigType.LOCAL)
localZoweConfig ?: return ZoweConfigState.NOT_EXISTS
Expand Down
15 changes: 15 additions & 0 deletions src/test/kotlin/org/zowe/explorer/config/ZoweConfigTestSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ class ZoweConfigTestSpec : WithApplicationShouldSpec({
Optional.of(ConnectionConfig())
}

val notificationsService = NotificationsService.getService() as TestNotificationsServiceImpl
notificationsService.testInstance = object : TestNotificationsServiceImpl() {
override fun notifyError(
t: Throwable,
project: Project?,
custTitle: String?,
custDetailsShort: String?,
custDetailsLong: String?
) {
if (custTitle == "Error with Zowe config file") {
notified = true
}
}
}

afterEach {
isFilesWriteTriggered = false
isRunWriteActionCalled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package org.zowe.explorer.config.connect.ui.zosmf

import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.Messages
Expand All @@ -29,7 +32,9 @@ import org.zowe.explorer.common.ui.ValidatingTableView
import org.zowe.explorer.config.ConfigStateV2
import org.zowe.explorer.config.connect.ConnectionConfig
import org.zowe.explorer.config.makeCrudableWithoutListeners
import org.zowe.explorer.telemetry.NotificationsService
import org.zowe.explorer.testutils.WithApplicationShouldSpec
import org.zowe.explorer.testutils.testServiceImpl.TestNotificationsServiceImpl
import org.zowe.kotlinsdk.annotations.ZVersion
import org.zowe.kotlinsdk.zowe.config.DefaultKeytarWrapper
import org.zowe.kotlinsdk.zowe.config.KeytarWrapper
Expand All @@ -49,6 +54,7 @@ class ZOSMFConnectionConfigurableTest : WithApplicationShouldSpec({
var isShowOkCancelDialogCalled = false
var isFindFileByNioPathCalled = false
var isInputStreamCalled = false
var notified = false

afterSpec {
clearAllMocks()
Expand All @@ -59,10 +65,26 @@ class ZOSMFConnectionConfigurableTest : WithApplicationShouldSpec({
isShowOkCancelDialogCalled = false
isFindFileByNioPathCalled = false
isInputStreamCalled = false
notified = false
}

context("ZOSMFConnectionConfigurable:") {

val notificationsService = NotificationsService.getService() as TestNotificationsServiceImpl
notificationsService.testInstance = object : TestNotificationsServiceImpl() {
override fun notifyError(
t: Throwable,
project: Project?,
custTitle: String?,
custDetailsShort: String?,
custDetailsLong: String?
) {
if (custTitle == "Error with Zowe config file") {
notified = true
}
}
}

val state = ConnectionDialogState(
connectionUuid = "0000",
connectionUrl = "https://111.111.111.111:111",
Expand Down Expand Up @@ -156,6 +178,42 @@ class ZOSMFConnectionConfigurableTest : WithApplicationShouldSpec({
isFindFileByNioPathCalled = true
vfMock
}
every { vfMock.inputStream } answers {
isInputStreamCalled = true
val fileCont = "{\n" +
" \"\$schema\": \"./zowe.schema.json\",\n" +
" \"profiles\": {\n" +
" \"zosmf\": {\n" +
"}"
fileCont.toByteArray().inputStream()
}
every { vfMock.path } returns "/zowe/file/path/zowe.config.json"
every { vfMock.charset } returns Charsets.UTF_8
every { vfMock.setBinaryContent(any()) } just Runs

mockkObject(ZoweConfig)
val confMap = mutableMapOf<String, MutableMap<String, String>>()
val configCredentialsMap = mutableMapOf<String, String>()
configCredentialsMap["profiles.base.properties.user"] = "testUser"
configCredentialsMap["profiles.base.properties.password"] = "testPass"
confMap.clear()
confMap["/zowe/file/path/zowe.config.json"] = configCredentialsMap
every { ZoweConfig.Companion["readZoweCredentialsFromStorage"](any<KeytarWrapper>()) } returns confMap

should("updateZoweConfigIfNeeded throw JsonSyntaxException") {
zOSMFConnectionConfigurableMock::class.declaredMemberFunctions.find { it.name == "updateZoweConfigIfNeeded" }
?.let {
it.isAccessible = true
try {
it.call(zOSMFConnectionConfigurableMock, state)
} catch (t: Throwable) {
println("ghjkk")
t.cause.toString().shouldContain("Zowe config file not found")
}
}
notified shouldBe true
}

every { vfMock.inputStream } answers {
isInputStreamCalled = true
val fileCont = "{\n" +
Expand Down Expand Up @@ -205,18 +263,6 @@ class ZOSMFConnectionConfigurableTest : WithApplicationShouldSpec({
"}"
fileCont.toByteArray().inputStream()
}
every { vfMock.path } returns "/zowe/file/path/zowe.config.json"
every { vfMock.charset } returns Charsets.UTF_8
every { vfMock.setBinaryContent(any()) } just Runs

mockkObject(ZoweConfig)
val confMap = mutableMapOf<String, MutableMap<String, String>>()
val configCredentialsMap = mutableMapOf<String, String>()
configCredentialsMap["profiles.base.properties.user"] = "testUser"
configCredentialsMap["profiles.base.properties.password"] = "testPass"
confMap.clear()
confMap["/zowe/file/path/zowe.config.json"] = configCredentialsMap
every { ZoweConfig.Companion["readZoweCredentialsFromStorage"](any<KeytarWrapper>()) } returns confMap

should("updateZoweConfigIfNeeded success") {
zOSMFConnectionConfigurableMock::class.declaredMemberFunctions.find { it.name == "updateZoweConfigIfNeeded" }
Expand Down

0 comments on commit 0871dae

Please sign in to comment.