@Test public void testExecuteWithAnsibleLintErrorOutput() throws IOException { InputFile playbook1 = Utils.getInputFile("playbooks/playbook1.yml"); InputFile playbook2 = Utils.getInputFile("playbooks/playbook2.yml"); InputFile playbook3 = Utils.getInputFile("playbooks/playbook3.yml"); context.fileSystem().add(playbook1).add(playbook2).add(playbook3); if (System.getProperty("os.name").toLowerCase().contains("windows")) { context.settings().appendProperty(AnsibleSettings.ANSIBLE_LINT_PATH_KEY, new File(getClass().getResource("/scripts/ansible-lint2.cmd").getFile()).getAbsolutePath()); } else { String path = new File(getClass().getResource("/scripts/ansible-lint2.sh").getFile()).getAbsolutePath(); context.settings().appendProperty(AnsibleSettings.ANSIBLE_LINT_PATH_KEY, path); setShellRights(path); } sensor.executeWithAnsibleLint(context, null); assertEquals(3, sensor.scannedFiles.size()); assertTrue(sensor.scannedFiles.contains(playbook1)); assertTrue(sensor.scannedFiles.contains(playbook2)); assertTrue(sensor.scannedFiles.contains(playbook3)); assertEquals(0, context.allIssues().size()); assertEquals(3, logTester.logs(LoggerLevel.WARN).size()); logTester.logs(LoggerLevel.WARN).stream().forEach(log -> assertTrue(log.startsWith("Errors happened during analysis:"))); }
protected void executeWithAnsibleLint(SensorContext context, @Nullable List<String> extraAnsibleLintArgs) { LOGGER.debug("Ansible sensor executed with context: " + context); if (context.activeRules().findByRepository(AnsibleCheckRepository.REPOSITORY_KEY).isEmpty()) { LOGGER.info("No active rules found for this plugin, skipping."); return; } for (InputFile inputFile : fileSystem.inputFiles(mainFilesPredicate)) { LOGGER.debug("Analyzing file: " + inputFile.filename()); scannedFiles.add(inputFile); List<String> command = new ArrayList<>(); command.addAll(Arrays.asList(getAnsibleLintPath(context), "-p", "--nocolor")); String confPath = getAnsibleLintConfPath(context); if (!"".equals(confPath.trim())) { command.addAll(Arrays.asList("-c", confPath)); } if (extraAnsibleLintArgs != null) { command.addAll(extraAnsibleLintArgs); } command.add(new File(inputFile.uri()).getAbsolutePath()); List<String> output = new ArrayList<>(); List<String> error = new ArrayList<>(); try { executeCommand(command, output, error); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } catch (IOException e) { return; } if (!error.isEmpty()) { LOGGER.warn("Errors happened during analysis:{}{}", System.getProperty("line.separator"), String.join(System.getProperty("line.separator"), error) ); } LOGGER.debug(output.size() + " issue(s) found"); output.forEach(this::registerIssue); } saveIssues(context); }
AbstractAnsibleSensor implements Sensor { protected void executeWithAnsibleLint(SensorContext context, @Nullable List<String> extraAnsibleLintArgs) { LOGGER.debug("Ansible sensor executed with context: " + context); if (context.activeRules().findByRepository(AnsibleCheckRepository.REPOSITORY_KEY).isEmpty()) { LOGGER.info("No active rules found for this plugin, skipping."); return; } for (InputFile inputFile : fileSystem.inputFiles(mainFilesPredicate)) { LOGGER.debug("Analyzing file: " + inputFile.filename()); scannedFiles.add(inputFile); List<String> command = new ArrayList<>(); command.addAll(Arrays.asList(getAnsibleLintPath(context), "-p", "--nocolor")); String confPath = getAnsibleLintConfPath(context); if (!"".equals(confPath.trim())) { command.addAll(Arrays.asList("-c", confPath)); } if (extraAnsibleLintArgs != null) { command.addAll(extraAnsibleLintArgs); } command.add(new File(inputFile.uri()).getAbsolutePath()); List<String> output = new ArrayList<>(); List<String> error = new ArrayList<>(); try { executeCommand(command, output, error); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } catch (IOException e) { return; } if (!error.isEmpty()) { LOGGER.warn("Errors happened during analysis:{}{}", System.getProperty("line.separator"), String.join(System.getProperty("line.separator"), error) ); } LOGGER.debug(output.size() + " issue(s) found"); output.forEach(this::registerIssue); } saveIssues(context); } }
AbstractAnsibleSensor implements Sensor { protected void executeWithAnsibleLint(SensorContext context, @Nullable List<String> extraAnsibleLintArgs) { LOGGER.debug("Ansible sensor executed with context: " + context); if (context.activeRules().findByRepository(AnsibleCheckRepository.REPOSITORY_KEY).isEmpty()) { LOGGER.info("No active rules found for this plugin, skipping."); return; } for (InputFile inputFile : fileSystem.inputFiles(mainFilesPredicate)) { LOGGER.debug("Analyzing file: " + inputFile.filename()); scannedFiles.add(inputFile); List<String> command = new ArrayList<>(); command.addAll(Arrays.asList(getAnsibleLintPath(context), "-p", "--nocolor")); String confPath = getAnsibleLintConfPath(context); if (!"".equals(confPath.trim())) { command.addAll(Arrays.asList("-c", confPath)); } if (extraAnsibleLintArgs != null) { command.addAll(extraAnsibleLintArgs); } command.add(new File(inputFile.uri()).getAbsolutePath()); List<String> output = new ArrayList<>(); List<String> error = new ArrayList<>(); try { executeCommand(command, output, error); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } catch (IOException e) { return; } if (!error.isEmpty()) { LOGGER.warn("Errors happened during analysis:{}{}", System.getProperty("line.separator"), String.join(System.getProperty("line.separator"), error) ); } LOGGER.debug(output.size() + " issue(s) found"); output.forEach(this::registerIssue); } saveIssues(context); } protected  AbstractAnsibleSensor(FileSystem fileSystem); }
AbstractAnsibleSensor implements Sensor { protected void executeWithAnsibleLint(SensorContext context, @Nullable List<String> extraAnsibleLintArgs) { LOGGER.debug("Ansible sensor executed with context: " + context); if (context.activeRules().findByRepository(AnsibleCheckRepository.REPOSITORY_KEY).isEmpty()) { LOGGER.info("No active rules found for this plugin, skipping."); return; } for (InputFile inputFile : fileSystem.inputFiles(mainFilesPredicate)) { LOGGER.debug("Analyzing file: " + inputFile.filename()); scannedFiles.add(inputFile); List<String> command = new ArrayList<>(); command.addAll(Arrays.asList(getAnsibleLintPath(context), "-p", "--nocolor")); String confPath = getAnsibleLintConfPath(context); if (!"".equals(confPath.trim())) { command.addAll(Arrays.asList("-c", confPath)); } if (extraAnsibleLintArgs != null) { command.addAll(extraAnsibleLintArgs); } command.add(new File(inputFile.uri()).getAbsolutePath()); List<String> output = new ArrayList<>(); List<String> error = new ArrayList<>(); try { executeCommand(command, output, error); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } catch (IOException e) { return; } if (!error.isEmpty()) { LOGGER.warn("Errors happened during analysis:{}{}", System.getProperty("line.separator"), String.join(System.getProperty("line.separator"), error) ); } LOGGER.debug(output.size() + " issue(s) found"); output.forEach(this::registerIssue); } saveIssues(context); } protected  AbstractAnsibleSensor(FileSystem fileSystem);  }
AbstractAnsibleSensor implements Sensor { protected void executeWithAnsibleLint(SensorContext context, @Nullable List<String> extraAnsibleLintArgs) { LOGGER.debug("Ansible sensor executed with context: " + context); if (context.activeRules().findByRepository(AnsibleCheckRepository.REPOSITORY_KEY).isEmpty()) { LOGGER.info("No active rules found for this plugin, skipping."); return; } for (InputFile inputFile : fileSystem.inputFiles(mainFilesPredicate)) { LOGGER.debug("Analyzing file: " + inputFile.filename()); scannedFiles.add(inputFile); List<String> command = new ArrayList<>(); command.addAll(Arrays.asList(getAnsibleLintPath(context), "-p", "--nocolor")); String confPath = getAnsibleLintConfPath(context); if (!"".equals(confPath.trim())) { command.addAll(Arrays.asList("-c", confPath)); } if (extraAnsibleLintArgs != null) { command.addAll(extraAnsibleLintArgs); } command.add(new File(inputFile.uri()).getAbsolutePath()); List<String> output = new ArrayList<>(); List<String> error = new ArrayList<>(); try { executeCommand(command, output, error); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } catch (IOException e) { return; } if (!error.isEmpty()) { LOGGER.warn("Errors happened during analysis:{}{}", System.getProperty("line.separator"), String.join(System.getProperty("line.separator"), error) ); } LOGGER.debug(output.size() + " issue(s) found"); output.forEach(this::registerIssue); } saveIssues(context); } protected  AbstractAnsibleSensor(FileSystem fileSystem);   }