From 6c0da1115cd26a1e41195c3924d94d46dda0e38b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 1 Jul 2014 22:55:24 +0200 Subject: [PATCH] Fix some quality flaws --- .../core/qualityprofile/db/ActiveRuleDto.java | 3 + .../qualityprofile/db/ActiveRuleKeyTest.java | 61 +++++++++++++++++++ .../org/sonar/server/search/BaseIndex.java | 8 +-- .../java/org/sonar/server/ui/JRubyFacade.java | 4 -- .../app/views/gwt/_resource_viewers.html.erb | 11 ---- 5 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java index 8e730d517ef..8c3de2f29c6 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java @@ -49,6 +49,9 @@ public class ActiveRuleDto extends Dto { private Integer severity; private String inheritance; + /** + * for internal use, should be private + */ @Deprecated public ActiveRuleDto setKey(ActiveRuleKey key) { this.repository = key.ruleKey().repository(); diff --git a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java new file mode 100644 index 00000000000..10026049cca --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java @@ -0,0 +1,61 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.qualityprofile.db; + +import org.junit.Test; +import org.sonar.api.rule.RuleKey; + +import static org.fest.assertions.Assertions.assertThat; + +public class ActiveRuleKeyTest { + + @Test + public void of() throws Exception { + RuleKey ruleKey = RuleKey.of("xoo", "R1"); + ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey); + assertThat(key.qProfile()).isEqualTo("P1"); + assertThat(key.ruleKey()).isSameAs(ruleKey); + assertThat(key.toString()).isEqualTo("P1:xoo:R1"); + } + + @Test + public void parse() throws Exception { + ActiveRuleKey key = ActiveRuleKey.parse("P1:xoo:R1"); + assertThat(key.qProfile()).isEqualTo("P1"); + assertThat(key.ruleKey().repository()).isEqualTo("xoo"); + assertThat(key.ruleKey().rule()).isEqualTo("R1"); + } + + @Test + public void equals_and_hashcode() throws Exception { + ActiveRuleKey key1 = ActiveRuleKey.parse("P1:xoo:R1"); + ActiveRuleKey key1b = ActiveRuleKey.parse("P1:xoo:R1"); + ActiveRuleKey key2 = ActiveRuleKey.parse("P1:xoo:R2"); + ActiveRuleKey key3 = ActiveRuleKey.parse("P2:xoo:R1"); + assertThat(key1.equals(key1)).isTrue(); + assertThat(key1.equals(key1b)).isTrue(); + assertThat(key1.equals(null)).isFalse(); + assertThat(key1.equals("P1:xoo:R1")).isFalse(); + assertThat(key1.equals(key2)).isFalse(); + assertThat(key1.equals(key3)).isFalse(); + + assertThat(key1.hashCode()).isEqualTo(key1.hashCode()); + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java index c6d1ffc9790..83d457c1d59 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java @@ -481,8 +481,8 @@ public abstract class BaseIndex, KEY extends Serial this.deleteDocument(additionalKey); } } catch (Exception e) { - throw new IllegalStateException("Could not DELETE _id = '" + this.getKeyValue(key) + "' " + - "for index '" + this.getIndexName() + "': " + e.getMessage()); + throw new IllegalStateException(String.format("Could not DELETE _id = '%s' for index '%s", + getKeyValue(key), getIndexName()), e); } } @@ -494,8 +494,8 @@ public abstract class BaseIndex, KEY extends Serial this.deleteDocument(additionalItem.getKey()); } } catch (Exception e) { - throw new IllegalStateException("Could not DELETE _id = '" + this.getKeyValue(item.getKey()) + "' " + - "for index '" + this.getIndexName() + "': " + e.getMessage()); + throw new IllegalStateException(String.format("Could not DELETE _id = '%s' for index '%s", + getKeyValue(item.getKey()), getIndexName()), e); } } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 4c93d8a66cb..47ede48b641 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -211,10 +211,6 @@ public final class JRubyFacade { return get(Views.class).getPages(section, resourceScope, resourceQualifier, resourceLanguage, (String[]) availableMeasures); } - public List> getResourceTabs() { - return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, null, null, null, null); - } - public List> getResourceTabs(String scope, String qualifier, String language, Object[] availableMeasures) { return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, scope, qualifier, language, (String[]) availableMeasures); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb deleted file mode 100644 index 085bb7ff1ee..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -<% - gwt_pages=[] - controller.java_facade.getResourceTabs().each do |tab| - if tab.isGwt() -%> - - -<% - end - end -%> \ No newline at end of file -- 2.39.5