@@ -89,7 +89,7 @@ public class DefaultMeasure<G extends Serializable> extends DefaultStorable impl | |||
public void doSave() { | |||
Preconditions.checkNotNull(this.value, "Measure value can't be null"); | |||
Preconditions.checkNotNull(this.metric, "Measure metric can't be null"); | |||
Preconditions.checkState(this.metric.valueType().equals(this.value.getClass()), "Measure value should be of type " + this.metric.valueType()); | |||
Preconditions.checkState(this.metric.valueType().equals(this.value.getClass()), "Measure value should be of type %s", this.metric.valueType()); | |||
storage.store(this); | |||
} | |||
@@ -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; | |||
} | |||
@@ -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(); | |||
} | |||
} |
@@ -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), |
@@ -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), |
@@ -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; | |||
} | |||
@@ -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, " -> ")); | |||
} | |||
} | |||
} |
@@ -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())) { |
@@ -62,7 +62,7 @@ public class ExclusionFilters { | |||
if (patterns.length > 0) { | |||
LOG.info(title); | |||
for (PathPattern pattern : patterns) { | |||
LOG.info(" " + pattern); | |||
LOG.info(" {}", pattern); | |||
} | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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()); | |||
} | |||
} | |||
@@ -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); |
@@ -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; | |||
} | |||
@@ -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 { |
@@ -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(); |
@@ -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); | |||
} | |||
} | |||
} |
@@ -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); |
@@ -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 |