]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Restore compatibility with SQ before 5.2
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 26 Jun 2015 09:03:53 +0000 (11:03 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 26 Jun 2015 09:03:53 +0000 (11:03 +0200)
sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java
sonar-runner-api/src/main/java/org/sonar/runner/api/Utils.java
sonar-runner-api/src/main/java/org/sonar/runner/impl/VersionUtils.java [new file with mode: 0644]
sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java
sonar-runner-api/src/test/java/org/sonar/runner/impl/VersionUtilsTest.java [new file with mode: 0644]
sonar-runner-batch/src/main/java/org/sonar/runner/batch/BatchIsolatedLauncher.java
sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java [new file with mode: 0644]

index d48ca775c44198e1185d81141f424fc609c3a177..21f08625ea9957aab741b03e4ce4303242754890 100644 (file)
@@ -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();
index 1c0dc96cb3dae83abf7bc0cc226f1a89f12918b6..cef12b4bc049884a89300a6efed0a97712ac7a5e 100644 (file)
@@ -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 (file)
index 0000000..642f41e
--- /dev/null
@@ -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;
+    }
+  }
+
+}
index b8dfc3fa4e7802612d4be0269e43a14ce2c9caff..3d98cf07680f8c717d434baa1fcf3f6b6bd1f652 100644 (file)
  */
 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 (file)
index 0000000..e015a26
--- /dev/null
@@ -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();
+  }
+}
index 8723ed817a4866579fb6c917f4dc0211aab0108d..4241da4327a5fbb4f3f3ddaa414775dcdb42819d 100644 (file)
@@ -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 (file)
index 0000000..88dd0c9
--- /dev/null
@@ -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()));
+      }
+
+    });
+  }
+
+}