From: Simon Brandhof Date: Mon, 3 Feb 2014 14:20:42 +0000 (+0100) Subject: SONAR-926 move deprecated decorators to sonar-deprecated lib X-Git-Tag: 4.2~286 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5adb3998b2e33eb2bf454ba1a7b98927f4082ed3;p=sonarqube.git SONAR-926 move deprecated decorators to sonar-deprecated lib --- diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java new file mode 100644 index 00000000000..3ccc4edae81 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java @@ -0,0 +1,55 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +/** + * A pre-implementation to decorate the number of directories + * + * @since 1.10 + * @deprecated since 2.2, the number of directories is automatically calculated by sonar core (see metric formula) + */ +@Deprecated +public abstract class AbstractDirectoriesDecorator implements Decorator { + + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractDirectoriesDecorator(Language language) {//NOSONAR this unused parameter is kept for backward-compatibility of API + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return false; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java new file mode 100644 index 00000000000..ffd9b09ea3f --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java @@ -0,0 +1,89 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.MeasureUtils; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; +import org.sonar.api.resources.ResourceUtils; + +import java.util.Arrays; +import java.util.List; + +/** + * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore + * @since 1.10 + */ +@Deprecated +public abstract class AbstractFileComplexityDecorator implements Decorator { + + private Language language; + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractFileComplexityDecorator(Language language) { + this.language = language; + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return language.equals(project.getLanguage()); + } + + /** + * Used to define upstream dependencies + */ + @DependsUpon + public List dependsUponFileAndComplexityMetrics() { + return Arrays.asList(CoreMetrics.FILES, CoreMetrics.COMPLEXITY); + } + + /** + * Used to define downstream dependencies + */ + @DependedUpon + public Metric generateFileComplexityMetric() { + return CoreMetrics.FILE_COMPLEXITY; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + if (!shouldDecorateResource(resource, context)) { + return; + } + Double files = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FILES), null); + Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null); + if (complexity != null && files != null && files > 0.0) { + context.saveMeasure(CoreMetrics.FILE_COMPLEXITY, complexity / files); + } + } + + private boolean shouldDecorateResource(Resource resource, DecoratorContext context) { + return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FILE_COMPLEXITY)) && !ResourceUtils.isEntity(resource); + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java new file mode 100644 index 00000000000..35d9ba30b9a --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java @@ -0,0 +1,55 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +/** + * A pre-implementation to decorate the number of files + + * @since 1.10 + * @deprecated since 2.2, the number of files is automatically calculated by sonar core (see metric formula) + */ +@Deprecated +public abstract class AbstractFilesDecorator implements Decorator { + + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractFilesDecorator(Language language) { + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return false; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java new file mode 100644 index 00000000000..d3aeb079633 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java @@ -0,0 +1,88 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.MeasureUtils; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +import java.util.Arrays; +import java.util.List; + +/** + * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore + * @since 1.13 + */ +@Deprecated +public abstract class AbstractFunctionComplexityDecorator implements Decorator { + + private Language language; + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractFunctionComplexityDecorator(Language language) { + this.language = language; + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return language.equals(project.getLanguage()); + } + + /** + * Used to define upstream dependencies + */ + @DependsUpon + public List dependsUponFileAndComplexityMetrics() { + return Arrays.asList(CoreMetrics.FUNCTIONS, CoreMetrics.COMPLEXITY); + } + + /** + * Used to define downstream dependencies + */ + @DependedUpon + public Metric generateFileComplexityMetric() { + return CoreMetrics.FUNCTION_COMPLEXITY; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + if (!shouldDecorateResource(resource, context)) { + return; + } + Double functions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FUNCTIONS), null); + Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null); + if (complexity != null && functions != null && functions > 0.0) { + context.saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, complexity / functions); + } + } + + private boolean shouldDecorateResource(Resource resource, DecoratorContext context) { + return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY)); + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java new file mode 100644 index 00000000000..967a3048dec --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java @@ -0,0 +1,83 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.CountDistributionBuilder; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +/** + * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore + * @since 2.0 + */ +@Deprecated +public abstract class AbstractFunctionComplexityDistributionDecorator implements Decorator { + + private CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); + private Language language; + + public AbstractFunctionComplexityDistributionDecorator(Language language) { + this.language = language; + } + + @DependedUpon + public Metric generatesMetrics() { + return CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION; + } + + public boolean shouldExecuteOnProject(Project project) { + return language.equals(project.getLanguage()); + } + + public void decorate(Resource resource, DecoratorContext context) { + if (shouldDecorateResource(context)) { + reset(); + saveDistribution(context); + } + } + + private void saveDistribution(DecoratorContext context) { + for (Measure childMeasure : context.getChildrenMeasures(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION)) { + builder.add(childMeasure); + } + + if (!builder.isEmpty()) { + context.saveMeasure(builder.build()); + } + } + + private void reset() { + builder.clear(); + } + + private boolean shouldDecorateResource(DecoratorContext context) { + return context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) == null; + } + + @Override + public String toString() { + return getClass().getSimpleName(); + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java new file mode 100644 index 00000000000..a892c8ff1b5 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java @@ -0,0 +1,84 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.ProjectFileSystem; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Resource; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; + +/** + * @since 1.10 + * @deprecated since 4.2 Component indexing and source import are done by core and this extension is not used. + */ +@Deprecated +@Phase(name = Phase.Name.PRE) +public abstract class AbstractSourceImporter implements Sensor { + + private Language language; + + public AbstractSourceImporter(Language language) { + this.language = language; + } + + public boolean shouldExecuteOnProject(Project project) { + return false; + } + + public void analyse(Project project, SensorContext context) { + // Do not remove for backward compatibility + } + + protected void onFinished() { + + } + + protected void analyse(ProjectFileSystem fileSystem, SensorContext context) { + // Do not remove for backward compatibility + } + + protected void parseDirs(SensorContext context, List files, List sourceDirs, boolean unitTest, Charset sourcesEncoding) { + // Do not remove for backward compatibility + } + + protected Resource createResource(File file, List sourceDirs, boolean unitTest) { + org.sonar.api.resources.File resource = org.sonar.api.resources.File.fromIOFile(file, sourceDirs); + if (resource != null) { + resource.setLanguage(language); + if (unitTest) { + resource.setQualifier(Qualifiers.UNIT_TEST_FILE); + } + } + return resource; + } + + protected boolean isEnabled(Project project) { + return false; + } + + public Language getLanguage() { + return language; + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java new file mode 100644 index 00000000000..8a4d0a9e53e --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java @@ -0,0 +1,88 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.junit.Test; +import static org.mockito.Mockito.*; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Directory; +import org.sonar.api.resources.File; +import org.sonar.api.resources.Java; +import org.sonar.api.resources.Resource; + +public class AbstractFileComplexityDecoratorTest { + + @Test + public void calculateFileComplexity() { + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 20.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + new AbstractFileComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context).saveMeasure(CoreMetrics.FILE_COMPLEXITY, 25.0); + } + + @Test + public void noAverageIfMissingData() { + + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 20.0)); + Resource directory = new Directory("fake"); + + new AbstractFileComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); + } + + @Test + public void noAverageIfZeroFiles() { + AbstractFileComplexityDecorator decorator = new AbstractFileComplexityDecorator(Java.INSTANCE) { + }; + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 0.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + decorator.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); + } + + @Test + public void doNotCalculateOnFiles() { + + Resource file = new File("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 1.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 25.0)); + + new AbstractFileComplexityDecorator(Java.INSTANCE) { + }.decorate(file, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java new file mode 100644 index 00000000000..e2777379fa3 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java @@ -0,0 +1,88 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.batch; + +import org.junit.Test; +import static org.mockito.Mockito.*; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Directory; +import org.sonar.api.resources.File; +import org.sonar.api.resources.Java; +import org.sonar.api.resources.Resource; + +public class AbstractFunctionComplexityDecoratorTest { + + @Test + public void calculateFunctionComplexity() { + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 200.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context).saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, 2.5); + } + + @Test + public void noAverageIfMissingData() { + + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0)); + Resource directory = new Directory("fake"); + + new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); + } + + @Test + public void noAverageIfZeroFiles() { + AbstractFunctionComplexityDecorator decorator = new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }; + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 0.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + decorator.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); + } + + @Test + public void doNotCalculateOnFiles() { + + Resource file = new File("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 1.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 25.0)); + + new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }.decorate(file, context); + + verify(context).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java deleted file mode 100644 index 3ccc4edae81..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; - -/** - * A pre-implementation to decorate the number of directories - * - * @since 1.10 - * @deprecated since 2.2, the number of directories is automatically calculated by sonar core (see metric formula) - */ -@Deprecated -public abstract class AbstractDirectoriesDecorator implements Decorator { - - - /** - * @param language this will be use to defined whether the decorator should be executed on a project - */ - public AbstractDirectoriesDecorator(Language language) {//NOSONAR this unused parameter is kept for backward-compatibility of API - } - - /** - * {@inheritDoc} - */ - public boolean shouldExecuteOnProject(Project project) { - return false; - } - - /** - * {@inheritDoc} - */ - public void decorate(Resource resource, DecoratorContext context) { - - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java deleted file mode 100644 index ffd9b09ea3f..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; - -import java.util.Arrays; -import java.util.List; - -/** - * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore - * @since 1.10 - */ -@Deprecated -public abstract class AbstractFileComplexityDecorator implements Decorator { - - private Language language; - - /** - * @param language this will be use to defined whether the decorator should be executed on a project - */ - public AbstractFileComplexityDecorator(Language language) { - this.language = language; - } - - /** - * {@inheritDoc} - */ - public boolean shouldExecuteOnProject(Project project) { - return language.equals(project.getLanguage()); - } - - /** - * Used to define upstream dependencies - */ - @DependsUpon - public List dependsUponFileAndComplexityMetrics() { - return Arrays.asList(CoreMetrics.FILES, CoreMetrics.COMPLEXITY); - } - - /** - * Used to define downstream dependencies - */ - @DependedUpon - public Metric generateFileComplexityMetric() { - return CoreMetrics.FILE_COMPLEXITY; - } - - /** - * {@inheritDoc} - */ - public void decorate(Resource resource, DecoratorContext context) { - if (!shouldDecorateResource(resource, context)) { - return; - } - Double files = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FILES), null); - Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null); - if (complexity != null && files != null && files > 0.0) { - context.saveMeasure(CoreMetrics.FILE_COMPLEXITY, complexity / files); - } - } - - private boolean shouldDecorateResource(Resource resource, DecoratorContext context) { - return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FILE_COMPLEXITY)) && !ResourceUtils.isEntity(resource); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java deleted file mode 100644 index 35d9ba30b9a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; - -/** - * A pre-implementation to decorate the number of files - - * @since 1.10 - * @deprecated since 2.2, the number of files is automatically calculated by sonar core (see metric formula) - */ -@Deprecated -public abstract class AbstractFilesDecorator implements Decorator { - - - /** - * @param language this will be use to defined whether the decorator should be executed on a project - */ - public AbstractFilesDecorator(Language language) { - } - - /** - * {@inheritDoc} - */ - public boolean shouldExecuteOnProject(Project project) { - return false; - } - - /** - * {@inheritDoc} - */ - public void decorate(Resource resource, DecoratorContext context) { - - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java deleted file mode 100644 index d3aeb079633..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; - -import java.util.Arrays; -import java.util.List; - -/** - * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore - * @since 1.13 - */ -@Deprecated -public abstract class AbstractFunctionComplexityDecorator implements Decorator { - - private Language language; - - /** - * @param language this will be use to defined whether the decorator should be executed on a project - */ - public AbstractFunctionComplexityDecorator(Language language) { - this.language = language; - } - - /** - * {@inheritDoc} - */ - public boolean shouldExecuteOnProject(Project project) { - return language.equals(project.getLanguage()); - } - - /** - * Used to define upstream dependencies - */ - @DependsUpon - public List dependsUponFileAndComplexityMetrics() { - return Arrays.asList(CoreMetrics.FUNCTIONS, CoreMetrics.COMPLEXITY); - } - - /** - * Used to define downstream dependencies - */ - @DependedUpon - public Metric generateFileComplexityMetric() { - return CoreMetrics.FUNCTION_COMPLEXITY; - } - - /** - * {@inheritDoc} - */ - public void decorate(Resource resource, DecoratorContext context) { - if (!shouldDecorateResource(resource, context)) { - return; - } - Double functions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FUNCTIONS), null); - Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null); - if (complexity != null && functions != null && functions > 0.0) { - context.saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, complexity / functions); - } - } - - private boolean shouldDecorateResource(Resource resource, DecoratorContext context) { - return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY)); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java deleted file mode 100644 index 967a3048dec..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.CountDistributionBuilder; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; - -/** - * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore - * @since 2.0 - */ -@Deprecated -public abstract class AbstractFunctionComplexityDistributionDecorator implements Decorator { - - private CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); - private Language language; - - public AbstractFunctionComplexityDistributionDecorator(Language language) { - this.language = language; - } - - @DependedUpon - public Metric generatesMetrics() { - return CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION; - } - - public boolean shouldExecuteOnProject(Project project) { - return language.equals(project.getLanguage()); - } - - public void decorate(Resource resource, DecoratorContext context) { - if (shouldDecorateResource(context)) { - reset(); - saveDistribution(context); - } - } - - private void saveDistribution(DecoratorContext context) { - for (Measure childMeasure : context.getChildrenMeasures(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION)) { - builder.add(childMeasure); - } - - if (!builder.isEmpty()) { - context.saveMeasure(builder.build()); - } - } - - private void reset() { - builder.clear(); - } - - private boolean shouldDecorateResource(DecoratorContext context) { - return context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) == null; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java deleted file mode 100644 index 3d3000cbef8..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.List; - -/** - * @since 1.10 - * @deprecated since 4.2 Resource indexing/source import is done by the core and this extension will not be used. - */ -@Deprecated -@Phase(name = Phase.Name.PRE) -public abstract class AbstractSourceImporter implements Sensor { - - private Language language; - - public AbstractSourceImporter(Language language) { - this.language = language; - } - - public boolean shouldExecuteOnProject(Project project) { - return false; - } - - public void analyse(Project project, SensorContext context) { - // Do not remove for backward compatibility - } - - protected void onFinished() { - - } - - protected void analyse(ProjectFileSystem fileSystem, SensorContext context) { - // Do not remove for backward compatibility - } - - protected void parseDirs(SensorContext context, List files, List sourceDirs, boolean unitTest, Charset sourcesEncoding) { - // Do not remove for backward compatibility - } - - protected Resource createResource(File file, List sourceDirs, boolean unitTest) { - org.sonar.api.resources.File resource = org.sonar.api.resources.File.fromIOFile(file, sourceDirs); - if (resource != null) { - resource.setLanguage(language); - if (unitTest) { - resource.setQualifier(Qualifiers.UNIT_TEST_FILE); - } - } - return resource; - } - - protected boolean isEnabled(Project project) { - return false; - } - - public Language getLanguage() { - return language; - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java deleted file mode 100644 index 8a4d0a9e53e..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.junit.Test; -import static org.mockito.Mockito.*; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.Directory; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Java; -import org.sonar.api.resources.Resource; - -public class AbstractFileComplexityDecoratorTest { - - @Test - public void calculateFileComplexity() { - - Resource directory = new Directory("fake"); - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 20.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); - - new AbstractFileComplexityDecorator(Java.INSTANCE) { - }.decorate(directory, context); - - verify(context).saveMeasure(CoreMetrics.FILE_COMPLEXITY, 25.0); - } - - @Test - public void noAverageIfMissingData() { - - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 20.0)); - Resource directory = new Directory("fake"); - - new AbstractFileComplexityDecorator(Java.INSTANCE) { - }.decorate(directory, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); - } - - @Test - public void noAverageIfZeroFiles() { - AbstractFileComplexityDecorator decorator = new AbstractFileComplexityDecorator(Java.INSTANCE) { - }; - - Resource directory = new Directory("fake"); - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 0.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); - - decorator.decorate(directory, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); - } - - @Test - public void doNotCalculateOnFiles() { - - Resource file = new File("fake"); - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 1.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 25.0)); - - new AbstractFileComplexityDecorator(Java.INSTANCE) { - }.decorate(file, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java deleted file mode 100644 index e2777379fa3..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.batch; - -import org.junit.Test; -import static org.mockito.Mockito.*; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.Directory; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Java; -import org.sonar.api.resources.Resource; - -public class AbstractFunctionComplexityDecoratorTest { - - @Test - public void calculateFunctionComplexity() { - - Resource directory = new Directory("fake"); - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 200.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); - - new AbstractFunctionComplexityDecorator(Java.INSTANCE) { - }.decorate(directory, context); - - verify(context).saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, 2.5); - } - - @Test - public void noAverageIfMissingData() { - - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0)); - Resource directory = new Directory("fake"); - - new AbstractFunctionComplexityDecorator(Java.INSTANCE) { - }.decorate(directory, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); - } - - @Test - public void noAverageIfZeroFiles() { - AbstractFunctionComplexityDecorator decorator = new AbstractFunctionComplexityDecorator(Java.INSTANCE) { - }; - - Resource directory = new Directory("fake"); - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 0.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); - - decorator.decorate(directory, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); - } - - @Test - public void doNotCalculateOnFiles() { - - Resource file = new File("fake"); - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 1.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 25.0)); - - new AbstractFunctionComplexityDecorator(Java.INSTANCE) { - }.decorate(file, context); - - verify(context).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); - } -}