public void doSave() { | public void doSave() { | ||||
Preconditions.checkNotNull(this.value, "Measure value can't be null"); | Preconditions.checkNotNull(this.value, "Measure value can't be null"); | ||||
Preconditions.checkNotNull(this.metric, "Measure metric 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); | storage.store(this); | ||||
} | } | ||||
@Override | @Override | ||||
public PluginInfo getPluginInfo(String key) { | public PluginInfo getPluginInfo(String key) { | ||||
PluginInfo info = infosByKeys.get(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; | return info; | ||||
} | } | ||||
@Override | @Override | ||||
public Plugin getPluginInstance(String key) { | public Plugin getPluginInstance(String key) { | ||||
Plugin instance = pluginInstancesByKeys.get(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; | return instance; | ||||
} | } | ||||
*/ | */ | ||||
package org.sonar.scanner.cpd.deprecated; | package org.sonar.scanner.cpd.deprecated; | ||||
import org.slf4j.Logger; | |||||
import org.sonar.api.batch.ScannerSide; | import org.sonar.api.batch.ScannerSide; | ||||
import org.sonar.api.utils.log.Logger; | |||||
import org.sonar.api.utils.log.Loggers; | |||||
@ScannerSide | @ScannerSide | ||||
public abstract class CpdBlockIndexer { | public abstract class CpdBlockIndexer { | ||||
private static final Logger LOG = Loggers.get(CpdBlockIndexer.class); | |||||
abstract boolean isLanguageSupported(String language); | abstract boolean isLanguageSupported(String language); | ||||
abstract void index(String language); | abstract void index(String language); | ||||
protected void logExclusions(String[] exclusions, Logger logger) { | |||||
protected void logExclusions(String[] exclusions) { | |||||
if (exclusions.length > 0) { | if (exclusions.length > 0) { | ||||
StringBuilder message = new StringBuilder("Copy-paste detection exclusions:"); | StringBuilder message = new StringBuilder("Copy-paste detection exclusions:"); | ||||
for (String exclusion : exclusions) { | for (String exclusion : exclusions) { | ||||
message.append(exclusion); | message.append(exclusion); | ||||
} | } | ||||
logger.info(message.toString()); | |||||
LOG.info(message.toString()); | |||||
} | } | ||||
} | } | ||||
@Override | |||||
public String toString() { | |||||
return getClass().getSimpleName(); | |||||
} | |||||
} | } |
import com.google.common.annotations.VisibleForTesting; | import com.google.common.annotations.VisibleForTesting; | ||||
import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | ||||
import java.util.List; | import java.util.List; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.sonar.api.CoreProperties; | import org.sonar.api.CoreProperties; | ||||
import org.sonar.api.batch.CpdMapping; | import org.sonar.api.batch.CpdMapping; | ||||
import org.sonar.api.batch.fs.FilePredicates; | import org.sonar.api.batch.fs.FilePredicates; | ||||
import org.sonar.api.batch.fs.InputFile; | import org.sonar.api.batch.fs.InputFile; | ||||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | import org.sonar.api.batch.fs.internal.DefaultInputFile; | ||||
import org.sonar.api.config.Settings; | 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.Block; | ||||
import org.sonar.duplications.internal.pmd.TokenizerBridge; | import org.sonar.duplications.internal.pmd.TokenizerBridge; | ||||
import org.sonar.scanner.cpd.index.SonarCpdBlockIndex; | import org.sonar.scanner.cpd.index.SonarCpdBlockIndex; | ||||
public class DefaultCpdBlockIndexer extends CpdBlockIndexer { | 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 CpdMappings mappings; | ||||
private final FileSystem fs; | private final FileSystem fs; | ||||
public void index(String languageKey) { | public void index(String languageKey) { | ||||
CpdMapping mapping = mappings.getMapping(languageKey); | CpdMapping mapping = mappings.getMapping(languageKey); | ||||
if (mapping == null) { | if (mapping == null) { | ||||
LOG.debug("No CpdMapping for language " + languageKey); | |||||
LOG.debug("No CpdMapping for language {}", languageKey); | |||||
return; | return; | ||||
} | } | ||||
String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); | String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); | ||||
logExclusions(cpdExclusions, LOG); | |||||
logExclusions(cpdExclusions); | |||||
FilePredicates p = fs.predicates(); | FilePredicates p = fs.predicates(); | ||||
List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and( | List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and( | ||||
p.hasType(InputFile.Type.MAIN), | p.hasType(InputFile.Type.MAIN), |
import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||
import java.io.Reader; | import java.io.Reader; | ||||
import java.util.List; | import java.util.List; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.sonar.api.CoreProperties; | import org.sonar.api.CoreProperties; | ||||
import org.sonar.api.batch.fs.FilePredicates; | import org.sonar.api.batch.fs.FilePredicates; | ||||
import org.sonar.api.batch.fs.FileSystem; | import org.sonar.api.batch.fs.FileSystem; | ||||
import org.sonar.api.batch.fs.InputFile; | import org.sonar.api.batch.fs.InputFile; | ||||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | import org.sonar.api.batch.fs.internal.DefaultInputFile; | ||||
import org.sonar.api.config.Settings; | 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.Block; | ||||
import org.sonar.duplications.block.BlockChunker; | import org.sonar.duplications.block.BlockChunker; | ||||
import org.sonar.duplications.java.JavaStatementBuilder; | import org.sonar.duplications.java.JavaStatementBuilder; | ||||
public class JavaCpdBlockIndexer extends CpdBlockIndexer { | 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; | private static final int BLOCK_SIZE = 10; | ||||
@Override | @Override | ||||
public void index(String languageKey) { | public void index(String languageKey) { | ||||
String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); | String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); | ||||
logExclusions(cpdExclusions, LOG); | |||||
logExclusions(cpdExclusions); | |||||
FilePredicates p = fs.predicates(); | FilePredicates p = fs.predicates(); | ||||
List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and( | List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and( | ||||
p.hasType(InputFile.Type.MAIN), | p.hasType(InputFile.Type.MAIN), |
} | } | ||||
if (StringUtils.isBlank(resource.getKey())) { | 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; | return null; | ||||
} | } | ||||
Bucket parentBucket = getBucket(parent); | Bucket parentBucket = getBucket(parent); | ||||
if (parentBucket == null && parent != null) { | 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; | return null; | ||||
} | } | ||||
package org.sonar.scanner.phases; | package org.sonar.scanner.phases; | ||||
import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | ||||
import java.util.Collection; | |||||
import org.apache.commons.lang.StringUtils; | 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.PostJob; | ||||
import org.sonar.api.batch.ScannerSide; | |||||
import org.sonar.api.batch.SensorContext; | import org.sonar.api.batch.SensorContext; | ||||
import org.sonar.api.resources.Project; | 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.bootstrap.BatchExtensionDictionnary; | ||||
import org.sonar.scanner.events.EventBus; | import org.sonar.scanner.events.EventBus; | ||||
import org.sonar.scanner.util.BatchUtils; | import org.sonar.scanner.util.BatchUtils; | ||||
import java.util.Collection; | |||||
@ScannerSide | @ScannerSide | ||||
public class PostJobsExecutor { | 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 BatchExtensionDictionnary selector; | ||||
private final Project project; | private final Project project; | ||||
private static void logPostJobs(Collection<PostJob> postJobs) { | private static void logPostJobs(Collection<PostJob> postJobs) { | ||||
if (LOG.isDebugEnabled()) { | if (LOG.isDebugEnabled()) { | ||||
LOG.debug("Post-jobs : {}", StringUtils.join(postJobs, " -> ")); | |||||
LOG.debug(() -> "Post-jobs : " + StringUtils.join(postJobs, " -> ")); | |||||
} | } | ||||
} | } | ||||
} | } |
for (String lang : fs.languages()) { | for (String lang : fs.languages()) { | ||||
QProfile profile = profiles.findByLanguage(lang); | QProfile profile = profiles.findByLanguage(lang); | ||||
if (profile == null) { | if (profile == null) { | ||||
logger.warn("No Quality profile found for language " + lang); | |||||
logger.warn("No Quality profile found for language {}", lang); | |||||
} else { | } else { | ||||
logger.info("Quality profile for {}: {}", lang, profile.getName()); | logger.info("Quality profile for {}: {}", lang, profile.getName()); | ||||
if (isNotEmpty(defaultName) && defaultName.equals(profile.getName())) { | if (isNotEmpty(defaultName) && defaultName.equals(profile.getName())) { |
if (patterns.length > 0) { | if (patterns.length > 0) { | ||||
LOG.info(title); | LOG.info(title); | ||||
for (PathPattern pattern : patterns) { | for (PathPattern pattern : patterns) { | ||||
LOG.info(" " + pattern); | |||||
LOG.info(" {}", pattern); | |||||
} | } | ||||
} | } | ||||
} | } |
progressReport.stop(progress.count() + " files indexed"); | progressReport.stop(progress.count() + " files indexed"); | ||||
if (exclusionFilters.hasPattern()) { | 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()); | |||||
} | } | ||||
} | } | ||||
tasks.add(executorService.submit(() -> { | tasks.add(executorService.submit(() -> { | ||||
DefaultInputFile completedInputFile = inputFileBuilder.completeAndComputeMetadata(inputFile, type); | DefaultInputFile completedInputFile = inputFileBuilder.completeAndComputeMetadata(inputFile, type); | ||||
if (completedInputFile != null && accept(completedInputFile)) { | 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); | fs.add(completedInputFile); | ||||
status.markAsIndexed(completedInputFile); | status.markAsIndexed(completedInputFile); | ||||
File parentDir = completedInputFile.file().getParentFile(); | File parentDir = completedInputFile.file().getParentFile(); | ||||
// InputFileFilter extensions | // InputFileFilter extensions | ||||
for (InputFileFilter filter : filters) { | for (InputFileFilter filter : filters) { | ||||
if (!filter.accept(inputFile)) { | if (!filter.accept(inputFile)) { | ||||
LOG.debug("'{}' excluded by {}", inputFile.relativePath(), filter.getClass().getName()); | |||||
return false; | return false; | ||||
} | } | ||||
} | } |
private void logEncoding(Logger logger, Charset charset) { | private void logEncoding(Logger logger, Charset charset) { | ||||
if (!fs.isDefaultJvmEncoding()) { | if (!fs.isDefaultJvmEncoding()) { | ||||
logger.info("Source encoding: " + charset.displayName() + ", default locale: " + Locale.getDefault()); | |||||
logger.info("Source encoding: {}, default locale: {}", charset.displayName(), Locale.getDefault()); | |||||
} else { | } 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()); | |||||
} | } | ||||
} | } | ||||
String lang = langDetection.language(inputFile); | String lang = langDetection.language(inputFile); | ||||
if (lang == null && !settings.getBoolean(CoreProperties.IMPORT_UNKNOWN_FILES_KEY)) { | 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; | return null; | ||||
} | } | ||||
inputFile.setLanguage(lang); | inputFile.setLanguage(lang); |
import com.google.common.base.Joiner; | import com.google.common.base.Joiner; | ||||
import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | ||||
import com.google.common.collect.Maps; | 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.apache.commons.lang.StringUtils; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.sonar.api.utils.MessageException; | import org.sonar.api.utils.MessageException; | ||||
import org.sonar.scanner.repository.language.Language; | import org.sonar.scanner.repository.language.Language; | ||||
import org.sonar.scanner.repository.language.LanguagesRepository; | 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. | * Detect language of a source file based on its suffix and configured patterns. | ||||
} | } | ||||
PathPattern[] defaultLanguagePatterns = PathPattern.create(patterns); | PathPattern[] defaultLanguagePatterns = PathPattern.create(patterns); | ||||
patternsByLanguage.put(language.key(), defaultLanguagePatterns); | 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())); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (detectedLanguage != null) { | if (detectedLanguage != null) { | ||||
LOG.debug(String.format("Language of file '%s' is detected to be '%s'", inputFile.relativePath(), detectedLanguage)); | |||||
return detectedLanguage; | return detectedLanguage; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
private String getFileLangPatternPropKey(String languageKey) { | |||||
private static String getFileLangPatternPropKey(String languageKey) { | |||||
return "sonar.lang.patterns." + languageKey; | return "sonar.lang.patterns." + languageKey; | ||||
} | } | ||||
reportFileDir = new File(fs.workDir(), reportFileDirStr); | reportFileDir = new File(fs.workDir(), reportFileDirStr); | ||||
} | } | ||||
if (StringUtils.endsWith(reportFileDirStr, ".html")) { | 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(); | reportFileDir = reportFileDir.getParentFile(); | ||||
} | } | ||||
try { | try { |
import javax.annotation.CheckForNull; | import javax.annotation.CheckForNull; | ||||
import org.apache.commons.io.input.BOMInputStream; | import org.apache.commons.io.input.BOMInputStream; | ||||
import org.apache.commons.lang.StringUtils; | 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.ScannerSide; | ||||
import org.sonar.api.batch.sensor.highlighting.NewHighlighting; | import org.sonar.api.batch.sensor.highlighting.NewHighlighting; | ||||
import org.sonar.api.utils.log.Loggers; | |||||
import org.sonar.api.web.CodeColorizerFormat; | import org.sonar.api.web.CodeColorizerFormat; | ||||
import org.sonar.colorizer.JavaTokenizers; | import org.sonar.colorizer.JavaTokenizers; | ||||
import org.sonar.colorizer.Tokenizer; | import org.sonar.colorizer.Tokenizer; | ||||
@ScannerSide | @ScannerSide | ||||
public class CodeColorizers { | 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; | private final Map<String, CodeColorizerFormat> byLang; | ||||
byLang.put(format.getLanguageKey(), format); | 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(), ",")); | |||||
} | } | ||||
/** | /** | ||||
List<Tokenizer> tokenizers; | List<Tokenizer> tokenizers; | ||||
if (format == null) { | if (format == null) { | ||||
// Workaround for Java test code since Java plugin only provides highlighting for main source and no colorizer | // 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 | // See SONARJAVA-830 | ||||
if ("java".equals(language)) { | if ("java".equals(language)) { | ||||
tokenizers = JavaTokenizers.forHtml(); | tokenizers = JavaTokenizers.forHtml(); |
*/ | */ | ||||
package org.sonar.scanner.source; | package org.sonar.scanner.source; | ||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.sonar.api.batch.sensor.highlighting.NewHighlighting; | import org.sonar.api.batch.sensor.highlighting.NewHighlighting; | ||||
import org.sonar.api.batch.sensor.highlighting.TypeOfText; | import org.sonar.api.batch.sensor.highlighting.TypeOfText; | ||||
import org.sonar.colorizer.HtmlCodeBuilder; | import org.sonar.colorizer.HtmlCodeBuilder; | ||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
public class HighlightingCodeBuilder extends HtmlCodeBuilder { | public class HighlightingCodeBuilder extends HtmlCodeBuilder { | ||||
private static final Logger LOG = LoggerFactory.getLogger(HighlightingCodeBuilder.class); | private static final Logger LOG = LoggerFactory.getLogger(HighlightingCodeBuilder.class); | ||||
startOffset = currentOffset; | startOffset = currentOffset; | ||||
cssClass = startMatcher.group(1); | cssClass = startMatcher.group(1); | ||||
} else { | } 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 { | } else { | ||||
Matcher endMatcher = END_TAG_PATTERN.matcher(htmlTag); | Matcher endMatcher = END_TAG_PATTERN.matcher(htmlTag); | ||||
highlighting.highlight(startOffset, currentOffset, TypeOfText.forCssClass(cssClass)); | highlighting.highlight(startOffset, currentOffset, TypeOfText.forCssClass(cssClass)); | ||||
startOffset = -1; | startOffset = -1; | ||||
} else { | } 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); | |||||
} | } | ||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.sonar.scanner.storage; | 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.base.Preconditions; | ||||
import com.google.common.collect.Maps; | |||||
import com.persistit.Exchange; | import com.persistit.Exchange; | ||||
import com.persistit.Persistit; | |||||
import com.persistit.Value; | import com.persistit.Value; | ||||
import com.persistit.Volume; | |||||
import com.persistit.encoding.CoderManager; | import com.persistit.encoding.CoderManager; | ||||
import com.persistit.Persistit; | |||||
import com.persistit.encoding.ValueCoder; | import com.persistit.encoding.ValueCoder; | ||||
import com.persistit.exception.PersistitException; | import com.persistit.exception.PersistitException; | ||||
import com.persistit.Volume; | |||||
import java.util.Map; | |||||
import java.util.Map.Entry; | |||||
import org.picocontainer.Startable; | import org.picocontainer.Startable; | ||||
import org.sonar.api.batch.ScannerSide; | import org.sonar.api.batch.ScannerSide; | ||||
public <V> Storage<V> createCache(String cacheName) { | public <V> Storage<V> createCache(String cacheName) { | ||||
Preconditions.checkState(volume != null && volume.isOpened(), "Caches are not initialized"); | 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 { | try { | ||||
Exchange exchange = persistit.getExchange(volume, cacheName, true); | Exchange exchange = persistit.getExchange(volume, cacheName, true); | ||||
exchange.setMaximumValueSize(Value.MAXIMUM_SIZE); | exchange.setMaximumValueSize(Value.MAXIMUM_SIZE); |
package org.sonar.scanner.cpd.deprecated; | package org.sonar.scanner.cpd.deprecated; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Rule; | |||||
import org.junit.Test; | 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.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.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 { | public class DefaultCpdBlockIndexerTest { | ||||
private DefaultCpdBlockIndexer engine; | private DefaultCpdBlockIndexer engine; | ||||
private Settings settings; | private Settings settings; | ||||
@Rule | |||||
public LogTester logTester = new LogTester(); | |||||
@Before | @Before | ||||
public void init() { | public void init() { | ||||
settings = new MapSettings(); | settings = new MapSettings(); | ||||
@Test | @Test | ||||
public void shouldLogExclusions() { | 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:" | String message = "Copy-paste detection exclusions:" | ||||
+ "\n Foo*" | + "\n Foo*" | ||||
+ "\n **/Bar*"; | + "\n **/Bar*"; | ||||
verify(logger, times(1)).info(message); | |||||
assertThat(logTester.logs()).containsExactly(message); | |||||
} | } | ||||
@Test | @Test |