Skip to content

Commit

Permalink
Simplify if conditions by using the null-safe operator
Browse files Browse the repository at this point in the history
  • Loading branch information
mnonnenmacher committed Jun 26, 2018
1 parent e769fee commit 5fc9202
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions plugin/src/main/resources/seedJobGroovyScript.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 5fc9202

Please sign in to comment.