]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2733 Fix unit test and remove useless code
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 26 Oct 2011 17:47:20 +0000 (19:47 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 26 Oct 2011 17:47:20 +0000 (19:47 +0200)
plugins/sonar-core-gwt/pom.xml
plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java [deleted file]
plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java [deleted file]
plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewer.gwt.xml [deleted file]
plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewerDev.gwt.xml [deleted file]
plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/DuplicationsViewer.css [deleted file]
plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/test.html [deleted file]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java

index 75e85715f225f31b87a4e418cb4f4f6d6dcdd138..ee0d9c4cd20dca9533784de45db120d1812d2af9 100644 (file)
@@ -59,7 +59,6 @@
           <execution>
             <configuration>
               <modules>
-                <module>org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer${gwt.permutationSuffix}</module>
                 <module>org.sonar.plugins.core.testdetailsviewer.TestsViewer${gwt.permutationSuffix}</module>
                 <module>org.sonar.plugins.core.hotspots.GwtHotspots${gwt.permutationSuffix}</module>
               </modules>
diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java
deleted file mode 100644 (file)
index 681205f..0000000
+++ /dev/null
@@ -1,174 +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.core.duplicationsviewer.client;
-
-import com.google.gwt.i18n.client.Dictionary;
-import org.sonar.gwt.Metrics;
-import org.sonar.gwt.ui.DefaultSourcePanel;
-import org.sonar.gwt.ui.ExpandCollapseLink;
-import org.sonar.gwt.ui.Loading;
-import org.sonar.gwt.ui.SourcePanel;
-
-import com.google.gwt.gen2.table.override.client.FlexTable;
-import com.google.gwt.gen2.table.override.client.FlexTable.FlexCellFormatter;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.VerticalPanel;
-import com.google.gwt.xml.client.Document;
-import com.google.gwt.xml.client.Element;
-import com.google.gwt.xml.client.NodeList;
-import com.google.gwt.xml.client.XMLParser;
-import org.sonar.wsclient.gwt.AbstractCallback;
-import org.sonar.wsclient.gwt.Sonar;
-import org.sonar.wsclient.services.Measure;
-import org.sonar.wsclient.services.Resource;
-import org.sonar.wsclient.services.ResourceQuery;
-
-public class DuplicationsPanel extends Composite {
-
-  private final Panel panel;
-  private Loading loading;
-
-  public DuplicationsPanel(Resource resource) {
-    panel = new VerticalPanel();
-    loading = new Loading();
-    panel.add(loading);
-    initWidget(panel);
-    setStyleName("gwt-DuplicationsPanel");
-    getElement().setId("gwt-DuplicationsPanel");
-
-    loadDuplications(resource);
-  }
-
-  public void loadDuplications(Resource resource) {
-    ResourceQuery query = ResourceQuery.createForResource(resource, Metrics.DUPLICATIONS_DATA);
-    Sonar.getInstance().find(query, new DuplicationCallback());
-  }
-
-  private class DuplicationCallback extends AbstractCallback<Resource> {
-
-    public DuplicationCallback() {
-      super(loading);
-    }
-
-    @Override
-    protected void doOnResponse(Resource resource) {
-      loading.removeFromParent();
-      String duplications = null;
-      if (resource != null) {
-        Measure data = resource.getMeasure(Metrics.DUPLICATIONS_DATA);
-        if (data != null) {
-          duplications = data.getData();
-        }
-      }
-      if (duplications != null) {
-        processDuplications(duplications, resource);
-      }
-    }
-
-    private void processDuplications(String duplicationXMLData, Resource resource) {
-      Document parsed = XMLParser.parse(duplicationXMLData);
-      NodeList duplicationsXML = parsed.getElementsByTagName("duplication");
-      
-      FlexTable table = getDuplicationsTable();
-      
-      panel.add(table);
-      int rowCounter = 1;
-
-      String projectKey = resource.getKey().substring(0, resource.getKey().lastIndexOf(':'));
-      for (int i = 0; i < duplicationsXML.getLength(); i++) {
-        Element duplicationXML = (Element) duplicationsXML.item(i);
-        String lines = duplicationXML.getAttribute("lines");
-        String startLine = duplicationXML.getAttribute("start");
-        String targetStartLine = duplicationXML.getAttribute("target-start");
-        String targetResourceKey = duplicationXML.getAttribute("target-resource");
-        renderDuplication(rowCounter, i, table, lines, startLine, targetStartLine, targetResourceKey, resource, projectKey);
-        rowCounter+=2;
-      }
-    }
-
-    private FlexTable getDuplicationsTable() {
-      Dictionary l10n = Dictionary.getDictionary("l10n");
-      FlexTable table = new FlexTable();
-      table.setStylePrimaryName("duplicationsTable");
-      table.setText(0, 0, "");
-      table.setText(0, 1, l10n.get("dupl.colSize"));
-      table.setText(0, 2, l10n.get("dupl.colFromLine"));
-      table.setText(0, 3, l10n.get("dupl.colFile"));
-      table.setText(0, 4, l10n.get("dupl.colFromLine"));
-      
-      table.getCellFormatter().getElement(0, 0).setId("expandCollapseCol");
-      table.getCellFormatter().getElement(0, 1).setId("nbLineCol");
-      table.getCellFormatter().getElement(0, 2).setId("lineFromCol");
-      table.getCellFormatter().getElement(0, 3).setId("fileCol");
-      
-      setRowStyle(0, table, "header", false);
-      return table;
-    }
-
-    private void renderDuplication(int row, int duplicationCounter, FlexTable table, String lines, String startLine, String targetStartLine, String targetResourceKey, final Resource resource, String projectKey) {
-      String style = (duplicationCounter % 2 == 0) ? "odd" : "even";
-      
-      SourcePanel src = new DefaultSourcePanel(resource, new Integer(startLine), new Integer(lines));
-      src.getElement().setId("source-panel-" + targetResourceKey.replace('.', '_'));
-      src.setVisible(false);
-      
-      ExpandCollapseLink link = new ExpandCollapseLink(src);
-
-      table.setWidget(row, 0, link);
-      table.setText(row, 1, lines);
-      table.setText(row, 2, startLine);
-      if (targetResourceKey.equals(resource.getKey())) {
-        targetResourceKey = "Same file";
-      }
-      if (targetResourceKey.contains(":")) {
-        int i = targetResourceKey.lastIndexOf(':');
-        String targetProjectKey = targetResourceKey.substring(0, i);
-        String targetFileKey = targetResourceKey.substring(i + 1);
-        if (targetProjectKey.equals(projectKey)) {
-          // same project
-          targetResourceKey = targetFileKey;
-        } else {
-          // another project
-          targetResourceKey = targetProjectKey + "<br/>" + targetFileKey;
-        }
-      }
-      table.setHTML(row, 3, targetResourceKey);
-      table.setText(row, 4, targetStartLine);
-      setRowStyle(row, table, style, false);
-      
-      FlexCellFormatter frmt = (FlexCellFormatter)table.getCellFormatter();
-      frmt.setColSpan(row + 1, 1, 4);
-      table.setWidget(row + 1, 1, src);
-      setRowStyle(row + 1, table, style, true);
-
-    }
-
-    private void setRowStyle(int row, FlexTable table, String style, boolean isPanelRow) {
-      table.getCellFormatter().setStyleName(row, 0, style);
-      table.getCellFormatter().setStyleName(row, 1, style);
-      if (!isPanelRow) {
-        table.getCellFormatter().setStyleName(row, 2, style);
-        table.getCellFormatter().setStyleName(row, 3, style);
-        table.getCellFormatter().setStyleName(row, 4, style);
-      }
-    }
-  }
-}
diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java
deleted file mode 100644 (file)
index a25c588..0000000
+++ /dev/null
@@ -1,81 +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.core.duplicationsviewer.client;
-
-import com.google.gwt.i18n.client.Dictionary;
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.Widget;
-import org.sonar.gwt.Metrics;
-import org.sonar.gwt.ui.Page;
-import org.sonar.gwt.ui.ViewerHeader;
-import org.sonar.wsclient.services.Measure;
-import org.sonar.wsclient.services.Resource;
-
-public class DuplicationsViewer extends Page {
-
-  public static final String GWT_ID = "org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer";
-
-  @Override
-  protected Widget doOnResourceLoad(Resource resource) {
-    FlowPanel panel = new FlowPanel();
-    panel.setWidth("100%");
-    panel.add(new DuplicationsHeader(resource));
-    panel.add(new DuplicationsPanel(resource));
-    return panel;
-  }
-
-  private static class DuplicationsHeader extends ViewerHeader {
-    public DuplicationsHeader(Resource resource) {
-      super(resource, new String[]{Metrics.DUPLICATED_LINES_DENSITY, Metrics.LINES, Metrics.DUPLICATED_LINES, Metrics.DUPLICATED_BLOCKS});
-    }
-
-    @Override
-    protected void display(FlowPanel header, Resource resource) {
-      Panel panel = new HorizontalPanel();
-      header.add(panel);
-
-      Measure measure = resource.getMeasure(Metrics.DUPLICATED_LINES_DENSITY);
-      if (measure == null) {
-        addBigCell(panel, "0");
-      } else {
-        addBigCell(panel, measure.getFormattedValue());
-      }
-
-      Dictionary l10n = Dictionary.getDictionary("l10n");
-      addCell(panel, getDefaultMeasure(resource, Metrics.LINES, l10n.get("dupl.lines")));
-      addCell(panel, getDefaultMeasure(resource, Metrics.DUPLICATED_LINES, l10n.get("dupl.duplicated_lines")));
-      addCell(panel, getDefaultMeasure(resource, Metrics.DUPLICATED_BLOCKS, l10n.get("dupl.duplicated_blocks")));
-    }
-
-    private Measure getDefaultMeasure(Resource resource, String metric, String label) {
-      Measure measure = resource.getMeasure(metric);
-      if (measure == null || measure.getValue() == null) {
-        measure = new Measure();
-        measure.setMetricName(label);
-        measure.setValue(0.0);
-        measure.setFormattedValue("0");
-      }
-      return measure;
-    }
-  }
-
-}
diff --git a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewer.gwt.xml b/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewer.gwt.xml
deleted file mode 100644 (file)
index b480cc0..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<module>
-  <inherits name="com.google.gwt.xml.XML"/>
-  <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"/>
-  <inherits name="com.google.gwt.gen2.table.Table"/>
-
-  <stylesheet src="DuplicationsViewer.css"/>
-
-  <entry-point class="org.sonar.plugins.core.duplicationsviewer.client.DuplicationsViewer"/>
-
-</module>
diff --git a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewerDev.gwt.xml b/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewerDev.gwt.xml
deleted file mode 100644 (file)
index d3a0ffd..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<module rename-to="org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer">
-  <inherits name="org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer"/>
-  <inherits name="org.sonar.SonarDev"/>
-
-  <entry-point class="org.sonar.plugins.core.duplicationsviewer.client.DuplicationsViewer"/>
-</module>
diff --git a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/DuplicationsViewer.css b/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/DuplicationsViewer.css
deleted file mode 100644 (file)
index 2cc0ced..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-.gwt-DuplicationsPanel {
-  width: 100%;
-}
-
-.duplicationsTable {
-  border: 1px solid #C0C0C0;
-  width: 100%;
-  vertical-align: top;
-}
-
-.duplicationsTable td {
-  vertical-align: top;
-  text-align: left;
-  padding: 3px;
-  white-space: nowrap;
-}
-
-.duplicationsTable #expandCollapseCol {
-  width: 60px;
-}
-
-.duplicationsTable #nbLineCol {
-  width: 80px;
-}
-
-.duplicationsTable #lineFromCol {
-  width: 80px;
-}
-
-.duplicationsTable #fileCol {
-  width: 80px;
-}
-
-.duplicationsTable .header {
-  background-color: #EFEFEF;
-  font-weight: bold;
-  color: #333;
-  vertical-align: top;
-}
-
-.expandCollapseLink {
-  margin-left: 5px;
-}
-
-.gwt-SourcePanel table.sources td {
-  vertical-align: top;
-  padding: 0px;
-}
\ No newline at end of file
diff --git a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/test.html b/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/test.html
deleted file mode 100644 (file)
index 37b1bb4..0000000
+++ /dev/null
@@ -1,43 +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">
-  <title>Duplications</title>
-  <link href="http://localhost:9000/dev/stylesheets/yui-2.6.0.css" media="all" rel="Stylesheet" type="text/css"/>
-  <link href="http://localhost:9000/dev/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/>
-  <script src="http://localhost:9000/dev/javascripts/application.js" type="text/javascript"></script>
-  <script src="http://localhost:9000/dev/javascripts/prototype.js" type="text/javascript"></script>
-  <script src="http://localhost:9000/dev/javascripts/scriptaculous.js" type="text/javascript"></script>
-</head>
-
-<body>
-<script type="text/javascript">
-  var registeredTabs = [];
-  var config = {
-    "sonar_url": "http://localhost:9000/dev",
-    "viewer_resource_key" : "org.sonar.tests:reference:org.sonar.samples.duplicated_lines_within_same_class.DuplicatedLinesInSameClass"
-  };
-
-  
-</script>
-<div class="error" id="error" style="display:none"><span id="errormsg"></span> &nbsp;&nbsp;[<a href="#"
-                                                                                               onclick="javascript:$('error').hide();return false;">hide</a>]
-</div>
-<div class="warning" id="warning" style="display:none"><span id="warningmsg"></span> &nbsp;&nbsp;[<a href="#"
-                                                                                                     onclick="javascript:$('warning').hide();return false;">hide</a>]
-</div>
-<div class="notice" id="info" style="display:none"><span id="infomsg"></span> &nbsp;&nbsp;[<a href="#"
-                                                                                              onclick="javascript:$('info').hide();return false;">hide</a>]
-</div>
-
-<div id="resource_viewers">
-  <div id='loading'></div>
-</div>
-<script type="text/javascript" language="javascript"
-        src="org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer.nocache.js"></script>
-
-<a href="#" onclick="load_org_sonar_plugins_core_duplicationsviewer_DuplicationsViewer();">load</a>
-</body>
-</html>
\ No newline at end of file
index e0aba2cc264d11c58ce469ad2df0190f4bcac574..82e3a1c872304ad6e0608811150b16913142278a 100644 (file)
@@ -19,8 +19,7 @@
  */
 package org.sonar.plugins.core;
 
-import java.util.List;
-
+import com.google.common.collect.Lists;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.Properties;
 import org.sonar.api.Property;
@@ -37,50 +36,12 @@ import org.sonar.plugins.core.colorizers.JavaColorizerFormat;
 import org.sonar.plugins.core.hotspots.Hotspots;
 import org.sonar.plugins.core.metrics.UserManagedMetrics;
 import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
-import org.sonar.plugins.core.sensors.BranchCoverageDecorator;
-import org.sonar.plugins.core.sensors.CheckAlertThresholds;
-import org.sonar.plugins.core.sensors.CloseReviewsDecorator;
-import org.sonar.plugins.core.sensors.CommentDensityDecorator;
-import org.sonar.plugins.core.sensors.CoverageDecorator;
-import org.sonar.plugins.core.sensors.DirectoriesDecorator;
-import org.sonar.plugins.core.sensors.FilesDecorator;
-import org.sonar.plugins.core.sensors.GenerateAlertEvents;
-import org.sonar.plugins.core.sensors.LineCoverageDecorator;
-import org.sonar.plugins.core.sensors.ManualMeasureDecorator;
-import org.sonar.plugins.core.sensors.ProfileEventsSensor;
-import org.sonar.plugins.core.sensors.ProfileSensor;
-import org.sonar.plugins.core.sensors.ProjectLinksSensor;
-import org.sonar.plugins.core.sensors.UnitTestDecorator;
-import org.sonar.plugins.core.sensors.VersionEventsSensor;
-import org.sonar.plugins.core.sensors.ViolationsDecorator;
-import org.sonar.plugins.core.sensors.ViolationsDensityDecorator;
-import org.sonar.plugins.core.sensors.WeightedViolationsDecorator;
+import org.sonar.plugins.core.sensors.*;
 import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition;
-import org.sonar.plugins.core.timemachine.NewCoverageAggregator;
-import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer;
-import org.sonar.plugins.core.timemachine.NewViolationsDecorator;
-import org.sonar.plugins.core.timemachine.ReferenceAnalysis;
-import org.sonar.plugins.core.timemachine.TendencyDecorator;
-import org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister;
-import org.sonar.plugins.core.timemachine.VariationDecorator;
-import org.sonar.plugins.core.timemachine.ViolationPersisterDecorator;
-import org.sonar.plugins.core.timemachine.ViolationTrackingDecorator;
-import org.sonar.plugins.core.widgets.AlertsWidget;
-import org.sonar.plugins.core.widgets.CodeCoverageWidget;
-import org.sonar.plugins.core.widgets.CommentsDuplicationsWidget;
-import org.sonar.plugins.core.widgets.ComplexityWidget;
-import org.sonar.plugins.core.widgets.CustomMeasuresWidget;
-import org.sonar.plugins.core.widgets.DescriptionWidget;
-import org.sonar.plugins.core.widgets.EventsWidget;
-import org.sonar.plugins.core.widgets.HotspotMetricWidget;
-import org.sonar.plugins.core.widgets.HotspotMostViolatedResourcesWidget;
-import org.sonar.plugins.core.widgets.HotspotMostViolatedRulesWidget;
-import org.sonar.plugins.core.widgets.RulesWidget;
-import org.sonar.plugins.core.widgets.SizeWidget;
-import org.sonar.plugins.core.widgets.TimeMachineWidget;
-import org.sonar.plugins.core.widgets.TimelineWidget;
+import org.sonar.plugins.core.timemachine.*;
+import org.sonar.plugins.core.widgets.*;
 
-import com.google.common.collect.Lists;
+import java.util.List;
 
 @Properties({
     @Property(
index c1930b2e1366c09b19c3e6055e2d56c97f790495..f1c5720a4e7f94ba5e0d1dd7665e17a9aa5d247a 100644 (file)
@@ -68,7 +68,7 @@ public class ViewsTest {
   public void getResourceViewers() {
     final Views views = new Views(VIEWS);
     List resourceViewers = views.getPages(NavigationSection.RESOURCE_TAB);
-    assertThat(resourceViewers.size(), is(1 + 3 /* default */));
+    assertThat(resourceViewers.size(), is(1 + 4 /* default */));
     assertThat(resourceViewers.contains(new ViewProxy((View)FAKE_TAB)), is(true));
   }