From d4ae5228bb668e65baa644b52d41286d5f3d55cd Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Sun, 27 Mar 2011 23:43:19 +0200 Subject: [PATCH] Fix coding violations --- .../org/sonar/plugins/core/CorePlugin.java | 8 +++-- .../core/sensors/CoverageDecorator.java | 5 +-- .../core/timemachine/TendencyDecorator.java | 1 - .../java/org/sonar/plugins/cpd/CpdPlugin.java | 32 +++++++++---------- .../plugins/findbugs/FindbugsPlugin.java | 17 +++++----- .../org/sonar/plugins/pmd/PmdExecutor.java | 5 +-- .../squid/bridges/ChidamberKemererBridge.java | 4 +-- .../src/main/java/org/sonar/batch/Module.java | 2 +- .../PastSnapshotFinderByPreviousAnalysis.java | 4 +-- .../components/TimeMachineConfiguration.java | 1 - .../batch/index/DefaultResourcePersister.java | 2 +- .../main/java/org/sonar/jpa/dao/RulesDao.java | 6 ---- .../org/sonar/duplications/cpd/Match.java | 6 ++-- .../api/batch/AbstractCoverageExtension.java | 1 + .../org/sonar/api/batch/SensorContext.java | 2 +- .../api/checks/AnnotationCheckFactory.java | 2 +- .../api/database/model/MeasureModel.java | 1 - .../org/sonar/api/measures/CoreMetrics.java | 3 ++ .../api/rules/Iso9126RulesCategories.java | 15 ++++++--- .../java/org/sonar/api/utils/DateUtils.java | 4 +-- .../org/sonar/api/utils/KeyValueFormat.java | 5 ++- .../org/sonar/api/utils/ServerHttpClient.java | 2 +- .../java/org/sonar/api/utils/ZipUtils.java | 2 +- .../server/charts/jruby/TrendsChart.java | 3 +- .../configuration/ConfigurationFactory.java | 4 +-- .../sonar/server/filters/FilterResult.java | 4 ++- .../platform/PlatformLifecycleListener.java | 4 --- .../sonar/server/startup/EnableProfiles.java | 4 +-- .../startup/RegisterProvidedProfiles.java | 4 +-- .../server/startup/RegisterQualityModels.java | 3 +- .../org/sonar/server/ui/DefaultPages.java | 4 +-- .../java/org/sonar/squid/api/SourceCode.java | 1 + .../main/java/org/sonar/test/TestUtils.java | 7 ++-- .../channel/ReaderHasNextCharMatcher.java | 1 - .../sonar/wsclient/services/Dependency.java | 4 ++- .../sonar/wsclient/services/ProfileQuery.java | 2 +- .../wsclient/services/UpdateCenterQuery.java | 2 +- 37 files changed, 88 insertions(+), 89 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 8363f5b9297..236581dc351 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -113,7 +113,9 @@ import java.util.List; @Property( key = "sonar.timemachine.period1", name = "Period 1", - description = "Period used to compare measures and track new violations. Values are : ", + description = "Period used to compare measures and track new violations. Values are : ", project = false, global = true, defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1 @@ -137,7 +139,9 @@ import java.util.List; @Property( key = "sonar.timemachine.period4", name = "Period 4", - description = "Period used to compare measures and track new violations. This property is specific to the project. Values are : ", + description = "Period used to compare measures and track new violations. This property is specific to the project. Values are : " + + "", project = true, global = false, defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java index 0944f8dabcd..1ea98d87a15 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java @@ -20,7 +20,6 @@ package org.sonar.plugins.core.sensors; import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; import org.sonar.api.batch.DependsUpon; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.MeasureUtils; @@ -28,7 +27,6 @@ import org.sonar.api.measures.Metric; import java.util.Arrays; import java.util.Collection; -import java.util.List; public final class CoverageDecorator extends AbstractCoverageDecorator { @@ -61,7 +59,6 @@ public final class CoverageDecorator extends AbstractCoverageDecorator { } - @Override protected Metric getGeneratedMetricForNewCode() { return CoreMetrics.NEW_COVERAGE; @@ -70,7 +67,7 @@ public final class CoverageDecorator extends AbstractCoverageDecorator { @Override protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) { Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER), periodIndex); - if (newLinesToCover!=null) { + if (newLinesToCover != null) { long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L); return newLinesToCover + newConditionsToCover; } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java index e68ae61ce77..0758fdeb57d 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java @@ -30,7 +30,6 @@ import org.sonar.api.measures.Metric; import org.sonar.api.measures.MetricFinder; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; import org.sonar.api.resources.Scopes; import org.sonar.batch.components.TimeMachineConfiguration; diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java index 3c64cd47ff4..4950b178270 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java @@ -19,11 +19,14 @@ */ package org.sonar.plugins.cpd; -import org.sonar.api.*; +import org.sonar.api.CoreProperties; +import org.sonar.api.Plugin; +import org.sonar.api.Properties; +import org.sonar.api.Property; import org.sonar.plugins.cpd.decorators.DuplicationDensityDecorator; import org.sonar.plugins.cpd.decorators.SumDuplicationsDecorator; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; @Properties({ @@ -36,14 +39,14 @@ import java.util.List; module = true, global = true), @Property( - key = CoreProperties.CPD_IGNORE_LITERALS_PROPERTY, - defaultValue = CoreProperties.CPD_IGNORE_LITERALS_DEFAULT_VALUE + "", - name = "Ignore literals", - description = "if true, CPD ignores literal value differences when evaluating a duplicate block. " + - "This means that foo=\"first string\"; and foo=\"second string\"; will be seen as equivalent.", - project = true, - module = true, - global = true), + key = CoreProperties.CPD_IGNORE_LITERALS_PROPERTY, + defaultValue = CoreProperties.CPD_IGNORE_LITERALS_DEFAULT_VALUE + "", + name = "Ignore literals", + description = "if true, CPD ignores literal value differences when evaluating a duplicate block. " + + "This means that foo=\"first string\"; and foo=\"second string\"; will be seen as equivalent.", + project = true, + module = true, + global = true), @Property( key = CoreProperties.CPD_IGNORE_IDENTIFIERS_PROPERTY, defaultValue = CoreProperties.CPD_IGNORE_IDENTIFIERS_DEFAULT_VALUE + "", @@ -75,12 +78,7 @@ public class CpdPlugin implements Plugin { return "Find duplicated source code within project."; } - public List> getExtensions() { - List> list = new ArrayList>(); - list.add(CpdSensor.class); - list.add(SumDuplicationsDecorator.class); - list.add(DuplicationDensityDecorator.class); - list.add(JavaCpdMapping.class); - return list; + public List getExtensions() { + return Arrays.asList(CpdSensor.class, SumDuplicationsDecorator.class, DuplicationDensityDecorator.class, JavaCpdMapping.class); } } \ No newline at end of file diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java index 29eb7551453..994b9e46f46 100644 --- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java +++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java @@ -19,27 +19,25 @@ */ package org.sonar.plugins.findbugs; +import org.sonar.api.*; + import java.util.ArrayList; import java.util.List; -import org.sonar.api.CoreProperties; -import org.sonar.api.Extension; -import org.sonar.api.Plugin; -import org.sonar.api.Properties; -import org.sonar.api.Property; - @Properties({ @Property( key = CoreProperties.FINDBUGS_EFFORT_PROPERTY, defaultValue = CoreProperties.FINDBUGS_EFFORT_DEFAULT_VALUE, name = "Effort", - description = "Effort of the bug finders. Valid values are Min, Default and Max. Setting 'Max' increases precision but also increases memory consumption.", + description = "Effort of the bug finders. Valid values are Min, Default and Max. Setting 'Max' increases precision but also increases " + + "memory consumption.", project = true, module = true, global = true), @Property( key = CoreProperties.FINDBUGS_TIMEOUT_PROPERTY, defaultValue = CoreProperties.FINDBUGS_TIMEOUT_DEFAULT_VALUE + "", name = "Timeout", - description = "Specifies the amount of time, in milliseconds, that FindBugs may run before it is assumed to be hung and is terminated. The default is 600,000 milliseconds, which is ten minutes.", + description = "Specifies the amount of time, in milliseconds, that FindBugs may run before it is assumed to be hung and is terminated. " + + "The default is 600,000 milliseconds, which is ten minutes.", project = true, module = true, global = true) }) public class FindbugsPlugin implements Plugin { @@ -52,7 +50,8 @@ public class FindbugsPlugin implements Plugin { } public String getDescription() { - return "FindBugs is a program that uses static analysis to look for bugs in Java code. It can detect a variety of common coding mistakes, including thread synchronization problems, misuse of API methods... You can find more by going to the Findbugs web site."; + return "FindBugs is a program that uses static analysis to look for bugs in Java code. It can detect a variety of common coding mistakes, " + + "including thread synchronization problems, misuse of API methods... You can find more by going to the Findbugs web site."; } public List> getExtensions() { diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java index e1552a340f7..e60b2b06748 100644 --- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java +++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java @@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.BatchExtension; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; +import org.sonar.api.utils.SonarException; import org.sonar.api.utils.TimeProfiler; import org.sonar.java.api.JavaUtils; @@ -122,7 +123,7 @@ public class PmdExecutor implements BatchExtension { return stream; } catch (FileNotFoundException e) { - throw new RuntimeException("The PMD ruleset can not be found: " + rulesetPath); + throw new SonarException("The PMD ruleset can not be found: " + rulesetPath, e); } } @@ -159,7 +160,7 @@ public class PmdExecutor implements BatchExtension { LOG.info("Java version: " + javaVersion); pmd.setJavaVersion(sourceType); } else { - throw new RuntimeException("Unsupported Java version for PMD: " + javaVersion); + throw new SonarException("Unsupported Java version for PMD: " + javaVersion); } } } diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java index 8a103e593ea..f09b08e5a5d 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java @@ -21,8 +21,6 @@ package org.sonar.plugins.squid.bridges; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.resources.Resource; -import org.sonar.java.api.JavaClass; -import org.sonar.squid.api.SourceClass; import org.sonar.squid.api.SourceFile; import org.sonar.squid.measures.Metric; @@ -39,7 +37,7 @@ public class ChidamberKemererBridge extends Bridge { context.saveMeasure(sonarFile, CoreMetrics.RFC, squidFile.getDouble(Metric.RFC)); double lcom4 = squidFile.getDouble(Metric.LCOM4); - if (lcom4>0.0) { + if (lcom4 > 0.0) { context.saveMeasure(sonarFile, CoreMetrics.LCOM4, lcom4); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/Module.java b/sonar-batch/src/main/java/org/sonar/batch/Module.java index f4ee3279c2d..6bf82c97051 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/Module.java +++ b/sonar-batch/src/main/java/org/sonar/batch/Module.java @@ -46,7 +46,7 @@ public abstract class Module { /** * @return this */ - private final Module init(MutablePicoContainer container) { + private Module init(MutablePicoContainer container) { this.container = container; configure(); return this; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java index 2168ad2bfb4..d3eb23519e9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java @@ -23,14 +23,12 @@ import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Project; +import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.DateUtils; import java.text.SimpleDateFormat; import java.util.List; -import org.sonar.api.resources.Qualifiers; - public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { private DatabaseSession session; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java index fb8d071f5d2..ff317f2b01a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java @@ -27,7 +27,6 @@ import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; import org.sonar.api.utils.Logs; import java.util.Collections; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java index ca65806e20e..157867cbe2a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java @@ -228,7 +228,7 @@ public final class DefaultResourcePersister implements ResourcePersister { return model; } catch (NonUniqueResultException e) { - throw new SonarException("The resource '" + resource.getEffectiveKey() + "' is duplicated in database."); + throw new SonarException("The resource '" + resource.getEffectiveKey() + "' is duplicated in database.", e); } } diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java index 4870ad168e7..94f5e9b377b 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java @@ -20,15 +20,9 @@ package org.sonar.jpa.dao; import org.sonar.api.database.DatabaseSession; -import org.sonar.api.database.model.RuleFailureModel; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.ActiveRuleParam; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleParam; -import java.util.Iterator; import java.util.List; public class RulesDao extends BaseDao { diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java index a4f44aa335a..0ec9a9ad72c 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java @@ -59,10 +59,12 @@ public class Match implements Comparable { public static final Comparator LabelComparator = new Comparator() { public int compare(Match ma, Match mb) { - if (ma.getLabel() == null) + if (ma.getLabel() == null) { return 1; - if (mb.getLabel() == null) + } + if (mb.getLabel() == null) { return -1; + } return mb.getLabel().compareTo(ma.getLabel()); } }; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java index 2567b0c79ca..92bd5fa8132 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java @@ -29,6 +29,7 @@ import org.sonar.api.resources.Project; * @since 1.10 * @deprecated since 2.6 was superseded by interface {@link CoverageExtension} */ +@Deprecated public abstract class AbstractCoverageExtension implements CoverageExtension { /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java index 872e6f7f027..8f09a59e68f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java @@ -194,7 +194,7 @@ public interface SensorContext { * if the source has already been set on this resource * @since 1.10. Returns a boolean since 2.6. */ - void saveSource(Resource reference, String source) throws DuplicatedSourceException; + void saveSource(Resource reference, String source); // ----------- LINKS -------------- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java index 017ab98ac34..7844a375578 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java @@ -138,7 +138,7 @@ public final class AnnotationCheckFactory extends CheckFactory { throw new SonarException("The type of the field " + field + " is not supported: " + field.getType()); } } catch (IllegalAccessException e) { - throw new SonarException("Can not set the value of the field " + field + " in the class: " + check.getClass().getName()); + throw new SonarException("Can not set the value of the field " + field + " in the class: " + check.getClass().getName(), e); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java index adc29ed1ddf..2afffb5e307 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java @@ -20,7 +20,6 @@ package org.sonar.api.database.model; import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.database.DatabaseSession; import org.sonar.api.measures.Metric; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index ec6c75f5af1..33c3f4b4680 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -365,6 +365,9 @@ public final class CoreMetrics { .setBestValue(100.0) .create(); + /** + * @deprecated since 2.7. Replaced by COVERED_CONDITIONS_BY_LINE_KEY and COVERED_CONDITIONS_BY_LINE_KEY + */ @Deprecated public static final String BRANCH_COVERAGE_HITS_DATA_KEY = "branch_coverage_hits_data"; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Iso9126RulesCategories.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Iso9126RulesCategories.java index 4fc69f2332e..70501b4afdd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Iso9126RulesCategories.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Iso9126RulesCategories.java @@ -31,11 +31,16 @@ public final class Iso9126RulesCategories { private Iso9126RulesCategories() { } - public static final RulesCategory RELIABILITY = new RulesCategory("Reliability", "The extent to which the project can be expected to perform its intended function with rescission. Some examples : are loop indexes range tested? Is input data checked for range errors ? Is divide-by-zero avoided ? Is exception handling provided ?"); - public static final RulesCategory EFFICIENCY = new RulesCategory("Efficiency", "The extent to which the project fulfills its purpose without waste of resources. This means resources in the sense of memory utilisation and processor speed."); - public static final RulesCategory PORTABILITY = new RulesCategory("Portability", "The extent to which the project can be operated easily and well on multiple computer configurations. Portability can mean both between different hardware setups and between different operating systems -- such as running on both Mac OS X and GNU/Linux."); - public static final RulesCategory USABILITY = new RulesCategory("Usability", "The extent to which the project can be understood, learned, operated, attractive and compliant with usability regulations and guidelines. It commonly relies on naming conventions and formatting rules."); - public static final RulesCategory MAINTAINABILITY = new RulesCategory("Maintainability", "The extent to which the project facilitates updating to satisfy new requirements. Thus the the project which is maintainable should be not complex."); + public static final RulesCategory RELIABILITY = new RulesCategory("Reliability", + "The extent to which the project can be expected to perform its intended function with rescission. Some examples : are loop indexes range tested? Is input data checked for range errors ? Is divide-by-zero avoided ? Is exception handling provided ?"); + public static final RulesCategory EFFICIENCY = new RulesCategory("Efficiency", + "The extent to which the project fulfills its purpose without waste of resources. This means resources in the sense of memory utilisation and processor speed."); + public static final RulesCategory PORTABILITY = new RulesCategory("Portability", + "The extent to which the project can be operated easily and well on multiple computer configurations. Portability can mean both between different hardware setups and between different operating systems -- such as running on both Mac OS X and GNU/Linux."); + public static final RulesCategory USABILITY = new RulesCategory("Usability", + "The extent to which the project can be understood, learned, operated, attractive and compliant with usability regulations and guidelines. It commonly relies on naming conventions and formatting rules."); + public static final RulesCategory MAINTAINABILITY = new RulesCategory("Maintainability", + "The extent to which the project facilitates updating to satisfy new requirements. Thus the the project which is maintainable should be not complex."); public static final List ALL = Collections.unmodifiableList(Arrays.asList(RELIABILITY, EFFICIENCY, PORTABILITY, USABILITY, MAINTAINABILITY)); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java index 4d19a4144ac..d3b431ae076 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java @@ -50,7 +50,7 @@ public final class DateUtils { return dateFormat.parse(s); } catch (ParseException e) { - throw new SonarException("The date '" + s + "' does not respect format '" + DATE_FORMAT + "'"); + throw new SonarException("The date '" + s + "' does not respect format '" + DATE_FORMAT + "'", e); } } @@ -59,7 +59,7 @@ public final class DateUtils { return dateTimeFormat.parse(s); } catch (ParseException e) { - throw new SonarException("The date '" + s + "' does not respect format '" + DATETIME_FORMAT + "'"); + throw new SonarException("The date '" + s + "' does not respect format '" + DATETIME_FORMAT + "'", e); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java index 996bfccd826..6b4ff0f7293 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java @@ -432,7 +432,7 @@ public final class KeyValueFormat { /** - * @deprecated since 2.7 replaced by Converter + * @deprecated since 2.7. Replaced by Converter */ @Deprecated public interface Transformer { @@ -452,6 +452,7 @@ public final class KeyValueFormat { /** * Implementation of Transformer + * @deprecated since 2.7. Replaced by Converter */ @Deprecated public static class DoubleNumbersPairTransformer implements Transformer { @@ -462,6 +463,7 @@ public final class KeyValueFormat { /** * Implementation of Transformer + * @deprecated since 2.7. Replaced by Converter */ @Deprecated public static class IntegerNumbersPairTransformer implements Transformer { @@ -473,6 +475,7 @@ public final class KeyValueFormat { /** * Implementation of Transformer + * @deprecated since 2.7. Replaced by Converter */ @Deprecated public static class RulePriorityNumbersPairTransformer implements Transformer { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ServerHttpClient.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ServerHttpClient.java index 50f1933ca52..6f174980bb9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ServerHttpClient.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ServerHttpClient.java @@ -96,7 +96,7 @@ public class ServerHttpClient implements BatchComponent { protected String executeAction(String action) { String result = getRemoteContent(url + action); - if (result.trim().length() == 0) { + if (StringUtils.isBlank(result)) { throw new ServerApiEmptyContentException("Empty " + action + " returned from server"); } return result; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java index a4d107347a5..413aa9c1758 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java @@ -157,7 +157,7 @@ public final class ZipUtils { } } - public static interface ZipEntryFilter { + private static interface ZipEntryFilter { boolean accept(ZipEntry entry); } diff --git a/sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java b/sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java index e8f62192a6f..f0c8fc2fad3 100644 --- a/sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java +++ b/sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java @@ -45,12 +45,13 @@ import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseException; import java.util.Date; +import java.util.SortedMap; import java.util.TreeMap; public class TrendsChart extends BaseChart { private XYPlot plot; - private TreeMap seriesById; + private SortedMap seriesById; private int percentAxisId = -1; private boolean displayLegend; diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ConfigurationFactory.java b/sonar-server/src/main/java/org/sonar/server/configuration/ConfigurationFactory.java index e4d3b9d0586..bc7f086ec6d 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ConfigurationFactory.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ConfigurationFactory.java @@ -58,7 +58,7 @@ public final class ConfigurationFactory { return result; } - protected PropertiesConfiguration getConfigurationFromPropertiesFile(String filename) throws ConfigurationException { + protected PropertiesConfiguration getConfigurationFromPropertiesFile(String filename) { try { return new PropertiesConfiguration(ConfigurationFactory.class.getResource(filename)); @@ -67,7 +67,7 @@ public final class ConfigurationFactory { } } - public PropertiesConfiguration getConfigurationFromPropertiesFile() throws ConfigurationException { + public PropertiesConfiguration getConfigurationFromPropertiesFile() { return getConfigurationFromPropertiesFile("/conf/sonar.properties"); } diff --git a/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java b/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java index c0b54e1c8ad..9dfc0a5c260 100644 --- a/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java +++ b/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java @@ -21,6 +21,7 @@ package org.sonar.server.filters; import org.apache.commons.collections.comparators.ReverseComparator; +import java.io.Serializable; import java.util.*; public class FilterResult { @@ -97,7 +98,8 @@ public class FilterResult { } } - static class RowComparator implements Comparator { + static final class RowComparator implements Comparator, Serializable { + private static final long serialVersionUID = 4627704879575964978L; private int index; RowComparator(int index) { diff --git a/sonar-server/src/main/java/org/sonar/server/platform/PlatformLifecycleListener.java b/sonar-server/src/main/java/org/sonar/server/platform/PlatformLifecycleListener.java index 31bb8bf0f09..22d798048c1 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/PlatformLifecycleListener.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/PlatformLifecycleListener.java @@ -20,8 +20,6 @@ package org.sonar.server.platform; import org.apache.commons.configuration.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.sonar.server.configuration.ConfigurationFactory; import javax.servlet.ServletContextEvent; @@ -29,8 +27,6 @@ import javax.servlet.ServletContextListener; public final class PlatformLifecycleListener implements ServletContextListener { - private static final Logger LOG = LoggerFactory.getLogger(PlatformLifecycleListener.class); - public void contextInitialized(ServletContextEvent event) { Configuration configuration = new ConfigurationFactory().getConfiguration(event); Platform.getInstance().init(configuration); diff --git a/sonar-server/src/main/java/org/sonar/server/startup/EnableProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/EnableProfiles.java index 2ae0845dd02..64bdab89615 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/EnableProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/EnableProfiles.java @@ -37,8 +37,8 @@ public final class EnableProfiles { private Language[] languages; private DatabaseSessionFactory sessionFactory; - // NOSONAR the parameter registerProfilesBefore is used to define the execution order of startup components - public EnableProfiles(Language[] languages, DatabaseSessionFactory sessionFactory, RegisterProvidedProfiles registerProfilesBefore) { + + public EnableProfiles(Language[] languages, DatabaseSessionFactory sessionFactory, RegisterProvidedProfiles registerProfilesBefore) {// NOSONAR the parameter registerProfilesBefore is used to define the execution order of startup components this.languages = languages; this.sessionFactory = sessionFactory; } diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java index 5f36e4b84b2..2392c4e6213 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java @@ -46,7 +46,7 @@ public final class RegisterProvidedProfiles { private RuleFinder ruleFinder; public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory, - DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore, + DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore,// NOSONAR the parameter registerRulesBefore is unused must be declared for execution order of tasks ProfileDefinition[] definitions) { this.ruleFinder = ruleFinder; this.sessionFactory = sessionFactory; @@ -55,7 +55,7 @@ public final class RegisterProvidedProfiles { } public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory, - DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore) { + DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore) {// NOSONAR the parameter registerRulesBefore is unused must be declared for execution order of tasks this.ruleFinder = ruleFinder; this.sessionFactory = sessionFactory; this.deprecatedProfiles = deprecatedBridge; diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterQualityModels.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterQualityModels.java index bc9cc902396..d17cabf48fc 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterQualityModels.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterQualityModels.java @@ -29,8 +29,7 @@ public final class RegisterQualityModels { /** * @param registerRulesBeforeModels used only to be started after the creation of check templates */ - // NOSONAR the parameter registerRulesBeforeModels is only used to provide the execution order by picocontainer - public RegisterQualityModels(ModelManager manager, RegisterRules registerRulesBeforeModels) { + public RegisterQualityModels(ModelManager manager, RegisterRules registerRulesBeforeModels) {// NOSONAR the parameter registerRulesBeforeModels is only used to provide the execution order by picocontainer this.manager = manager; } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java index c8f33678b7d..cd02ce58e5f 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java @@ -21,7 +21,6 @@ package org.sonar.server.ui; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; import org.sonar.api.web.*; /** @@ -84,7 +83,8 @@ public final class DefaultPages { CoreMetrics.CRITICAL_VIOLATIONS_KEY, CoreMetrics.MAJOR_VIOLATIONS_KEY, CoreMetrics.MINOR_VIOLATIONS_KEY, CoreMetrics.INFO_VIOLATIONS_KEY, CoreMetrics.NEW_VIOLATIONS_KEY, CoreMetrics.NEW_BLOCKER_VIOLATIONS_KEY, CoreMetrics.NEW_CRITICAL_VIOLATIONS_KEY, CoreMetrics.NEW_MAJOR_VIOLATIONS_KEY, CoreMetrics.NEW_MINOR_VIOLATIONS_KEY, CoreMetrics.NEW_INFO_VIOLATIONS_KEY}) - @ResourceQualifier({Qualifiers.VIEW, Qualifiers.SUBVIEW, Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.PACKAGE, Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.CLASS}) /* all exept unit tests...*/ + @ResourceQualifier({Qualifiers.VIEW, Qualifiers.SUBVIEW, Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.PACKAGE, Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.CLASS}) + /* all exept unit tests...*/ @UserRole(UserRole.CODEVIEWER) private static final class ViolationsTab implements RubyRailsPage { public String getTemplate() { diff --git a/sonar-squid/src/main/java/org/sonar/squid/api/SourceCode.java b/sonar-squid/src/main/java/org/sonar/squid/api/SourceCode.java index 4114818c0e7..44440fd469d 100644 --- a/sonar-squid/src/main/java/org/sonar/squid/api/SourceCode.java +++ b/sonar-squid/src/main/java/org/sonar/squid/api/SourceCode.java @@ -141,6 +141,7 @@ public abstract class SourceCode implements Measurable, Comparable { /** * @deprecated since 2.1. It's replaced by getData(MetricDef). It's still defined for binary compatibility. */ + @Deprecated public Object getData(Metric metric) { return measures.getData(metric); } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java index 302d78538bc..a5cb54aa487 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java @@ -107,13 +107,13 @@ public class TestUtils { try { FileUtils.deleteDirectory(dir); } catch (IOException e) { - throw new RuntimeException("Can not delete the directory " + dir); + throw new SonarException("Can not delete the directory " + dir, e); } } try { FileUtils.forceMkdir(dir); } catch (IOException e) { - throw new RuntimeException("Can not create the directory " + dir); + throw new SonarException("Can not create the directory " + dir, e); } return dir; } @@ -134,7 +134,6 @@ public class TestUtils { static Diff isSimilarXml(String expectedXml, String xml) throws IOException, SAXException { XMLUnit.setIgnoreWhitespace(true); - Diff diff = XMLUnit.compareXML(xml, expectedXml); - return diff; + return XMLUnit.compareXML(xml, expectedXml); } } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java index c92be0960aa..ab664c07fc7 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java @@ -21,7 +21,6 @@ package org.sonar.test.channel; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.sonar.channel.Channel; import org.sonar.channel.CodeReader; public class ReaderHasNextCharMatcher extends BaseMatcher { diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java index b7aebd57ca1..72d20973542 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java @@ -134,7 +134,9 @@ public class Dependency extends Model { @Override public boolean equals(Object o) { - if (this == o) return true; + if (this == o) { + return true; + } if (o == null || getClass() != o.getClass()) { return false; } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProfileQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProfileQuery.java index 0012c3e11df..8f49a7213d0 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProfileQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProfileQuery.java @@ -22,7 +22,7 @@ package org.sonar.wsclient.services; /** * @since 2.7 */ -public class ProfileQuery extends Query { +public final class ProfileQuery extends Query { public static final String BASE_URL = "/api/profiles"; private String language; diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java index 19a3b989cb4..1feefbb2d7b 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java @@ -22,7 +22,7 @@ package org.sonar.wsclient.services; /** * @since 2.4 */ -public class UpdateCenterQuery extends Query { +public final class UpdateCenterQuery extends Query { public static final String BASE_URL = "/api/updatecenter/"; private String action; -- 2.39.5