List of usage examples for org.apache.commons.configuration Configuration getStringArray
String[] getStringArray(String key);
From source file:org.sonar.plugins.php.phpdepend.PhpDependConfigurationTest.java
@Test public void testGetExcludePackageWithNotNull() { Project project = getMockProject();//from w w w. j a va 2 s . co m PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] { "a", "b" }; when(c.getStringArray(PDEPEND_EXCLUDE_PACKAGE_KEY)).thenReturn(excludeDirs); assertEquals("a,b", config.getExcludePackages()); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependConfigurationTest.java
@Test public void testGetExcludePackageWithEmpty() { Project project = getMockProject();/*from w w w .java 2s . c o m*/ PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] {}; when(c.getStringArray(PDEPEND_EXCLUDE_PACKAGE_KEY)).thenReturn(excludeDirs); assertEquals(null, config.getExcludePackages()); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependConfigurationTest.java
@Test public void testGetIgnoreDirsWithNull() { Project project = getMockProject();//from w w w .j av a2 s.c o m PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); when(c.getStringArray(PDEPEND_IGNORE_KEY)).thenReturn(null); assertThat(config.getIgnoreDirs()).isEqualTo(""); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependExecutor.java
@Override protected List<String> getCommandLine() { List<String> result = new ArrayList<String>(); result.add(configuration.getOsDependentToolScriptName()); result.add(configuration.getReportFileCommandOption()); result.add(configuration.getSuffixesCommandOption()); if (configuration.isStringPropertySet(PDEPEND_EXCLUDE_PACKAGE_KEY)) { result.add(PDEPEND_EXCLUDE_OPTION + configuration.getExcludePackages()); }/*from w w w. ja v a 2s.c om*/ boolean sonarExclusionsIsSet = configuration.isStringPropertySet(PROJECT_EXCLUSIONS_PROPERTY); boolean ignoreKeyIsSet = configuration.isStringPropertySet(PDEPEND_IGNORE_KEY); if (ignoreKeyIsSet || sonarExclusionsIsSet) { String ignore = configuration.getIgnoreDirs(); Configuration projectConfiguration = configuration.getProject().getConfiguration(); String[] sonarExclusions = projectConfiguration.getStringArray(PROJECT_EXCLUSIONS_PROPERTY); if (sonarExclusionsIsSet && sonarExclusions != null) { ignore += StringUtils.isBlank(ignore) ? "" : ","; ignore += StringUtils.join(sonarExclusions, ","); } result.add(PDEPEND_IGNORE_OPTION + ignore); } if (configuration.isBadDocumentation()) { result.add(PDEPEND_BAD_DOCUMENTATION_OPTION); } if (configuration.isWithoutAnnotation()) { result.add(PDEPEND_WITHOUT_ANNOTATION_OPTION); } if (configuration.isStringPropertySet(PDEPEND_ARGUMENT_LINE_KEY)) { result.add(configuration.getArgumentLine()); } // SONARPLUGINS-547 PhpDependExecutor: wrong dirs params result.add(StringUtils.join(configuration.getSourceDirectories(), PHPDEPEND_DIRECTORY_SEPARATOR)); return result; }
From source file:org.sonar.plugins.php.phpdepend.PhpDependExecutorTest.java
/** * Test method for {@link org.sonar.plugins.php.codesniffer.PhpCodeSnifferExecutor#getCommandLine()} . *///from w w w. j av a 2 s .co m @Test public void testGetCommandLine1() { Configuration configuration = mock(Configuration.class); when(configuration.getStringArray(FILE_SUFFIXES_KEY)).thenReturn(null); Project project = getMockProject(); PhpDependConfiguration c = getWindowsConfiguration(project); PhpDependExecutor executor = new PhpDependExecutor(c); List<String> commandLine = executor.getCommandLine(); String s1 = "pdepend.bat"; String s2 = "--phpunit-xml=" + getFile("C:/projets/PHP/Monkey/target/logs/pdepend.xml"); String s3 = "--suffix=php,php3,php4,php5,phtml,inc"; String s4 = new File("C:/projets/PHP/Monkey/sources/main").toString(); List<String> expected = Arrays.asList(s1, s2, s3, s4); // assertThat(commandLine).isEqualTo(expected); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependExecutorTest.java
@Test public void testGetIgnoreDirsWithNotNullWithSonarExclusionNull() { Project project = getMockProject();/*from ww w . j av a 2s.c om*/ PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); when(config.isStringPropertySet(PDEPEND_IGNORE_KEY)).thenReturn(true); String pdependExclusionPattern = "Math,Math3*"; when(c.getStringArray(PDEPEND_IGNORE_KEY)).thenReturn(new String[] { pdependExclusionPattern }); when(c.getStringArray(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(null); assertThat(config.getIgnoreDirs()).isEqualTo(pdependExclusionPattern); PhpDependExecutor executor = new PhpDependExecutor(config); List<String> commandLine = executor.getCommandLine(); String s1 = "pdepend.bat"; String s2 = "--phpunit-xml=" + getFile("C:/projets/PHP/Monkey/target/logs/pdepend.xml"); String s3 = "--suffix=php,php3,php4,php5,phtml,inc"; String s4 = "--ignore=" + pdependExclusionPattern; String s5 = new File("C:/projets/PHP/Monkey/sources/main").toString(); List<String> expected = Arrays.asList(s1, s2, s3, s4, s5); assertThat(commandLine).isEqualTo(expected); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependExecutorTest.java
@Test public void testGetIgnoreDirsNullWithSonarExclusionNotNull() { Project project = getMockProject();/*from w w w . ja va2 s.c om*/ PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); when(config.isStringPropertySet(PDEPEND_IGNORE_KEY)).thenReturn(false); when(c.getStringArray(PDEPEND_IGNORE_KEY)).thenReturn(null); when(config.isStringPropertySet(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(true); String[] sonarExclusionPattern = { "*test", "**/math" }; when(c.getStringArray(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(sonarExclusionPattern); PhpDependExecutor executor = new PhpDependExecutor(config); List<String> commandLine = executor.getCommandLine(); String s1 = "pdepend.bat"; String s2 = "--phpunit-xml=" + getFile("C:/projets/PHP/Monkey/target/logs/pdepend.xml"); String s3 = "--suffix=php,php3,php4,php5,phtml,inc"; String s4 = "--ignore=" + StringUtils.join(sonarExclusionPattern, ","); String s5 = new File("C:/projets/PHP/Monkey/sources/main").toString(); List<String> expected = Arrays.asList(s1, s2, s3, s4, s5); assertThat(commandLine).isEqualTo(expected); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependExecutorTest.java
@Test public void testGetIgnoreDirsNotNullWithSonarExclusionNotNull() { Project project = getMockProject();// w ww . jav a 2s.c om PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); when(config.isStringPropertySet(PDEPEND_IGNORE_KEY)).thenReturn(true); String[] pdependExclusionPattern = { "*Math4.php" }; when(c.getStringArray(PDEPEND_IGNORE_KEY)).thenReturn(pdependExclusionPattern); when(config.isStringPropertySet(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(true); String[] sonarExclusionPattern = { "sites/all/", "files", "*Math4.php" }; when(c.getStringArray(PROJECT_EXCLUSIONS_PROPERTY)).thenReturn(sonarExclusionPattern); PhpDependExecutor executor = new PhpDependExecutor(config); List<String> commandLine = executor.getCommandLine(); String s1 = "pdepend.bat"; String s2 = "--phpunit-xml=" + getFile("C:/projets/PHP/Monkey/target/logs/pdepend.xml"); String s3 = "--suffix=php,php3,php4,php5,phtml,inc"; String s4 = "--ignore=" + StringUtils.join(pdependExclusionPattern, ",") + "," + StringUtils.join(sonarExclusionPattern, ","); String s5 = new File("C:/projets/PHP/Monkey/sources/main").toString(); List<String> expected = Arrays.asList(s1, s2, s3, s4, s5); assertThat(commandLine).isEqualTo(expected); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependResultsParserTest.java
/** * Inits the result parser./*w ww . j a va 2 s . c om*/ */ private void init(String pdependResultFile) { try { File xmlReport = new File(getClass().getResource(pdependResultFile).toURI()); context = mock(SensorContext.class); project = mock(Project.class); ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); when(project.getFileSystem()).thenReturn(fileSystem); when(fileSystem.getSourceDirs()) .thenReturn(Arrays.asList(new File("C:/projets/PHP/Money/Sources/main"))); when(fileSystem.getTestDirs()).thenReturn(Arrays.asList(new File("C:/projets/PHP/Money/Sources/test"))); File f1 = new File("C:/projets/PHP/Money/Sources/test/MoneyTest.php"); File f2 = new File("C:/projets/PHP/Money/Sources/main/Money.php"); File f3 = new File("C:/projets/PHP/Money/Sources/main/MoneyBag.php"); File f4 = new File("C:/projets/PHP/Money/Sources/main/Common/IMoney.php"); File f5 = new File("C:/projets/PHP/Money/Sources/main/Money.inc"); when(fileSystem.getSourceFiles(PHP)).thenReturn(Arrays.asList(f1, f2, f3, f4, f5)); when(fileSystem.getTestFiles(PHP)).thenReturn(Arrays.asList(f1)); Set<Metric> metrics = new HashSet<Metric>(); metrics.add(metric); PhpDependResultsParser parser = new PhpDependResultsParser(project, context); Configuration configuration = mock(Configuration.class); // new Php(); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); Php.PHP.setConfiguration(configuration); parser.parse(xmlReport); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.sonar.plugins.php.phpdepend.sensor.PhpDependResultsParserTest.java
/** * Inits the result parser.// w w w . j av a 2 s.co m */ private void init(String pdependResultFile) { try { File xmlReport = new File(getClass().getResource(pdependResultFile).toURI()); context = mock(SensorContext.class); project = mock(Project.class); ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); when(project.getFileSystem()).thenReturn(fileSystem); when(fileSystem.getSourceDirs()) .thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Money\\Sources\\main"))); when(fileSystem.getTestDirs()) .thenReturn(Arrays.asList(new File("C:\\projets\\PHP\\Money\\Sources\\test"))); Set<Metric> metrics = new HashSet<Metric>(); metrics.add(metric); PhpDependResultsParser parser = new PhpDependResultsParser(project, context, metrics); Configuration configuration = mock(Configuration.class); Php php = new Php(configuration); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); parser.parse(xmlReport); } catch (Exception e) { throw new RuntimeException(e); } }