]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SQSCANNER-42 Stop support of SQ < 5.2
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 28 Jul 2017 09:56:24 +0000 (11:56 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 31 Jul 2017 06:55:41 +0000 (08:55 +0200)
pom.xml
src/main/java/org/sonarsource/scanner/cli/Main.java
src/main/java/org/sonarsource/scanner/cli/ScannerFactory.java
src/test/java/org/sonarsource/scanner/cli/MainTest.java

diff --git a/pom.xml b/pom.xml
index c4437e3b3f90ea33dab3d3b6985d32617b8bb37e..0f2dcfdbf2f8481268a3b9106b1ee30edc0db630 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <dependency>
       <groupId>org.sonarsource.scanner.api</groupId>
       <artifactId>sonar-scanner-api</artifactId>
-      <version>2.9.0.887</version>
+      <version>2.10.0.1049</version>
     </dependency>
     <dependency>
       <groupId>com.google.code.findbugs</groupId>
       <artifactId>jsr305</artifactId>
-      <version>2.0.1</version>
+      <version>2.0.3</version>
       <scope>provided</scope>
     </dependency>
 
@@ -74,7 +74,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.11</version>
+      <version>4.12</version>
       <scope>test</scope>
     </dependency>
     <dependency>
@@ -91,8 +91,8 @@
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <version>1.9.5</version>
+      <artifactId>mockito-core</artifactId>
+      <version>2.8.47</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
             <configuration>
               <rules>
                 <requireFilesSize>
-                  <minsize>490000</minsize>
-                  <maxsize>510000</maxsize>
+                  <minsize>530000</minsize>
+                  <maxsize>550000</maxsize>
                   <files>
                     <file>${project.build.directory}/sonar-scanner-${project.version}.zip</file>
                   </files>
index d93116bc3b5021a9511376cd477df8c1a8f47876..7144ec826d7d876edeaf15efcbf9f8ca5b1263c2 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonarsource.scanner.cli;
 
+import java.util.Map;
 import java.util.Properties;
 import org.sonarsource.scanner.api.EmbeddedScanner;
 import org.sonarsource.scanner.api.ScanProperties;
@@ -64,32 +65,20 @@ public class Main {
     Stats stats = new Stats(logger).start();
 
     int status = Exit.ERROR;
-    boolean started = false;
     try {
       Properties p = conf.properties();
       checkSkip(p);
       configureLogging(p);
       init(p);
       runner.start();
-      started = true;
       logger.info("SonarQube server " + runner.serverVersion());
-      runAnalysis(stats, p);
+      execute(stats, p);
       status = Exit.SUCCESS;
     } catch (Throwable e) {
-      status = Exit.ERROR;
       displayExecutionResult(stats, "FAILURE");
       showError("Error during SonarQube Scanner execution", e, cli.isDebugEnabled());
     } finally {
-      try {
-        if (started) {
-          runner.stop();
-        }
-      } catch (Throwable e) {
-        status = Exit.ERROR;
-        logger.error("Unable to properly stop the scanner", e);
-      } finally {
-        exit.exit(status);
-      }
+      exit.exit(status);
     }
 
   }
@@ -118,8 +107,8 @@ public class Main {
     }
   }
 
-  private void runAnalysis(Stats stats, Properties p) {
-    runner.runAnalysis(p);
+  private void execute(Stats stats, Properties p) {
+    runner.execute((Map) p);
     displayExecutionResult(stats, "SUCCESS");
   }
 
index 04a6684d28c24ca097ebdd4b10f1738daaa78ff9..7fe4d9f37ddde4ff21573b7042bf6e09191fa387 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonarsource.scanner.cli;
 
+import java.util.Map;
 import java.util.Properties;
 import org.sonarsource.scanner.api.EmbeddedScanner;
 import org.sonarsource.scanner.api.LogOutput;
@@ -32,9 +33,8 @@ class ScannerFactory {
   }
 
   EmbeddedScanner create(Properties props) {
-    return EmbeddedScanner.create(new DefaultLogOutput())
-      .addGlobalProperties(props)
-      .setApp("ScannerCli", ScannerVersion.version());
+    return EmbeddedScanner.create("ScannerCli", ScannerVersion.version(), new DefaultLogOutput())
+      .addGlobalProperties((Map) props);
   }
 
   class DefaultLogOutput implements LogOutput {
index 26e1a71d6f269df0da62638be681707eee5c98fb..869a1835acafa947d297c583ef86e182b7b17c64 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonarsource.scanner.cli;
 
 import java.io.IOException;
+import java.util.Map;
 import java.util.Properties;
 import org.junit.Before;
 import org.junit.Test;
@@ -33,7 +34,7 @@ import org.sonarsource.scanner.api.EmbeddedScanner;
 import org.sonarsource.scanner.api.ScanProperties;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -52,82 +53,63 @@ public class MainTest {
   @Mock
   private Properties properties;
   @Mock
-  private ScannerFactory runnerFactory;
+  private ScannerFactory scannerFactory;
   @Mock
-  private EmbeddedScanner runner;
+  private EmbeddedScanner scanner;
   @Mock
   private Logs logs;
 
   @Before
   public void setUp() throws IOException {
     MockitoAnnotations.initMocks(this);
-    when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
+    when(scannerFactory.create(any(Properties.class))).thenReturn(scanner);
     when(conf.properties()).thenReturn(properties);
   }
 
   @Test
   public void should_execute_runner() {
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
 
     verify(exit).exit(Exit.SUCCESS);
-    verify(runnerFactory).create(properties);
+    verify(scannerFactory).create(properties);
 
-    verify(runner, times(1)).start();
-    verify(runner, times(1)).runAnalysis(properties);
-    verify(runner, times(1)).stop();
+    verify(scanner, times(1)).start();
+    verify(scanner, times(1)).execute((Map) properties);
   }
 
   @Test
-  public void should_call_stop_on_error_during_analysis() {
+  public void should_exit_with_error_on_error_during_analysis() {
     EmbeddedScanner runner = mock(EmbeddedScanner.class);
     Exception e = new NullPointerException("NPE");
     e = new IllegalStateException("Error", e);
-    doThrow(e).when(runner).runAnalysis(any(Properties.class));
-    when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
+    doThrow(e).when(runner).execute(any(Map.class));
+    when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
 
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
 
-    verify(runner).stop();
     verify(exit).exit(Exit.ERROR);
     verify(logs).error("Error during SonarQube Scanner execution", e);
   }
 
   @Test
-  public void should_not_call_stop_on_error_during_start() {
+  public void should_exit_with_error_on_error_during_start() {
     EmbeddedScanner runner = mock(EmbeddedScanner.class);
     Exception e = new NullPointerException("NPE");
     e = new IllegalStateException("Error", e);
     doThrow(e).when(runner).start();
-    when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
+    when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
 
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
 
     verify(runner).start();
-    verify(runner, never()).runAnalysis(any());
-    verify(runner, never()).stop();
+    verify(runner, never()).execute(any(Map.class));
     verify(exit).exit(Exit.ERROR);
     verify(logs).error("Error during SonarQube Scanner execution", e);
   }
 
-  @Test
-  public void should_exit_on_error() {
-    EmbeddedScanner runner = mock(EmbeddedScanner.class);
-    Exception e = new NullPointerException("NPE");
-    e = new IllegalStateException("Error", e);
-    doThrow(e).when(runner).stop();
-    when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
-
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
-    main.execute();
-
-    verify(runner).stop();
-    verify(exit).exit(Exit.ERROR);
-    verify(logs).error("Unable to properly stop the scanner", e);
-  }
-
   @Test
   public void show_error_with_stacktrace() {
     Exception e = createException(false);
@@ -160,13 +142,12 @@ public class MainTest {
     when(cli.isDebugEnabled()).thenReturn(debugEnabled);
 
     EmbeddedScanner runner = mock(EmbeddedScanner.class);
-    doThrow(e).when(runner).runAnalysis(any(Properties.class));
-    when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
+    doThrow(e).when(runner).execute(any(Map.class));
+    when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
 
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
 
-    verify(runner).stop();
     verify(exit).exit(Exit.ERROR);
   }
 
@@ -188,13 +169,13 @@ public class MainTest {
     when(cli.isDisplayVersionOnly()).thenReturn(true);
     when(conf.properties()).thenReturn(p);
 
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
 
-    InOrder inOrder = Mockito.inOrder(exit, runnerFactory);
+    InOrder inOrder = Mockito.inOrder(exit, scannerFactory);
 
     inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
-    inOrder.verify(runnerFactory, times(1)).create(p);
+    inOrder.verify(scannerFactory, times(1)).create(p);
     inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
   }
 
@@ -204,25 +185,25 @@ public class MainTest {
     p.setProperty(ScanProperties.SKIP, "true");
     when(conf.properties()).thenReturn(p);
 
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
 
     verify(logs).info("SonarQube Scanner analysis skipped");
-    InOrder inOrder = Mockito.inOrder(exit, runnerFactory);
+    InOrder inOrder = Mockito.inOrder(exit, scannerFactory);
 
     inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
-    inOrder.verify(runnerFactory, times(1)).create(p);
+    inOrder.verify(scannerFactory, times(1)).create(p);
     inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
   }
 
   @Test
   public void shouldLogServerVersion() throws IOException {
-    when(runner.serverVersion()).thenReturn("5.5");
+    when(scanner.serverVersion()).thenReturn("5.5");
     Properties p = new Properties();
     when(cli.isDisplayVersionOnly()).thenReturn(true);
     when(conf.properties()).thenReturn(p);
 
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
     verify(logs).info("SonarQube server 5.5");
   }
@@ -250,14 +231,14 @@ public class MainTest {
     p.put(propKey, propValue);
     when(conf.properties()).thenReturn(p);
 
-    Main main = new Main(exit, cli, conf, runnerFactory, logs);
+    Main main = new Main(exit, cli, conf, scannerFactory, logs);
     main.execute();
 
     // Logger used for callback should have debug enabled
     verify(logs).setDebugEnabled(true);
 
     ArgumentCaptor<Properties> propertiesCapture = ArgumentCaptor.forClass(Properties.class);
-    verify(runner).runAnalysis(propertiesCapture.capture());
+    verify(scanner).execute((Map) propertiesCapture.capture());
 
     return propertiesCapture.getValue();
   }