From: Simon Brandhof Date: Thu, 20 Feb 2014 16:25:04 +0000 (+0100) Subject: SONAR-926 Fix NPE in sonar-java during first analysis with 4.2 X-Git-Tag: 4.2~78 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=78c84a41ecaff34417d76dc71e52e4703b253b71;p=sonarqube.git SONAR-926 Fix NPE in sonar-java during first analysis with 4.2 --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java index 3305b627a44..21d10c38f01 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java @@ -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 inputFiles) { + public void migrateIfNeeded(Project module, FileSystem fs) { + migrateIfNeeded(module, fs.inputFiles(FilePredicates.all())); + } + + void migrateIfNeeded(Project module, Iterable inputFiles) { if (migrationNeeded) { logger.info("Starting migration of resource keys"); Map deprecatedFileKeyMapper = new HashMap(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java index 8621fb4e9a0..ee96bf4ffac 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java @@ -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 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(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java index a9b1a9bd058..9e2095a1e0a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java @@ -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 { protected Highlightable loadPerspective(Class 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; diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java index 776f9b4a4b7..826785021a4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java @@ -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"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java index 757b0e0cf55..4390c66207c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java @@ -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(); - } }