Example usage for org.apache.commons.configuration Configuration getBoolean

List of usage examples for org.apache.commons.configuration Configuration getBoolean

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getBoolean.

Prototype

Boolean getBoolean(String key, Boolean defaultValue);

Source Link

Document

Get a Boolean associated with the given configuration key.

Usage

From source file:org.sonar.plugins.php.core.PhpSourceImporterTest.java

@Before
public void init() throws Exception {
    tempFolder.create();//from  ww w  .j  a  v a2 s .  c o m
    sources = tempFolder.newFolder("sources");
    tests = tempFolder.newFolder("tests");
    testsBelowSources = tempFolder.newFolder("sources/tests");

    Configuration configuration = mock(Configuration.class);
    when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null);
    when(configuration.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY,
            CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE)).thenReturn(true);

    context = mock(SensorContext.class);
    project = mock(Project.class);
    when(project.getPom()).thenReturn(new MavenProject());
    when(project.getConfiguration()).thenReturn(configuration);

    DefaultProjectFileSystem fileSystem = new DefaultProjectFileSystem(project, new Languages(Php.PHP));
    fileSystem.addSourceDir(sources);
    fileSystem.addTestDir(tests);
    fileSystem.addTestDir(testsBelowSources);

    when(project.getFileSystem()).thenReturn(fileSystem);
}

From source file:org.sonar.plugins.php.cpd.PhpCpdSensor.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  2  s . co  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 c = project.getConfiguration();
    Language language = project.getLanguage();

    Boolean phpcpdShouldRun = c.getBoolean(PHPCPD_SHOULD_RUN_PROPERTY_KEY,
            parseBoolean(PHPCPD_DEFAULT_SHOULD_RUN));
    Boolean deprecatedPhpcpdSkip = c.getBoolean(SONAR_PHP_CPD_SKIP_KEY, !phpcpdShouldRun);
    Boolean phpcpdSkip = c.getBoolean(PHPCPD_SKIP_PROPERTY_KEY, deprecatedPhpcpdSkip);

    return (PHP.equals(language) && !phpcpdSkip);
}

From source file:org.sonar.plugins.php.phpdepend.PhpDependSensor.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 a v  a2  s.  com*/
 * @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();
    return PHP.equals(language) && configuration.getBoolean(PDEPEND_SHOULD_RUN_PROPERTY_KEY,
            parseBoolean(PDEPEND_DEFAULT_SHOULD_RUN));
}

From source file:org.sonar.plugins.php.phpdepend.PhpDependSensorTest.java

@Test
public void shouldLaunchOnPhpProjectIfConfiguredSo() {
    Project project = mock(Project.class);
    when(project.getLanguage()).thenReturn(Php.PHP);
    ProjectFileSystem fs = mock(ProjectFileSystem.class);
    when(project.getFileSystem()).thenReturn(fs);
    when(fs.getBuildDir()).thenReturn(new File(DEFAULT_REPORT_FILE_NAME));
    Configuration configuration = mock(Configuration.class);

    PhpDependResultsParser parser = mock(PhpDependResultsParser.class);
    PhpDependExecutor executor = mock(PhpDependExecutor.class);
    PhpDependSensor sensor = new PhpDependSensor(executor, parser);
    PhpDependConfiguration config = mock(PhpDependConfiguration.class);
    when(executor.getConfiguration()).thenReturn(config);
    when(config.getProject()).thenReturn(project);

    String reportFileNamePropertyKey = PDEPEND_REPORT_FILE_NAME_PROPERTY_KEY;
    when(configuration.getString(reportFileNamePropertyKey, DEFAULT_REPORT_FILE_NAME))
            .thenReturn("pdepend.xml");
    when(configuration.getString(REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY, DEFAULT_REPORT_FILE_PATH))
            .thenReturn("reports");
    // when(config.shouldExecuteOnProject()).thenReturn(true);
    when(configuration.getBoolean(SHOULD_RUN_PROPERTY_KEY, Boolean.parseBoolean(DEFAULT_SHOULD_RUN)))
            .thenReturn(Boolean.TRUE);
    when(project.getConfiguration()).thenReturn(configuration);
    when(project.getLanguage()).thenReturn(Php.PHP);
    when(project.getPom()).thenReturn(new MavenProject());
    assertEquals(true, sensor.shouldExecuteOnProject(project));
}

From source file:org.sonar.plugins.php.phpdepend.PhpDependSensorTest.java

@Test
public void shouldNotLaunchOnPhpProjectIfConfiguredSo() {
    Project project = mock(Project.class);
    when(project.getLanguage()).thenReturn(Php.PHP);
    ProjectFileSystem fs = mock(ProjectFileSystem.class);
    when(project.getFileSystem()).thenReturn(fs);
    when(fs.getBuildDir()).thenReturn(new File(DEFAULT_REPORT_FILE_PATH));
    Configuration configuration = mock(Configuration.class);

    PhpDependResultsParser parser = mock(PhpDependResultsParser.class);
    PhpDependExecutor executor = mock(PhpDependExecutor.class);
    PhpDependSensor sensor = new PhpDependSensor(executor, parser);
    PhpDependConfiguration config = mock(PhpDependConfiguration.class);
    when(executor.getConfiguration()).thenReturn(config);

    when(configuration.getString(PDEPEND_REPORT_FILE_NAME_PROPERTY_KEY, DEFAULT_REPORT_FILE_NAME))
            .thenReturn("pdepend.xml");
    when(configuration.getString(REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY, DEFAULT_REPORT_FILE_PATH))
            .thenReturn("reports");
    when(configuration.getBoolean(SHOULD_RUN_PROPERTY_KEY, Boolean.FALSE)).thenReturn(Boolean.FALSE);
    when(project.getConfiguration()).thenReturn(configuration);
    assertEquals(false, sensor.shouldExecuteOnProject(project));
}

From source file:org.sonar.plugins.php.phpdepend.sensor.PhpDependSensorTest.java

@Test
public void shouldLaunchOnPhpProjectIfConfiguredSo() {
    Project project = mock(Project.class);
    when(project.getLanguage()).thenReturn(Php.INSTANCE);
    ProjectFileSystem fs = mock(ProjectFileSystem.class);
    when(project.getFileSystem()).thenReturn(fs);
    when(fs.getBuildDir()).thenReturn(new File(PhpDependConfiguration.DEFAULT_REPORT_FILE_NAME));
    Configuration configuration = mock(Configuration.class);
    PhpDependSensor sensor = new PhpDependSensor();
    when(configuration.getString(PhpDependConfiguration.REPORT_FILE_NAME_PROPERTY_KEY,
            PhpDependConfiguration.DEFAULT_REPORT_FILE_NAME)).thenReturn("pdepend.xml");
    when(configuration.getString(PhpDependConfiguration.REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY,
            PhpDependConfiguration.DEFAULT_REPORT_FILE_PATH)).thenReturn("reports");
    when(configuration.getBoolean(PhpDependConfiguration.SHOULD_RUN_PROPERTY_KEY,
            Boolean.parseBoolean(PhpDependConfiguration.DEFAULT_SHOULD_RUN))).thenReturn(Boolean.TRUE);
    when(project.getConfiguration()).thenReturn(configuration);
    assertEquals(true, sensor.shouldExecuteOnProject(project));
}

From source file:org.sonar.plugins.php.phpdepend.sensor.PhpDependSensorTest.java

@Test
public void shouldNotLaunchOnPhpProjectIfConfiguredSo() {
    Project project = mock(Project.class);
    when(project.getLanguage()).thenReturn(Php.INSTANCE);
    ProjectFileSystem fs = mock(ProjectFileSystem.class);
    when(project.getFileSystem()).thenReturn(fs);
    when(fs.getBuildDir()).thenReturn(new File(PhpDependConfiguration.DEFAULT_REPORT_FILE_PATH));
    Configuration configuration = mock(Configuration.class);
    PhpDependSensor sensor = new PhpDependSensor();
    when(configuration.getString(PhpDependConfiguration.REPORT_FILE_NAME_PROPERTY_KEY,
            PhpDependConfiguration.DEFAULT_REPORT_FILE_NAME)).thenReturn("pdepend.xml");
    when(configuration.getString(PhpDependConfiguration.REPORT_FILE_RELATIVE_PATH_PROPERTY_KEY,
            PhpDependConfiguration.DEFAULT_REPORT_FILE_PATH)).thenReturn("reports");
    when(configuration.getBoolean(PhpDependConfiguration.SHOULD_RUN_PROPERTY_KEY, Boolean.FALSE))
            .thenReturn(Boolean.FALSE);
    when(project.getConfiguration()).thenReturn(configuration);
    assertEquals(false, sensor.shouldExecuteOnProject(project));
}

From source file:org.sonar.plugins.php.phpunit.PhpUnitConfiguration.java

/**
 * Instantiates a new php unit configuration.
 *
 * @param project//from   w  w  w  . j a  v a2  s  .c o  m
 *          the a project
 */
public PhpUnitConfiguration(Project project) {
    super(project);
    if (getShouldAnalyzeOnlyKey() != null) {
        // Enable dynamic anaylisis if analyze only is set or dynamic analysis is set to false
        Configuration configuration = project.getConfiguration();
        analyzeOnly = configuration.getBoolean(getShouldAnalyzeOnlyKey(), shouldAnalyzeOnlyDefault())
                || !configuration.getBoolean(SONAR_DYNAMIC_ANALYSIS, DEFAULT_SONAR_DYNAMIC_ANALYSIS);
    }
}

From source file:org.sonar.plugins.php.phpunit.PhpUnitConfiguration.java

/**
 * Should run coverage./*from   www  . j  a v  a2s.co m*/
 *
 * @return true, if successful
 */
public boolean shouldRunCoverage() {
    Configuration configuration = getProject().getConfiguration();
    return configuration.getBoolean(PHPUNIT_SHOULD_RUN_COVERAGE_PROPERTY_KEY,
            Boolean.parseBoolean(PHPUNIT_DEFAULT_SHOULD_RUN_COVERAGE));
}

From source file:org.sonar.plugins.php.phpunit.PhpUnitConfigurationTest.java

/**
 * Should get valid suffixe option.//from w  w w  . j  ava2 s  .  c  o m
 */
@Test
public void testConfigurationParameters() {
    Project project = mock(Project.class);
    Configuration c = getMockConfiguration(project);
    when(c.getBoolean(PHPUNIT_SHOULD_RUN_COVERAGE_PROPERTY_KEY, true)).thenReturn(true);

    when(project.getConfiguration()).thenReturn(c);
    PhpUnitConfiguration config = new PhpUnitConfiguration(project);
    assertEquals(true, config.shouldRunCoverage());

    when(c.getString(PHPUNIT_FILTER_PROPERTY_KEY, PHPUNIT_DEFAULT_FILTER)).thenReturn(PHPUNIT_DEFAULT_FILTER);
    assertEquals(PHPUNIT_DEFAULT_FILTER, config.getFilter());

    when(c.getString(PHPUNIT_BOOTSTRAP_PROPERTY_KEY, PHPUNIT_DEFAULT_BOOTSTRAP))
            .thenReturn(PHPUNIT_DEFAULT_BOOTSTRAP);
    assertEquals(PHPUNIT_DEFAULT_BOOTSTRAP, config.getBootstrap());

    when(c.getString(PHPUNIT_CONFIGURATION_PROPERTY_KEY, PHPUNIT_DEFAULT_CONFIGURATION))
            .thenReturn(PHPUNIT_DEFAULT_CONFIGURATION);
    assertEquals(PHPUNIT_DEFAULT_CONFIGURATION, config.getConfiguration());

    when(c.getString(PHPUNIT_LOADER_PROPERTY_KEY, PHPUNIT_DEFAULT_LOADER)).thenReturn(PHPUNIT_DEFAULT_LOADER);
    assertEquals(PHPUNIT_DEFAULT_LOADER, config.getLoader());

    when(c.getString(PHPUNIT_GROUP_PROPERTY_KEY, PHPUNIT_DEFAULT_GROUP)).thenReturn(PHPUNIT_DEFAULT_GROUP);
    assertEquals(PHPUNIT_DEFAULT_GROUP, config.getGroup());

    when(c.getString(PHPUNIT_COVERAGE_REPORT_FILE_PROPERTY_KEY, PHPUNIT_DEFAULT_COVERAGE_REPORT_FILE))
            .thenReturn(PHPUNIT_DEFAULT_COVERAGE_REPORT_FILE);
    File expectedReportFile = new File(project.getFileSystem().getBuildDir(),
            config.getReportFileRelativePath() + File.separator + PHPUNIT_DEFAULT_COVERAGE_REPORT_FILE);
    assertEquals(expectedReportFile, config.getCoverageReportFile());

}