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.

DistributionTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SonarSource :: IT :: SonarScanner CLI
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT 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 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.
  19. */
  20. package com.sonarsource.scanner.it;
  21. import com.sonar.orchestrator.build.BuildFailureException;
  22. import com.sonar.orchestrator.build.SonarScanner;
  23. import java.io.File;
  24. import java.io.IOException;
  25. import java.util.Map;
  26. import org.junit.Test;
  27. import org.sonarqube.ws.Measures.Measure;
  28. import static java.lang.Integer.parseInt;
  29. import static org.assertj.core.api.Assertions.assertThat;
  30. public class DistributionTest extends ScannerTestCase {
  31. @Test
  32. public void should_succeed_with_self_contained_jre_despite_rubbish_java_home()
  33. throws IOException, InterruptedException {
  34. String projectKey = "basedir-with-source";
  35. File projectDir = new File("projects/basedir-with-source");
  36. SonarScanner build = newScanner(projectDir, "sonar.projectKey", projectKey)
  37. .setEnvironmentVariable("JAVA_HOME", "nonexistent")
  38. .useNative();
  39. orchestrator.executeBuild(build, true);
  40. Map<String, Measure> projectMeasures = getMeasures(projectKey, "files",
  41. "ncloc");
  42. assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
  43. assertThat(parseInt(projectMeasures.get("ncloc").getValue()))
  44. .isGreaterThan(1);
  45. }
  46. @Test(expected = BuildFailureException.class)
  47. public void should_fail_without_self_contained_jre_when_rubbish_java_home()
  48. throws IOException, InterruptedException {
  49. String projectKey = "basedir-with-source";
  50. File projectDir = new File("projects/basedir-with-source");
  51. SonarScanner build = newScanner(projectDir, "sonar.projectKey", projectKey)
  52. .setEnvironmentVariable("JAVA_HOME", "nonexistent");
  53. orchestrator.executeBuild(build, true);
  54. }
  55. }