From 02f0c2b639c941c204896cf8418bfc88fbf95300 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 5 Aug 2013 15:33:57 -0700 Subject: [PATCH] Get the version to clean from the pom.xml --- .../boot/cli/GrapesCleaner.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrapesCleaner.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrapesCleaner.java index 52b6571458..244724eaa0 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrapesCleaner.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrapesCleaner.java @@ -18,15 +18,34 @@ package org.springframework.boot.cli; import java.io.File; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + import org.springframework.boot.cli.command.CleanCommand; +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * @author Dave Syer */ public class GrapesCleaner { - // FIXME get the version - private static final String VERSION = "0.5.0.BUILD-SNAPSHOT"; + private static final String VERSION; + static { + try { + File pom = new File("pom.xml"); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(pom); + Element parent = (Element) document.getDocumentElement() + .getElementsByTagName("parent").item(0); + VERSION = parent.getElementsByTagName("version").item(0).getFirstChild() + .getTextContent(); + } + catch (Exception ex) { + throw new RuntimeException(ex); + } + } public static void cleanIfNecessary() throws Exception { File installedJar = new File(getMavenRepository(), String.format(