]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 Fix deprecated key of indexed resources
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 12 Feb 2014 11:15:39 +0000 (12:15 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 12 Feb 2014 11:15:39 +0000 (12:15 +0100)
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java

index bf8696b057eb0d3fceb1ea1056b5cc8a6d9bcd89..d6911d66f331ac4334074b5ebd743f014faa23a8 100644 (file)
@@ -27,6 +27,8 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.SonarIndex;
 import org.sonar.api.config.Settings;
 import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.JavaFile;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
@@ -77,9 +79,10 @@ public class ComponentIndexer implements BatchComponent {
         pathFromSourceDir = inputFile.path();
       }
       Resource sonarFile = File.create(inputFile.path(), pathFromSourceDir, languages.get(languageKey), unitTest);
-      String deprecatedKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY);
-      if (deprecatedKey != null) {
-        sonarFile.setDeprecatedKey(deprecatedKey);
+      if (Java.KEY.equals(languageKey)) {
+        sonarFile.setDeprecatedKey(JavaFile.fromRelativePath(pathFromSourceDir, false).getDeprecatedKey());
+      } else {
+        sonarFile.setDeprecatedKey(pathFromSourceDir);
       }
       if (sonarFile != null) {
         moduleLanguages.addLanguage(languageKey);
index 5ca14958749b8e9628bc63c3af0863d9f398abf5..c45ac2b2a8e45e348280613bcfb7ccc69e98738f 100644 (file)
@@ -106,7 +106,7 @@ public class ComponentIndexerTest {
       @Override
       public boolean matches(Object arg0) {
         org.sonar.api.resources.File javaFile = (org.sonar.api.resources.File) arg0;
-        return javaFile.getKey().equals("src/test/java/foo/bar/FooTest.java")
+        return javaFile.getKey().equals("src/test/java/foo/bar/FooTest.java") && javaFile.getDeprecatedKey().equals("foo.bar.FooTest")
           && javaFile.getPath().equals("src/test/java/foo/bar/FooTest.java")
           && javaFile.getQualifier().equals(Qualifiers.UNIT_TEST_FILE);
       }