@@ -18,9 +18,14 @@ package io.spring.github.event
1818
1919import  io.spring.github.api.* 
2020import  org.springframework.stereotype.Component 
21+ import  org.w3c.dom.Document 
2122import  reactor.core.publisher.Flux 
2223import  reactor.core.publisher.Mono 
2324import  java.util.* 
25+ import  javax.xml.parsers.DocumentBuilderFactory 
26+ import  javax.xml.xpath.XPath 
27+ import  javax.xml.xpath.XPathConstants 
28+ import  javax.xml.xpath.XPathFactory 
2429
2530/* *
2631 * @author Rob Winch 
@@ -56,13 +61,28 @@ class DefaultBackportService(val github: GitHubApi) : BackportService {
5661
5762    private  fun  findMilestoneTitle (ref :  BranchRef ): Mono <String > {
5863        return  this .github.findFile(ref, " gradle.properties"  )
59-                 .map { input  -> 
64+                 .map { file  -> 
6065                    val  p =  Properties ()
61-                     p.load(input)
62-                     val  version =  p.getProperty(" version"  )
63-                     version.replace(" .BUILD-SNAPSHOT"  , " "  ).replace(" -SNAPSHOT"  , " "  )
66+                     p.load(file)
67+                     p.getProperty(" version"  )
6468                }
65-                 .switchIfEmpty(Mono .error { IllegalStateException (" Cannot find file gradle.properties for $ref "  ) })
69+             	.switchIfEmpty(Mono .defer {
70+                     this .github.findFile(ref, " pom.xml"  )
71+                     .map { file -> 
72+                         val  builderFactory =  DocumentBuilderFactory .newInstance()
73+                         val  builder =  builderFactory.newDocumentBuilder()
74+                         val  xmlDocument:  Document  =  builder.parse(file)
75+ 
76+                         val  xPath:  XPath  =  XPathFactory .newInstance().newXPath()
77+                         var  version =  xPath.compile(" /project/properties/revision"  ).evaluate(xmlDocument)
78+                         if  (version ==  null ) {
79+                             version =  xPath.compile(" /project/version"  ).evaluate(xmlDocument)
80+                         }
81+                         version
82+                     }
83+                 })
84+                 .map { it.replace(" .BUILD-SNAPSHOT"  , " "  ).replace(" -SNAPSHOT"  , " "  ) }
85+                 .switchIfEmpty(Mono .error { IllegalStateException (" Cannot find 'gradle.properties' or 'pom.xml' for $ref "  ) })
6686    }
6787
6888    private  fun  findMilestoneNumberByTitle (repositoryRef :  RepositoryRef , title :  String ): Mono <Int > {
0 commit comments