From 41c60e6840839b4071ee2230f74736f064454737 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 12 Oct 2015 16:52:51 +0200 Subject: [PATCH] SONAR-6663 Disable DSM computation on views --- .../design/batch/ProjectDsmDecorator.java | 16 ++++--- .../design/batch/ProjectDsmDecoratorTest.java | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/ProjectDsmDecoratorTest.java diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/ProjectDsmDecorator.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/ProjectDsmDecorator.java index c84a98ebee0..5c616caf2ba 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/ProjectDsmDecorator.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/ProjectDsmDecorator.java @@ -20,6 +20,9 @@ package org.sonar.plugins.design.batch; import com.google.common.collect.Lists; +import java.util.Collection; +import java.util.List; +import java.util.Set; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.batch.SonarIndex; @@ -29,11 +32,12 @@ import org.sonar.api.measures.PersistenceMode; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; -import org.sonar.graph.*; - -import java.util.Collection; -import java.util.List; -import java.util.Set; +import org.sonar.graph.Cycle; +import org.sonar.graph.CycleDetector; +import org.sonar.graph.Dsm; +import org.sonar.graph.DsmTopologicalSorter; +import org.sonar.graph.Edge; +import org.sonar.graph.MinimumFeedbackEdgeSetSolver; /** * For performance reasons, this decorator is currently limited to matrix between modules. @@ -49,7 +53,7 @@ public class ProjectDsmDecorator implements Decorator { } public boolean shouldExecuteOnProject(Project project) { - return true; + return !ResourceUtils.isView(project) && !ResourceUtils.isSubview(project); } public void decorate(final Resource resource, DecoratorContext context) { diff --git a/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/ProjectDsmDecoratorTest.java b/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/ProjectDsmDecoratorTest.java new file mode 100644 index 00000000000..9fa7a30d831 --- /dev/null +++ b/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/ProjectDsmDecoratorTest.java @@ -0,0 +1,48 @@ +/* + * 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.plugins.design.batch; + +import org.junit.Test; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Scopes; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ProjectDsmDecoratorTest { + + @Test + public void disableOnViews() { + assertThat(new ProjectDsmDecorator(null).shouldExecuteOnProject(new Project("foo"))).isTrue(); + + Project view = mock(Project.class); + when(view.getScope()).thenReturn(Scopes.PROJECT); + when(view.getQualifier()).thenReturn(Qualifiers.VIEW); + assertThat(new ProjectDsmDecorator(null).shouldExecuteOnProject(view)).isFalse(); + + Project subview = mock(Project.class); + when(subview.getScope()).thenReturn(Scopes.PROJECT); + when(subview.getQualifier()).thenReturn(Qualifiers.SUBVIEW); + assertThat(new ProjectDsmDecorator(null).shouldExecuteOnProject(subview)).isFalse(); + } + +} -- 2.39.5