From 9324c65fc550b13cb5593f2f958e34d246f7c42b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 28 Aug 2013 14:49:38 +0200 Subject: [PATCH] Fix quality flaws --- .../plugins/core/timemachine/TendencyAnalyser.java | 3 ++- .../plugins/core/timemachine/TendencyDecorator.java | 11 +++-------- .../java/org/sonar/batch/ProjectConfigurator.java | 3 ++- .../sonar/batch/index/DefaultResourcePersister.java | 13 +++++-------- .../org/sonar/batch/index/MeasurePersister.java | 3 ++- .../org/sonar/batch/phases/UpdateStatusJob.java | 4 +++- .../api/measures/CountDistributionBuilder.java | 6 ++++-- .../main/java/org/sonar/api/measures/Measure.java | 3 ++- .../org/sonar/api/platform/ComponentContainer.java | 3 ++- .../java/org/sonar/api/utils/KeyValueFormat.java | 3 ++- .../sonar/server/charts/deprecated/BarChart.java | 3 ++- .../server/charts/deprecated/CustomBarChart.java | 3 ++- .../sonar/server/configuration/MetricsBackup.java | 3 ++- .../sonar/server/configuration/ProfilesManager.java | 6 ++++-- .../java/org/sonar/server/platform/Platform.java | 12 ++++++++---- .../java/org/sonar/server/platform/SonarHome.java | 3 ++- .../org/sonar/server/plugins/ClassLoaderUtils.java | 4 +++- .../sonar/server/plugins/UpdateCenterClient.java | 6 ++++-- .../org/sonar/squid/text/LiteralValueHandler.java | 3 ++- .../org/sonar/squid/text/StringArrayReader.java | 3 ++- 20 files changed, 58 insertions(+), 40 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java index 92c964f7b61..0a62a0244ba 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java @@ -105,7 +105,8 @@ public class TendencyAnalyser { private double sumXPower2; private double sumYPower2; private double sumXY; - private double yIntercept; // not used today + // not used today + private double yIntercept; private Double slope; private Double correlationRate; 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 6868cba1a95..39003a8e688 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 @@ -24,13 +24,7 @@ import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; -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.TimeMachine; -import org.sonar.api.batch.TimeMachineQuery; +import org.sonar.api.batch.*; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; import org.sonar.api.measures.MetricFinder; @@ -81,7 +75,8 @@ public class TendencyDecorator implements Decorator { protected TimeMachineQuery initQuery(Project project) { int days = configuration.getTendencyPeriodInDays(); - query = new TimeMachineQuery(null) // resource is set after + // resource is set after + query = new TimeMachineQuery(null) .setFrom(DateUtils.addDays(project.getAnalysisDate(), -days)) .setToCurrentAnalysis(true) .setMetrics(metrics); diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index b7c83521e58..027191be7df 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -71,7 +71,8 @@ public class ProjectConfigurator implements BatchComponent { checkCurrentAnalysisIsTheLatestOne(project.getKey(), analysisDate); project - .setConfiguration(new PropertiesConfiguration()) // will be populated by ProjectSettings + // will be populated by ProjectSettings + .setConfiguration(new PropertiesConfiguration()) .setAnalysisDate(analysisDate) .setAnalysisVersion(loadAnalysisVersion()) .setAnalysisType(loadAnalysisType()); 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 15b0933f77c..636122f849a 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 @@ -25,12 +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.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; @@ -79,7 +74,8 @@ public final class DefaultResourcePersister implements ResourcePersister { project.setEffectiveKey(project.getKey()); ResourceModel model = findOrCreateModel(project); - model.setLanguageKey(project.getLanguageKey());// ugly, only for projects + // ugly, only for projects + model.setLanguageKey(project.getLanguageKey()); // For views if (project instanceof ResourceCopy) { @@ -162,7 +158,8 @@ public final class DefaultResourcePersister implements ResourcePersister { private Snapshot persistLibrary(Project project, Library library) { ResourceModel model = findOrCreateModel(library); model = session.save(model); - library.setId(model.getId()); // TODO to be removed + // TODO to be removed + library.setId(model.getId()); library.setEffectiveKey(library.getKey()); Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java index aadca4bbd76..50493b4c410 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java @@ -130,7 +130,8 @@ public final class MeasurePersister { private MeasureModel model(Measure measure) { MeasureModel model = new MeasureModel(); - model.setMetricId(measure.getMetric().getId()); // we assume that the index has updated the metric + // we assume that the index has updated the metric + model.setMetricId(measure.getMetric().getId()); model.setDescription(measure.getDescription()); model.setData(measure.getData()); model.setAlertStatus(measure.getAlertStatus()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java index 02056e53899..f25f92de517 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java @@ -33,13 +33,15 @@ import org.sonar.batch.bootstrap.ServerClient; import org.sonar.batch.index.ResourcePersister; import javax.persistence.Query; + import java.util.List; public class UpdateStatusJob implements BatchComponent { private DatabaseSession session; private ServerClient server; - private Snapshot snapshot; // TODO remove this component + // TODO remove this component + private Snapshot snapshot; private ResourcePersister resourcePersister; private Settings settings; private Project project; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java index bdca4449e65..ad58da21ca7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java @@ -64,7 +64,8 @@ public class CountDistributionBuilder implements MeasureBuilder { } else { if (this.countBag.add(value, count)) { - this.countBag.add(value, 1);//hack + //hack + this.countBag.add(value, 1); } } return this; @@ -151,7 +152,8 @@ public class CountDistributionBuilder implements MeasureBuilder { */ public Measure build(boolean allowEmptyData) { if (!isEmpty() || allowEmptyData) { - return new Measure(metric, KeyValueFormat.format(countBag, -1)); //-1 is a hack to include zero values + //-1 is a hack to include zero values + return new Measure(metric, KeyValueFormat.format(countBag, -1)); } return null; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java index f8b135458ca..c08ad379867 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java @@ -43,7 +43,8 @@ public class Measure { */ public static final int DEFAULT_PRECISION = 1; - private Long id; // for internal use + // for internal use + private Long id; protected String metricKey; protected Metric metric; protected Double value; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/ComponentContainer.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/ComponentContainer.java index 860f297b032..4301fdcca16 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/platform/ComponentContainer.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/platform/ComponentContainer.java @@ -40,7 +40,8 @@ import java.util.List; */ public class ComponentContainer implements BatchComponent, ServerComponent { - ComponentContainer parent, child; // no need for multiple children + // no need for multiple children + ComponentContainer parent, child; MutablePicoContainer pico; PropertyDefinitions propertyDefinitions; 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 2a5a0c63640..a6c2a1c0c1b 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 @@ -288,7 +288,8 @@ public final class KeyValueFormat { * @since 2.7 */ public static Multiset parseMultiset(String data, Converter keyConverter) { - Multiset multiset = LinkedHashMultiset.create();// to keep the same order + // to keep the same order + Multiset multiset = LinkedHashMultiset.create(); if (data != null) { String[] pairs = StringUtils.split(data, PAIR_SEPARATOR); for (String pair : pairs) { diff --git a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java index bb26e1186d6..0fde182ad97 100644 --- a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java +++ b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java @@ -67,7 +67,8 @@ public class BarChart extends BaseChartWeb implements DeprecatedChart { protected void configureCategoryPlot() { CategoryPlot plot = jfreechart.getCategoryPlot(); plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA); - plot.setInsets(RectangleInsets.ZERO_INSETS); // To remove inner space around chart + // To remove inner space around chart + plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setDataset(dataset); plot.setDomainAxis(categoryAxis); plot.setRenderer(renderer); diff --git a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java index 54e7ad29515..647ee03e323 100644 --- a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java +++ b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java @@ -70,7 +70,8 @@ public class CustomBarChart extends BarChart { protected void configureCategoryPlot() { CategoryPlot plot = jfreechart.getCategoryPlot(); plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA); - plot.setInsets(RectangleInsets.ZERO_INSETS); // To remove inner space around chart + // To remove inner space around chart + plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setDataset(dataset); plot.setDomainAxis(categoryAxis); plot.setRenderer(renderer); diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java index 45e8e11e81b..922915cbcb9 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java @@ -83,7 +83,8 @@ public class MetricsBackup implements Backupable { public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Metric unmarshalled = (Metric) builtIn.unmarshal(reader, context); - unmarshalled.setId(null); // See http://jira.codehaus.org/browse/SONAR-1819 + // See http://jira.codehaus.org/browse/SONAR-1819 + unmarshalled.setId(null); unmarshalled.setUserManaged(true); unmarshalled.setEnabled(true); return unmarshalled; diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java index e16bd2e6d67..2d3977ae4e7 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java @@ -323,7 +323,8 @@ public class ProfilesManager extends BaseDao { } else { oldActiveRule.setInheritance(ActiveRule.OVERRIDES); getSession().saveWithoutFlush(oldActiveRule); - return; // no need to change in children + // no need to change in children + return; } } ActiveRule newActiveRule = (ActiveRule) parentActiveRule.clone(); @@ -352,7 +353,8 @@ public class ProfilesManager extends BaseDao { } else { activeRule.setInheritance(null); getSession().saveWithoutFlush(activeRule); - return; // no need to change in children + // no need to change in children + return; } for (RulesProfile child : getChildren(profile)) { diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 554de95b521..6b3b74d0f4d 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -101,9 +101,12 @@ import javax.servlet.ServletContext; public final class Platform { private static final Platform INSTANCE = new Platform(); - private ComponentContainer rootContainer;// level 1 : only database connectors - private ComponentContainer coreContainer;// level 2 : level 1 + core components - private ComponentContainer servicesContainer;// level 3 : level 2 + plugin extensions + core components that depend on plugin extensions + // level 1 : only database connectors + private ComponentContainer rootContainer; + // level 2 : level 1 + core components + private ComponentContainer coreContainer; + // level 3 : level 2 + plugin extensions + core components that depend on plugin extensions + private ComponentContainer servicesContainer; private boolean connected = false; private boolean started = false; @@ -221,7 +224,8 @@ public final class Platform { servicesContainer.addSingleton(UpdateCenterMatrixFactory.class); servicesContainer.addSingleton(PluginDownloader.class); servicesContainer.addSingleton(ServerIdGenerator.class); - servicesContainer.addSingleton(DefaultModelFinder.class); // depends on plugins + // depends on plugins + servicesContainer.addSingleton(DefaultModelFinder.class); servicesContainer.addSingleton(DefaultModelManager.class); servicesContainer.addSingleton(ChartFactory.class); servicesContainer.addSingleton(Languages.class); diff --git a/sonar-server/src/main/java/org/sonar/server/platform/SonarHome.java b/sonar-server/src/main/java/org/sonar/server/platform/SonarHome.java index 4d1b9de91bb..a830ccc758f 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/SonarHome.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/SonarHome.java @@ -83,7 +83,8 @@ final class SonarHome { private static Properties openWarProperties() { try { InputStream input = SonarHome.class.getResourceAsStream("/sonar-war.properties"); - return ConfigurationUtils.readInputStream(input); // it closes the stream + // it closes the stream + return ConfigurationUtils.readInputStream(input); } catch (IOException e) { throw new IllegalStateException("Fail to load the file sonar-war.properties", e); } diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java b/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java index c85ae22fce6..66ef0e0a5e3 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java @@ -27,6 +27,7 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory; import javax.annotation.Nullable; + import java.io.File; import java.io.IOException; import java.net.URL; @@ -112,7 +113,8 @@ public final class ClassLoaderUtils { if (StringUtils.substringAfterLast(rootPath, "/").indexOf('.') >= 0) { rootDirectory = StringUtils.substringBeforeLast(rootPath, "/"); } - jarPath = root.getPath().substring(5, root.getPath().indexOf("!")); //strip out only the JAR file + //strip out only the JAR file + jarPath = root.getPath().substring(5, root.getPath().indexOf("!")); jar = new JarFile(URLDecoder.decode(jarPath, CharEncoding.UTF_8)); Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java b/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java index f07a092d3f9..3ab9f56d37c 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java @@ -48,7 +48,8 @@ import java.util.Date; defaultValue = "true", name = "Enable Update Center", project = false, - global = false, // hidden from UI + // hidden from UI + global = false, category = "Update Center", type = PropertyType.BOOLEAN), @Property( @@ -56,7 +57,8 @@ import java.util.Date; defaultValue = "http://update.sonarsource.org/update-center.properties", name = "Update Center URL", project = false, - global = false, // hidden from UI + // hidden from UI + global = false, category = "Update Center") }) public class UpdateCenterClient implements ServerComponent { diff --git a/sonar-squid/src/main/java/org/sonar/squid/text/LiteralValueHandler.java b/sonar-squid/src/main/java/org/sonar/squid/text/LiteralValueHandler.java index 86d50b66421..44da56e117b 100644 --- a/sonar-squid/src/main/java/org/sonar/squid/text/LiteralValueHandler.java +++ b/sonar-squid/src/main/java/org/sonar/squid/text/LiteralValueHandler.java @@ -55,6 +55,7 @@ public class LiteralValueHandler extends LineContextHandler { @Override boolean matchWithEndOfLine(Line line, StringBuilder pendingLine) { - return true; //see http://jira.codehaus.org/browse/SONAR-1555 + //see http://jira.codehaus.org/browse/SONAR-1555 + return true; } } diff --git a/sonar-squid/src/main/java/org/sonar/squid/text/StringArrayReader.java b/sonar-squid/src/main/java/org/sonar/squid/text/StringArrayReader.java index 0fb92a49738..c430fbaccfc 100644 --- a/sonar-squid/src/main/java/org/sonar/squid/text/StringArrayReader.java +++ b/sonar-squid/src/main/java/org/sonar/squid/text/StringArrayReader.java @@ -60,7 +60,8 @@ public class StringArrayReader extends Reader { content.append("\r\n"); break; default: - throw new IllegalStateException(); // should never happen + // should never happen + throw new IllegalStateException(); } } } -- 2.39.5