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

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

Introduction

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

Prototype

boolean containsKey(String key);

Source Link

Document

Check if the configuration contains the specified key.

Usage

From source file:org.sonar.plugins.clover.CloverMavenInitializer.java

@Override
public void execute(Project project) {
    Configuration conf = project.getConfiguration();
    if (!conf.containsKey(CloverConstants.REPORT_PATH_PROPERTY)) {
        String report = getReportPathFromPluginConfiguration(project);
        if (report == null) {
            report = getDefaultReportPath(project);
        }//w  w  w . ja  v a  2  s. com
        conf.setProperty(CloverConstants.REPORT_PATH_PROPERTY, report);
    }
}

From source file:org.sonar.plugins.cobertura.CoberturaMavenInitializer.java

@Override
public void execute(Project project) {
    Configuration conf = project.getConfiguration();
    if (conf.containsKey(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)) {
        String report = getReportPathFromPluginConfiguration(project);
        if (report == null) {
            report = getDefaultReportPath(project);
        }// w  w w  . j  a v a  2 s .  c  o  m
        conf.setProperty(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY, report);
    }
}

From source file:org.sonar.plugins.cobertura.CoberturaMavenInitializerTest.java

@Test
public void doNotSetReportPathIfAlreadyConfigured() {
    Configuration configuration = mock(Configuration.class);
    when(configuration.containsKey(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn(true);
    when(project.getConfiguration()).thenReturn(configuration);
    initializer.execute(project);//from ww w  .j a  v  a 2  s  . c  om
    verify(configuration, never()).setProperty(eq(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY), anyString());
}

From source file:org.sonar.plugins.emma.EmmaMavenInitializer.java

@Override
public void execute(Project project) {
    Configuration conf = project.getConfiguration();
    if (!conf.containsKey(EmmaPlugin.REPORT_PATH_PROPERTY)) {
        String report = getReportFromPluginConfiguration(project);
        if (report == null) {
            report = getReportFromDefaultPath(project);
        }//w  w w .  j a  va  2  s .  co m
        conf.setProperty(EmmaPlugin.REPORT_PATH_PROPERTY, report);
    }
}

From source file:org.sonar.plugins.emma.EmmaMavenInitializerTest.java

@Test
public void doNotSetReportPathIfAlreadyConfigured() {
    Configuration configuration = mock(Configuration.class);
    when(configuration.containsKey(EmmaPlugin.REPORT_PATH_PROPERTY)).thenReturn(true);
    when(project.getConfiguration()).thenReturn(configuration);
    initializer.execute(project);//www.j a  v a  2 s.co  m
    verify(configuration, never()).setProperty(eq(EmmaPlugin.REPORT_PATH_PROPERTY), anyString());
}

From source file:org.sonar.plugins.findbugs.FindbugsMavenInitializer.java

@Override
public void execute(Project project) {
    Configuration conf = project.getConfiguration();
    if (!conf.containsKey(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY)) {
        conf.setProperty(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY,
                getExcludesFiltersFromPluginConfiguration(project));
    }/*  ww  w  .  ja  v  a  2s .c  o  m*/
}

From source file:org.sonar.plugins.findbugs.FindbugsMavenInitializerTest.java

@Test
public void doNotSetExcludesFiltersIfAlreadyConfigured() {
    Configuration configuration = mock(Configuration.class);
    when(configuration.containsKey(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY)).thenReturn(true);
    when(project.getConfiguration()).thenReturn(configuration);
    initializer.execute(project);//w w w  . j a  v  a2s .co  m
    verify(configuration, never()).setProperty(eq(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY), anyString());
}

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

/**
 * @see org.sonar.plugins.php.core.PhpPluginAbstractExecutor#getCommandLine()
 *///ww w  .j  av a2 s  . c o m
@Override
protected List<String> getCommandLine() {
    List<String> result = new ArrayList<String>();
    result.add(configuration.getOsDependentToolScriptName());
    Configuration c = configuration.getProject().getConfiguration();
    addBasicOptions(result);

    boolean useMaintTestClass = true;
    if (configuration.isStringPropertySet(PHPUNIT_CONFIGURATION_PROPERTY_KEY)) {
        result.add(PHPUNIT_CONFIGURATION_OPTION + configuration.getConfiguration());
        useMaintTestClass = false;
    }
    addExtendedOptions(result, c);
    if (useMaintTestClass && configuration.isStringPropertySet(PHPUNIT_MAIN_TEST_FILE_PROPERTY_KEY)) {
        result.add(project.getName());
        result.add(configuration.getMainTestClass());
    }
    // source directory is appended phpunit.
    if (!useMaintTestClass || !c.containsKey(PHPUNIT_ANALYZE_TEST_DIRECTORY_KEY)
            || c.getBoolean(PHPUNIT_ANALYZE_TEST_DIRECTORY_KEY)) {
        result.add(getTestDirectoryOrFiles());
    }
    return result;
}

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

/**
 * @param result//from   w  w w.j  a v  a2s . c  o  m
 * @param c
 */
private void addExtendedOptions(List<String> result, Configuration c) {
    if (configuration.isStringPropertySet(PHPUNIT_LOADER_PROPERTY_KEY)) {
        result.add(PHPUNIT_LOADER_OPTION + configuration.getLoader());
    }
    if (configuration.isStringPropertySet(PHPUNIT_GROUP_PROPERTY_KEY)) {
        result.add(PHPUNIT_GROUP_OPTION + configuration.getGroup());
    }
    if (configuration.isStringPropertySet(PHPUNIT_ARGUMENT_LINE_KEY)) {
        result.add(configuration.getArgumentLine());
    }
    if (c.containsKey(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)
            && c.getBoolean(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)) {
        result.add(PHPUNIT_IGNORE_CONFIGURATION_OPTION);
    }
    result.add(PHPUNIT_LOG_JUNIT_OPTION + configuration.getReportFile());
    if (configuration.shouldRunCoverage()) {
        result.add(PHPUNIT_COVERAGE_CLOVER_OPTION + configuration.getCoverageReportFile());
    }
}

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

@Test
public void testIgnoreDefaultConfigurationFile() {
    PhpUnitConfiguration config = mock(PhpUnitConfiguration.class);
    Project project = mock(Project.class);
    MavenProject mProject = mock(MavenProject.class);
    when(project.getPom()).thenReturn(mProject);
    when(mProject.getBasedir()).thenReturn(new File("toto"));

    Configuration configuration = mock(Configuration.class);
    when(project.getConfiguration()).thenReturn(configuration);
    when(config.getProject()).thenReturn(project);

    when(configuration.containsKey(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(true);
    when(configuration.getBoolean(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(true);

    String phpunit = "phpunit";
    when(config.getOsDependentToolScriptName()).thenReturn(phpunit);
    ProjectFileSystem pfs = mock(ProjectFileSystem.class);
    when(project.getFileSystem()).thenReturn(pfs);
    File testDir = new File("c:/php/math-php-test/sources/test");
    when(project.getFileSystem().getTestDirs()).thenReturn(Arrays.asList(testDir));

    PhpUnitExecutor executor = new PhpUnitExecutor(config, project);
    when(config.shouldRunCoverage()).thenReturn(false);
    when(config.getCoverageReportFile()).thenReturn(new File("phpUnit.coverage.xml"));
    File reportFile = new File("phpunit.xml");
    when(config.getReportFile()).thenReturn(reportFile);

    List<String> commandLine = executor.getCommandLine();
    assertThat(commandLine).isNotEmpty();
    assertThat(commandLine).contains(PHPUNIT_IGNORE_CONFIGURATION_OPTION);

    List<String> expected = Arrays.asList(phpunit, "--no-configuration", "--log-junit=" + reportFile,
            testDir.toString());//from  ww  w .ja v a  2  s. c  o m
    assertThat(commandLine).isEqualTo(expected);
}