aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-01-02 18:03:31 +0100
committerJulien HENRY <henryju@yahoo.fr>2017-01-03 14:41:27 +0100
commit806e0ead74101e2409f4d995128015d0ca6f26b8 (patch)
tree8493f55acb1b7ca7041574c0c3b4c13523d45515 /sonar-scanner-engine
parent8f429bd30146ed064f37440312548d5fcde20a9b (diff)
downloadsonarqube-806e0ead74101e2409f4d995128015d0ca6f26b8.tar.gz
sonarqube-806e0ead74101e2409f4d995128015d0ca6f26b8.zip
Fix some quality flaws
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchPluginRepository.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdBlockIndexer.java14
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java10
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ExclusionFilters.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java14
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java9
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/source/HighlightingCodeBuilder.java9
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java14
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java23
17 files changed, 69 insertions, 72 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchPluginRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchPluginRepository.java
index 08f7ea09bdd..0bad3324f52 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchPluginRepository.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchPluginRepository.java
@@ -91,14 +91,14 @@ public class BatchPluginRepository implements PluginRepository, Startable {
@Override
public PluginInfo getPluginInfo(String key) {
PluginInfo info = infosByKeys.get(key);
- Preconditions.checkState(info != null, String.format("Plugin [%s] does not exist", key));
+ Preconditions.checkState(info != null, "Plugin [%s] does not exist", key);
return info;
}
@Override
public Plugin getPluginInstance(String key) {
Plugin instance = pluginInstancesByKeys.get(key);
- Preconditions.checkState(instance != null, String.format("Plugin [%s] does not exist", key));
+ Preconditions.checkState(instance != null, "Plugin [%s] does not exist", key);
return instance;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdBlockIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdBlockIndexer.java
index 97a0a7e96ae..a44227e8db6 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdBlockIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdBlockIndexer.java
@@ -19,17 +19,20 @@
*/
package org.sonar.scanner.cpd.deprecated;
-import org.slf4j.Logger;
import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
@ScannerSide
public abstract class CpdBlockIndexer {
+ private static final Logger LOG = Loggers.get(CpdBlockIndexer.class);
+
abstract boolean isLanguageSupported(String language);
abstract void index(String language);
- protected void logExclusions(String[] exclusions, Logger logger) {
+ protected void logExclusions(String[] exclusions) {
if (exclusions.length > 0) {
StringBuilder message = new StringBuilder("Copy-paste detection exclusions:");
for (String exclusion : exclusions) {
@@ -37,13 +40,8 @@ public abstract class CpdBlockIndexer {
message.append(exclusion);
}
- logger.info(message.toString());
+ LOG.info(message.toString());
}
}
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java
index 6ff5e27b878..41d9a2ad2cc 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java
@@ -22,8 +22,6 @@ package org.sonar.scanner.cpd.deprecated;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.CpdMapping;
import org.sonar.api.batch.fs.FilePredicates;
@@ -31,13 +29,15 @@ 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.config.Settings;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.internal.pmd.TokenizerBridge;
import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
public class DefaultCpdBlockIndexer extends CpdBlockIndexer {
- private static final Logger LOG = LoggerFactory.getLogger(DefaultCpdBlockIndexer.class);
+ private static final Logger LOG = Loggers.get(DefaultCpdBlockIndexer.class);
private final CpdMappings mappings;
private final FileSystem fs;
@@ -60,12 +60,12 @@ public class DefaultCpdBlockIndexer extends CpdBlockIndexer {
public void index(String languageKey) {
CpdMapping mapping = mappings.getMapping(languageKey);
if (mapping == null) {
- LOG.debug("No CpdMapping for language " + languageKey);
+ LOG.debug("No CpdMapping for language {}", languageKey);
return;
}
String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
- logExclusions(cpdExclusions, LOG);
+ logExclusions(cpdExclusions);
FilePredicates p = fs.predicates();
List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and(
p.hasType(InputFile.Type.MAIN),
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java
index 635b1248b70..80052576c84 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java
@@ -27,14 +27,14 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.FilePredicates;
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.config.Settings;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.BlockChunker;
import org.sonar.duplications.java.JavaStatementBuilder;
@@ -46,7 +46,7 @@ import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
public class JavaCpdBlockIndexer extends CpdBlockIndexer {
- private static final Logger LOG = LoggerFactory.getLogger(JavaCpdBlockIndexer.class);
+ private static final Logger LOG = Loggers.get(JavaCpdBlockIndexer.class);
private static final int BLOCK_SIZE = 10;
@@ -68,7 +68,7 @@ public class JavaCpdBlockIndexer extends CpdBlockIndexer {
@Override
public void index(String languageKey) {
String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
- logExclusions(cpdExclusions, LOG);
+ logExclusions(cpdExclusions);
FilePredicates p = fs.predicates();
List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and(
p.hasType(InputFile.Type.MAIN),
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java
index 030518b26f5..a1db20b949e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java
@@ -315,7 +315,7 @@ public class DefaultIndex {
}
if (StringUtils.isBlank(resource.getKey())) {
- LOG.warn("Unable to index a resource without key " + resource);
+ LOG.warn("Unable to index a resource without key: {}", resource);
return null;
}
@@ -323,7 +323,7 @@ public class DefaultIndex {
Bucket parentBucket = getBucket(parent);
if (parentBucket == null && parent != null) {
- LOG.warn("Resource ignored, parent is not indexed: " + resource);
+ LOG.warn("Resource ignored, parent is not indexed: {}", resource);
return null;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java
index 0d25e5884c2..f01ab46a896 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java
@@ -20,21 +20,21 @@
package org.sonar.scanner.phases;
import com.google.common.collect.Lists;
+import java.util.Collection;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.PostJob;
+import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.bootstrap.BatchExtensionDictionnary;
import org.sonar.scanner.events.EventBus;
import org.sonar.scanner.util.BatchUtils;
-import java.util.Collection;
@ScannerSide
public class PostJobsExecutor {
- private static final Logger LOG = LoggerFactory.getLogger(PostJobsExecutor.class);
+ private static final Logger LOG = Loggers.get(PostJobsExecutor.class);
private final BatchExtensionDictionnary selector;
private final Project project;
@@ -67,7 +67,7 @@ public class PostJobsExecutor {
private static void logPostJobs(Collection<PostJob> postJobs) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Post-jobs : {}", StringUtils.join(postJobs, " -> "));
+ LOG.debug(() -> "Post-jobs : " + StringUtils.join(postJobs, " -> "));
}
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
index 42537768da3..d5b479ceebf 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
@@ -56,7 +56,7 @@ public class QProfileVerifier {
for (String lang : fs.languages()) {
QProfile profile = profiles.findByLanguage(lang);
if (profile == null) {
- logger.warn("No Quality profile found for language " + lang);
+ logger.warn("No Quality profile found for language {}", lang);
} else {
logger.info("Quality profile for {}: {}", lang, profile.getName());
if (isNotEmpty(defaultName) && defaultName.equals(profile.getName())) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ExclusionFilters.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ExclusionFilters.java
index 030e61062ff..2d7975e7ea3 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ExclusionFilters.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ExclusionFilters.java
@@ -62,7 +62,7 @@ public class ExclusionFilters {
if (patterns.length > 0) {
LOG.info(title);
for (PathPattern pattern : patterns) {
- LOG.info(" " + pattern);
+ LOG.info(" {}", pattern);
}
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
index adb316b5669..13aa962ccca 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
@@ -103,7 +103,7 @@ public class FileIndexer {
progressReport.stop(progress.count() + " files indexed");
if (exclusionFilters.hasPattern()) {
- LOG.info(progress.excludedByPatternsCount() + " files ignored because of inclusion/exclusion patterns");
+ LOG.info("{} files ignored because of inclusion/exclusion patterns", progress.excludedByPatternsCount());
}
}
@@ -162,6 +162,11 @@ public class FileIndexer {
tasks.add(executorService.submit(() -> {
DefaultInputFile completedInputFile = inputFileBuilder.completeAndComputeMetadata(inputFile, type);
if (completedInputFile != null && accept(completedInputFile)) {
+ LOG.debug("'{}' indexed {}with language '{}' and charset '{}'",
+ inputFile.relativePath(),
+ type == Type.TEST ? "as test " : "",
+ inputFile.language(),
+ inputFile.charset());
fs.add(completedInputFile);
status.markAsIndexed(completedInputFile);
File parentDir = completedInputFile.file().getParentFile();
@@ -180,6 +185,7 @@ public class FileIndexer {
// InputFileFilter extensions
for (InputFileFilter filter : filters) {
if (!filter.accept(inputFile)) {
+ LOG.debug("'{}' excluded by {}", inputFile.relativePath(), filter.getClass().getName());
return false;
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java
index 879abdec13d..b23713dff75 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java
@@ -56,9 +56,9 @@ public class FileSystemLogger {
private void logEncoding(Logger logger, Charset charset) {
if (!fs.isDefaultJvmEncoding()) {
- logger.info("Source encoding: " + charset.displayName() + ", default locale: " + Locale.getDefault());
+ logger.info("Source encoding: {}, default locale: {}", charset.displayName(), Locale.getDefault());
} else {
- logger.warn("Source encoding is platform dependent (" + charset.displayName() + "), default locale: " + Locale.getDefault());
+ logger.warn("Source encoding is platform dependent ({}), default locale: {}", charset.displayName(), Locale.getDefault());
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java
index 31fff15071b..0cdf970a4e1 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java
@@ -105,6 +105,8 @@ class InputFileBuilder {
String lang = langDetection.language(inputFile);
if (lang == null && !settings.getBoolean(CoreProperties.IMPORT_UNKNOWN_FILES_KEY)) {
+ // Return fast to skip costly metadata computation
+ LOG.debug("'{}' language is not supported by any analyzer. Skipping it.", inputFile.relativePath());
return null;
}
inputFile.setLanguage(lang);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java
index f17a593add9..10708b1d392 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java
@@ -22,6 +22,10 @@ package org.sonar.scanner.scan.filesystem;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,11 +36,6 @@ import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.repository.language.Language;
import org.sonar.scanner.repository.language.LanguagesRepository;
-import javax.annotation.CheckForNull;
-
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.Map;
/**
* Detect language of a source file based on its suffix and configured patterns.
@@ -68,7 +67,7 @@ class LanguageDetection {
}
PathPattern[] defaultLanguagePatterns = PathPattern.create(patterns);
patternsByLanguage.put(language.key(), defaultLanguagePatterns);
- LOG.debug("Declared extensions of language " + language + " were converted to " + getDetails(language.key()));
+ LOG.debug("Declared extensions of language {} were converted to {}", language, getDetails(language.key()));
}
}
@@ -103,7 +102,6 @@ class LanguageDetection {
}
}
if (detectedLanguage != null) {
- LOG.debug(String.format("Language of file '%s' is detected to be '%s'", inputFile.relativePath(), detectedLanguage));
return detectedLanguage;
}
@@ -127,7 +125,7 @@ class LanguageDetection {
return false;
}
- private String getFileLangPatternPropKey(String languageKey) {
+ private static String getFileLangPatternPropKey(String languageKey) {
return "sonar.lang.patterns." + languageKey;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java
index 6e5caf6b7e8..1aee9066f4a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java
@@ -110,7 +110,7 @@ public class HtmlReport implements Reporter {
reportFileDir = new File(fs.workDir(), reportFileDirStr);
}
if (StringUtils.endsWith(reportFileDirStr, ".html")) {
- LOG.warn(HTML_REPORT_LOCATION_KEY + " should indicate a directory. Using parent folder.");
+ LOG.warn("{} should indicate a directory. Using parent folder.", HTML_REPORT_LOCATION_KEY);
reportFileDir = reportFileDir.getParentFile();
}
try {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java
index 847bc99fa95..c30dd8ea091 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java
@@ -32,10 +32,9 @@ import java.util.Map;
import javax.annotation.CheckForNull;
import org.apache.commons.io.input.BOMInputStream;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.CodeColorizerFormat;
import org.sonar.colorizer.JavaTokenizers;
import org.sonar.colorizer.Tokenizer;
@@ -46,7 +45,7 @@ import org.sonar.colorizer.Tokenizer;
@ScannerSide
public class CodeColorizers {
- private static final Logger LOG = LoggerFactory.getLogger(CodeColorizers.class);
+ private static final org.sonar.api.utils.log.Logger LOG = Loggers.get(CodeColorizers.class);
private final Map<String, CodeColorizerFormat> byLang;
@@ -56,7 +55,7 @@ public class CodeColorizers {
byLang.put(format.getLanguageKey(), format);
}
- LOG.debug("Code colorizer, supported languages: " + StringUtils.join(byLang.keySet(), ","));
+ LOG.debug(() -> "Code colorizer, supported languages: " + StringUtils.join(byLang.keySet(), ","));
}
/**
@@ -72,7 +71,7 @@ public class CodeColorizers {
List<Tokenizer> tokenizers;
if (format == null) {
// Workaround for Java test code since Java plugin only provides highlighting for main source and no colorizer
- // TODO can be dropped when Java plugin embed its own CodeColorizerFormat of (better) provides highlighting for tests
+ // TODO can be dropped when Java plugin embed its own CodeColorizerFormat or (better) provides highlighting for tests
// See SONARJAVA-830
if ("java".equals(language)) {
tokenizers = JavaTokenizers.forHtml();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/HighlightingCodeBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/HighlightingCodeBuilder.java
index d529351ea58..284160a4de1 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/HighlightingCodeBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/HighlightingCodeBuilder.java
@@ -19,15 +19,14 @@
*/
package org.sonar.scanner.source;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import org.sonar.colorizer.HtmlCodeBuilder;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
public class HighlightingCodeBuilder extends HtmlCodeBuilder {
private static final Logger LOG = LoggerFactory.getLogger(HighlightingCodeBuilder.class);
@@ -65,7 +64,7 @@ public class HighlightingCodeBuilder extends HtmlCodeBuilder {
startOffset = currentOffset;
cssClass = startMatcher.group(1);
} else {
- LOG.warn("Expected to match highlighting start html tag but was: " + htmlTag);
+ LOG.warn("Expected to match highlighting start html tag but was: {}", htmlTag);
}
} else {
Matcher endMatcher = END_TAG_PATTERN.matcher(htmlTag);
@@ -73,7 +72,7 @@ public class HighlightingCodeBuilder extends HtmlCodeBuilder {
highlighting.highlight(startOffset, currentOffset, TypeOfText.forCssClass(cssClass));
startOffset = -1;
} else {
- LOG.warn("Expected to match highlighting end html tag but was: " + htmlTag);
+ LOG.warn("Expected to match highlighting end html tag but was: {}", htmlTag);
}
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java
index c7ecb2eb32a..392f29c07b3 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java
@@ -19,19 +19,17 @@
*/
package org.sonar.scanner.storage;
-import com.google.common.collect.Maps;
-
-import java.util.Map;
-import java.util.Map.Entry;
-
import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import com.persistit.Exchange;
+import com.persistit.Persistit;
import com.persistit.Value;
+import com.persistit.Volume;
import com.persistit.encoding.CoderManager;
-import com.persistit.Persistit;
import com.persistit.encoding.ValueCoder;
import com.persistit.exception.PersistitException;
-import com.persistit.Volume;
+import java.util.Map;
+import java.util.Map.Entry;
import org.picocontainer.Startable;
import org.sonar.api.batch.ScannerSide;
@@ -67,7 +65,7 @@ public class Storages implements Startable {
public <V> Storage<V> createCache(String cacheName) {
Preconditions.checkState(volume != null && volume.isOpened(), "Caches are not initialized");
- Preconditions.checkState(!cacheMap.containsKey(cacheName), "Cache is already created: " + cacheName);
+ Preconditions.checkState(!cacheMap.containsKey(cacheName), "Cache is already created: %s", cacheName);
try {
Exchange exchange = persistit.getExchange(volume, cacheName, true);
exchange.setMaximumValueSize(Value.MAXIMUM_SIZE);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java
index f748f296d8a..f07624bc21b 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java
@@ -20,23 +20,22 @@
package org.sonar.scanner.cpd.deprecated;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.sonar.api.config.Settings;
import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.LogTester;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
public class DefaultCpdBlockIndexerTest {
private DefaultCpdBlockIndexer engine;
private Settings settings;
+ @Rule
+ public LogTester logTester = new LogTester();
+
@Before
public void init() {
settings = new MapSettings();
@@ -45,17 +44,15 @@ public class DefaultCpdBlockIndexerTest {
@Test
public void shouldLogExclusions() {
- Logger logger = mock(Logger.class);
- engine.logExclusions(new String[0], logger);
- verify(logger, never()).info(anyString());
+ engine.logExclusions(new String[0]);
+ assertThat(logTester.logs()).isEmpty();
- logger = mock(Logger.class);
- engine.logExclusions(new String[] {"Foo*", "**/Bar*"}, logger);
+ engine.logExclusions(new String[] {"Foo*", "**/Bar*"});
String message = "Copy-paste detection exclusions:"
+ "\n Foo*"
+ "\n **/Bar*";
- verify(logger, times(1)).info(message);
+ assertThat(logTester.logs()).containsExactly(message);
}
@Test