]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3039 Refactor the LCOM4 viewer with Ruby extension
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 28 Nov 2011 14:37:25 +0000 (15:37 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 28 Nov 2011 14:59:16 +0000 (15:59 +0100)
13 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/web/Lcom4Viewer.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/lcom4_viewer.html.erb [new file with mode: 0644]
plugins/sonar-design-plugin/pom.xml
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/GwtLcom4Tab.java [deleted file]
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Data.java [deleted file]
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Lcom4Tab.java [deleted file]
plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/Lcom4Tab.gwt.xml [deleted file]
plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/Lcom4TabDev.gwt.xml [deleted file]
plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/public/lcom4.css [deleted file]
plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/public/lcom4.html [deleted file]
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties

index 8fa1ac51be7e754ea5ac515823ac048667a997bc..4299ce8c699c86529176c9d450ee0cafd7fa1f2b 100644 (file)
@@ -39,6 +39,7 @@ import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
 import org.sonar.plugins.core.sensors.*;
 import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition;
 import org.sonar.plugins.core.timemachine.*;
+import org.sonar.plugins.core.web.Lcom4Viewer;
 import org.sonar.plugins.core.widgets.*;
 import org.sonar.plugins.core.widgets.reviews.FalsePositiveReviewsWidget;
 import org.sonar.plugins.core.widgets.reviews.MyReviewsWidget;
@@ -207,7 +208,7 @@ import java.util.List;
 })
 public class CorePlugin extends SonarPlugin {
 
-  @SuppressWarnings({ "rawtypes", "unchecked" })
+  @SuppressWarnings({"rawtypes", "unchecked"})
   public List getExtensions() {
     List extensions = Lists.newLinkedList();
 
@@ -225,6 +226,7 @@ public class CorePlugin extends SonarPlugin {
     // pages
     extensions.add(TestsViewerDefinition.class);
     extensions.add(Hotspots.class);
+    extensions.add(Lcom4Viewer.class);
 
     // widgets
     extensions.add(AlertsWidget.class);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/web/Lcom4Viewer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/web/Lcom4Viewer.java
new file mode 100644 (file)
index 0000000..60a5f75
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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
+ */
+package org.sonar.plugins.core.web;
+
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.web.*;
+
+@NavigationSection(NavigationSection.RESOURCE_TAB)
+@UserRole(UserRole.CODEVIEWER)
+@ResourceLanguage(Java.KEY)
+@ResourceQualifier(Qualifiers.CLASS)
+@DefaultTab(metrics = {"lcom4", "lcom4_blocks"})
+public class Lcom4Viewer extends AbstractRubyTemplate implements RubyRailsPage {
+
+  public String getId() {
+    return "lcom4_viewer";
+  }
+
+  public String getTitle() {
+    return "LCOM4";
+  }
+
+  @Override
+  protected String getTemplatePath() {
+    return "/org/sonar/plugins/core/web/lcom4_viewer.html.erb";
+  }
+}
\ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/lcom4_viewer.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/lcom4_viewer.html.erb
new file mode 100644 (file)
index 0000000..6e1a283
--- /dev/null
@@ -0,0 +1,85 @@
+<style type="text/css">
+  table#lcom4blocks {
+    width: 100%;
+  }
+
+  table#lcom4blocks td {
+    vertical-align: top;
+  }
+
+  table#lcom4blocks td.lcom4BlockIndex {
+    font-size: 130%;
+    margin-top: 3px;
+    text-align: center;
+    width: 2em;
+  }
+
+  table.lcom4block {
+    background-color: #EEEEEE;
+    border: 1px solid #CCCCCC;
+    margin-bottom: 15px;
+    width: 100%;
+  }
+
+  table.lcom4block td {
+    height: 22px;
+    line-height: 22px;
+    vertical-align: middle;
+  }
+
+  table.lcom4block td img {
+    vertical-align: middle;
+  }
+
+  table.lcom4block td.lcom4Qualifier {
+    width: 20px;
+  }
+</style>
+
+<%
+   lcom4 = measure('lcom4')
+   lcom4_blocks = measure('lcom4_blocks')
+%>
+<div class="tab_header" id="source_header">
+  <p>
+    <span><%= Metric.by_key('lcom4').description -%>: </span>
+    <span id="m_lcom4" class="big"><%= lcom4 ? number_with_precision(lcom4.value(), :precision => 0) : '-' -%></span>
+  </p>
+</div>
+
+<%
+   if lcom4_blocks && lcom4_blocks.data
+%>
+  <table id="lcom4blocks">
+    <tbody>
+    <%
+       blocks = JSON(lcom4_blocks.data)
+       blocks.each_with_index do |block, index|
+    %>
+      <tr id="lcom4block_<%= index+1 -%>">
+        <td class="lcom4BlockIndex">
+          <%= index+1 -%>
+        </td>
+        <td>
+          <table cellspacing="0" cellpadding="0" class="lcom4block">
+            <tbody>
+            <% block.each do |hash| %>
+              <tr id="">
+                <td align="left" class="lcom4Qualifier">
+                  <%= image_tag "q/#{hash['q']}.png" -%>
+                </td>
+                <td><%= hash['n'] -%></td>
+              </tr>
+            <% end %>
+            </tbody>
+          </table>
+        </td>
+      </tr>
+    <%
+       end
+    %>
+    </tbody>
+  </table>
+<%
+   end
+%>
\ No newline at end of file
index 6961f66435aae3d6ffe78aaf8048e8b2a03afcd8..b73ceecdbd4258e8675d134ead679990386829d7 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.codehaus.sonar</groupId>
@@ -73,7 +74,6 @@
           <execution>
             <configuration>
               <modules>
-                <module>org.sonar.plugins.design.ui.lcom4.Lcom4Tab${gwt.permutationSuffix}</module>
                 <module>org.sonar.plugins.design.ui.page.DesignPage${gwt.permutationSuffix}</module>
                 <module>org.sonar.plugins.design.ui.dependencies.DependenciesTab${gwt.permutationSuffix}</module>
                 <module>org.sonar.plugins.design.ui.libraries.LibrariesPage${gwt.permutationSuffix}</module>
index ac392718a4f1725087e6db1284458dac0c732ad9..c4a8aabe8e85b05b3615b2900b0bb62894c10714 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
 import org.sonar.api.SonarPlugin;
 import org.sonar.plugins.design.batch.*;
 import org.sonar.plugins.design.ui.dependencies.GwtDependenciesTab;
-import org.sonar.plugins.design.ui.lcom4.GwtLcom4Tab;
 import org.sonar.plugins.design.ui.libraries.GwtLibrariesPage;
 import org.sonar.plugins.design.ui.page.GwtDesignPage;
 import org.sonar.plugins.design.ui.widgets.ChidamberKemererWidget;
@@ -51,7 +50,6 @@ public class DesignPlugin extends SonarPlugin {
     extensions.add(FileDesignWidget.class);
     extensions.add(PackageDesignWidget.class);
     extensions.add(ChidamberKemererWidget.class);
-    extensions.add(GwtLcom4Tab.class);
 
     return extensions;
   }
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/GwtLcom4Tab.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/GwtLcom4Tab.java
deleted file mode 100644 (file)
index 51eef44..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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
- */
-package org.sonar.plugins.design.ui.lcom4;
-
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.web.*;
-import org.sonar.plugins.design.ui.lcom4.client.Lcom4Tab;
-
-@ResourceLanguage(Java.KEY)
-@ResourceQualifier({Resource.QUALIFIER_CLASS})
-@DefaultTab(metrics = {CoreMetrics.LCOM4_KEY})
-@NavigationSection({NavigationSection.RESOURCE_TAB})
-@UserRole(UserRole.CODEVIEWER)
-public class GwtLcom4Tab extends GwtPage {
-
-  public String getTitle() {
-    return "LCOM4";
-  }
-
-  public String getGwtId() {
-    return Lcom4Tab.GWT_ID;
-  }
-}
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Data.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Data.java
deleted file mode 100644 (file)
index 76ee317..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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
- */
-package org.sonar.plugins.design.ui.lcom4.client;
-
-import com.google.gwt.core.client.JavaScriptObject;
-
-public final class Data {
-
-  public static class Entity extends JavaScriptObject {
-    // Overlay types always have protected, zero-arg ctors
-    protected Entity() {
-    }
-
-    public final native String getName()  /*-{ return this.n;  }-*/;
-    public final native String getQualifier()  /*-{ return this.q;  }-*/;
-  }
-
-  public static class Block extends JavaScriptObject {
-    protected Block() {
-    }
-    public final native int size() /*-{ return this.length; }-*/;
-    public final native Entity get(int i) /*-{ return this[i];     }-*/;
-  }
-
-  public static class Blocks extends JavaScriptObject {
-    protected Blocks() {
-    }
-    public final native int size() /*-{ return this.length; }-*/;
-    public final native Block get(int i) /*-{ return this[i];     }-*/;
-  }
-
-  public static native Blocks parse(String json) /*-{
-    return eval('(' + json + ')')
-  }-*/;
-}
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Lcom4Tab.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Lcom4Tab.java
deleted file mode 100644 (file)
index b9aaba0..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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
- */
-package org.sonar.plugins.design.ui.lcom4.client;
-
-import com.google.gwt.i18n.client.Dictionary;
-import com.google.gwt.user.client.ui.*;
-import org.sonar.gwt.ui.Icons;
-import org.sonar.gwt.ui.Loading;
-import org.sonar.gwt.ui.Page;
-import org.sonar.wsclient.gwt.AbstractCallback;
-import org.sonar.wsclient.gwt.Sonar;
-import org.sonar.wsclient.services.Resource;
-import org.sonar.wsclient.services.ResourceQuery;
-
-public class Lcom4Tab extends Page {
-  public static final String GWT_ID = "org.sonar.plugins.design.ui.lcom4.Lcom4Tab";
-
-  private VerticalPanel panel;
-
-  @Override
-  protected Widget doOnResourceLoad(Resource resource) {
-    panel = new VerticalPanel();
-    panel.setWidth("100%");
-    loadData(resource);
-    return panel;
-  }
-
-  private void loadData(Resource resource) {
-    panel.add(new Loading());
-    ResourceQuery query = ResourceQuery.createForMetrics(resource.getId().toString(), "lcom4", "lcom4_blocks");
-    Sonar.getInstance().find(query, new AbstractCallback<Resource>() {
-      @Override
-      protected void doOnResponse(Resource resource) {
-        panel.clear();
-        panel.add(new Header(resource));
-        if (resource != null && resource.getMeasure("lcom4_blocks") != null) {
-          String json = resource.getMeasure("lcom4_blocks").getData();
-          Data.Blocks blocks = Data.parse(json);
-
-          Grid grid = new Grid(blocks.size(), 2);
-          grid.setStyleName("lcom4blocks");
-          grid.getColumnFormatter().setStyleName(0, "index");
-          
-          for (int indexBlock = 0; indexBlock < blocks.size(); indexBlock++) {
-            Data.Block block = blocks.get(indexBlock);
-            grid.setHTML(indexBlock, 0, "<div class='index'>" + (indexBlock + 1) + "</div>");
-
-            VerticalPanel blockPanel = new VerticalPanel();
-            blockPanel.setStyleName("lcom4block");
-
-            for (int indexEntity = 0; indexEntity < block.size(); indexEntity++) {
-              Data.Entity entity = block.get(indexEntity);
-              HTML row = new HTML(Icons.forQualifier(entity.getQualifier()).getHTML() + " " + entity.getName());
-              row.setStyleName("lcom4row");
-              blockPanel.add(row);
-            }
-            grid.setWidget(indexBlock, 1, blockPanel);
-
-          }
-          panel.add(grid);
-        }
-      }
-    });
-  }
-
-  private static class Header extends Composite {
-    private FlowPanel header;
-
-    public Header(Resource resource) {
-      header = new FlowPanel();
-      header.setStyleName("gwt-ViewerHeader");
-
-      HorizontalPanel panel = new HorizontalPanel();
-      HTML html = new HTML(Dictionary.getDictionary("l10n").get("lcom4.metric") + ": ");
-      html.setStyleName("metric");
-      panel.add(html);
-
-      if (resource != null) {
-        html = new HTML(resource.getMeasureFormattedValue("lcom4", "-"));
-        html.setStyleName("value");
-        panel.add(html);
-      }
-
-      header.add(panel);
-      initWidget(header);
-    }
-  }
-}
diff --git a/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/Lcom4Tab.gwt.xml b/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/Lcom4Tab.gwt.xml
deleted file mode 100644 (file)
index 124aa37..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<module>
-  <inherits name="com.google.gwt.user.User"/>
-  <inherits name="com.google.gwt.json.JSON"/>
-  <inherits name="com.google.gwt.http.HTTP"/>
-  <inherits name="org.sonar.Sonar"/>
-  <stylesheet src="lcom4.css"/>
-  <entry-point class="org.sonar.plugins.design.ui.lcom4.client.Lcom4Tab"/>
-</module>
diff --git a/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/Lcom4TabDev.gwt.xml b/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/Lcom4TabDev.gwt.xml
deleted file mode 100644 (file)
index c4f98f0..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<module rename-to="org.sonar.plugins.design.ui.lcom4.Lcom4Tab">
-  <inherits name="org.sonar.plugins.design.ui.lcom4.Lcom4Tab"/>
-  <inherits name="org.sonar.SonarDev"/>
-
-  <entry-point class="org.sonar.plugins.design.ui.lcom4.client.Lcom4Tab"/>
-</module>
diff --git a/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/public/lcom4.css b/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/public/lcom4.css
deleted file mode 100644 (file)
index bbd35eb..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-.lcom4blocks {
-  width: 100%;
-  margin-top: 10px;
-}
-.lcom4blocks td {
-  vertical-align: top;
-}
-.lcom4blocks .index {
-  font-size: 130%;
-  text-align: center;
-  width: 2em;
-  margin-top: 3px;
-}
-.lcom4block {
-  width: 100%;
-  border: 1px solid #ccc;
-  margin-bottom: 15px;
-  background-color: #eee;
-}
-.lcom4row {
-  padding: 2px 5px;
-  word-wrap:break-word;
-}
\ No newline at end of file
diff --git a/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/public/lcom4.html b/plugins/sonar-design-plugin/src/main/resources/org/sonar/plugins/design/ui/lcom4/public/lcom4.html
deleted file mode 100644 (file)
index 8ae47cd..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-    "http://www.w3.org/TR/html4/loose.dtd">
-
-<html>
-<head>
-  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
-  <meta name="gwt:property" content="locale=fr_CH">
-
-  <title>LCOM4</title>
-  <link href="http://localhost:9000/stylesheets/sonar.css" media="all" rel="Stylesheet" type="text/css" />
-  <script src="http://localhost:9000/javascripts/sonar.js" type="text/javascript"></script>
-</head>
-
-<body>
-<h1>LCOM4</h1>
-<div id="gwtpage">
-</div>
-<script type="text/javascript">
-var config = {
-  "sonar_url": "http://localhost:9000",
-  "metric":"lcom4",
-  "resource":[{"id":11, "key":"org.apache.struts:struts-core:org.apache.struts.action.Action","scope": "FIL", "qualifier": "CLA", "name": "ActionServlet", "lang":"java"}]
-};
-  var modules = {};
-</script>
-<script type="text/javascript" language="javascript" src="org.sonar.plugins.design.ui.lcom4.Lcom4Tab.nocache.js"></script>
-</body>
-</html>
\ No newline at end of file
index 18c84fe77abb51b530c15a5e082894ad0f0d7559..dae063778286b0ffc05fcc2744d050804c2c463c 100644 (file)
@@ -299,6 +299,7 @@ users.page=Users
 violations.page=Violations
 violations_drilldown.page=Violations Drilldown
 update_center.page=Update Center
+lcom4_viewer.page=LCOM4
 
 
 # GWT pages
@@ -306,7 +307,6 @@ org.sonar.plugins.core.hotspots.GwtHotspots.page=Hotspots
 org.sonar.plugins.design.ui.page.DesignPage.page=Design
 org.sonar.plugins.design.ui.libraries.LibrariesPage.page=Libraries
 org.sonar.plugins.design.ui.dependencies.DependenciesTab.page=Dependencies
-org.sonar.plugins.design.ui.lcom4.Lcom4Tab.page=LCOM4
 
 
 #------------------------------------------------------------------------------