diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-07-05 18:00:16 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-07-05 18:00:59 +0200 |
commit | 8dc62acc9f20e1400af64f8073fd4cb77d78cc14 (patch) | |
tree | 9135b1433367903975feac25f26485b2b7cdd7d2 /plugins/sonar-core-plugin/src/main | |
parent | 0c4f2bbafbe616e95d73b983c3e7b5be29644720 (diff) | |
download | sonarqube-8dc62acc9f20e1400af64f8073fd4cb77d78cc14.tar.gz sonarqube-8dc62acc9f20e1400af64f8073fd4cb77d78cc14.zip |
SONAR-3543 Fail analysis if a project has no files
=> The Sonar analysis must fail when a project has been analysed
but the measure 'files' is 0.
Diffstat (limited to 'plugins/sonar-core-plugin/src/main')
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FilesDecorator.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FilesDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FilesDecorator.java index 2b6fc1a9a04..7f3b1097cdd 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FilesDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FilesDecorator.java @@ -28,6 +28,8 @@ import org.sonar.api.measures.MeasureUtils; import org.sonar.api.measures.Metric; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; +import org.sonar.api.resources.ResourceUtils; +import org.sonar.api.utils.SonarException; import java.util.Collection; @@ -45,8 +47,10 @@ public final class FilesDecorator implements Decorator { return CoreMetrics.FILES; } + @SuppressWarnings("rawtypes") public void decorate(Resource resource, DecoratorContext context) { if (MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FILES))) { + checkRootProjectHasFiles(resource, context.getMeasure(CoreMetrics.FILES).getValue()); return; } @@ -56,9 +60,17 @@ public final class FilesDecorator implements Decorator { } else { Collection<Measure> childrenMeasures = context.getChildrenMeasures(CoreMetrics.FILES); Double sum = MeasureUtils.sum(false, childrenMeasures); + checkRootProjectHasFiles(resource, sum); if (sum != null) { context.saveMeasure(CoreMetrics.FILES, sum); } } } + + @SuppressWarnings("rawtypes") + private void checkRootProjectHasFiles(Resource resource, Double sum) { + if (ResourceUtils.isRootProject(resource) && (sum == null || sum.doubleValue() == 0)) { + throw new SonarException("Project \"" + resource.getName() + "\" does not contain any file. Please check your project configuration."); + } + } } |