List of usage examples for org.apache.commons.configuration Configuration getBoolean
Boolean getBoolean(String key, Boolean defaultValue);
From source file:org.sonar.plugins.cxx.cppcheck.CxxCppCheckSensor.java
public CxxCppCheckSensor(RuleFinder ruleFinder, Configuration conf) { this.ruleFinder = ruleFinder; this.dynamicAnalysis = conf.getBoolean("sonar.cxx.cppcheck.runAnalysis", this.dynamicAnalysis); }
From source file:org.sonar.plugins.cxx.CxxSourceImporterTest.java
private Project mockProject() { Project project = TestUtils.mockProject(); File sourceFile;/*from ww w .j av a 2s . c o m*/ File sourceDir; try { sourceFile = new File(getClass().getResource("/org/sonar/plugins/cxx/source.cc").toURI()); sourceDir = new File(getClass().getResource("/org/sonar/plugins/cxx").toURI()); } catch (java.net.URISyntaxException e) { System.out.println("Error while mocking project: " + e); return null; } List<File> sourceFiles = project.getFileSystem().getSourceFiles(TestUtils.mockCxxLanguage()); sourceFiles.clear(); sourceFiles.add(sourceFile); List<File> sourceDirs = project.getFileSystem().getSourceDirs(); sourceDirs.clear(); sourceDirs.add(sourceDir); Configuration config = mock(Configuration.class); when(config.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY, CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE)).thenReturn(true); when(project.getConfiguration()).thenReturn(config); return project; }
From source file:org.sonar.plugins.cxx.TestUtils.java
/** * Mock project//from ww w. ja v a 2 s .c om * @param baseDir project base dir * @param sourceFiles project source files * @return mocked project */ public static Project mockProject(File baseDir, List<File> sourceDirs, List<File> testDirs) { List<File> mainSourceFiles = scanForSourceFiles(sourceDirs); List<File> testSourceFiles = scanForSourceFiles(testDirs); List<InputFile> mainFiles = fromSourceFiles(mainSourceFiles); List<InputFile> testFiles = fromSourceFiles(testSourceFiles); ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); when(fileSystem.getBasedir()).thenReturn(baseDir); when(fileSystem.getSourceCharset()).thenReturn(Charset.defaultCharset()); when(fileSystem.getSourceFiles(mockCxxLanguage())).thenReturn(mainSourceFiles); when(fileSystem.getTestFiles(mockCxxLanguage())).thenReturn(testSourceFiles); when(fileSystem.mainFiles(CxxLanguage.KEY)).thenReturn(mainFiles); when(fileSystem.testFiles(CxxLanguage.KEY)).thenReturn(testFiles); when(fileSystem.getSourceDirs()).thenReturn(sourceDirs); when(fileSystem.getTestDirs()).thenReturn(testDirs); Project project = mock(Project.class); when(project.getFileSystem()).thenReturn(fileSystem); CxxLanguage lang = mockCxxLanguage(); when(project.getLanguage()).thenReturn(lang); when(project.getLanguageKey()).thenReturn(lang.getKey()); // only for testing, Configuration is deprecated Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY, CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE)).thenReturn(true); when(project.getConfiguration()).thenReturn(configuration); return project; }
From source file:org.sonar.plugins.email.EmailPublisher.java
Email getEmail(Project project) throws EmailException { Configuration configuration = project.getConfiguration(); SonarEmail email = newEmail();// w w w.j a v a2s . c o m String host = configuration.getString(HOST_PROPERTY, SMTP_HOST_DEFAULT_VALUE); String port = configuration.getString(PORT_PROPERTY, PORT_DEFAULT_VALUE); String username = configuration.getString(USERNAME_PROPERTY); String password = configuration.getString(PASSWORD_PROPERTY); boolean withTLS = configuration.getBoolean(TLS_PROPERTY, TLS_DEFAULT_VALUE); String from = configuration.getString(FROM_PROPERTY, ""); String to = configuration.getString(TO_PROPERTY, ""); email.setHostName(host); email.setSmtpPort(port); if (!StringUtils.isBlank(username) || !StringUtils.isBlank(password)) { email.setAuthentication(username, password); } email.setTLS(withTLS); email.setFrom(from); String[] addrs = StringUtils.split(to, "\t\r\n;, "); for (String addr : addrs) { email.addTo(addr); } email.setSubject(String.format("Sonar analysis of %s", project.getName())); email.setMsg(String.format("Sonar analysis of %s available %s%s%s", project.getName(), server.getURL(), PROJECT_INDEX_URI, project.getKey())); return email; }
From source file:org.sonar.plugins.javascript.TestUtils.java
/** * Mock project// www . ja v a 2 s . co m * @param baseDir project base dir * @param sourceFiles project source files * @return mocked project */ public static Project mockProject(File baseDir, List<File> sourceDirs, List<File> testDirs) { List<File> mainSourceFiles = scanForSourceFiles(sourceDirs); List<File> testSourceFiles = scanForSourceFiles(testDirs); List<InputFile> mainFiles = fromSourceFiles(mainSourceFiles); List<InputFile> testFiles = fromSourceFiles(testSourceFiles); ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); when(fileSystem.getBasedir()).thenReturn(baseDir); when(fileSystem.getSourceCharset()).thenReturn(Charset.defaultCharset()); when(fileSystem.getSourceFiles(mockJavaScriptLanguage())).thenReturn(mainSourceFiles); when(fileSystem.getTestFiles(mockJavaScriptLanguage())).thenReturn(testSourceFiles); when(fileSystem.mainFiles(JavaScript.KEY)).thenReturn(mainFiles); when(fileSystem.testFiles(JavaScript.KEY)).thenReturn(testFiles); when(fileSystem.getSourceDirs()).thenReturn(sourceDirs); when(fileSystem.getTestDirs()).thenReturn(testDirs); Project project = mock(Project.class); when(project.getFileSystem()).thenReturn(fileSystem); JavaScript lang = mockJavaScriptLanguage(); when(project.getLanguage()).thenReturn(lang); when(project.getLanguageKey()).thenReturn(lang.getKey()); // only for testing, Configuration is deprecated Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY, CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE)).thenReturn(true); when(project.getConfiguration()).thenReturn(configuration); return project; }
From source file:org.sonar.plugins.php.atoum.AtoumConfiguration.java
public AtoumConfiguration(Project project) { super(project); Configuration configuration = project.getConfiguration(); analyzeOnly = configuration.getBoolean(getShouldAnalyzeOnlyKey(), false); this.project = project; }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferSensor.java
/** * Returns <code>true</code> if the given project language is PHP and * the project configuration is set to allow plugin to run. * * @param Project the project/*w w w.java2 s . co m*/ * * @return bool * * @see org.sonar.api.batch.CheckProject#shouldExecuteOnProject(org.sonar.api .resources.Project) */ public boolean shouldExecuteOnProject(Project project) { if (!PHP.equals(project.getLanguage())) { return false; } Configuration configuration = project.getConfiguration(); boolean skip = configuration.getBoolean(PHPCS_SKIP_KEY, !configuration.getBoolean(PHPCS_SHOULD_RUN_KEY, !parseBoolean(PHPCS_DEFAULT_SKIP))); if (skip) { return false; } if (!project.getReuseExistingRulesConfig() && profile.getActiveRulesByRepository(PHPCS_REPOSITORY_KEY).isEmpty()) { return false; } return true; }
From source file:org.sonar.plugins.php.codesniffer.sensor.PhpCodesnifferSensorTest.java
/** * Sould not launche on non php project. *//*from ww w . java 2s .c om*/ @Test public void shouldNotLauncheOnNonPhpProject() { Project project = mock(Project.class); Configuration configuration = mock(Configuration.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(fs.getBuildDir()).thenReturn(new File("C:\\projets\\PHP\\Monkey\\target")); when(configuration.getString(PhpCodesnifferConfiguration.REPORT_FILE_NAME_PROPERTY_KEY, PhpCodesnifferConfiguration.DEFAULT_REPORT_FILE_NAME)).thenReturn("tot.xml"); when(configuration.getString(PhpCodesnifferConfiguration.REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY, PhpCodesnifferConfiguration.DEFAULT_REPORT_FILE_PATH)) .thenReturn(PhpCodesnifferConfiguration.DEFAULT_REPORT_FILE_PATH); when(configuration.getBoolean(PhpCodesnifferConfiguration.ANALYZE_ONLY_KEY, false)).thenReturn(true); when(project.getConfiguration()).thenReturn(configuration); when(project.getLanguage()).thenReturn(Php.INSTANCE); PhpCodesnifferSensor sensor = new PhpCodesnifferSensor(); assertEquals(false, sensor.shouldExecuteOnProject(project)); }
From source file:org.sonar.plugins.php.core.AbstractPhpConfiguration.java
/** * @param project//from w w w . j a v a 2s . co m */ protected AbstractPhpConfiguration(Project project) { this.project = project; Configuration configuration = getProject().getConfiguration(); this.reportFileName = configuration.getString(getReportFileNameKey(), getDefaultReportFileName()); this.reportFileRelativePath = configuration.getString(getReportFileRelativePathKey(), getDefaultReportFilePath()); this.argumentLine = configuration.getString(getArgumentLineKey(), getDefaultArgumentLine()); this.analyzeOnly = configuration.getBoolean(getShouldAnalyzeOnlyKey(), false); this.timeout = configuration.getInt(getTimeoutKey(), DEFAULT_TIMEOUT); if (isStringPropertySet(getSkipKey())) { // NOSONAR Use of non final method, that is not final for mocking purposes skip = project.getConfiguration().getBoolean(getSkipKey()); } else if (isStringPropertySet(getShouldRunKey())) { // NOSONAR Use of non final method, that is not final for mocking purposes skip = !project.getConfiguration().getBoolean(getShouldRunKey()); } String dynamicAnalysis = configuration.getString("sonar.dynamicAnalysis", "true"); if (!"false".equalsIgnoreCase(dynamicAnalysis)) { isDynamicAnalysis = true; } }
From source file:org.sonar.plugins.php.core.AbstractPhpPluginConfiguration.java
/** * @param project//from w w w . j av a2 s.c om */ protected AbstractPhpPluginConfiguration(Project project) { this.project = project; Configuration configuration = getProject().getConfiguration(); if (getReportFileNameKey() != null) { this.reportFileName = configuration.getString(getReportFileNameKey(), getDefaultReportFileName()); } if (getReportFileRelativePathKey() != null) { this.reportFileRelativePath = configuration.getString(getReportFileRelativePathKey(), getDefaultReportFilePath()); String absolutePath = getProject().getFileSystem().getBuildDir().getAbsolutePath(); File reportDirectory = new File(absolutePath, reportFileRelativePath); reportDirectory.mkdir(); } if (getArgumentLineKey() != null) { this.argumentLine = configuration.getString(getArgumentLineKey(), getDefaultArgumentLine()); } if (getShouldAnalyzeOnlyKey() != null) { this.analyzeOnly = configuration.getBoolean(getShouldAnalyzeOnlyKey(), shouldAnalyzeOnlyDefault()); } }