summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-12 11:45:10 +0200
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-12 11:45:10 +0200
commit18bf4d4d261314af93dc2855517fbdb519b8004a (patch)
treef4e1c15b75df249940c013e1f238998d8f0e4142
parentb7198c1980800a2473bcbc6232b03536f4bc01f8 (diff)
downloadsonarqube-18bf4d4d261314af93dc2855517fbdb519b8004a.tar.gz
sonarqube-18bf4d4d261314af93dc2855517fbdb519b8004a.zip
SONAR-3775 Don't fail the build if there's no file
=> Revert back changes introduced in SONAR-3543
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FilesDecorator.java25
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FilesDecoratorTest.java47
2 files changed, 0 insertions, 72 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 d03878878a7..2b6fc1a9a04 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,10 +28,7 @@ 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.io.File;
import java.util.Collection;
/**
@@ -48,10 +45,8 @@ 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;
}
@@ -61,29 +56,9 @@ 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)) {
- String sourceFoldersList = printSourceFoldersList((Project) resource);
- throw new SonarException("Project \"" + resource.getName() + "\" does not contain any file in its source folders:\n" +
- sourceFoldersList + "\nPlease check your project configuration.");
- }
- }
-
- private String printSourceFoldersList(Project project) {
- StringBuilder result = new StringBuilder();
- for (File sourceDir : project.getFileSystem().getSourceDirs()) {
- result.append(" - ");
- result.append(sourceDir.getAbsolutePath());
- result.append("\n");
- }
- return result.toString();
- }
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FilesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FilesDecoratorTest.java
index ba14e46d292..fd53c197930 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FilesDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FilesDecoratorTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.plugins.core.sensors;
-import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -30,12 +29,9 @@ import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
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 org.sonar.api.utils.SonarException;
-import java.io.File;
import java.util.Arrays;
import static org.fest.assertions.Assertions.assertThat;
@@ -113,47 +109,4 @@ public class FilesDecoratorTest {
verify(context).saveMeasure(eq(CoreMetrics.FILES), eq(5.0));
}
- @Test
- public void shouldFailOnRootProjectIfNoFile() {
- Project project = createMockProject();
- when(context.getChildrenMeasures(CoreMetrics.FILES)).thenReturn(Arrays.asList(new Measure(CoreMetrics.FILES, 0.0)));
-
- thrown.expect(SonarException.class);
- thrown.expectMessage("Project \"Foo\" does not contain any file in its source folders:\n");
- thrown.expectMessage("- " + new File("target/temp").getAbsolutePath() + "\n");
- thrown.expectMessage("\nPlease check your project configuration.");
-
- decorator.decorate(project, context);
- }
-
- @Test
- public void shouldFailOnRootProjectIfNoFileMeasure() {
- Project project = createMockProject();
-
- thrown.expect(SonarException.class);
- thrown.expectMessage("Project \"Foo\" does not contain any file in its source folders");
-
- decorator.decorate(project, context);
- }
-
- private Project createMockProject() {
- Project project = mock(Project.class);
- when(project.getQualifier()).thenReturn(Qualifiers.PROJECT);
- when(project.getName()).thenReturn("Foo");
- ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
- when(fileSystem.getSourceDirs()).thenReturn(Lists.newArrayList(new File("target/temp")));
- when(project.getFileSystem()).thenReturn(fileSystem);
- return project;
- }
-
- @Test
- public void shouldNotFailOnModuleIfNoFile() {
- when(resource.getQualifier()).thenReturn(Qualifiers.MODULE);
- when(context.getChildrenMeasures(CoreMetrics.FILES)).thenReturn(Arrays.asList(new Measure(CoreMetrics.FILES, 0.0)));
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(eq(CoreMetrics.FILES), eq(0.0));
- }
-
}