]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 1 Jul 2014 20:55:24 +0000 (22:55 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 1 Jul 2014 20:58:36 +0000 (22:58 +0200)
sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java
sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb [deleted file]

index 8e730d517ef0fad7a3dbbc5b6bbb875c596cf358..8c3de2f29c6ac9feb7bf984ccf2bfd62c2166214 100644 (file)
@@ -49,6 +49,9 @@ public class ActiveRuleDto extends Dto<ActiveRuleKey> {
   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 (file)
index 0000000..1002604
--- /dev/null
@@ -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());
+  }
+}
index c6d1ffc979046d8ca101f4fdadb7fd77306de346..83d457c1d5990cc8b5619c521bdd502c3cbb2bae 100644 (file)
@@ -481,8 +481,8 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, 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<DOMAIN, DTO extends Dto<KEY>, 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);
     }
   }
 
index 4c93d8a66cb93c09e098dd899d2cc4542c39a560..47ede48b64178592bbdd82c8f17cbd1b6155550b 100644 (file)
@@ -211,10 +211,6 @@ public final class JRubyFacade {
     return get(Views.class).getPages(section, resourceScope, resourceQualifier, resourceLanguage, (String[]) availableMeasures);
   }
 
-  public List<ViewProxy<Page>> getResourceTabs() {
-    return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, null, null, null, null);
-  }
-
   public List<ViewProxy<Page>> 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 (file)
index 085bb7f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<%
-  gwt_pages=[]
-  controller.java_facade.getResourceTabs().each do |tab|
-    if tab.isGwt()
-%>
-    <script src="<%= ApplicationController.root_context -%>/deploy/gwt/<%= tab.getId() -%>/<%= tab.getId() -%>.nocache.js"></script>
-
-<%
-    end
-  end
-%>
\ No newline at end of file