From 911c66cab3137ba840b856a4750088ea6709064f Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Wed, 26 Oct 2011 19:47:20 +0200 Subject: [PATCH] SONAR-2733 Fix unit test and remove useless code --- plugins/sonar-core-gwt/pom.xml | 1 - .../client/DuplicationsPanel.java | 174 ------------------ .../client/DuplicationsViewer.java | 81 -------- .../DuplicationsViewer.gwt.xml | 13 -- .../DuplicationsViewerDev.gwt.xml | 6 - .../public/DuplicationsViewer.css | 48 ----- .../core/duplicationsviewer/public/test.html | 43 ----- .../org/sonar/plugins/core/CorePlugin.java | 49 +---- .../java/org/sonar/server/ui/ViewsTest.java | 2 +- 9 files changed, 6 insertions(+), 411 deletions(-) delete mode 100644 plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java delete mode 100644 plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java delete mode 100644 plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewer.gwt.xml delete mode 100644 plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewerDev.gwt.xml delete mode 100644 plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/DuplicationsViewer.css delete mode 100644 plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/test.html diff --git a/plugins/sonar-core-gwt/pom.xml b/plugins/sonar-core-gwt/pom.xml index 75e85715f22..ee0d9c4cd20 100644 --- a/plugins/sonar-core-gwt/pom.xml +++ b/plugins/sonar-core-gwt/pom.xml @@ -59,7 +59,6 @@ - org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer${gwt.permutationSuffix} org.sonar.plugins.core.testdetailsviewer.TestsViewer${gwt.permutationSuffix} org.sonar.plugins.core.hotspots.GwtHotspots${gwt.permutationSuffix} 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 index 681205f4679..00000000000 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java +++ /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 { - - 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 + "
" + 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 index a25c5888fa3..00000000000 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java +++ /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 index b480cc0b418..00000000000 --- a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewer.gwt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - 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 index d3a0ffd3806..00000000000 --- a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/DuplicationsViewerDev.gwt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - 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 index 2cc0ced131c..00000000000 --- a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/DuplicationsViewer.css +++ /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 index 37b1bb43253..00000000000 --- a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/duplicationsviewer/public/test.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - Duplications - - - - - - - - - - - - - -
-
-
- - -load - - \ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index e0aba2cc264..82e3a1c8723 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -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( diff --git a/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java b/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java index c1930b2e136..f1c5720a4e7 100644 --- a/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java @@ -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)); } -- 2.39.5