Search in sources :

Example 1 with FileData

use of org.sonar.scanner.repository.FileData in project sonarqube by SonarSource.

the class SameInputFilePredicate method test.

@Override
public boolean test(InputFile inputFile) {
    FileData fileDataPerPath = projectRepositories.fileData(moduleKey, inputFile.relativePath());
    if (fileDataPerPath == null) {
        // ADDED
        return true;
    }
    String previousHash = fileDataPerPath.hash();
    if (StringUtils.isEmpty(previousHash)) {
        // ADDED
        return true;
    }
    // this will trigger computation of metadata
    String hash = ((DefaultInputFile) inputFile).hash();
    if (StringUtils.equals(hash, previousHash)) {
        // SAME
        LOG.debug("'{}' filtering unmodified file", inputFile.relativePath());
        return false;
    }
    // CHANGED
    return true;
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) FileData(org.sonar.scanner.repository.FileData)

Example 2 with FileData

use of org.sonar.scanner.repository.FileData in project sonarqube by SonarSource.

the class StatusDetection method status.

InputFile.Status status(String projectKey, String relativePath, String hash) {
    FileData fileDataPerPath = projectSettings.fileData(projectKey, relativePath);
    if (fileDataPerPath == null) {
        return InputFile.Status.ADDED;
    }
    String previousHash = fileDataPerPath.hash();
    if (StringUtils.equals(hash, previousHash)) {
        return InputFile.Status.SAME;
    }
    if (StringUtils.isEmpty(previousHash)) {
        return InputFile.Status.ADDED;
    }
    return InputFile.Status.CHANGED;
}
Also used : FileData(org.sonar.scanner.repository.FileData)

Example 3 with FileData

use of org.sonar.scanner.repository.FileData in project sonarqube by SonarSource.

the class ScanOnlyChangedTest method prepare.

@Before
public void prepare() throws IOException {
    String filePath = "xources/hello/HelloJava.xoo";
    String md5sum = DigestUtils.md5Hex(FileUtils.readFileToString(new File(Resources.getResource("mediumtest/xoo/sample/" + filePath).getPath())));
    tester = ScannerMediumTester.builder().bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)).registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo").addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo").addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo").addFileData("sample", filePath, new FileData(md5sum, null)).setPreviousAnalysisDate(new Date()).mockServerIssue(ServerIssue.newBuilder().setKey("xyz").setModuleKey("sample").setMsg("One issue per Line copied").setPath("xources/hello/HelloJava.xoo").setRuleRepository("xoo").setRuleKey("OneIssuePerLine").setLine(1).setSeverity(Severity.MAJOR).setCreationDate(date("14/03/2004")).setChecksum(DigestUtils.md5Hex("packagehello;")).setStatus("OPEN").build()).mockServerIssue(ServerIssue.newBuilder().setKey("resolved-on-project").setModuleKey("sample").setRuleRepository("xoo").setRuleKey("OneIssuePerModule").setSeverity(Severity.CRITICAL).setCreationDate(date("14/03/2004")).setStatus("OPEN").build()).build();
    tester.start();
}
Also used : XooPlugin(org.sonar.xoo.XooPlugin) XooRulesDefinition(org.sonar.xoo.rule.XooRulesDefinition) File(java.io.File) FileData(org.sonar.scanner.repository.FileData) Date(java.util.Date) Before(org.junit.Before)

Example 4 with FileData

use of org.sonar.scanner.repository.FileData in project sonarqube by SonarSource.

the class ProjectRepositoriesProviderTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    Table<String, String, String> t1 = HashBasedTable.create();
    Table<String, String, FileData> t2 = HashBasedTable.create();
    project = new ProjectRepositories(t1, t2, new Date());
    provider = new ProjectRepositoriesProvider();
    when(projectKey.get()).thenReturn("key");
}
Also used : ProjectRepositoriesProvider(org.sonar.scanner.repository.ProjectRepositoriesProvider) FileData(org.sonar.scanner.repository.FileData) ProjectRepositories(org.sonar.scanner.repository.ProjectRepositories) Date(java.util.Date) Before(org.junit.Before)

Example 5 with FileData

use of org.sonar.scanner.repository.FileData in project sonarqube by SonarSource.

the class StatusDetectionTest method createTable.

private static Table<String, String, FileData> createTable() {
    Table<String, String, FileData> t = HashBasedTable.create();
    t.put("foo", "src/Foo.java", new FileData("ABCDE", "12345789"));
    t.put("foo", "src/Bar.java", new FileData("FGHIJ", "123456789"));
    return t;
}
Also used : FileData(org.sonar.scanner.repository.FileData)

Aggregations

FileData (org.sonar.scanner.repository.FileData)5 Date (java.util.Date)2 Before (org.junit.Before)2 File (java.io.File)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 ProjectRepositories (org.sonar.scanner.repository.ProjectRepositories)1 ProjectRepositoriesProvider (org.sonar.scanner.repository.ProjectRepositoriesProvider)1 XooPlugin (org.sonar.xoo.XooPlugin)1 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)1