Commit 86701510 authored by Phillip Webb's avatar Phillip Webb

Fix the way integration tests find version numbers

Update the integration tests so that the version number is found using
the main POM.xml files. Without this change `${revision}` would be
used.

See gh-9316
parent 80562247
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
package org.springframework.boot.context.embedded; package org.springframework.boot.context.embedded;
import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import javax.xml.xpath.XPath; import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.springframework.util.StringUtils;
/** /**
* Provides access to dependency versions by querying the project's pom. * Provides access to dependency versions by querying the project's pom.
* *
...@@ -31,22 +33,25 @@ import org.xml.sax.InputSource; ...@@ -31,22 +33,25 @@ import org.xml.sax.InputSource;
*/ */
final class Versions { final class Versions {
private static final String PROPERTIES = "/*[local-name()='project']/*[local-name()='properties']";
private Versions() { private Versions() {
} }
public static String getBootVersion() { public static String getBootVersion() {
return evaluateExpression( String baseDir = StringUtils.cleanPath(new File(".").getAbsolutePath());
"/*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']" String mainBaseDir = evaluateExpression("pom.xml",
+ "/text()"); PROPERTIES + "/*[local-name()='main.basedir']/text()");
mainBaseDir = mainBaseDir.replace("${basedir}", baseDir);
return evaluateExpression(mainBaseDir + "/pom.xml",
PROPERTIES + "/*[local-name()='revision']/text()");
} }
private static String evaluateExpression(String expression) { private static String evaluateExpression(String file, String expression) {
try { try {
XPathFactory xPathFactory = XPathFactory.newInstance(); InputSource source = new InputSource(new FileReader(file));
XPath xpath = xPathFactory.newXPath(); XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile(expression); return xpath.compile(expression).evaluate(source);
String version = expr.evaluate(new InputSource(new FileReader("pom.xml")));
return version;
} }
catch (Exception ex) { catch (Exception ex) {
throw new IllegalStateException("Failed to evaluate expression", ex); throw new IllegalStateException("Failed to evaluate expression", ex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment