aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-07-20 17:38:19 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-08-07 11:44:06 +0200
commitc69324daaf2b08efa2fdc68d01c2fff105b34cdf (patch)
tree337723a33e7592e252463e2c08ec367a176f119d /sonar-scanner-engine
parentdd380b60b61eb5de47051a746d0141b8250e5560 (diff)
downloadsonarqube-c69324daaf2b08efa2fdc68d01c2fff105b34cdf.tar.gz
sonarqube-c69324daaf2b08efa2fdc68d01c2fff105b34cdf.zip
SONAR-9576 Add analysis mode in the scanner report
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/pom.xml16
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java17
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java1
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalMode.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java1
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java21
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java6
9 files changed, 51 insertions, 30 deletions
diff --git a/sonar-scanner-engine/pom.xml b/sonar-scanner-engine/pom.xml
index b36d8e6cd45..580ee0095ff 100644
--- a/sonar-scanner-engine/pom.xml
+++ b/sonar-scanner-engine/pom.xml
@@ -140,6 +140,22 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
<profiles>
<profile>
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java
index 28fefb1080a..d0a847f828f 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java
@@ -22,20 +22,16 @@ package org.sonar.scanner.analysis;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.bootstrap.AbstractAnalysisMode;
import org.sonar.scanner.bootstrap.GlobalProperties;
-/**
- * @since 4.0
- */
@Immutable
public class DefaultAnalysisMode extends AbstractAnalysisMode {
- private static final Logger LOG = LoggerFactory.getLogger(DefaultAnalysisMode.class);
+ private static final Logger LOG = Loggers.get(DefaultAnalysisMode.class);
private static final String KEY_SCAN_ALL = "sonar.scanAllFiles";
private boolean scanAllFiles;
@@ -54,7 +50,7 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
boolean analysisPreview = isIssues(analysisProps);
if (!globalPreview && analysisPreview) {
- throw new IllegalStateException("Inconsistent properties: global properties doesn't enable issues mode while analysis properties enables it");
+ throw new IllegalStateException("Inconsistent properties: global properties doesn't enable issues mode while analysis properties enables it");
}
load(globalProps, analysisProps);
@@ -85,6 +81,11 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
}
}
+ @Override
+ public boolean isIncremental() {
+ return false;
+ }
+
@CheckForNull
private static String getPropertyWithFallback(Map<String, String> props1, Map<String, String> props2, String key) {
if (props1.containsKey(key)) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java
index c6eccc9eb4c..d9ba1203e42 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java
@@ -67,6 +67,7 @@ public abstract class AbstractAnalysisMode implements AnalysisMode {
if (!Arrays.asList(VALID_MODES).contains(mode)) {
throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES));
}
+
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalMode.java
index 743294be0f8..df217760051 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalMode.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalMode.java
@@ -20,7 +20,6 @@
package org.sonar.scanner.bootstrap;
import javax.annotation.concurrent.Immutable;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
@@ -46,4 +45,9 @@ public class GlobalMode extends AbstractAnalysisMode {
}
}
+ @Override
+ public boolean isIncremental() {
+ throw new UnsupportedOperationException();
+ }
+
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
index 871f65ca0f0..df162b78f24 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
@@ -20,6 +20,7 @@
package org.sonar.scanner.report;
import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
@@ -38,14 +39,16 @@ public class MetadataPublisher implements ReportPublisherStep {
private final ProjectAnalysisInfo projectAnalysisInfo;
private final InputModuleHierarchy moduleHierarchy;
private final CpdSettings cpdSettings;
+ private final AnalysisMode mode;
public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, Configuration settings,
- ModuleQProfiles qProfiles, CpdSettings cpdSettings) {
+ ModuleQProfiles qProfiles, CpdSettings cpdSettings, AnalysisMode mode) {
this.projectAnalysisInfo = projectAnalysisInfo;
this.moduleHierarchy = moduleHierarchy;
this.settings = settings;
this.qProfiles = qProfiles;
this.cpdSettings = cpdSettings;
+ this.mode = mode;
}
@Override
@@ -57,7 +60,8 @@ public class MetadataPublisher implements ReportPublisherStep {
// Here we want key without branch
.setProjectKey(rootDef.getKey())
.setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled())
- .setRootComponentRef(rootProject.batchId());
+ .setRootComponentRef(rootProject.batchId())
+ .setIncremental(mode.isIncremental());
settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY).ifPresent(builder::setOrganizationKey);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
index 291630228c7..29a2461a70b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
@@ -122,7 +122,6 @@ public class ProjectScanContainer extends ComponentContainer {
private void addBatchComponents() {
add(
props,
- DefaultAnalysisMode.class,
ProjectReactorBuilder.class,
WorkDirectoryCleaner.class,
new MutableProjectReactorProvider(),
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java
index a0bf20c835b..3e75a016033 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java
@@ -24,6 +24,7 @@ import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.scanner.analysis.AnalysisProperties;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.ProjectScanContainer;
public class ScanTask implements Task {
@@ -44,6 +45,8 @@ public class ScanTask implements Task {
@Override
public void execute() {
AnalysisProperties props = new AnalysisProperties(taskProps.properties(), taskProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
- new ProjectScanContainer(taskContainer, props).execute();
+ ProjectScanContainer scanContainer = new ProjectScanContainer(taskContainer, props);
+ scanContainer.add(DefaultAnalysisMode.class);
+ scanContainer.execute();
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
index ea3ffc3737d..8d679016b61 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
@@ -19,11 +19,12 @@
*/
package org.sonar.scanner.mediumtest.tasks;
-import com.google.common.collect.ImmutableMap;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.Arrays;
import java.util.List;
+
import org.assertj.core.api.Condition;
-import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -32,10 +33,9 @@ import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.scanner.bootstrap.MockHttpServer;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import static org.assertj.core.api.Assertions.assertThat;
+import com.google.common.collect.ImmutableMap;
public class TasksMediumTest {
@@ -49,15 +49,6 @@ public class TasksMediumTest {
public ScannerMediumTester tester = new ScannerMediumTester()
.registerPlugin("faketask", new FakeTaskPlugin());
- private MockHttpServer server = null;
-
- @After
- public void stopServer() {
- if (server != null) {
- server.stop();
- }
- }
-
@Test
public void listTasksIncludingBroken() throws Exception {
tester.newTask()
@@ -96,8 +87,6 @@ public class TasksMediumTest {
@Test
public void incrementalNotFound() throws Exception {
- tester.start();
-
thrown.expect(MessageException.class);
thrown.expectMessage(
"Incremental mode is not available. Please contact your administrator.");
@@ -105,7 +94,7 @@ public class TasksMediumTest {
tester.newTask()
.properties(ImmutableMap.<String, String>builder()
.put("sonar.incremental", "true").build())
- .start();
+ .execute();
}
private static class FakeTaskPlugin extends SonarPlugin {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
index b804fd08df2..fbe8a44cf43 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
@@ -27,6 +27,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
@@ -58,6 +59,7 @@ public class MetadataPublisherTest {
private ProjectAnalysisInfo projectAnalysisInfo;
private CpdSettings cpdSettings;
private InputModuleHierarchy inputModuleHierarchy;
+ private AnalysisMode analysisMode;
@Before
public void prepare() throws IOException {
@@ -73,7 +75,8 @@ public class MetadataPublisherTest {
rootModule = new DefaultInputModule(def.setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()), TestInputFileBuilder.nextBatchId());
inputModuleHierarchy = mock(InputModuleHierarchy.class);
when(inputModuleHierarchy.root()).thenReturn(rootModule);
- underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings);
+ analysisMode = mock(AnalysisMode.class);
+ underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings, analysisMode);
}
@Test
@@ -91,6 +94,7 @@ public class MetadataPublisherTest {
assertThat(metadata.getAnalysisDate()).isEqualTo(1234567L);
assertThat(metadata.getProjectKey()).isEqualTo("foo");
assertThat(metadata.getProjectKey()).isEqualTo("foo");
+ assertThat(metadata.getIncremental()).isFalse();
assertThat(metadata.getQprofilesPerLanguage()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile.newBuilder()
.setKey("q1")
.setName("Q1")