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;
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);
@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);
}