From: Evgeny Mandrikov Date: Thu, 15 Dec 2011 08:38:36 +0000 (+0000) Subject: Fix violations X-Git-Tag: 2.5-rc1~324 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=650807cc45fbdb2a8f732f00a91da259b07e9fbd;p=sonar-scanner-cli.git Fix violations --- diff --git a/src/main/java/org/sonar/runner/Main.java b/src/main/java/org/sonar/runner/Main.java index 839275e..0580c8b 100644 --- a/src/main/java/org/sonar/runner/Main.java +++ b/src/main/java/org/sonar/runner/Main.java @@ -33,7 +33,8 @@ import java.util.Properties; * Arguments : * diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index 25e3932..5928c8f 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -118,7 +118,7 @@ public final class Runner { private void checkSonarVersion(Bootstrapper bootstrapper) { String serverVersion = bootstrapper.getServerVersion(); - if (isVersionPriorTo2Dot6(serverVersion)) { + if (isUnsupportedVersion(serverVersion)) { throw new BootstrapException("Sonar " + serverVersion + " does not support Standalone Runner. Please upgrade Sonar to version 2.6 or more."); } @@ -131,14 +131,15 @@ public final class Runner { getClass().getClassLoader()); } - static boolean isVersionPriorTo2Dot6(String version) { - return isVersion(version, "1") - || isVersion(version, "2.0") - || isVersion(version, "2.1") - || isVersion(version, "2.2") - || isVersion(version, "2.3") - || isVersion(version, "2.4") - || isVersion(version, "2.5"); + private static final String[] unsupportedVersions = { "1", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5" }; + + static boolean isUnsupportedVersion(String version) { + for (String unsupportedVersion : unsupportedVersions) { + if (isVersion(version, unsupportedVersion)) { + return true; + } + } + return false; } static boolean isVersion(String version, String prefix) { diff --git a/src/test/java/org/sonar/runner/RunnerTest.java b/src/test/java/org/sonar/runner/RunnerTest.java index 9718830..e747313 100644 --- a/src/test/java/org/sonar/runner/RunnerTest.java +++ b/src/test/java/org/sonar/runner/RunnerTest.java @@ -32,15 +32,15 @@ import static org.junit.Assert.assertThat; public class RunnerTest { @Test public void shouldCheckVersion() { - assertThat(Runner.isVersionPriorTo2Dot6("1.0"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.0"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.1"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.2"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.3"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.4"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.4.1"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.5"), is(true)); - assertThat(Runner.isVersionPriorTo2Dot6("2.6"), is(false)); + assertThat(Runner.isUnsupportedVersion("1.0"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.0"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.1"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.2"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.3"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.4"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.4.1"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.5"), is(true)); + assertThat(Runner.isUnsupportedVersion("2.6"), is(false)); } /**