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 org.apache.commons.io.FileUtils;
23 import org.apache.commons.io.filefilter.FileFilterUtils;
27 import static org.assertj.core.api.Assertions.assertThat;
29 import com.google.common.collect.ImmutableMap;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.TemporaryFolder;
35 import org.sonar.api.CoreProperties;
36 import org.sonar.api.utils.log.LogTester;
37 import org.sonar.scanner.mediumtest.ScannerMediumTester;
38 import org.sonar.scanner.mediumtest.TaskResult;
39 import org.sonar.xoo.XooPlugin;
40 import org.sonar.xoo.rule.XooRulesDefinition;
42 public class NoPreviousAnalysisTest {
44 public TemporaryFolder temp = new TemporaryFolder();
47 public LogTester logTester = new LogTester();
49 public ScannerMediumTester tester = ScannerMediumTester.builder()
50 .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
51 .registerPlugin("xoo", new XooPlugin())
52 .addRules(new XooRulesDefinition())
53 .addDefaultQProfile("xoo", "Sonar Way")
54 .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
55 .setPreviousAnalysisDate(null)
59 public void prepare() {
69 public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
70 File projectDir = copyProject("/mediumtest/xoo/sample");
72 TaskResult result = tester
73 .newScanTask(new File(projectDir, "sonar-project.properties"))
76 assertThat(result.trackedIssues()).hasSize(14);
80 private File copyProject(String path) throws Exception {
81 File projectDir = temp.newFolder();
82 File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI());
83 FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar")));