SonarVersionExtractor { public String welcomePageVersion(URL url) { try { byte[] byteArray = ByteStreams.toByteArray(url.openStream()); String htmlContent = new String(byteArray); Pattern p = Pattern.compile(".* - v\\.([0-9]\\.[0-9]*.[0-9]*) - .*"); Matcher m = p.matcher(htmlContent); while (m.find()) { return m.group(1); } } catch (IOException e) { return "unknown"; } return "unknown"; }  String propertiesVersion(Properties properties); String welcomePageVersion(URL url);  }
@Test public void should_extract_version_from_sonar_welcome_page_v211() { URL resource = classLoader.getResource("sonar_2.11.html"); String version = sve.welcomePageVersion(resource); assertEquals("2.11", version); }
@Test public void should_extract_version_from_sonar_welcome_page_v201() { URL resource = classLoader.getResource("sonar_2.0.1.html"); String version = sve.welcomePageVersion(resource); assertEquals("2.0.1", version); }
@Test public void should_extract_version_from_sonar_welcome_page_v212() { URL resource = classLoader.getResource("sonar_2.12.html"); String version = sve.welcomePageVersion(resource); assertEquals("2.12", version); }