package pl.touk.sputnik.processor.sonar;

import java.util.List;

import org.sonar.runner.api.EmbeddedRunner;

import pl.touk.sputnik.review.Review;
import pl.touk.sputnik.review.ReviewFile;

import com.google.common.collect.Lists;

class SonarRunnerBuilder {
    public SonarRunner prepareRunner(Review review) {
        List<String> files = Lists.newArrayList();
        for (ReviewFile file : review.getFiles()) {
            files.add(file.getReviewFilename());
        }
        SonarRunner sonarRunner = new SonarRunner(files, EmbeddedRunner.create());
        return sonarRunner;
    }
}

package pl.touk.sputnik.processor.sonar;

import java.io.File;
import java.util.List;

import org.sonar.runner.api.EmbeddedRunner;

import pl.touk.sputnik.review.Review;
import pl.touk.sputnik.review.ReviewFile;

import com.google.common.collect.Lists;

class SonarRunnerBuilder {
    public SonarRunner prepareRunner(Review review) {
        List<String> files = Lists.newArrayList();

        /*
         * Some sonar plugin do no include git path as the source file path (for
         * example, sonar-visual-studio plugin generates filenames that are relative
         * to the module csproj file).
         *
         * Using the file basename and a recursive match allows Sonar to match
         * modified files with their indexed names in Sonar.
         *
         * Although this can generate useless analysis (as some files that are not
         * included in a review may be analysed), this has a limited additional
         * cost considering that few files have the same basename inside a
         * repository.
         */
        for (ReviewFile file : review.getFiles()) {
            files.add("**/" + new File(file.getReviewFilename()).getName());
        }
        SonarRunner sonarRunner = new SonarRunner(files, EmbeddedRunner.create());
        return sonarRunner;
    }
}

Use file basename instead of fullname in sonar
Use file basename instead of fullname in sonar

Some sonar plugin do no include git path as the source file path (for
example, sonar-visual-studio plugin generates filenames that are
relative to the module csproj file).

Using the file basename and a recursive match allows Sonar to match
modified files with their indexed names in Sonar.

Although this can generate useless analysis (as some files that are not
included in a review may be analysed), this has a limited additional
cost considering that few files have the same basename inside a
repository.

Change-Id: Ib74289e201098d15c618791f47b2dd657c3a1744
