List of usage examples for org.apache.commons.configuration Configuration getBoolean
Boolean getBoolean(String key, Boolean defaultValue);
From source file:org.sonar.plugins.php.phpunit.PhpUnitSensor.java
/** * Determines whether or not this sensor will be executed on the given project. * // ww w .j a v a 2 s. co m * @param project * The project to be analyzed * @return boolean <code>true</code> if project's language is php a,d the project configuration says so, <code>false</code> in any other * case. * @see org.sonar.api.batch.CheckProject#shouldExecuteOnProject(org.sonar.api .resources.Project) */ public boolean shouldExecuteOnProject(Project project) { Configuration configuration = project.getConfiguration(); Language language = project.getLanguage(); boolean shouldExecute = PHP.equals(language); shouldExecute = shouldExecute && (configuration.getBoolean(PHPUNIT_SHOULD_RUN_PROPERTY_KEY, parseBoolean(PHPUNIT_DEFAULT_SHOULD_RUN)) || configuration.getBoolean(PHPUNIT_SHOULD_RUN_COVERAGE_PROPERTY_KEY, parseBoolean(PHPUNIT_DEFAULT_SHOULD_RUN_COVERAGE))); return shouldExecute; }
From source file:org.sonar.plugins.php.pmd.PhpmdSensor.java
/** * Returns <code>true</code> if the given project language is PHP and the project configuration is set to allow plugin to run. * //from ww w. j av a 2s . c o m * @param project * the project * * @return true, if should execute on project * * @see org.sonar.api.batch.CheckProject#shouldExecuteOnProject(org.sonar.api .resources.Project) */ public boolean shouldExecuteOnProject(Project project) { Configuration configuration = project.getConfiguration(); Language language = project.getLanguage(); boolean result = PHP.equals(language); result = result && configuration.getBoolean(PHPMD_SHOULD_RUN_KEY, parseBoolean(PHPMD_DEFAULT_SHOULD_RUN)); result = result && (project.getReuseExistingRulesConfig() || !profile.getActiveRulesByRepository(PHPMD_REPOSITORY_KEY).isEmpty()); return result; }
From source file:org.sonar.plugins.php.pmd.PhpPmdSensorTest.java
/** * Sould not launch parsing when no report can be found. *//*from w w w . j av a2s .co m*/ @Test(expected = SonarException.class) public void shouldNotLaunchParsingWhenNoReportCanBeFound() { 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(PHPMD_REPORT_FILE_NAME_PROPERTY_KEY, PHPMD_DEFAULT_REPORT_FILE_NAME)) .thenReturn("tot.xml"); String defaultReportFile = PHPMD_DEFAULT_REPORT_FILE_PATH; when(configuration.getString(PHPMD_REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY, defaultReportFile)) .thenReturn(defaultReportFile); when(configuration.getBoolean(PhpmdConfiguration.PHPMD_ANALYZE_ONLY_KEY, false)).thenReturn(true); when(project.getConfiguration()).thenReturn(configuration); when(project.getLanguage()).thenReturn(Php.PHP); PhpmdSensor sensor = getSensor(project); SensorContext context = mock(SensorContext.class); sensor.analyse(project, context); verify(context, never()).saveViolation(any(Violation.class)); }
From source file:org.sonar.plugins.php.pmd.sensor.PhpPmdSensorTest.java
/** * Sould not launch parsing when no report can be found. *//* w ww . ja v a 2 s . c om*/ @Test public void shouldNotLaunchParsingWhenNoReportCanBeFound() { 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(PhpPmdConfiguration.REPORT_FILE_NAME_PROPERTY_KEY, PhpPmdConfiguration.DEFAULT_REPORT_FILE_NAME)).thenReturn("tot.xml"); when(configuration.getString(PhpPmdConfiguration.REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY, PhpPmdConfiguration.DEFAULT_REPORT_FILE_PATH)) .thenReturn(PhpPmdConfiguration.DEFAULT_REPORT_FILE_PATH); when(configuration.getBoolean(PhpPmdConfiguration.ANALYSE_ONLY_KEY, false)).thenReturn(true); when(project.getConfiguration()).thenReturn(configuration); when(project.getLanguage()).thenReturn(Php.INSTANCE); PhpPmdSensor sensor = new PhpPmdSensor(); SensorContext context = mock(SensorContext.class); sensor.analyse(project, context); verify(context, never()).saveViolation(any(Violation.class)); }
From source file:org.sonar.plugins.scmactivity.ScmConfiguration.java
public ScmConfiguration(Project project, Configuration configuration, MavenScmConfiguration mavenConfiguration) { this.fileSystem = project.getFileSystem(); this.conf = configuration; this.mavenConf = mavenConfiguration; isJavaProject = Java.KEY.equals(project.getLanguageKey()); isIgnoreLocalModifications = configuration.getBoolean(ScmActivityPlugin.IGNORE_LOCAL_MODIFICATIONS, ScmActivityPlugin.IGNORE_LOCAL_MODIFICATIONS_DEFAULT_VALUE); }
From source file:org.sonar.plugins.xaml.XamlSourceImporterTest.java
private Project mockProject() { Project project = XamlTestUtils.mockProject(); File sourceFile;/* w w w.jav a 2 s .com*/ 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(XamlTestUtils.mockXamlLanguage()); 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.server.ui.AuthenticatorFactory.java
public AuthenticatorFactory(Configuration configuration, LoginPasswordAuthenticator[] authenticators) { classname = configuration.getString(CoreProperties.CORE_AUTHENTICATOR_CLASS); ignoreStartupFailure = configuration.getBoolean(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE, false);/*ww w . ja va 2 s . c om*/ this.authenticators = authenticators; }
From source file:org.topazproject.mulgara.resolver.CacheInvalidator.java
/** * Create a new cache-invalidator instance. * /*from w w w. j a v a 2 s . c o m*/ * @param config the configuration to use * @param base the prefix under which the current <var>config</var> was retrieved * @param sf the session-factory we belong to * @param dbURI the uri of our database * @throws Exception */ public CacheInvalidator(Configuration config, String base, SessionFactory sf, URI dbURI) throws Exception { super(0, getInvIval(config), "CacheInvalidator-Worker", false, logger); xaResource = new CIXAResource(); config = config.subset("cacheInvalidator"); base += ".cacheInvalidator"; // parse the rules file String rulesLoc = config.getString("rulesFile", null); if (rulesLoc == null) throw new IOException("Missing configuration entry '" + base + ".rulesFile"); URL loc = findResOrURL(rulesLoc); if (loc == null) throw new IOException("Rules-file '" + rulesLoc + "' not found"); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setIgnoringComments(true); builderFactory.setCoalescing(true); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Element rules = builder.parse(new InputSource(loc.toString())).getDocumentElement(); this.aliases = parseAliases(rules, dbURI); this.rules = parseRules(rules, aliases); // set up the Ehcache disableJULInfoMessages(); String ehcConfigLoc = config.getString("ehcacheConfig", null); boolean useSingleton = config.getBoolean("useSharedCacheManager", false); if (ehcConfigLoc != null) { loc = findResOrURL(ehcConfigLoc); if (loc == null) throw new IOException("Ehcache config file '" + ehcConfigLoc + "' not found"); cacheManager = useSingleton ? CacheManager.create(loc) : new CacheManager(loc); } else { cacheManager = useSingleton ? CacheManager.create() : new CacheManager(); } String qcName = config.getString("queryCache", DEF_QC_NAME); queryCache = cacheManager.getEhcache(qcName); if (queryCache != null) logger.info("Using cache '" + qcName + "' for the query caching"); else logger.info("No cache named '" + qcName + "' found - disabling query caching"); // delay session creation because at this point we're already in a session-creation call sessFactory = sf; // we're ready worker.start(); }
From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java
@Override public void init() throws VStorageFailureException { Configuration config = getStorageConfig(); // get file storage location logger.info("Checking configured storage directory"); storageDirectoryPathString = config.getString(CONF_STORAGE_DIR, "/tmp/veronica"); logger.info("Storage configured to:" + storageDirectoryPathString); // get is underlying disk is a Solid State Drive (this will have implications on how the flush sizes are computed) ssd = config.getBoolean(CONF_STORAGE_SSD, false); logger.info("Storage is " + (ssd ? "SSD" : " not SSD")); storageDirectory = new File(storageDirectoryPathString); compress = config.getBoolean("compress", false); if (compress) { compressor = GzipCompressorOutputStream.class; decompressor = GzipCompressorInputStream.class; }/* w w w.java 2 s .co m*/ // perform validations with the storage if (!storageDirectory.exists()) { throw new VStorageFailureException(this.getClass(), "Storage directory '" + storageDirectory.getAbsolutePath() + "' does not exist", new FileNotFoundException()); } if (!storageDirectory.isDirectory()) { throw new VStorageFailureException(this.getClass(), "Storage path '" + storageDirectory.getAbsolutePath() + "' is not a directory", new FileNotFoundException()); } logger.info("Storage directory exists"); if (!storageDirectory.canRead() || !storageDirectory.canWrite()) { throw new VStorageFailureException(this.getClass(), "Need read/write permissions to write to local storage directory:" + storageDirectory.getAbsolutePath()); } logger.info("Found correct permissions on storage directory"); }
From source file:org.zaproxy.zap.control.ExtensionFactory.java
private static void addExtensionImpl(Configuration config, Extension extension) { if (mapAllExtension.containsKey(extension.getName())) { if (mapAllExtension.get(extension.getName()).getClass().equals(extension.getClass())) { // Same name, same class cant currently replace exts already loaded log.debug("Duplicate extension: " + extension.getName() + " " + extension.getClass().getCanonicalName()); extension.setEnabled(false); return; }//from w w w.j av a2s . c o m // Same name but different class, log but still load it log.error("Duplicate extension name: " + extension.getName() + " " + extension.getClass().getCanonicalName() + " " + mapAllExtension.get(extension.getName()).getClass().getCanonicalName()); } if (extension.isDepreciated()) { log.debug("Depreciated extension " + extension.getName()); return; } extension.setEnabled(config.getBoolean("ext." + extension.getName(), true)); listAllExtension.add(extension); mapAllExtension.put(extension.getName(), extension); // Order actually irrelevant when adding an addon;) int order = extension.getOrder(); if (order == 0) { unorderedExtensions.add(extension); } else if (mapOrderToExtension.containsKey(order)) { log.error("Duplicate order " + order + " " + mapOrderToExtension.get(order).getName() + "/" + mapOrderToExtension.get(order).getClass().getCanonicalName() + " already registered, " + extension.getName() + "/" + extension.getClass().getCanonicalName() + " will be added as an unordered extension"); unorderedExtensions.add(extension); } else { mapOrderToExtension.put(order, extension); } }