From 86d584bd2c9f31c033d9a833558fa6a80d614211 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 29 May 2012 11:09:20 +0200 Subject: [PATCH] Fix some quality flaws --- .../persistence/dialect/DialectUtils.java | 4 ++-- .../sonar/server/startup/GwtPublisher.java | 6 ++--- .../server/startup/JdbcDriverDeployer.java | 2 +- .../sonar/server/startup/RegisterMetrics.java | 6 ++--- .../server/startup/RegisterQualityModels.java | 2 +- .../sonar/server/startup/RegisterRules.java | 8 +++---- .../startup/ServerMetadataPersister.java | 4 ++-- .../sonar/server/startup/package-info.java | 23 +++++++++++++++++++ 8 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 sonar-server/src/main/java/org/sonar/server/startup/package-info.java diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/DialectUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/DialectUtils.java index 573b34d2c96..6618d536064 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/DialectUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/DialectUtils.java @@ -52,8 +52,8 @@ public final class DialectUtils { private static Dialect findById(final String dialectId) { return findDialect(new Predicate() { - public boolean apply(Dialect dialect) { - return dialect.getId().equals(dialectId); + public boolean apply(@Nullable Dialect dialect) { + return dialect != null && dialect.getId().equals(dialectId); } }); } diff --git a/sonar-server/src/main/java/org/sonar/server/startup/GwtPublisher.java b/sonar-server/src/main/java/org/sonar/server/startup/GwtPublisher.java index f02174b3c7e..d7224cf2442 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/GwtPublisher.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/GwtPublisher.java @@ -63,11 +63,11 @@ public class GwtPublisher { try { cleanDirectory(); this.outputDir = new File(settings.getString(ServerSettings.DEPLOY_DIR), "gwt"); - Logs.INFO.debug("publish {} GWT extensions to {}", extensions.length, outputDir); + LoggerFactory.getLogger(GwtPublisher.class).debug("Deploy {} GWT extensions to {}", extensions.length, outputDir); publish(); } catch (Exception e) { - throw new SonarException("can not publish GWT extensions", e); + throw new IllegalStateException("Fail to deploy GWT extensions", e); } profiler.stop(); } @@ -102,7 +102,7 @@ public class GwtPublisher { if (sourceDir == null) { throw new SonarException("Can not find the directory " + module.getGwtId() + " defined by the GWT module " + module.getClass().getName()); } - Logs.INFO.info("publish {} to {}", module.getGwtId(), outputDir); + Logs.INFO.info("Deploy {} to {}", module.getGwtId(), outputDir); if (sourceDir.toString().startsWith("jar:file")) { // unzip the JAR String path = StringUtils.substringBetween(sourceDir.toString(), "jar:file:", "!"); diff --git a/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java b/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java index c1088af721c..8bf17a700bb 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java @@ -27,7 +27,7 @@ import java.io.IOException; public class JdbcDriverDeployer { - private DefaultServerFileSystem fileSystem; + private final DefaultServerFileSystem fileSystem; public JdbcDriverDeployer(DefaultServerFileSystem fileSystem) { this.fileSystem = fileSystem; diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java index 7c8c404338e..91a9b9fb09a 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java @@ -37,9 +37,9 @@ import java.util.Map; public class RegisterMetrics { - private MeasuresDao measuresDao; - private Metrics[] metricsRepositories = null; - private DatabaseSession session; + private final MeasuresDao measuresDao; + private final Metrics[] metricsRepositories; + private final DatabaseSession session; public RegisterMetrics(DatabaseSession session, MeasuresDao measuresDao, Metrics[] metricsRepositories) { this.session = session; 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 d8f5307216a..8cd11babaf1 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 @@ -24,7 +24,7 @@ import org.sonar.server.qualitymodel.ModelManager; public final class RegisterQualityModels { - private ModelManager manager; + private final ModelManager manager; /** * @param registerRulesBeforeModels used only to be started after the creation of check templates diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java index 6c9846ef8e0..8c849a376f2 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java @@ -37,13 +37,13 @@ import java.util.*; public final class RegisterRules { - private DatabaseSessionFactory sessionFactory; - private List repositories = Lists.newArrayList(); - private RuleI18nManager ruleI18nManager; + private final DatabaseSessionFactory sessionFactory; + private final List repositories; + private final RuleI18nManager ruleI18nManager; public RegisterRules(DatabaseSessionFactory sessionFactory, RuleRepository[] repos, RuleI18nManager ruleI18nManager) { this.sessionFactory = sessionFactory; - this.repositories.addAll(Arrays.asList(repos)); + this.repositories = Arrays.asList(repos); this.ruleI18nManager = ruleI18nManager; } diff --git a/sonar-server/src/main/java/org/sonar/server/startup/ServerMetadataPersister.java b/sonar-server/src/main/java/org/sonar/server/startup/ServerMetadataPersister.java index 8118858de56..93c3a92e877 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/ServerMetadataPersister.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/ServerMetadataPersister.java @@ -28,8 +28,8 @@ import java.text.SimpleDateFormat; public class ServerMetadataPersister { - private Server server; - private DatabaseSession session; + private final Server server; + private final DatabaseSession session; public ServerMetadataPersister(Server server, DatabaseSession session) { this.server = server; diff --git a/sonar-server/src/main/java/org/sonar/server/startup/package-info.java b/sonar-server/src/main/java/org/sonar/server/startup/package-info.java new file mode 100644 index 00000000000..cbfea87fb02 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/startup/package-info.java @@ -0,0 +1,23 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +@ParametersAreNonnullByDefault +package org.sonar.server.startup; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file -- 2.39.5