From: Julien HENRY Date: Fri, 26 Jun 2015 09:03:53 +0000 (+0200) Subject: Restore compatibility with SQ before 5.2 X-Git-Tag: 2.5-rc1~71 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=244f5ea57e9a0b11408cfff45391d8ea4585e94e;p=sonar-scanner-cli.git Restore compatibility with SQ before 5.2 --- diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java index d48ca77..21f0862 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java @@ -30,6 +30,7 @@ import org.sonar.home.cache.Logger; import org.sonar.runner.batch.IsolatedLauncher; import org.sonar.runner.impl.InternalProperties; import org.sonar.runner.impl.IsolatedLauncherFactory; +import org.sonar.runner.impl.VersionUtils; /** * Entry point to run SonarQube analysis programmatically. @@ -197,7 +198,7 @@ public class EmbeddedRunner { protected void doStart() { launcher = launcherFactory.createLauncher(globalProperties()); - if (Utils.isAtLeast52(launcher.getVersion())) { + if (VersionUtils.isAtLeast52(launcher.getVersion())) { launcher.start(globalProperties(), new org.sonar.runner.batch.LogOutput() { @Override @@ -210,13 +211,13 @@ public class EmbeddedRunner { } protected void doStop() { - if (Utils.isAtLeast52(launcher.getVersion())) { + if (VersionUtils.isAtLeast52(launcher.getVersion())) { launcher.stop(); } } protected void doExecute(Properties analysisProperties) { - if (Utils.isAtLeast52(launcher.getVersion())) { + if (VersionUtils.isAtLeast52(launcher.getVersion())) { launcher.execute(analysisProperties); } else { Properties prop = new Properties(); diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java index 1c0dc96..cef12b4 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java @@ -19,8 +19,6 @@ */ package org.sonar.runner.api; -import javax.annotation.Nullable; - import java.io.Closeable; import java.io.File; import java.io.FileOutputStream; @@ -30,30 +28,17 @@ import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; import java.util.Iterator; import java.util.Properties; -import java.nio.file.attribute.BasicFileAttributes; +import javax.annotation.Nullable; class Utils { private Utils() { // only util static methods } - static boolean isAtLeast52(String version) { - // it can be snapshot (5.2-SNAPSHOT) - if (version == null) { - return false; - } - - int endIndex = Math.min(3, version.length()); - try { - return Double.parseDouble(version.substring(0, endIndex)) >= 5.2; - } catch (NumberFormatException e) { - return false; - } - } - /** * Similar to org.apache.commons.lang.StringUtils#join() */ diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/impl/VersionUtils.java b/sonar-runner-api/src/main/java/org/sonar/runner/impl/VersionUtils.java new file mode 100644 index 0000000..642f41e --- /dev/null +++ b/sonar-runner-api/src/main/java/org/sonar/runner/impl/VersionUtils.java @@ -0,0 +1,41 @@ +/* + * SonarQube Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.impl; + +public class VersionUtils { + private VersionUtils() { + // only util static methods + } + + public static boolean isAtLeast52(String version) { + // it can be snapshot (5.2-SNAPSHOT) + if (version == null) { + return false; + } + + int endIndex = Math.min(3, version.length()); + try { + return Double.parseDouble(version.substring(0, endIndex)) >= 5.2; + } catch (NumberFormatException e) { + return false; + } + } + +} diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java index b8dfc3f..3d98cf0 100644 --- a/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java @@ -19,19 +19,17 @@ */ package org.sonar.runner.api; -import org.junit.Test; - import java.io.Closeable; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Properties; +import org.junit.Test; -import static org.mockito.Mockito.verify; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.doThrow; import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; public class UtilsTest { @Test @@ -41,18 +39,6 @@ public class UtilsTest { assertThat(Utils.join(new String[] {"foo", "bar"}, ",")).isEqualTo("foo,bar"); } - @Test - public void parse_version() { - assertThat(Utils.isAtLeast52("5.2")).isTrue(); - assertThat(Utils.isAtLeast52(null)).isFalse(); - assertThat(Utils.isAtLeast52("52")).isTrue(); - assertThat(Utils.isAtLeast52("5.0")).isFalse(); - assertThat(Utils.isAtLeast52("")).isFalse(); - assertThat(Utils.isAtLeast52("trash")).isFalse(); - assertThat(Utils.isAtLeast52("6.0.0")).isTrue(); - assertThat(Utils.isAtLeast52("5.2-SNAPSHOT")).isTrue(); - } - @Test public void task_should_require_project() { Properties props = new Properties(); diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/impl/VersionUtilsTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/impl/VersionUtilsTest.java new file mode 100644 index 0000000..e015a26 --- /dev/null +++ b/sonar-runner-api/src/test/java/org/sonar/runner/impl/VersionUtilsTest.java @@ -0,0 +1,39 @@ +/* + * SonarQube Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.impl; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class VersionUtilsTest { + + @Test + public void parse_version() { + assertThat(VersionUtils.isAtLeast52("5.2")).isTrue(); + assertThat(VersionUtils.isAtLeast52(null)).isFalse(); + assertThat(VersionUtils.isAtLeast52("52")).isTrue(); + assertThat(VersionUtils.isAtLeast52("5.0")).isFalse(); + assertThat(VersionUtils.isAtLeast52("")).isFalse(); + assertThat(VersionUtils.isAtLeast52("trash")).isFalse(); + assertThat(VersionUtils.isAtLeast52("6.0.0")).isTrue(); + assertThat(VersionUtils.isAtLeast52("5.2-SNAPSHOT")).isTrue(); + } +} diff --git a/sonar-runner-batch/src/main/java/org/sonar/runner/batch/BatchIsolatedLauncher.java b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/BatchIsolatedLauncher.java index 8723ed8..4241da4 100644 --- a/sonar-runner-batch/src/main/java/org/sonar/runner/batch/BatchIsolatedLauncher.java +++ b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/BatchIsolatedLauncher.java @@ -29,7 +29,6 @@ import java.util.Properties; import org.picocontainer.annotations.Nullable; import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonar.batch.bootstrapper.LogOutput; /** * This class is executed within the classloader provided by the server. It contains the installed plugins and @@ -62,14 +61,8 @@ public class BatchIsolatedLauncher implements IsolatedLauncher { .setBootstrapProperties((Map) properties); if (logOutput != null) { - builder.setLogOutput(new LogOutput() { - - @Override - public void log(String formattedMessage, Level level) { - logOutput.log(formattedMessage, org.sonar.runner.batch.LogOutput.Level.valueOf(level.name())); - } - - }); + // Do that is a separate class to avoid NoClassDefFoundError for org/sonar/batch/bootstrapper/LogOutput + Compatibility.setLogOutputFor5dot2(builder, logOutput); } return builder.build(); diff --git a/sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java new file mode 100644 index 0000000..88dd0c9 --- /dev/null +++ b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java @@ -0,0 +1,42 @@ +/* + * SonarQube Runner - Batch + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.batch; + +import org.sonar.batch.bootstrapper.Batch; +import org.sonar.batch.bootstrapper.LogOutput; + +public class Compatibility { + + private Compatibility() { + // Utility class + } + + static void setLogOutputFor5dot2(Batch.Builder builder, final org.sonar.runner.batch.LogOutput logOutput) { + builder.setLogOutput(new LogOutput() { + + @Override + public void log(String formattedMessage, Level level) { + logOutput.log(formattedMessage, org.sonar.runner.batch.LogOutput.Level.valueOf(level.name())); + } + + }); + } + +}