]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 13 Jul 2016 15:12:46 +0000 (17:12 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 13 Jul 2016 15:18:06 +0000 (17:18 +0200)
20 files changed:
sonar-plugin-api/src/main/java/org/sonar/api/SonarRuntime.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LogOutput.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/events/BatchStepHandler.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/ScanTaskObserver.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/AbstractPhaseExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisherStep.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ConsoleReport.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReport.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReportBuilder.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ReportSummary.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/Reporter.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/index/DefaultIndexTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java

index 0760fb77244faf218bcd9856da6d306e500b2e7f..86b37e9e54c7d69a33607aa7aa60881ce7bb453f 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.api;
 import com.google.common.base.Preconditions;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.BatchSide;
+import org.sonar.api.batch.ScannerSide;
 import org.sonar.api.batch.sensor.Sensor;
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
@@ -121,7 +121,7 @@ import static java.util.Objects.requireNonNull;
  *
  * @since 6.0
  */
-@BatchSide
+@ScannerSide
 @ServerSide
 @ComputeEngineSide
 @SonarLintSide
index 031fa6de245c5a3f1748c28e13865dee62559e40..a3d4de2865433c1218b1926f3334e7147d838cde 100644 (file)
@@ -120,6 +120,7 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
     return moduleKey;
   }
 
+  @Override
   public Charset charset() {
     return charset;
   }
index 34df663e54ab0cbaa0b3f9226d3450765246e0fa..6ccc541dad3bb9e621c113942007a4e3bd6d46df 100644 (file)
@@ -79,8 +79,6 @@ public class DefaultHighlighting extends DefaultStorable implements NewHighlight
     checkInputFileNotNull();
     TextRange newRange;
     try {
-      // TODO remove when SONAR-7664 is implemented
-      Preconditions.checkArgument(startOffset < endOffset, "start offset should be strictly before end offset");
       newRange = inputFile.newRange(startOffset, endOffset);
     } catch (Exception e) {
       throw new IllegalArgumentException("Unable to highlight file " + inputFile, e);
index b69c405d9313fe9bd205a65cdd432d87d4dd8fc1..8bfa4301e1d7d43c366fbaaa4812d1d8cb9cb48e 100644 (file)
@@ -23,6 +23,7 @@ package org.sonar.batch.bootstrapper;
  * Allow to redirect batch logs to a custom output. By defaults logs are written to System.out
  * @since 5.2
  */
+@FunctionalInterface
 public interface LogOutput {
 
   void log(String formattedMessage, Level level);
index 285a25d6848285aa63b07c4907216122f4f68638..c3ca55c4507b1b9581815c758f34248a49abb2e1 100644 (file)
@@ -22,6 +22,14 @@ package org.sonar.scanner.cpd;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.log.Logger;
@@ -39,15 +47,6 @@ import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
 import org.sonar.scanner.report.ReportPublisher;
 import org.sonar.scanner.util.ProgressReport;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 
 import static com.google.common.collect.FluentIterable.from;
 
index c2c437d73693d7c11437e4b9fa384cc9548153b9..f2c6b47222942ee1454c99b3fada30e8c2e905b3 100644 (file)
@@ -24,6 +24,7 @@ import org.sonar.api.batch.events.EventHandler;
 /**
  * @since 3.7
  */
+@FunctionalInterface
 public interface BatchStepHandler extends EventHandler {
 
   /**
index ffad84c3e68e8e784e35031f3c3383e03fa38257..4cb9f5b48d8d0e50d278a59c2a15642010c21efc 100644 (file)
@@ -278,14 +278,6 @@ public class DefaultIndex {
     return bucket;
   }
 
-  public boolean isExcluded(@Nullable Resource reference) {
-    return false;
-  }
-
-  public boolean isIndexed(@Nullable Resource reference, boolean acceptExcluded) {
-    return getBucket(reference) != null;
-  }
-
   private Bucket getBucket(@Nullable Resource reference) {
     if (reference == null) {
       return null;
index a45a601cdb04f6d28163093efd4e542921a8cd6b..0e8df6952db3d20053a247ea31522ae22e97be63 100644 (file)
  */
 package org.sonar.scanner.issue.ignore.scanner;
 
+import java.nio.charset.Charset;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.resources.Project;
 import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
 import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
-import java.nio.charset.Charset;
 
 public final class IssueExclusionsLoader {
 
@@ -43,7 +42,7 @@ public final class IssueExclusionsLoader {
     this.fileSystem = fileSystem;
   }
 
-  public boolean shouldExecuteOnProject(Project project) {
+  public boolean shouldExecute() {
     return inclusionPatternInitializer.hasConfiguredPatterns()
       || exclusionPatternInitializer.hasConfiguredPatterns();
   }
index 02881a66caa8041e6132bd1f6513d316f3cb5f73..9b1ab15ade17fb071013201d507de9f0e985e67b 100644 (file)
  */
 package org.sonar.scanner.mediumtest;
 
+import org.sonar.api.ExtensionPoint;
 import org.sonar.api.batch.ScannerSide;
 import org.sonar.scanner.scan.ProjectScanContainer;
-import org.sonar.api.ExtensionPoint;
 
 @ScannerSide
 @ExtensionPoint
+@FunctionalInterface
 public interface ScanTaskObserver {
 
   void scanTaskCompleted(ProjectScanContainer container);
index 3174c667682a4f46eace9832acb804da357ae8e3..ec6ca476708eb3f51687c40967dce0461950adcf 100644 (file)
@@ -88,10 +88,12 @@ public abstract class AbstractPhaseExecutor {
   protected abstract void executeOnRoot();
 
   private void initIssueExclusions() {
-    String stepName = "Init issue exclusions";
-    eventBus.fireEvent(new BatchStepEvent(stepName, true));
-    issueExclusionsLoader.execute();
-    eventBus.fireEvent(new BatchStepEvent(stepName, false));
+    if (issueExclusionsLoader.shouldExecute()) {
+      String stepName = "Init issue exclusions";
+      eventBus.fireEvent(new BatchStepEvent(stepName, true));
+      issueExclusionsLoader.execute();
+      eventBus.fireEvent(new BatchStepEvent(stepName, false));
+    }
   }
 
   private void indexFs() {
index a1f7221ce6dd5755e1a99ef6292ca0f44c0dce61..374f3cf060dd87b338762467e279a3ed308aac22 100644 (file)
@@ -24,6 +24,7 @@ import org.sonar.scanner.protocol.output.ScannerReportWriter;
 /**
  * Adds a sub-part of data to output report
  */
+@FunctionalInterface
 public interface ReportPublisherStep {
 
   void publish(ScannerReportWriter writer);
index a1689c5dc6ec1e3847c2f7e5ab6f70ebffe8af9f..cee346fc94c3e64dee0fdb9fb0c8bf4b19905b85 100644 (file)
@@ -34,11 +34,6 @@ import org.sonar.api.rules.RuleQuery;
 
 import static org.sonar.core.util.stream.Collectors.toList;
 
-/**
- * FIXME Waiting for the list of all server rules on batch side this is implemented by redirecting on ActiveRules. This is not correct
- * since there is a difference between a rule that doesn't exists and a rule that is not activated in project quality profile.
- *
- */
 public class RuleFinderCompatibility implements RuleFinder {
 
   private final Rules rules;
index d89d897c9e27e7e6bce9b9d34f69e1fee84a8c37..0a2148c762dae0abad0b36841f4e64aa8c3fd9de 100644 (file)
@@ -33,7 +33,6 @@ import org.sonar.scanner.DefaultFileLinesContextFactory;
 import org.sonar.scanner.DefaultProjectTree;
 import org.sonar.scanner.bootstrap.BatchExtensionDictionnary;
 import org.sonar.scanner.bootstrap.ExtensionInstaller;
-import org.sonar.scanner.bootstrap.ExtensionMatcher;
 import org.sonar.scanner.bootstrap.ExtensionUtils;
 import org.sonar.scanner.deprecated.DeprecatedSensorContext;
 import org.sonar.scanner.deprecated.perspectives.BatchPerspectives;
@@ -174,12 +173,7 @@ public class ModuleScanContainer extends ComponentContainer {
 
   private void addExtensions() {
     ExtensionInstaller installer = getComponentByType(ExtensionInstaller.class);
-    installer.install(this, new ExtensionMatcher() {
-      @Override
-      public boolean accept(Object extension) {
-        return ExtensionUtils.isScannerSide(extension) && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT);
-      }
-    });
+    installer.install(this, e -> ExtensionUtils.isScannerSide(e) && ExtensionUtils.isInstantiationStrategy(e, InstantiationStrategy.PER_PROJECT));
   }
 
   @Override
index 6add4c065b6093432771a6213b9f2d8a20184cf5..d4ddff8b2e78be5bad92c698d25e377d6ae2abac 100644 (file)
@@ -126,17 +126,17 @@ public class ConsoleReport implements Reporter {
     int newIssues = r.totalNewIssues;
     if (newIssues > 0) {
       sb.append(StringUtils.leftPad("+" + newIssues, LEFT_PAD)).append(" issue" + (newIssues > 1 ? "s" : "")).append("\n\n");
-      printNewIssues(sb, r.newBlockerIssues, Severity.BLOCKER, "blocker");
-      printNewIssues(sb, r.newCriticalIssues, Severity.CRITICAL, "critical");
-      printNewIssues(sb, r.newMajorIssues, Severity.MAJOR, "major");
-      printNewIssues(sb, r.newMinorIssues, Severity.MINOR, "minor");
-      printNewIssues(sb, r.newInfoIssues, Severity.INFO, "info");
+      printNewIssues(sb, r.newBlockerIssues, "blocker");
+      printNewIssues(sb, r.newCriticalIssues, "critical");
+      printNewIssues(sb, r.newMajorIssues, "major");
+      printNewIssues(sb, r.newMinorIssues, "minor");
+      printNewIssues(sb, r.newInfoIssues, "info");
     } else {
       sb.append("  No new issue").append("\n");
     }
   }
 
-  private static void printNewIssues(StringBuilder sb, int issueCount, String severity, String severityLabel) {
+  private static void printNewIssues(StringBuilder sb, int issueCount, String severityLabel) {
     if (issueCount > 0) {
       sb.append(StringUtils.leftPad("+" + issueCount, LEFT_PAD)).append(" ").append(severityLabel).append("\n");
     }
index 33c3bf7de97fcb3de60e61b17330669f1017d9c5..470c2d0339e2905d3f4c6c6d0ac6ea9f5fe716d4 100644 (file)
 package org.sonar.scanner.scan.report;
 
 import com.google.common.collect.Maps;
-
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
-
 import org.sonar.api.batch.rule.Rule;
 import org.sonar.api.rules.RulePriority;
 import org.sonar.scanner.index.BatchComponent;
@@ -83,13 +81,13 @@ public class IssuesReport {
   public void addIssueOnResource(BatchComponent resource, TrackedIssue issue, Rule rule, RulePriority severity) {
     addResource(resource);
     getSummary().addIssue(issue, rule, severity);
-    resourceReportsByResource.get(resource).addIssue(issue, rule, RulePriority.valueOf(issue.severity()));
+    resourceReportsByResource.get(resource).addIssue(issue, rule, severity);
   }
 
-  public void addResolvedIssueOnResource(BatchComponent resource, TrackedIssue issue, Rule rule, RulePriority severity) {
+  public void addResolvedIssueOnResource(BatchComponent resource, Rule rule, RulePriority severity) {
     addResource(resource);
-    getSummary().addResolvedIssue(issue, rule, severity);
-    resourceReportsByResource.get(resource).addResolvedIssue(rule, RulePriority.valueOf(issue.severity()));
+    getSummary().addResolvedIssue(rule, severity);
+    resourceReportsByResource.get(resource).addResolvedIssue(rule, severity);
   }
 
   private void addResource(BatchComponent resource) {
index d598f36c1451f5d6a7bf58a1eddea56fa0e2ba23..d69ba0f70f38e8a49a8911ec70d65d0948ca46b5 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.scanner.scan.report;
 
 import javax.annotation.CheckForNull;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.ScannerSide;
@@ -75,7 +74,7 @@ public class IssuesReportBuilder {
         continue;
       }
       if (issue.resolution() != null) {
-        issuesReport.addResolvedIssueOnResource(resource, issue, rule, severity);
+        issuesReport.addResolvedIssueOnResource(resource, rule, severity);
       } else {
         issuesReport.addIssueOnResource(resource, issue, rule, severity);
       }
index 7fb0554de0b640682d92ff2d9e60a0ed279da0f7..d915acd6005dea673eb5e2183e640551a6f6f67e 100644 (file)
@@ -63,7 +63,7 @@ public class ReportSummary {
     return totalByRuleKey;
   }
 
-  public void addResolvedIssue(TrackedIssue issue, Rule rule, RulePriority severity) {
+  public void addResolvedIssue(Rule rule, RulePriority severity) {
     ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity);
     initMaps(reportRuleKey);
     total.incrementResolvedIssuesCount();
index 3d1f9e2f3da07d658a3e49a6c5aa93bad6462465..6c462a64de96c6dc9fc4f4563e03f7b38950cd94 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.scanner.scan.report;
 import org.sonar.api.batch.ScannerSide;
 
 @ScannerSide
+@FunctionalInterface
 public interface Reporter {
 
   void execute();
index 33462983e6255f08be25602b1cbcd9573773ee64..9d52431cd4f33d274a8a00c4e498373e80a06043 100644 (file)
@@ -34,10 +34,8 @@ import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
-import org.sonar.scanner.FakeJava;
 import org.sonar.scanner.DefaultProjectTree;
-import org.sonar.scanner.index.BatchComponentCache;
-import org.sonar.scanner.index.DefaultIndex;
+import org.sonar.scanner.FakeJava;
 import org.sonar.scanner.scan.measure.MeasureCache;
 import org.sonar.scanner.sensor.DefaultSensorStorage;
 
@@ -93,8 +91,6 @@ public class DefaultIndexTest {
 
     Directory reference = Directory.create("src/org/foo");
     assertThat(index.getResource(reference).getName()).isEqualTo("src/org/foo");
-    assertThat(index.isIndexed(reference, true)).isTrue();
-    assertThat(index.isExcluded(reference)).isFalse();
     assertThat(index.getChildren(reference)).hasSize(1);
     assertThat(index.getParent(reference)).isInstanceOf(Project.class);
   }
@@ -110,8 +106,6 @@ public class DefaultIndexTest {
     File fileRef = File.create("src/org/foo/Bar.java", null, false);
     assertThat(index.getResource(fileRef).getKey()).isEqualTo("src/org/foo/Bar.java");
     assertThat(index.getResource(fileRef).getLanguage().getKey()).isEqualTo("java");
-    assertThat(index.isIndexed(fileRef, true)).isTrue();
-    assertThat(index.isExcluded(fileRef)).isFalse();
     assertThat(index.getChildren(fileRef)).isEmpty();
     assertThat(index.getParent(fileRef)).isInstanceOf(Directory.class);
   }
@@ -137,9 +131,6 @@ public class DefaultIndexTest {
     assertThat(index.index(file, directory)).isFalse();
 
     File fileRef = File.create("src/org/foo/Bar.java", null, false);
-    assertThat(index.isIndexed(directory, true)).isFalse();
-    assertThat(index.isIndexed(fileRef, true)).isFalse();
-    assertThat(index.isExcluded(fileRef)).isFalse();
     assertThat(index.getChildren(fileRef)).isEmpty();
     assertThat(index.getParent(fileRef)).isNull();
   }
@@ -149,7 +140,6 @@ public class DefaultIndexTest {
     Resource dir = Directory.create("src/org/foo");
     index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
 
-    assertThat(index.isIndexed(dir, true)).isFalse();
     assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc"))).isNull();
   }
 
index 0ba0ee0178ded0b8b9a46c32dd75ae4deb603224..f0b9ef844f5671a310ce94023c3fc3752b9b4d5d 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.scanner.issue.ignore.scanner;
 
+import java.io.File;
+import java.io.IOException;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -32,10 +34,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
 import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
 import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsRegexpScanner;
-import java.io.File;
-import java.io.IOException;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -85,19 +83,19 @@ public class IssueExclusionsLoaderTest {
   public void shouldExecute() {
     when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
     when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
-    assertThat(scanner.shouldExecuteOnProject(null)).isTrue();
+    assertThat(scanner.shouldExecute()).isTrue();
 
     when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
     when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
-    assertThat(scanner.shouldExecuteOnProject(null)).isTrue();
+    assertThat(scanner.shouldExecute()).isTrue();
 
     when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
     when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
-    assertThat(scanner.shouldExecuteOnProject(null)).isTrue();
+    assertThat(scanner.shouldExecute()).isTrue();
 
     when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
     when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
-    assertThat(scanner.shouldExecuteOnProject(null)).isFalse();
+    assertThat(scanner.shouldExecute()).isFalse();
 
   }