List of usage examples for org.apache.commons.configuration Configuration getStringArray
String[] getStringArray(String key);
From source file:org.sonar.plugins.php.PhpTest.java
/** * Should check valid php extensions.//from w w w . j av a2 s .co m */ @Test public void shouldCheckDefaultValidPhpExtensions() { Configuration configuration = mock(Configuration.class); Php.PHP.setConfiguration(configuration); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); assertTrue(Php.hasValidSuffixes("goodExtension.php")); assertTrue(Php.hasValidSuffixes("goodExtension.php5")); assertTrue(Php.hasValidSuffixes("goodExtension.inc")); assertFalse(Php.hasValidSuffixes("wrong.extension")); assertFalse(Php.hasValidSuffixes("goodExtension.java")); assertFalse(Php.hasValidSuffixes("goodExtension.cs")); assertFalse(Php.hasValidSuffixes("goodExtension.php7")); }
From source file:org.sonar.plugins.php.PhpTest.java
@Test public void shouldCheckCustomValidPhpExtensions() { Configuration configuration = mock(Configuration.class); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)) .thenReturn(StringUtils.split(PhpPlugin.DEFAULT_SUFFIXES + ",php6,php7", ",")); Php.PHP.setConfiguration(configuration); assertTrue(Php.hasValidSuffixes("goodExtension.php6")); assertTrue(Php.hasValidSuffixes("goodExtension.php7")); }
From source file:org.sonar.plugins.php.phpunit.PhpUnitCoverageResultParserTest.java
/** * Inits the.//from ww w. j a v a 2 s .c o m */ private void init() { try { config = mock(PhpUnitConfiguration.class); project = mock(Project.class); context = mock(SensorContext.class); MavenProject mavenProject = mock(MavenProject.class); ProjectFileSystem fs = mock(ProjectFileSystem.class); when(project.getPom()).thenReturn(mavenProject); when(project.getFileSystem()).thenReturn(fs); when(fs.getSourceDirs()).thenReturn(Arrays.asList(new File("C:/projets/PHP/Monkey/sources/main"))); File f1 = new File("C:/projets/PHP/Money/Sources/main/Monkey2.php"); File f2 = new File("C:/projets/PHP/Monkey/sources/main/Monkey.php"); File f3 = new File("C:/projets/PHP/Monkey/sources/main/Banana1.php"); File f4 = new File("C:/projets/PHP/Monkey/sources/test/Banana.php"); File f5 = new File("C:/projets/PHP/Monkey/sources/main/Money.inc"); when(fs.getSourceFiles(PHP)).thenReturn(Arrays.asList(f1, f2, f3, f5)); when(fs.getTestDirs()).thenReturn(Arrays.asList(new File("C:/projets/PHP/Monkey/sources/test"))); when(fs.getTestFiles(PHP)).thenReturn(Arrays.asList(f4)); when(mavenProject.getPackaging()).thenReturn("maven-plugin"); File reportFile = new File( getClass().getResource("/org/sonar/plugins/php/phpunit/sensor/phpunit.coverage.xml").getFile()); when(config.getReportFile()).thenReturn(reportFile); Configuration configuration = mock(Configuration.class); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); PhpUnitCoverageResultParser parser = new PhpUnitCoverageResultParser(project, context); parser.parse(config.getReportFile()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.sonar.plugins.php.phpunit.PhpUnitResultParserTest.java
/** * Inits the./*from www . ja v a 2 s .c o m*/ */ private void init() { try { Configuration configuration = mock(Configuration.class); config = mock(PhpUnitConfiguration.class); project = mock(Project.class); context = mock(SensorContext.class); when(project.getConfiguration()).thenReturn(configuration); when(config.getProject()).thenReturn(project); MavenProject mavenProject = mock(MavenProject.class); ProjectFileSystem fs = mock(ProjectFileSystem.class); when(project.getPom()).thenReturn(mavenProject); when(project.getFileSystem()).thenReturn(fs); when(fs.getSourceDirs()).thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Monkey\\sources\\main"))); when(fs.getTestDirs()).thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Monkey\\Sources\\test"))); when(mavenProject.getPackaging()).thenReturn("php"); File reportFile = new File( getClass().getResource("/org/sonar/plugins/php/phpunit/sensor/phpunit.xml").getFile()); when(config.getReportFile()).thenReturn(reportFile); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); PhpUnitResultParser parser = new PhpUnitResultParser(project, context); parser.parse(config.getReportFile()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.sonar.plugins.php.phpunit.sensor.PhpUnitCoverageResultParserTest.java
/** * Inits the.// ww w. j a v a 2 s . c om */ private void init() { try { config = mock(PhpUnitConfiguration.class); project = mock(Project.class); context = mock(SensorContext.class); MavenProject mavenProject = mock(MavenProject.class); ProjectFileSystem fs = mock(ProjectFileSystem.class); when(project.getPom()).thenReturn(mavenProject); when(project.getFileSystem()).thenReturn(fs); when(fs.getSourceDirs()).thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Monkey\\sources\\main"))); when(fs.getTestDirs()).thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Monkey\\sources\\test"))); when(mavenProject.getPackaging()).thenReturn("maven-plugin"); when(config.getReportFile()).thenReturn(new File(getClass() .getResource("/org/sonar/plugins/php/phpunit/sensor/phpunit.coverage.xml").getFile())); Configuration configuration = mock(Configuration.class); Php php = new Php(configuration); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); PhpUnitCoverageResultParser parser = new PhpUnitCoverageResultParser(project, context); parser.parse(config.getReportFile()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.sonar.plugins.php.phpunit.sensor.PhpUnitResultParserTest.java
/** * Inits the./*from w ww. j av a2 s. c o m*/ */ private void init() { try { config = mock(PhpUnitConfiguration.class); project = mock(Project.class); context = mock(SensorContext.class); MavenProject mavenProject = mock(MavenProject.class); ProjectFileSystem fs = mock(ProjectFileSystem.class); when(project.getPom()).thenReturn(mavenProject); when(project.getFileSystem()).thenReturn(fs); when(fs.getSourceDirs()).thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Monkey\\sources\\main"))); when(fs.getTestDirs()).thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Monkey\\Sources\\test"))); when(mavenProject.getPackaging()).thenReturn("php"); File reportFile = new File( getClass().getResource("/org/sonar/plugins/php/phpunit/sensor/phpunit.xml").getFile()); when(config.getReportFile()).thenReturn(reportFile); Configuration configuration = mock(Configuration.class); Php php = new Php(configuration); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); PhpUnitResultParser parser = new PhpUnitResultParser(project, context); parser.parse(config.getReportFile()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.sonar.plugins.php.pmd.PhpmdExecutor.java
/** * @return the command line ignore option depending on sonar exclusions and phpmd specific exclusion. *//* ww w . j av a 2s .c o m*/ private List<String> getIgnoreArguments() { List<String> ignoreArguments = new ArrayList<String>(); boolean sonarExclusionsIsSet = configuration.isStringPropertySet(PROJECT_EXCLUSIONS_PROPERTY); boolean ignoreKeyIsSet = configuration.isStringPropertySet(PHPMD_IGNORE_OPTION); if (ignoreKeyIsSet || sonarExclusionsIsSet) { String ignoreList = configuration.getIgnoreList(); String ignore = ignoreList != null ? ignoreList : ""; Configuration projectConfiguration = configuration.getProject().getConfiguration(); String[] sonarExclusions = projectConfiguration.getStringArray(PROJECT_EXCLUSIONS_PROPERTY); if (sonarExclusionsIsSet && sonarExclusions != null) { ignore += StringUtils.isBlank(ignore) ? "" : ","; ignore += StringUtils.join(sonarExclusions, ","); } ignoreArguments.add(PHPMD_IGNORE_OPTION); ignoreArguments.add(ignore); } return ignoreArguments; }
From source file:org.sonar.plugins.php.pmd.PhpmdExecutorTest.java
/** * Test method for {@link org.sonar.plugins.php.codesniffer.PhpCodeSnifferExecutor#getCommandLine()} . *//*from w w w . j av a2 s . c o m*/ @Test public void testGetCommandLine1() { Project project = getMockProject(); 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); PhpmdExecutor executor = new PhpmdExecutor(c, e, null); List<String> commandLine = executor.getCommandLine(); String f1 = new File("C:/projets/PHP/Monkey/sources/main").toString(); String f2 = getFile("C:/projets/PHP/Monkey/target/pmd.xml"); String[] expected = new String[] { "phpmd.bat", f1, "xml", "codesize,unusedcode,naming", "--reportfile", f2, "--extensions", StringUtils.join(extensions, ",") }; assertThat(commandLine).isEqualTo(Arrays.asList(expected)); }
From source file:org.sonar.plugins.php.pmd.PhpmdExecutorTest.java
@Test public void testGetIgnoreDirsWithNotNullWithSonarExclusionNull() { Project project = getMockProject();/*from w w w . j ava 2 s .co m*/ 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 pdependExclusionPattern = "Math,Math3*"; when(configuration.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)) .thenReturn(new String[] { pdependExclusionPattern }); when(configuration.getStringArray(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(null); assertThat(c.getIgnoreList()).isEqualTo(pdependExclusionPattern); PhpmdExecutor executor = new PhpmdExecutor(c, e, null); List<String> commandLine = executor.getCommandLine(); String f1 = new File("C:/projets/PHP/Monkey/sources/main").toString(); String f2 = getFile("C:/projets/PHP/Monkey/target/pmd.xml"); String[] expected = new String[] { "phpmd.bat", f1, "xml", "codesize,unusedcode,naming", "--reportfile", f2, "--extensions", StringUtils.join(extensions, ",") }; assertThat(commandLine).isEqualTo(Arrays.asList(expected)); }
From source file:org.sonar.plugins.php.pmd.PhpmdExecutorTest.java
@Test public void testGetIgnoreDirsNullWithSonarExclusionNotNull() { Project project = getMockProject();//from w ww. j a v a 2 s . com 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(false); when(configuration.getStringArray(PHPMD_IGNORE_ARGUMENT_KEY)).thenReturn(null); when(c.isStringPropertySet(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(true); String[] sonarExclusionPattern = { "*test", "**/math" }; 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(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); }