You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScannerTestCase.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * SonarSource :: IT :: SonarQube Scanner
  3. * Copyright (C) 2009 SonarSource
  4. * sonarqube@googlegroups.com
  5. *
  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.
  10. *
  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.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package com.sonar.runner.it;
  21. import com.sonar.orchestrator.Orchestrator;
  22. import com.sonar.orchestrator.build.SonarScanner;
  23. import com.sonar.orchestrator.version.Version;
  24. import java.io.File;
  25. import java.io.FileInputStream;
  26. import java.io.IOException;
  27. import java.util.Properties;
  28. import org.junit.ClassRule;
  29. import org.junit.Rule;
  30. import org.junit.rules.ExpectedException;
  31. public abstract class ScannerTestCase {
  32. @Rule
  33. public ExpectedException thrown = ExpectedException.none();
  34. @ClassRule
  35. public static Orchestrator orchestrator = SonarScannerTestSuite.ORCHESTRATOR;
  36. private static Version artifactVersion;
  37. private static Version artifactVersion() {
  38. if (artifactVersion == null) {
  39. try (FileInputStream fis = new FileInputStream(new File("../target/maven-archiver/pom.properties"))) {
  40. Properties props = new Properties();
  41. props.load(fis);
  42. artifactVersion = Version.create(props.getProperty("version"));
  43. return artifactVersion;
  44. } catch (IOException e) {
  45. throw new IllegalStateException(e);
  46. }
  47. }
  48. return artifactVersion;
  49. }
  50. SonarScanner newScanner(File baseDir, String... keyValueProperties) {
  51. SonarScanner scannerCli = SonarScanner.create(baseDir, keyValueProperties);
  52. scannerCli.setRunnerVersion(artifactVersion().toString());
  53. return scannerCli;
  54. }
  55. }