From 5fc920206f751980872e5437ad6d2e24413c60eb Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Tue, 26 Jun 2018 14:30:14 +0200 Subject: [PATCH] Simplify if conditions by using the null-safe operator --- .../com/here/gradle/plugins/jobdsl/RestJobManagement.groovy | 6 ++---- plugin/src/main/resources/seedJobGroovyScript.groovy | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/plugin/src/main/groovy/com/here/gradle/plugins/jobdsl/RestJobManagement.groovy b/plugin/src/main/groovy/com/here/gradle/plugins/jobdsl/RestJobManagement.groovy index e393340..f2ac779 100644 --- a/plugin/src/main/groovy/com/here/gradle/plugins/jobdsl/RestJobManagement.groovy +++ b/plugin/src/main/groovy/com/here/gradle/plugins/jobdsl/RestJobManagement.groovy @@ -365,10 +365,8 @@ class RestJobManagement extends AbstractJobManagement implements DeferredJobMana def folderCredentialsProviderKey = 'com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty' def existingXmlParsed = new XmlParser().parseText(existingXml) def newXmlParsed = new XmlParser().parseText(item.xml) - if (existingXmlParsed.properties != null && - existingXmlParsed.properties."${folderCredentialsProviderKey}".size() > 0 && - newXmlParsed.properties != null && - newXmlParsed.properties."${folderCredentialsProviderKey}".size() == 0) { + if (existingXmlParsed.properties?."${folderCredentialsProviderKey}".size() > 0 && + newXmlParsed.properties?."${folderCredentialsProviderKey}".size() == 0) { def node = existingXmlParsed.properties[0]."${folderCredentialsProviderKey}"[0] as Node newXmlParsed.properties[0].children().add(node) return updateItem(item, XmlUtil.serialize(newXmlParsed)) diff --git a/plugin/src/main/resources/seedJobGroovyScript.groovy b/plugin/src/main/resources/seedJobGroovyScript.groovy index 1229b43..ccc70ef 100644 --- a/plugin/src/main/resources/seedJobGroovyScript.groovy +++ b/plugin/src/main/resources/seedJobGroovyScript.groovy @@ -33,10 +33,8 @@ def updateItem(Item item, String name, FilePath file) { def folderCredentialsProviderKey = 'com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty' def existingXmlParsed = new XmlParser().parseText(oldConfig) def newXmlParsed = new XmlParser().parseText(newConfig) - if (existingXmlParsed.properties != null && - existingXmlParsed.properties."${folderCredentialsProviderKey}".size() > 0 && - newXmlParsed.properties != null && - newXmlParsed.properties."${folderCredentialsProviderKey}".size() == 0) { + if (existingXmlParsed.properties?."${folderCredentialsProviderKey}".size() > 0 && + newXmlParsed.properties?."${folderCredentialsProviderKey}".size() == 0) { def node = existingXmlParsed.properties[0]."${folderCredentialsProviderKey}"[0] as Node newXmlParsed.properties[0].children().add(node) inputStream = new ByteArrayInputStream(XmlUtil.serialize(newXmlParsed).getBytes('UTF-8'))