]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3775 Don't fail the build if there's no file
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 12 Sep 2012 09:45:10 +0000 (11:45 +0200)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 12 Sep 2012 09:45:10 +0000 (11:45 +0200)
=> Revert back changes introduced in SONAR-3543

plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FilesDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FilesDecoratorTest.java

index d03878878a7a1a65b661f488f09b4771c32a83b9..2b6fc1a9a047ed8565f58850ae00e283556c5ca0 100644 (file)
@@ -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();
-  }
 }
index ba14e46d2922ed2f709cf6417530a4dd0174422b..fd53c19793059b7f13cb71230b937db1b8350d5c 100644 (file)
@@ -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));
-  }
-
 }