/* * SonarQube * Copyright (C) 2009-2017 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package org.sonar.scanner.mediumtest.issuesmode; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import java.io.File; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableMap; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.api.utils.log.LogTester; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; public class NoPreviousAnalysisTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); @Rule public LogTester logTester = new LogTester(); public ScannerMediumTester tester = ScannerMediumTester.builder() .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) .addDefaultQProfile("xoo", "Sonar Way") .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo") .setPreviousAnalysisDate(null) .build(); @Before public void prepare() { tester.start(); } @After public void stop() { tester.stop(); } @Test public void testIssueTrackingWithIssueOnEmptyFile() throws Exception { File projectDir = copyProject("/mediumtest/xoo/sample"); TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) .start(); assertThat(result.trackedIssues()).hasSize(14); } private File copyProject(String path) throws Exception { File projectDir = temp.newFolder(); File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI()); FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar"))); return projectDir; } }