Example usage for org.apache.commons.lang SystemUtils IS_OS_WINDOWS

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_WINDOWS

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_WINDOWS.

Prototype

boolean IS_OS_WINDOWS

To view the source code for org.apache.commons.lang SystemUtils IS_OS_WINDOWS.

Click Source Link

Document

Is true if this is Windows.

The field will return false if OS_NAME is null.

Usage

From source file:org.sonar.api.utils.command.CommandExecutorTest.java

private static String getScript(String name) throws IOException {
    String filename;//from  www  .  ja  va 2  s.c  o  m
    if (SystemUtils.IS_OS_WINDOWS) {
        filename = name + ".bat";
    } else {
        filename = name + ".sh";
    }
    return new File("src/test/scripts/" + filename).getCanonicalPath();
}

From source file:org.sonar.api.utils.command.CommandTest.java

@Test
public void should_use_new_shell() {
    if (SystemUtils.IS_OS_WINDOWS) {
        Command command = Command.create("foo.bat");
        command.setNewShell(true);/*w w w .j  a v a2  s. c  o m*/
        assertThat(command.toCommandLine()).isEqualTo("cmd /C call foo.bat");
        assertThat(command.isNewShell()).isTrue();
    } else {
        Command command = Command.create("foo.sh");
        command.setNewShell(true);
        assertThat(command.toCommandLine()).isEqualTo("sh foo.sh");
        assertThat(command.isNewShell()).isTrue();
    }
}

From source file:org.sonar.api.utils.System2.java

/**
 * True if this is MS Windows.
 */
public boolean isOsWindows() {
    return SystemUtils.IS_OS_WINDOWS;
}

From source file:org.sonar.api.utils.System2Test.java

@Test
public void testIsOsWindows() {
    assertThat(System2.INSTANCE.isOsWindows()).isEqualTo(SystemUtils.IS_OS_WINDOWS);
}

From source file:org.sonar.plugins.csharp.CSharpSensor.java

private static boolean shouldExecuteOnProject(FileSystem fs) {
    if (!SystemUtils.IS_OS_WINDOWS) {
        LOG.debug("OS is not Windows. Skip Sensor.");
        return false;
    }//from   w ww .  j a  v  a2  s . com

    if (!filesToAnalyze(fs).iterator().hasNext()) {
        LOG.debug("No files to analyze. Skip Sensor.");
        return false;
    }

    return true;
}

From source file:org.sonar.plugins.csharp.CSharpSensorTest.java

@Before
public void prepare() throws Exception {
    workDir = temp.newFolder().toPath();
    Path srcDir = Paths.get("src/test/resources/CSharpSensorTest");
    Files.walk(srcDir).forEach(path -> {
        if (Files.isDirectory(path)) {
            return;
        }/*www.  j  a  va 2 s  .com*/
        Path relativized = srcDir.relativize(path);
        try {
            Path destFile = workDir.resolve(relativized);
            if (!Files.exists(destFile.getParent())) {
                Files.createDirectories(destFile.getParent());
            }
            Files.copy(path, destFile, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    });
    File csFile = new File("src/test/resources/Program.cs").getAbsoluteFile();

    EncodingInfo msg = EncodingInfo.newBuilder().setEncoding("UTF-8").setFilePath(csFile.getAbsolutePath())
            .build();
    try (OutputStream output = Files.newOutputStream(workDir.resolve("output-cs\\encoding.pb"))) {
        msg.writeDelimitedTo(output);
    } catch (IOException e) {
        throw new IllegalStateException("could not save message to file", e);
    }

    Path roslynReport = workDir.resolve("roslyn-report.json");
    Files.write(roslynReport,
            StringUtils
                    .replace(new String(Files.readAllBytes(roslynReport), StandardCharsets.UTF_8), "Program.cs",
                            StringEscapeUtils.escapeJavaScript(csFile.getAbsolutePath()))
                    .getBytes(StandardCharsets.UTF_8),
            StandardOpenOption.WRITE);

    tester = SensorContextTester.create(new File("src/test/resources"));
    tester.fileSystem().setWorkDir(workDir.toFile());

    inputFile = new DefaultInputFile(tester.module().key(), "Program.cs").setLanguage(CSharpPlugin.LANGUAGE_KEY)
            .initMetadata(new FileMetadata().readMetadata(new FileReader(csFile)));
    tester.fileSystem().add(inputFile);

    fileLinesContext = mock(FileLinesContext.class);
    fileLinesContextFactory = mock(FileLinesContextFactory.class);
    when(fileLinesContextFactory.createFor(inputFile)).thenReturn(fileLinesContext);

    extractor = mock(SonarAnalyzerScannerExtractor.class);
    when(extractor.executableFile(CSharpPlugin.LANGUAGE_KEY))
            .thenReturn(new File(workDir.toFile(), SystemUtils.IS_OS_WINDOWS ? "fake.bat" : "fake.sh"));

    noSonarFilter = mock(NoSonarFilter.class);
    settings = new Settings();

    CSharpConfiguration csConfigConfiguration = new CSharpConfiguration(settings);
    sensor = new CSharpSensor(settings, extractor, fileLinesContextFactory, noSonarFilter,
            csConfigConfiguration,
            new EncodingPerFile(
                    ProjectDefinition.create().setProperty(CoreProperties.ENCODING_PROPERTY, "UTF-8"),
                    new SonarQubeVersion(tester.getSonarQubeVersion())));
}

From source file:org.sonar.plugins.csharp.sarif.SarifParser10Test.java

@Test
public void sarif_version_1_0() throws IOException {
    new SarifParser10(getContents("v1_0.json")).parse(callback);

    if (SystemUtils.IS_OS_WINDOWS) {
        InOrder inOrder = inOrder(callback);
        inOrder.verify(callback).onIssue("S1234", "C:\\Foo.cs", "One issue per line", 1);
        inOrder.verify(callback).onIssue("S1234", "C:\\Bar.cs", "One issue per line", 2);
        inOrder.verifyNoMoreInteractions();
    }/*ww  w.  j a  v a2s.  co  m*/
}

From source file:org.sonar.plugins.csharp.sarif.SarifParser10Test.java

@Test
public void sarif_version_1_0_no_location() throws IOException {
    new SarifParser10(getContents("v1_0_no_location.json")).parse(callback);

    if (SystemUtils.IS_OS_WINDOWS) {
        InOrder inOrder = inOrder(callback);
        inOrder.verify(callback).onProjectIssue("S1234", "One issue per line");
        inOrder.verifyNoMoreInteractions();
    }/*from   www .  ja v a  2  s  .  c o m*/
}

From source file:org.sonar.plugins.csharp.sarif.SarifParser10Test.java

@Test
public void sarif_version_1_0_incomplete_result_file() throws IOException {
    new SarifParser10(getContents("v1_0_incomplete_result_file.json")).parse(callback);

    if (SystemUtils.IS_OS_WINDOWS) {
        InOrder inOrder = inOrder(callback);
        inOrder.verify(callback).onIssue("S1186", "C:\\Program.cs",
                "Add a nested comment explaining why this method is empty, throw a \"NotSupportedException\" or complete the implementation.",
                26);//from  www.  jav  a  2  s. c om
        inOrder.verify(callback).onProjectIssue("S1172", "Remove this unused method parameter \"args\".");
        inOrder.verifyNoMoreInteractions();
    }
}

From source file:org.sonar.plugins.csharp.sarif.SarifParser10Test.java

@Test
public void sarif_version_1_0_empty_location() throws IOException {
    new SarifParser10(getContents("v1_0_empty_location.json")).parse(callback);

    if (SystemUtils.IS_OS_WINDOWS) {
        InOrder inOrder = inOrder(callback);
        inOrder.verify(callback).onProjectIssue("S1234", "One issue per line");
        inOrder.verifyNoMoreInteractions();
    }/*from  w  ww.  j ava 2s .  c o  m*/
}