diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-27 09:20:44 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-27 09:26:11 +0100 |
commit | 7bad03950e4ec3e82a5fef2ef50867a2e4ac29e2 (patch) | |
tree | e8c2f4f586bafe536fb80d396565715818c4b11d | |
parent | 8218494577a870ae3ef81997f3a17da50d199403 (diff) | |
download | sonarqube-7bad03950e4ec3e82a5fef2ef50867a2e4ac29e2.tar.gz sonarqube-7bad03950e4ec3e82a5fef2ef50867a2e4ac29e2.zip |
Fix some quality flaws
11 files changed, 21 insertions, 52 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 38083fed3db..169246a096f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -19,9 +19,6 @@ */ package org.sonar.plugins.core.timemachine; -import org.sonar.batch.components.TimeMachineConfiguration; - -import org.sonar.batch.components.PastSnapshot; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorBarriers; import org.sonar.api.batch.DecoratorContext; @@ -31,6 +28,8 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.index.ResourceCache; import java.util.List; @@ -59,7 +58,7 @@ public final class TimeMachineConfigurationPersister implements Decorator { void persistConfiguration(Resource module) { List<PastSnapshot> pastSnapshots = timeMachineConfiguration.getProjectPastSnapshots(); - Snapshot projectSnapshot = resourceCache.get(module.getEffectiveKey()).snapshot(); + Snapshot projectSnapshot = resourceCache.get(module).snapshot(); for (PastSnapshot pastSnapshot : pastSnapshots) { Snapshot snapshot = session.reattach(Snapshot.class, projectSnapshot.getId()); updatePeriodParams(snapshot, pastSnapshot); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java b/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java index 3fc092e72a6..fa98e02d0b8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java @@ -492,7 +492,6 @@ public class Cache<V> { return key; } - @CheckForNull public V value() { return value; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java index 3b1ec2fe187..db5c29edeb4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java @@ -47,7 +47,6 @@ public class ResourceCache implements BatchComponent { return resources.get(componentKey); } - @CheckForNull public BatchResource get(Resource resource) { if (!(resource instanceof Library)) { return resources.get(resource.getEffectiveKey()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java index 66d5623c04b..3566bb0edcd 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java @@ -25,13 +25,7 @@ import org.apache.commons.lang.StringUtils; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Library; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.api.resources.Scopes; +import org.sonar.api.resources.*; import org.sonar.api.security.ResourcePermissions; import org.sonar.api.utils.SonarException; import org.sonar.api.utils.internal.Uuids; @@ -213,7 +207,7 @@ public class ResourcePersister implements ScanPersister { * Everything except project and library */ private Snapshot persistFileOrDirectory(Project project, Resource resource, @Nullable Resource parentReference) { - BatchResource moduleResource = resourceCache.get(project.getEffectiveKey()); + BatchResource moduleResource = resourceCache.get(project); Integer moduleId = moduleResource.resource().getId(); ResourceModel model = findOrCreateModel(resource, parentReference != null ? parentReference : project); model.setRootId(moduleId); @@ -223,7 +217,7 @@ public class ResourcePersister implements ScanPersister { Snapshot parentSnapshot; if (parentReference != null) { - parentSnapshot = resourceCache.get(parentReference.getEffectiveKey()).snapshot(); + parentSnapshot = resourceCache.get(parentReference).snapshot(); } else { parentSnapshot = moduleResource.snapshot(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java index 5a86495495d..bf537550a8c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java @@ -87,9 +87,9 @@ public class SourcePersister implements ScanPersister { } private void persist(DbSession session, FileSourceMapper mapper, DefaultInputFile inputFile, Map<String, FileSourceDto> previousDtosByUuid) { - String fileUuid = resourceCache.get(inputFile.key()).resource().getUuid(); + String fileUuid = resourceCache.get(inputFile).resource().getUuid(); - InputFileMetadata metadata = inputPathCache.getFileMetadata(inputFile.moduleKey(), inputFile.relativePath()); + InputFileMetadata metadata = inputPathCache.getFileMetadata(inputFile); byte[] data = computeData(inputFile, metadata); String dataHash = DigestUtils.md5Hex(data); FileSourceDto previousDto = previousDtosByUuid.get(fileUuid); diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java index 6d2eeabcc73..3dc913b005b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java @@ -50,13 +50,7 @@ import org.sonar.core.source.SnapshotDataTypes; import javax.annotation.CheckForNull; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver { @@ -96,8 +90,7 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver { String componentKey = measureEntry.key()[0].toString(); InputFile file = inputFileCache.getFile(StringUtils.substringBeforeLast(componentKey, ":"), StringUtils.substringAfterLast(componentKey, ":")); Measure oldMeasure = measureEntry.value(); - DefaultMeasure<Serializable> newMeasure = new DefaultMeasure<>() - .forMetric(oldMeasure.getMetric()); + DefaultMeasure<Serializable> newMeasure = new DefaultMeasure<>().forMetric(oldMeasure.getMetric()); if (file != null) { newMeasure.onFile(file); } else { diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java index bf709694f6f..657dbaba303 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java +++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java @@ -23,11 +23,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorBarriers; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; +import org.sonar.api.batch.*; import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; import org.sonar.api.measures.CoreMetrics; @@ -42,11 +38,7 @@ import org.sonar.batch.index.ResourceCache; import org.sonar.core.qualitygate.db.QualityGateConditionDto; import org.sonar.core.timemachine.Periods; -import java.util.Collection; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; +import java.util.*; public class QualityGateVerifier implements Decorator { @@ -169,7 +161,7 @@ public class QualityGateVerifier implements Decorator { .append(alertValue(condition, level)); if (alertPeriod != null) { - Snapshot snapshot = resourceCache.get(project.getEffectiveKey()).snapshot(); + Snapshot snapshot = resourceCache.get(project).snapshot(); stringBuilder.append(" ").append(periods.label(snapshot, alertPeriod)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java index 16181f83098..22cbe41124f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java @@ -25,17 +25,12 @@ import org.sonar.api.BatchComponent; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; +import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.batch.index.BatchResource; import javax.annotation.CheckForNull; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; +import java.util.*; /** * Cache of all files and dirs. This cache is shared amongst all project modules. Inclusion and @@ -143,6 +138,10 @@ public class InputPathCache implements BatchComponent { return null; } + public InputFileMetadata getFileMetadata(DefaultInputFile inputFile) { + return getFileMetadata(inputFile.moduleKey(), inputFile.relativePath()); + } + @CheckForNull public InputDir getDir(String moduleKey, String relativePath) { if (inputDirCache.containsKey(moduleKey)) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java index 4323e5cff92..c12a6afc58e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java @@ -26,8 +26,6 @@ import org.slf4j.LoggerFactory; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.scm.BlameCommand.BlameOutput; import org.sonar.api.batch.scm.BlameLine; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.PropertiesBuilder; import org.sonar.batch.index.BatchResource; import org.sonar.batch.index.ResourceCache; import org.sonar.batch.protocol.output.BatchReport; @@ -134,10 +132,6 @@ class DefaultBlameOutput implements BlameOutput { return NON_ASCII_CHARS.matcher(inputString).replaceAll("_"); } - private static PropertiesBuilder<Integer, String> propertiesBuilder(Metric metric) { - return new PropertiesBuilder<Integer, String>(metric); - } - public void finish() { progressReport.stop(count + "/" + total + " files analyzed"); if (!allFilesToBlame.isEmpty()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java index 700098ab142..8795742ba5b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java @@ -110,7 +110,7 @@ public final class ScmSensor implements Sensor { } private void addIfNotEmpty(List<InputFile> filesToBlame, DefaultInputFile f) { - InputFileMetadata metadata = inputPathCache.getFileMetadata(f.moduleKey(), f.relativePath()); + InputFileMetadata metadata = inputPathCache.getFileMetadata(f); if (!metadata.isEmpty()) { filesToBlame.add(f); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java b/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java index aac994e30d4..5851824f169 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java @@ -58,7 +58,7 @@ public final class LinesSensor implements Sensor { .save(); if (f.language() == null) { // As an approximation for files with no language plugin we consider every non blank line as ncloc - InputFileMetadata metadata = inputPathCache.getFileMetadata(((DefaultInputFile) f).moduleKey(), f.relativePath()); + InputFileMetadata metadata = inputPathCache.getFileMetadata((DefaultInputFile) f); ((DefaultMeasure<Integer>) context.<Integer>newMeasure() .onFile(f) .forMetric(CoreMetrics.NCLOC) |