--- /dev/null
+/*
+ * 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) {
+
+ }
+}
--- /dev/null
+/*
+ * 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<Metric> 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);
+ }
+}
--- /dev/null
+/*
+ * 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) {
+
+ }
+}
--- /dev/null
+/*
+ * 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<Metric> 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));
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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<File> files, List<File> sourceDirs, boolean unitTest, Charset sourcesEncoding) {
+ // Do not remove for backward compatibility
+ }
+
+ protected Resource createResource(File file, List<File> 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;
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+}
+++ /dev/null
-/*
- * 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) {
-
- }
-}
+++ /dev/null
-/*
- * 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<Metric> 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);
- }
-}
+++ /dev/null
-/*
- * 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) {
-
- }
-}
+++ /dev/null
-/*
- * 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<Metric> 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));
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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<File> files, List<File> sourceDirs, boolean unitTest, Charset sourcesEncoding) {
- // Do not remove for backward compatibility
- }
-
- protected Resource createResource(File file, List<File> 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;
- }
-}
+++ /dev/null
-/*
- * 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());
- }
-}
+++ /dev/null
-/*
- * 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());
- }
-}