diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-12-10 15:43:24 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-12-10 15:43:24 +0100 |
commit | 99466d1784f8e6b791a2c0505d3a0202513172f8 (patch) | |
tree | a349e1fc655eaf049acb04d47fc1e86cc4b0b1ca | |
parent | 21af36c2c69eed6452201036315d38db1e64a385 (diff) | |
download | sonarqube-99466d1784f8e6b791a2c0505d3a0202513172f8.tar.gz sonarqube-99466d1784f8e6b791a2c0505d3a0202513172f8.zip |
Fix some quality flaws
11 files changed, 64 insertions, 69 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java index 82ea4532bf1..460e28b04b7 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.core.dashboards; +import org.sonar.api.measures.CoreMetrics; import org.sonar.api.web.Dashboard; import org.sonar.api.web.Dashboard.Widget; import org.sonar.api.web.DashboardLayout; @@ -38,7 +39,6 @@ public final class ProjectTimeMachineDashboard extends DashboardTemplate { private static final String METRIC5 = "metric5"; private static final String METRIC6 = "metric6"; private static final String METRIC7 = "metric7"; - private static final String COVERAGE = "coverage"; @Override public String getName() { @@ -56,58 +56,58 @@ public final class ProjectTimeMachineDashboard extends DashboardTemplate { private void addFirstColumn(Dashboard dashboard) { Widget timelineWidget = dashboard.addWidget("timeline", 1); - timelineWidget.setProperty(METRIC1, "complexity"); - timelineWidget.setProperty(METRIC2, "violations_density"); - timelineWidget.setProperty(METRIC3, COVERAGE); + timelineWidget.setProperty(METRIC1, CoreMetrics.COMPLEXITY_KEY); + timelineWidget.setProperty(METRIC2, CoreMetrics.VIOLATIONS_DENSITY_KEY); + timelineWidget.setProperty(METRIC3, CoreMetrics.COVERAGE_KEY); Widget sizeTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard); - sizeTimeMachineWidget.setProperty(METRIC1, "ncloc"); - sizeTimeMachineWidget.setProperty(METRIC2, "lines"); - sizeTimeMachineWidget.setProperty(METRIC3, "statements"); - sizeTimeMachineWidget.setProperty(METRIC4, "files"); - sizeTimeMachineWidget.setProperty(METRIC5, "classes"); - sizeTimeMachineWidget.setProperty(METRIC6, "functions"); - sizeTimeMachineWidget.setProperty(METRIC7, "accessors"); + sizeTimeMachineWidget.setProperty(METRIC1, CoreMetrics.NCLOC_KEY); + sizeTimeMachineWidget.setProperty(METRIC2, CoreMetrics.LINES_KEY); + sizeTimeMachineWidget.setProperty(METRIC3, CoreMetrics.STATEMENTS_KEY); + sizeTimeMachineWidget.setProperty(METRIC4, CoreMetrics.FILES_KEY); + sizeTimeMachineWidget.setProperty(METRIC5, CoreMetrics.CLASSES_KEY); + sizeTimeMachineWidget.setProperty(METRIC6, CoreMetrics.FUNCTIONS_KEY); + sizeTimeMachineWidget.setProperty(METRIC7, CoreMetrics.ACCESSORS_KEY); Widget commentsTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard); - commentsTimeMachineWidget.setProperty(METRIC1, "comment_lines_density"); - commentsTimeMachineWidget.setProperty(METRIC2, "comment_lines"); - commentsTimeMachineWidget.setProperty(METRIC3, "public_documented_api_density"); - commentsTimeMachineWidget.setProperty(METRIC4, "public_undocumented_api"); + commentsTimeMachineWidget.setProperty(METRIC1, CoreMetrics.COMMENT_LINES_DENSITY_KEY); + commentsTimeMachineWidget.setProperty(METRIC2, CoreMetrics.COMMENT_LINES_KEY); + commentsTimeMachineWidget.setProperty(METRIC3, CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY_KEY); + commentsTimeMachineWidget.setProperty(METRIC4, CoreMetrics.PUBLIC_UNDOCUMENTED_API_KEY); Widget duplicationTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard); - duplicationTimeMachineWidget.setProperty(METRIC1, "duplicated_lines_density"); - duplicationTimeMachineWidget.setProperty(METRIC2, "duplicated_lines"); - duplicationTimeMachineWidget.setProperty(METRIC3, "duplicated_blocks"); - duplicationTimeMachineWidget.setProperty(METRIC4, "duplicated_files"); + duplicationTimeMachineWidget.setProperty(METRIC1, CoreMetrics.DUPLICATED_LINES_DENSITY_KEY); + duplicationTimeMachineWidget.setProperty(METRIC2, CoreMetrics.DUPLICATED_LINES_KEY); + duplicationTimeMachineWidget.setProperty(METRIC3, CoreMetrics.DUPLICATED_BLOCKS_KEY); + duplicationTimeMachineWidget.setProperty(METRIC4, CoreMetrics.DUPLICATED_FILES_KEY); } private void addSecondColumn(Dashboard dashboard) { Widget rulesTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard); - rulesTimeMachineWidget.setProperty(METRIC1, "violations"); - rulesTimeMachineWidget.setProperty(METRIC2, "violation_density"); - rulesTimeMachineWidget.setProperty(METRIC3, "blocker_violations"); - rulesTimeMachineWidget.setProperty(METRIC4, "critical_violations"); - rulesTimeMachineWidget.setProperty(METRIC5, "major_violations"); - rulesTimeMachineWidget.setProperty(METRIC6, "minor_violations"); - rulesTimeMachineWidget.setProperty(METRIC7, "info_violations"); - rulesTimeMachineWidget.setProperty(METRIC7, "weighted_violations"); + rulesTimeMachineWidget.setProperty(METRIC1, CoreMetrics.VIOLATIONS_KEY); + rulesTimeMachineWidget.setProperty(METRIC2, CoreMetrics.VIOLATIONS_DENSITY_KEY); + rulesTimeMachineWidget.setProperty(METRIC3, CoreMetrics.BLOCKER_VIOLATIONS_KEY); + rulesTimeMachineWidget.setProperty(METRIC4, CoreMetrics.CRITICAL_VIOLATIONS_KEY); + rulesTimeMachineWidget.setProperty(METRIC5, CoreMetrics.MAJOR_VIOLATIONS_KEY); + rulesTimeMachineWidget.setProperty(METRIC6, CoreMetrics.MINOR_VIOLATIONS_KEY); + rulesTimeMachineWidget.setProperty(METRIC7, CoreMetrics.INFO_VIOLATIONS_KEY); + rulesTimeMachineWidget.setProperty(METRIC7, CoreMetrics.WEIGHTED_VIOLATIONS_KEY); Widget complexityTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard); - complexityTimeMachineWidget.setProperty(METRIC1, "complexity"); - complexityTimeMachineWidget.setProperty(METRIC2, "function_complexity"); - complexityTimeMachineWidget.setProperty(METRIC3, "class_complexity"); - complexityTimeMachineWidget.setProperty(METRIC4, "file_complexity"); + complexityTimeMachineWidget.setProperty(METRIC1, CoreMetrics.COMPLEXITY_KEY); + complexityTimeMachineWidget.setProperty(METRIC2, CoreMetrics.FUNCTION_COMPLEXITY_KEY); + complexityTimeMachineWidget.setProperty(METRIC3, CoreMetrics.CLASS_COMPLEXITY_KEY); + complexityTimeMachineWidget.setProperty(METRIC4, CoreMetrics.FILE_COMPLEXITY_KEY); Widget testsTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard); - testsTimeMachineWidget.setProperty(METRIC1, COVERAGE); - testsTimeMachineWidget.setProperty(METRIC2, "line_coverage"); - testsTimeMachineWidget.setProperty(METRIC3, "branch_coverage"); - testsTimeMachineWidget.setProperty(METRIC4, "test_success_density"); - testsTimeMachineWidget.setProperty(METRIC5, "test_failures"); - testsTimeMachineWidget.setProperty(METRIC6, "test_errors"); - testsTimeMachineWidget.setProperty(METRIC7, "tests"); - testsTimeMachineWidget.setProperty(METRIC7, "test_execution_time"); + testsTimeMachineWidget.setProperty(METRIC1, CoreMetrics.COVERAGE_KEY); + testsTimeMachineWidget.setProperty(METRIC2, CoreMetrics.LINE_COVERAGE_KEY); + testsTimeMachineWidget.setProperty(METRIC3, CoreMetrics.BRANCH_COVERAGE_KEY); + testsTimeMachineWidget.setProperty(METRIC4, CoreMetrics.TEST_SUCCESS_DENSITY_KEY); + testsTimeMachineWidget.setProperty(METRIC5, CoreMetrics.TEST_FAILURES_KEY); + testsTimeMachineWidget.setProperty(METRIC6, CoreMetrics.TEST_ERRORS_KEY); + testsTimeMachineWidget.setProperty(METRIC7, CoreMetrics.TESTS_KEY); + testsTimeMachineWidget.setProperty(METRIC7, CoreMetrics.TEST_EXECUTION_TIME_KEY); } private Widget addTimeMachineWidgetOnFirstColumn(Dashboard dashboard) { diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java index 37d74602045..f0c425ab955 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java @@ -41,6 +41,10 @@ import java.util.Locale; */ public class NewIssuesEmailTemplate extends EmailTemplate { + public static final String FIELD_PROJECT_NAME = "projectName"; + public static final String FIELD_PROJECT_KEY = "projectKey"; + public static final String FIELD_PROJECT_DATE = "projectDate"; + private final EmailSettings settings; private final I18n i18n; @@ -54,7 +58,7 @@ public class NewIssuesEmailTemplate extends EmailTemplate { if (!"new-issues".equals(notification.getType())) { return null; } - String projectName = notification.getFieldValue("projectName"); + String projectName = notification.getFieldValue(FIELD_PROJECT_NAME); StringBuilder sb = new StringBuilder(); sb.append("Project: ").append(projectName).append("\n\n"); @@ -73,7 +77,7 @@ public class NewIssuesEmailTemplate extends EmailTemplate { appendFooter(sb, notification); EmailMessage message = new EmailMessage() - .setMessageId("new-issues/" + notification.getFieldValue("projectKey")) + .setMessageId("new-issues/" + notification.getFieldValue(FIELD_PROJECT_KEY)) .setSubject(projectName + ": new issues") .setMessage(sb.toString()); @@ -81,8 +85,8 @@ public class NewIssuesEmailTemplate extends EmailTemplate { } private void appendFooter(StringBuilder sb, Notification notification) { - String projectKey = notification.getFieldValue("projectKey"); - String dateString = notification.getFieldValue("projectDate"); + String projectKey = notification.getFieldValue(FIELD_PROJECT_KEY); + String dateString = notification.getFieldValue(FIELD_PROJECT_DATE); if (projectKey != null && dateString != null) { Date date = DateUtils.parseDateTime(dateString); String url = String.format("%s/issues/search?componentRoots=%s&createdAt=%s", 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 a4af0205edc..bf48d6a5c58 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 @@ -349,6 +349,7 @@ public class Cache<K, V extends Serializable> { @Override public void remove() { + // nothing to do } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java index 995bfeaad0d..4dad09db531 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java @@ -46,11 +46,9 @@ class FileQueryFilter { filters.add(new AttributeFilter(entry.getKey(), entry.getValue())); } - // TODO speed-up the following algorithm. Cache ? if (analysisMode.isIncremental()) { Collection<String> status = query.attributes().get(InputFile.ATTRIBUTE_STATUS); if (status == null || status.isEmpty()) { - // TODO should be not(SAME) instead of is(ADDED, CHANGED) filters.add(new AttributeFilter(InputFile.ATTRIBUTE_STATUS, Lists.newArrayList(InputFile.STATUS_ADDED, InputFile.STATUS_CHANGED))); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/RemoteFileHashes.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/RemoteFileHashes.java index af6a5235b36..566a964eba4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/RemoteFileHashes.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/RemoteFileHashes.java @@ -73,5 +73,6 @@ public class RemoteFileHashes implements BatchComponent, Startable { @Override public void stop() { + // nothing to do } } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java index 3e4ab3683ef..14d196ed8a3 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java @@ -86,7 +86,7 @@ public class DefaultDatabase implements Database { * Override to execute post-startup code. */ protected void doAfterStart() { - + // nothing to do } @VisibleForTesting @@ -203,7 +203,7 @@ public class DefaultDatabase implements Database { } protected void doCompleteProperties(Properties properties) { - + // nothing } private static void completeProperties(Settings settings, Properties properties, String prefix) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java index f4ba8db90ba..1dbb7b888b9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java @@ -98,6 +98,7 @@ public class RuleMeasure extends Measure { */ @Deprecated public void setRuleCategory(Integer ruleCategory) { + // nothing } @Override 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 41aec974153..632242d65f5 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 @@ -99,16 +99,15 @@ public class ComponentContainer implements BatchComponent, ServerComponent { /** * This method aims to be overridden */ - protected void doBeforeStart() { - + // nothing } /** * This method aims to be overridden */ protected void doAfterStart() { - + // nothing } /** diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/violation/ViolationMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/violation/ViolationMigration.java index 5be57ab8a8d..087f921cd84 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/migrations/violation/ViolationMigration.java +++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/violation/ViolationMigration.java @@ -27,7 +27,6 @@ import org.sonar.core.persistence.Database; import org.sonar.server.db.migrations.DatabaseMigration; import java.sql.SQLException; -import java.util.concurrent.ExecutionException; /** * Used in the Active Record Migration 401 @@ -48,8 +47,13 @@ public class ViolationMigration implements DatabaseMigration { @Override public void execute() { try { - migrate(); - + logger.info("Initialize input"); + Referentials referentials = new Referentials(db); + if (referentials.totalViolations() > 0) { + logger.info("Migrate {} violations", referentials.totalViolations()); + ViolationConverters converters = new ViolationConverters(settings); + converters.execute(referentials, db); + } } catch (SQLException e) { logger.error(FAILURE_MESSAGE, e); SqlUtil.log(logger, e); @@ -61,17 +65,4 @@ public class ViolationMigration implements DatabaseMigration { } } - public void migrate() throws SQLException, ExecutionException, InterruptedException { - logger.info("Initialize input"); - Referentials referentials = new Referentials(db); - - if (referentials.totalViolations() > 0) { - logger.info("Migrate {} violations", referentials.totalViolations()); - - ViolationConverters converters = new ViolationConverters(settings); - converters.execute(referentials, db); - } - } - - } diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java index 6674f3d87e0..0bff291ad99 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java @@ -109,13 +109,13 @@ public class ApplicationDeployer { try { FileUtils.deleteDirectory(appsDir); } catch (IOException e) { - throw new IllegalStateException("Fail to delete temp directory: " + appsDir); + throw new IllegalStateException("Fail to delete temp directory: " + appsDir, e); } } try { FileUtils.forceMkdir(appsDir); } catch (IOException e) { - throw new IllegalStateException("Fail to create temp directory: " + appsDir); + throw new IllegalStateException("Fail to create temp directory: " + appsDir, 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 66ef0e0a5e3..6b8e5e3cae0 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 @@ -58,7 +58,7 @@ public final class ClassLoaderUtils { try { FileUtils.copyURLToFile(resource, toFile); } catch (IOException e) { - throw new IllegalStateException("Fail to extract " + relativePath + " to " + toFile.getAbsolutePath()); + throw new IllegalStateException("Fail to extract " + relativePath + " to " + toFile.getAbsolutePath(), e); } } |