List of usage examples for org.apache.commons.configuration Configuration getStringArray
String[] getStringArray(String key);
From source file:org.sonar.plugins.php.pmd.PhpmdExecutorTest.java
@Test public void testGetIgnoreDirsNotNullWithSonarExclusionNotNull() { Project project = getMockProject();//from ww w. jav a 2 s . c om Configuration configuration = project.getConfiguration(); String[] extensions = new String[] { "php", "php3", "php4" }; when(configuration.getStringArray(FILE_SUFFIXES_KEY)).thenReturn(extensions); when(configuration.getString(PHPMD_REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY, PHPMD_DEFAULT_REPORT_FILE_PATH)) .thenReturn("/"); when(configuration.getString(PHPMD_REPORT_FILE_NAME_PROPERTY_KEY, PHPMD_DEFAULT_REPORT_FILE_NAME)) .thenReturn("pmd.xml"); PhpmdConfiguration c = getWindowsConfiguration(project); PhpmdProfileExporter e = mock(PhpmdProfileExporter.class); when(c.isStringPropertySet(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(true); String[] phpmdExclusionPattern = { "*Math5.php" }; when(configuration.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(phpmdExclusionPattern); when(c.isStringPropertySet(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(true); String[] sonarExclusionPattern = { "sites/all/", "files", "*Math4.php" }; when(configuration.getStringArray(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(sonarExclusionPattern); PhpmdExecutor executor = new PhpmdExecutor(c, e, null); List<String> commandLine = executor.getCommandLine(); String s1 = "phpmd.bat"; String s2 = new File("C:/projets/PHP/Monkey/sources/main").toString(); String s3 = "xml"; String s4 = "codesize,unusedcode,naming"; String s5 = "--reportfile"; String s6 = getFile("C:/projets/PHP/Monkey/target/pmd.xml"); String s7 = "--ignore"; String s8 = StringUtils.join(phpmdExclusionPattern, ","); s8 += "," + StringUtils.join(sonarExclusionPattern, ","); String s9 = "--extensions"; String s10 = "php,php3,php4"; List<String> expected = Arrays.asList(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10); assertThat(commandLine).isEqualTo(expected); assertThat(commandLine).isEqualTo(expected); }
From source file:org.sonar.plugins.php.pmd.PhpPmdConfigurationTest.java
@Test public void testGetRulesetsWithNotNull() { Project project = getMockProject();//ww w . j av a 2 s . c o m PhpmdConfiguration config = new PhpmdConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] { "a", "b" }; when(c.getStringArray(PHPMD_RULESETS_ARGUMENT_KEY)).thenReturn(excludeDirs); assertEquals("a,b", config.getRulesets()); }
From source file:org.sonar.plugins.php.pmd.PhpPmdConfigurationTest.java
@Test public void testGetRulesetsWithEmpty() { Project project = getMockProject();//from w ww . j ava2 s . com PhpmdConfiguration config = new PhpmdConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] {}; when(c.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(excludeDirs); assertEquals(PHPMD_DEFAULT_RULESET_ARGUMENT, config.getRulesets()); }
From source file:org.sonar.plugins.php.pmd.PhpPmdConfigurationTest.java
@Test public void testGetRulesetsWithNull() { Project project = getMockProject();// w w w . j a v a2 s .c o m PhpmdConfiguration config = new PhpmdConfiguration(project); Configuration c = project.getConfiguration(); when(c.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(null); assertEquals(PHPMD_DEFAULT_RULESET_ARGUMENT, config.getRulesets()); }
From source file:org.sonar.plugins.php.pmd.PhpPmdConfigurationTest.java
@Test public void testGetIgnoreListWithNotNull() { Project project = getMockProject();/*from www . java2 s . c o m*/ PhpmdConfiguration config = new PhpmdConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] { "a", "b" }; when(c.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(excludeDirs); assertEquals("a,b", config.getIgnoreList()); }
From source file:org.sonar.plugins.php.pmd.PhpPmdConfigurationTest.java
@Test public void testGetIgnoreListWithEmpty() { Project project = getMockProject();//w w w. j a v a 2 s . c o m PhpmdConfiguration config = new PhpmdConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] {}; when(c.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(excludeDirs); assertEquals(null, config.getIgnoreList()); }
From source file:org.sonar.plugins.php.pmd.PhpPmdConfigurationTest.java
@Test public void testGetIgnoreListWithNull() { Project project = getMockProject();//from w w w.ja v a2s . c o m PhpmdConfiguration config = new PhpmdConfiguration(project); Configuration c = project.getConfiguration(); when(c.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(null); assertEquals(null, config.getIgnoreList()); }
From source file:org.sonar.plugins.php.pmd.sensor.PhpPmdViolationStaxParserTest.java
/** * Should save violations on classes./*from w w w. j a v a 2 s . c om*/ * * @throws URISyntaxException * the URI syntax exception * @throws XMLStreamException * the XML stream exception */ @Test public void shouldSaveViolationsOnClasses() throws URISyntaxException, XMLStreamException { SensorContext context = mock(SensorContext.class); Configuration configuration = mock(Configuration.class); Php php = new Php(configuration); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); parse(context, "/org/sonar/plugins/php/pmd/php-pmd-result.xml"); verify(context, times(30)).saveViolation(argThat(new IsViolationOnPhpClass())); verify(context, times(4)).saveViolation( argThat(new IsViolationOnPhpClass(new PhpFile("earth/animal/MonkeyWithComments.php")))); Violation wanted = new Violation(null, new PhpFile("earth/animal/MonkeyWithComments.php")) .setMessage("Avoid unused local variables such as 'toto'.").setLineId(22); verify(context, times(1)).saveViolation(argThat(new IsViolation(wanted))); }
From source file:org.sonar.plugins.secrules.RulesParser.java
protected RulesParser(Configuration configuration, RuleFinder ruleFinder) { rulesList = new ArrayList<Rule>(); String[] tokens = configuration.getStringArray(SecurityRulesPlugin.SEC_RULES); if (ArrayUtils.isEmpty(tokens)) { tokens = StringUtils.split(SecurityRulesPlugin.SEC_RULES_DEFAULT, ","); }/*from w w w .j av a2 s . c o m*/ for (String token : tokens) { String[] s = StringUtils.split(token, ":"); if (s.length != 2) { throw new SonarException( "Parameter of Security Rules Plugin is incorrectly set, should be pluginKey1:ruleKey1,pluginKey2:ruleKey2..."); } Rule rule = ruleFinder.findByKey(s[0], s[1]); if (rule == null) { throw new SonarException("Wrong plugin key (" + s[0] + ") or rule key (" + s[1] + ")"); } rulesList.add(rule); } }
From source file:org.sonar.plugins.xaml.utils.XamlReportSensor.java
protected List<File> getReports(Configuration conf, String baseDirPath, String reportPathPropertyKey, String defaultReportPath) { List<File> reports = new ArrayList<File>(); String[] padrons = conf.getStringArray(reportPathPropertyKey); if (padrons.length == 0) { padrons = new String[1]; padrons[0] = defaultReportPath;/* w ww. jav a 2s .c om*/ } for (String reportPath : padrons) { XamlUtils.LOG.debug("Using pattern '{}' to find reports", reportPath); DirectoryScanner scanner = new DirectoryScanner(); String[] includes = new String[1]; includes[0] = reportPath; scanner.setIncludes(includes); scanner.setBasedir(new File(baseDirPath)); scanner.scan(); String[] relPaths = scanner.getIncludedFiles(); for (String relPath : relPaths) { reports.add(new File(baseDirPath, relPath)); } } return reports; }