}
CpdMapping mapping = getMapping(languageKey);
+ if (mapping == null) {
+ return;
+ }
// Create index
SonarDuplicationsIndex index = indexFactory.create(project);
import org.sonar.api.BatchComponent;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
import org.sonar.api.utils.PathUtils;
}
resourceModel.setKey(newEffectiveKey);
resourceModel.setDeprecatedKey(oldEffectiveKey);
- logger.info("Migrated resource " + oldEffectiveKey + " to " + newEffectiveKey);
+ logger.info("Migrated resource {} to {}", oldEffectiveKey, newEffectiveKey);
} else {
- logger.warn("Unable to migrate resource " + oldEffectiveKey + ". No match was found.");
+ logger.warn("Unable to migrate resource {}. No match was found.", oldEffectiveKey);
}
}
}
String newEffectiveKey = deprecatedDirectoryKeyMapper.get(oldEffectiveKey);
resourceModel.setKey(newEffectiveKey);
resourceModel.setDeprecatedKey(oldEffectiveKey);
- logger.info("Migrated resource " + oldEffectiveKey + " to " + newEffectiveKey);
+ logger.info("Migrated resource {} to {}", oldEffectiveKey, newEffectiveKey);
} else {
- logger.warn("Unable to migrate resource " + oldEffectiveKey);
+ logger.warn("Unable to migrate resource {}. No match was found.", oldEffectiveKey);
}
}
}
import org.sonar.api.utils.SonarException;
import org.sonar.batch.index.ResourceKeyMigration;
import org.sonar.batch.scan.language.DefaultModuleLanguages;
-import org.sonar.core.resource.ResourceDao;
/**
* Index all files/directories of the module in SQ database and importing source code.
private final ResourceKeyMigration migration;
private final Project module;
private final DefaultModuleLanguages moduleLanguages;
- private final ResourceDao resourceDao;
private InputFileCache fileCache;
public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, Settings settings, ResourceKeyMigration migration,
- DefaultModuleLanguages moduleLanguages, ResourceDao resourceDao, InputFileCache fileCache) {
+ DefaultModuleLanguages moduleLanguages, InputFileCache fileCache) {
this.module = module;
this.languages = languages;
this.sonarIndex = sonarIndex;
this.settings = settings;
this.migration = migration;
this.moduleLanguages = moduleLanguages;
- this.resourceDao = resourceDao;
this.fileCache = fileCache;
}
*/
public class FileIndex implements BatchComponent {
+ private static final String FILE_S_IS_NOT_DECLARED_IN_MODULE_BASEDIR_S = "File '%s' is not declared in module basedir %s";
+
private static class Progress {
private final Set<String> removedPaths;
private final Set<String> indexed;
String path = pathResolver.relativePath(fileSystem.baseDir(), sourceFile);
if (path == null) {
LoggerFactory.getLogger(getClass()).warn(String.format(
- "File '%s' is not declared in module basedir %s", sourceFile.getAbsoluteFile(), fileSystem.baseDir()
+ FILE_S_IS_NOT_DECLARED_IN_MODULE_BASEDIR_S, sourceFile.getAbsoluteFile(), fileSystem.baseDir()
));
} else {
if (exclusionFilters.accept(sourceFile, path, type)) {
String path = pathResolver.relativePath(fileSystem.baseDir(), sourceFile);
if (path == null) {
LoggerFactory.getLogger(getClass()).warn(String.format(
- "File '%s' is not declared in module basedir %s", sourceFile.getAbsoluteFile(), fileSystem.baseDir()
+ FILE_S_IS_NOT_DECLARED_IN_MODULE_BASEDIR_S, sourceFile.getAbsoluteFile(), fileSystem.baseDir()
));
} else {
if (exclusionFilters.accept(sourceFile, path, InputFile.TYPE_MAIN)) {
if (file == null || !file.exists()) {
return null;
}
- PathResolver.RelativePath relativePath = pathResolver.relativePath(getSourceDirs(), file);
+ String relativePath = pathResolver.relativePath(getBasedir(), file);
if (relativePath == null) {
return null;
}
- return file.isFile() ? new org.sonar.api.resources.File(relativePath.path()) : new org.sonar.api.resources.Directory(relativePath.path());
+ return file.isFile() ? org.sonar.api.resources.File.create(relativePath) : org.sonar.api.resources.Directory.create(relativePath);
}
public List<InputFile> mainFiles(String... langs) {
import org.sonar.api.scan.filesystem.internal.InputFileBuilder;
import org.sonar.batch.index.ResourceKeyMigration;
import org.sonar.batch.scan.language.DefaultModuleLanguages;
-import org.sonar.core.resource.ResourceDao;
import java.io.File;
import java.io.IOException;
newInputFile("src/test/java/foo/bar/FooTest.java", "", "foo/bar/FooTest.java", "java", true)));
Languages languages = new Languages(Java.INSTANCE);
ComponentIndexer indexer = new ComponentIndexer(project, languages, sonarIndex, settings, mock(ResourceKeyMigration.class), new DefaultModuleLanguages(settings, languages),
- mock(ResourceDao.class), mock(InputFileCache.class));
+ mock(InputFileCache.class));
indexer.execute(fs);
verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false));
Languages languages = new Languages(cobolLanguage);
ComponentIndexer indexer = new ComponentIndexer(project, languages, sonarIndex, settings, mock(ResourceKeyMigration.class), new DefaultModuleLanguages(settings, languages),
- mock(ResourceDao.class), mock(InputFileCache.class));
+ mock(InputFileCache.class));
indexer.execute(fs);
verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false));
newInputFile("src/main/java/foo/bar/Foo.java", "sample code", "foo/bar/Foo.java", "java", false)));
Languages languages = new Languages(Java.INSTANCE);
ComponentIndexer indexer = new ComponentIndexer(project, languages, sonarIndex, settings, mock(ResourceKeyMigration.class), new DefaultModuleLanguages(settings, languages),
- mock(ResourceDao.class), mock(InputFileCache.class));
+ mock(InputFileCache.class));
indexer.execute(fs);
Resource sonarFile = org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
.build()));
Languages languages = new Languages(Java.INSTANCE);
ComponentIndexer indexer = new ComponentIndexer(project, languages, sonarIndex, settings, mock(ResourceKeyMigration.class), new DefaultModuleLanguages(settings, languages),
- mock(ResourceDao.class), mock(InputFileCache.class));
+ mock(InputFileCache.class));
indexer.execute(fs);
Resource sonarFile = org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
.build()));
Languages languages = new Languages(Java.INSTANCE);
ComponentIndexer indexer = new ComponentIndexer(project, languages, sonarIndex, settings, mock(ResourceKeyMigration.class), new DefaultModuleLanguages(settings, languages),
- mock(ResourceDao.class), mock(InputFileCache.class));
+ mock(InputFileCache.class));
indexer.execute(fs);
Resource sonarFile = org.sonar.api.resources.File.create("/src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
when(fs.inputFiles(FileQuery.all())).thenReturn((Iterable) Arrays.asList(inputFile3lines, inputFileEmpty, inputFileEndsWithNewLine, inputFileMixedLineEnds));
Languages languages = new Languages(Java.INSTANCE);
ComponentIndexer indexer = new ComponentIndexer(project, languages, sonarIndex, settings, mock(ResourceKeyMigration.class), new DefaultModuleLanguages(settings, languages),
- mock(ResourceDao.class), mock(InputFileCache.class));
+ mock(InputFileCache.class));
indexer.execute(fs);
assertThat(inputFile3lines.attribute(InputFile.ATTRIBUTE_LINE_COUNT)).isEqualTo("3");
* {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)} when resources are already indexed.
* Internal use only.
*/
- static Directory create(String relativePathFromBaseDir) {
+ public static Directory create(String relativePathFromBaseDir) {
Directory d = new Directory();
String normalizedPath = normalize(relativePathFromBaseDir);
d.setKey(normalizedPath);
public static final Language NONE_LANGUAGE = new AbstractLanguage("none", "None") {
@Override
public String[] getFileSuffixes() {
- return null;
+ return new String[0];
}
};