]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 Fix NPE in sonar-java during first analysis with 4.2
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 20 Feb 2014 16:25:04 +0000 (17:25 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 20 Feb 2014 16:25:04 +0000 (17:25 +0100)
sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java
sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java
sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java

index 3305b627a44a88426c6ac84a3ec9e743c56e492c..21d10c38f015090351c7ba4d0bce5fd18a99dc55 100644 (file)
@@ -24,6 +24,8 @@ import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.fs.FilePredicates;
+import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.database.DatabaseSession;
@@ -60,7 +62,11 @@ public class ResourceKeyMigration implements BatchComponent {
     }
   }
 
-  public void migrateIfNeeded(Project module, Iterable<InputFile> inputFiles) {
+  public void migrateIfNeeded(Project module, FileSystem fs) {
+    migrateIfNeeded(module, fs.inputFiles(FilePredicates.all()));
+  }
+
+  void migrateIfNeeded(Project module, Iterable<InputFile> inputFiles) {
     if (migrationNeeded) {
       logger.info("Starting migration of resource keys");
       Map<String, InputFile> deprecatedFileKeyMapper = new HashMap<String, InputFile>();
index 8621fb4e9a0556a2239f60cc169e805d441aadac..ee96bf4ffacec544939ee48f64f2ea2bb09808aa 100644 (file)
@@ -61,10 +61,10 @@ public class ComponentIndexer implements BatchComponent {
   }
 
   public void execute(FileSystem fs) {
+    migration.migrateIfNeeded(module, fs);
+
     boolean shouldImportSource = settings.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY);
-    Iterable<InputFile> inputFiles = fs.inputFiles(FilePredicates.all());
-    migration.migrateIfNeeded(module, inputFiles);
-    for (InputFile inputFile : inputFiles) {
+    for (InputFile inputFile : fs.inputFiles(FilePredicates.all())) {
       String languageKey = inputFile.language();
       boolean unitTest = InputFile.Type.TEST == inputFile.type();
       String pathFromSourceDir = ((DefaultInputFile) inputFile).pathRelativeToSourceDir();
index a9b1a9bd0586a3a37aad964479add4e36c39d89e..9e2095a1e0ac31f250c27e30a77650eb858e1654 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.batch.source;
 import com.google.common.collect.ImmutableSet;
 import org.sonar.api.component.Component;
 import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
 import org.sonar.api.source.Highlightable;
 import org.sonar.batch.index.ComponentDataCache;
 import org.sonar.core.component.PerspectiveBuilder;
@@ -49,11 +48,6 @@ public class HighlightableBuilder extends PerspectiveBuilder<Highlightable> {
   protected Highlightable loadPerspective(Class<Highlightable> perspectiveClass, Component component) {
     boolean supported = SUPPORTED_QUALIFIERS.contains(component.qualifier());
     if (supported && component instanceof ResourceComponent) {
-      // temporary hack waiting for the removal of JavaClass.
-      // JavaClass has the same qualifier than JavaFile, so they have to distinguished by their scope
-      supported = Scopes.FILE.equals(((ResourceComponent) component).scope());
-    }
-    if (supported) {
       return new DefaultHighlightable(component, cache);
     }
     return null;
index 776f9b4a4b75300478020e12d1e82c9995fe27ff..826785021a446c610876b6da2aea8e2b39f0ad2e 100644 (file)
@@ -32,8 +32,6 @@ import org.sonar.api.resources.Project;
 import org.sonar.jpa.test.AbstractDbUnitTestCase;
 
 import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 
@@ -44,6 +42,7 @@ public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase {
 
   @Rule
   public ExpectedException thrown = ExpectedException.none();
+
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
@@ -53,7 +52,7 @@ public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase {
   File baseDir;
 
   @Before
-  public void before() throws ParseException, IOException {
+  public void before() throws Exception {
     SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
 
     multiModuleProject = newProject("root", "java");
index 757b0e0cf5533d602f20fd98daea348a2b9be692..4390c66207cf6bdcefdccb3d033e2203c3b4f852 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.resources.Resource;
 import org.sonar.api.source.Highlightable;
 import org.sonar.batch.index.ComponentDataCache;
 import org.sonar.core.component.ResourceComponent;
-import org.sonar.java.api.JavaClass;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -57,14 +56,4 @@ public class HighlightableBuilderTest {
 
     assertThat(perspective).isNull();
   }
-
-  @Test
-  public void java_class_should_not_be_highlightable() {
-    Component component = new ResourceComponent(JavaClass.create("org.struts.Action").setEffectiveKey("struts:org.struts.Action"));
-
-    HighlightableBuilder builder = new HighlightableBuilder(cache);
-    Highlightable perspective = builder.loadPerspective(Highlightable.class, component);
-
-    assertThat(perspective).isNull();
-  }
 }