List<String> toStrings(boolean forLogs) { List<String> command = new ArrayList<>(); if (newShell) { if (system.isOsWindows()) { command.add("cmd"); command.add("/C"); command.add("call"); } else { command.add("sh"); } } command.add(executable); command.addAll(forLogs ? argumentsForLogs : arguments); return unmodifiableList(command); }
private static String getScript(String name) throws IOException { String filename; if (System2.INSTANCE.isOsWindows()) { filename = name + ".bat"; } else { filename = name + ".sh"; } return new File("src/test/scripts/" + filename).getCanonicalPath(); }
@Test public void testIsOsWindows() { assertThat(System2.INSTANCE.isOsWindows()).isEqualTo(SystemUtils.IS_OS_WINDOWS); }
@Test public void should_use_cmd_for_new_shell_on_windows() { System2 system = mock(System2.class); when(system.isOsWindows()).thenReturn(true); Command command = new Command("foo.bat", system); command.setNewShell(true); assertThat(command.toCommandLine()).isEqualTo("cmd /C call foo.bat"); assertThat(command.isNewShell()).isTrue(); }
@Test public void should_use_sh_for_new_shell_on_unix() { System2 system = mock(System2.class); when(system.isOsWindows()).thenReturn(false); Command command = new Command("foo.sh", system); command.setNewShell(true); assertThat(command.toCommandLine()).isEqualTo("sh foo.sh"); assertThat(command.isNewShell()).isTrue(); }
@Test public void homeIsSymbolicLink() throws IOException { assumeTrue(!System2.INSTANCE.isOsWindows()); File realSonarHome = temp.newFolder(); File symlink = temp.newFolder(); symlink.delete(); Files.createSymbolicLink(symlink.toPath(), realSonarHome.toPath()); ScannerProperties globalProperties = new ScannerProperties(ImmutableMap.of("sonar.userHome", symlink.getAbsolutePath())); TempFolder tempFolder = tempFolderProvider.provide(globalProperties); File newFile = tempFolder.newFile(); assertThat(newFile.getParentFile().getParentFile().getAbsolutePath()).isEqualTo(symlink.getAbsolutePath()); assertThat(newFile.getParentFile().getName()).startsWith(".sonartmp_"); }
@Test public void scanProjectWithSourceSymlink() { assumeTrue(!System2.INSTANCE.isOsWindows()); File projectDir = new File("test-resources/mediumtest/xoo/sample-with-symlink"); AnalysisResult result = tester .newAnalysis(new File(projectDir, "sonar-project.properties")) .execute(); assertThat(result.inputFiles()).hasSize(3); // check that symlink was not resolved to target assertThat(result.inputFiles()).extractingResultOf("path").toString().startsWith(projectDir.toString()); }
@Test public void scanProjectWithWrongCase() { // To please the quality gate, don't use assumeTrue, or the test will be reported as skipped if (System2.INSTANCE.isOsWindows()) { File projectDir = new File("test-resources/mediumtest/xoo/sample"); AnalysisResult result = tester .newAnalysis(new File(projectDir, "sonar-project.properties")) .property("sonar.sources", "XOURCES") .property("sonar.tests", "TESTX") .execute(); assertThat(result.inputFiles()).hasSize(3); assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly( "xources/hello/HelloJava.xoo", "xources/hello/helloscala.xoo", "testx/ClassOneTest.xoo"); } }
public TsLintExecutorImpl(System2 system, TempFolder tempFolder) { this.mustQuoteSpaceContainingPaths = system.isOsWindows(); this.tempFolder = tempFolder; }
List<String> toStrings(boolean forLogs) { ImmutableList.Builder<String> command = ImmutableList.builder(); if (newShell) { if (system.isOsWindows()) { command.add("cmd", "/C", "call"); } else { command.add("sh"); } } command.add(executable); command.addAll(forLogs ? argumentsForLogs : arguments); return command.build(); }
List<String> toStrings(boolean forLogs) { List<String> command = new ArrayList<>(); if (newShell) { if (system.isOsWindows()) { command.add("cmd"); command.add("/C"); command.add("call"); } else { command.add("sh"); } } command.add(executable); command.addAll(forLogs ? argumentsForLogs : arguments); return unmodifiableList(command); }