PackagingResolver { public Packaging resolve(SonarDistribution distribution) { File zip; Optional<Location> location = distribution.getZipLocation(); if (location.isPresent()) { zip = locators.locate(location.get()); if (zip == null || !zip.exists()) { throw new IllegalStateException(String.format("SonarQube not found at %s", location.get())); } } else { Version version = resolveVersion(distribution.getVersion()); String groupId; String artifactId; if (distribution.getEdition().equals(Edition.COMMUNITY) || !version.isGreaterThanOrEquals(7, 2)) { groupId = PUBLIC_GROUP_ID; artifactId = "sonar-application"; } else { switch (distribution.getEdition()) { case DEVELOPER: groupId = PRIVATE_GROUP_ID; artifactId = "sonarqube-developer"; break; case ENTERPRISE: groupId = PRIVATE_GROUP_ID; artifactId = "sonarqube-enterprise"; break; case DATACENTER: groupId = PRIVATE_GROUP_ID; artifactId = "sonarqube-datacenter"; break; default: throw new IllegalStateException("Unknown SonarQube edition : " + distribution.getEdition()); } } MavenLocation mavenLocation = newMavenLocationOfZip(groupId, artifactId, version.toString()); zip = locators.locate(mavenLocation); if (zip == null || !zip.exists()) { throw new IllegalStateException(String.format("SonarQube %s not found: %s", distribution.getVersion().get(), mavenLocation)); } } return new Packaging(distribution.getEdition(), guessVersionFromZipName(zip), zip); } PackagingResolver(Locators locators); Packaging resolve(SonarDistribution distribution);  }
@Test public void fail_if_version_cant_be_guessed_from_local_zip() throws Exception { File zip = temp.newFile("sonar.zip"); when(locators.locate(any())).thenReturn(zip); SonarDistribution distribution = new SonarDistribution().setZipLocation(FileLocation.of(zip)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Fail to extract version from filename: sonar.zip"); underTest.resolve(distribution); }
@Test public void fail_if_version_alias_cant_be_resolved() { SonarDistribution distribution = new SonarDistribution().setVersion("DOGFOOD"); prepareResolutionOfVersion("org.sonarsource.sonarqube", "sonar-application", "DOGFOOD", Optional.empty()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Version can not be resolved: [org.sonarsource.sonarqube:sonar-application:DOGFOOD:zip]"); underTest.resolve(distribution); }
@Test public void fail_if_zip_not_found() { when(locators.locate(any())).thenReturn(null); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("SonarQube 6.8 not found"); underTest.resolve(new SonarDistribution().setVersion("6.8")); }
@Test public void fail_if_requested_version_is_missing() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Missing SonarQube version"); underTest.resolve(new SonarDistribution()); }