Search in sources :

Example 11 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class DeprecatedResourceApiSensor method analyse.

@Override
public void analyse(Project module, org.sonar.api.batch.SensorContext context) {
    for (File f : fs.files(fs.predicates().and(fs.predicates().hasType(Type.MAIN), fs.predicates().hasLanguage(Xoo.KEY)))) {
        String relativePathFromBaseDir = new PathResolver().relativePath(fs.baseDir(), f);
        org.sonar.api.resources.File sonarFile = org.sonar.api.resources.File.create(relativePathFromBaseDir);
        Issuable issuable = perspectives.as(Issuable.class, sonarFile);
        issuable.addIssue(issuable.newIssueBuilder().ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)).message("Issue created using deprecated API").line(1).build());
        // Message and line are nullable
        issuable.addIssue(issuable.newIssueBuilder().ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)).message(null).line(null).build());
        sonarFile = context.getResource(sonarFile);
        Directory parent = sonarFile.getParent();
        createIssueOnDir(parent);
    }
}
Also used : Issuable(org.sonar.api.issue.Issuable) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) Directory(org.sonar.api.resources.Directory)

Example 12 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class AbsolutePathPredicate method get.

@Override
public Iterable<InputFile> get(Index index) {
    String relative = PathUtils.sanitize(new PathResolver().relativePath(baseDir.toFile(), new File(path)));
    if (relative == null) {
        return Collections.emptyList();
    }
    InputFile f = index.inputFile(relative);
    return f != null ? Arrays.asList(f) : Collections.<InputFile>emptyList();
}
Also used : PathResolver(org.sonar.api.scan.filesystem.PathResolver) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile)

Example 13 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class FileIndexer method indexParentDir.

private void indexParentDir(DefaultModuleFileSystem fileSystem, InputFile inputFile) {
    Path parentDir = inputFile.path().getParent();
    String relativePath = new PathResolver().relativePath(fileSystem.baseDirPath(), parentDir);
    if (relativePath == null) {
        throw new IllegalStateException("Failed to compute relative path of file: " + inputFile);
    }
    DefaultInputDir inputDir = (DefaultInputDir) componentStore.getDir(module.key(), relativePath);
    if (inputDir == null) {
        inputDir = new DefaultInputDir(fileSystem.moduleKey(), relativePath, batchIdGenerator.get());
        inputDir.setModuleBaseDir(fileSystem.baseDirPath());
        fileSystem.add(inputDir);
        componentTree.index(inputDir, module);
    }
    componentTree.index(inputFile, inputDir);
}
Also used : Path(java.nio.file.Path) PathResolver(org.sonar.api.scan.filesystem.PathResolver) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir)

Example 14 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class DefaultPostJobContextTest method prepare.

@Before
public void prepare() {
    issueCache = mock(IssueCache.class);
    componentStore = new InputComponentStore(new PathResolver());
    settings = new MapSettings();
    analysisMode = mock(AnalysisMode.class);
    context = new DefaultPostJobContext(settings, issueCache, componentStore, analysisMode);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) PathResolver(org.sonar.api.scan.filesystem.PathResolver) AnalysisMode(org.sonar.api.batch.AnalysisMode) IssueCache(org.sonar.scanner.issue.IssueCache) Before(org.junit.Before)

Example 15 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class InputFileBuilderTest method setUp.

@Before
public void setUp() throws IOException {
    baseDir = temp.newFolder().toPath();
    DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create().setKey("module1").setBaseDir(baseDir.toFile()), 0);
    PathResolver pathResolver = new PathResolver();
    LanguageDetection langDetection = mock(LanguageDetection.class);
    MetadataGenerator metadataGenerator = mock(MetadataGenerator.class);
    BatchIdGenerator idGenerator = new BatchIdGenerator();
    Settings settings = new MapSettings();
    builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) PathResolver(org.sonar.api.scan.filesystem.PathResolver) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Before(org.junit.Before)

Aggregations

PathResolver (org.sonar.api.scan.filesystem.PathResolver)19 File (java.io.File)12 Test (org.junit.Test)7 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)7 Before (org.junit.Before)6 InputFile (org.sonar.api.batch.fs.InputFile)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)5 MapSettings (org.sonar.api.config.internal.MapSettings)4 Path (java.nio.file.Path)3 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)3 Matchers.anyString (org.mockito.Matchers.anyString)2 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 MapSettings (org.sonar.api.config.MapSettings)2 AnalysisWarnings (org.sonar.api.notifications.AnalysisWarnings)2 MeasureCache (org.sonar.scanner.scan.measure.MeasureCache)2 ArrayList (java.util.ArrayList)1 CheckForNull (javax.annotation.CheckForNull)1 AnalysisMode (org.sonar.api.batch.AnalysisMode)1