3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.scanner.mediumtest.issuesmode;
22 import com.google.common.collect.ImmutableMap;
24 import org.apache.commons.io.FileUtils;
25 import org.apache.commons.io.filefilter.FileFilterUtils;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.TemporaryFolder;
31 import org.sonar.api.CoreProperties;
32 import org.sonar.api.utils.log.LogTester;
33 import org.sonar.scanner.mediumtest.ScannerMediumTester;
34 import org.sonar.scanner.mediumtest.TaskResult;
35 import org.sonar.xoo.XooPlugin;
36 import org.sonar.xoo.rule.XooRulesDefinition;
38 import static org.assertj.core.api.Assertions.assertThat;
40 public class NoPreviousAnalysisTest {
42 public TemporaryFolder temp = new TemporaryFolder();
45 public LogTester logTester = new LogTester();
47 public ScannerMediumTester tester = ScannerMediumTester.builder()
48 .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
49 .registerPlugin("xoo", new XooPlugin())
50 .addRules(new XooRulesDefinition())
51 .addDefaultQProfile("xoo", "Sonar Way")
52 .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
53 .setPreviousAnalysisDate(null)
57 public void prepare() {
67 public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
68 File projectDir = copyProject("/mediumtest/xoo/sample");
70 TaskResult result = tester
71 .newScanTask(new File(projectDir, "sonar-project.properties"))
74 assertThat(result.trackedIssues()).hasSize(14);
78 private File copyProject(String path) throws Exception {
79 File projectDir = temp.newFolder();
80 File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI());
81 FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar")));