List of usage examples for org.apache.commons.configuration PropertiesConfiguration setProperty
public void setProperty(String key, Object value)
From source file:org.sonar.plugins.dbcleaner.period.PeriodsTest.java
@Test public void getDateShouldReturnCurrentTimeMinusDesiredMonths() { Project project = new Project("myproject"); PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty("KEY", "2"); project.setConfiguration(conf);/*w ww . jav a2 s . c om*/ Date date = Periods.getDate(conf, "KEY", "2"); GregorianCalendar calendar = new GregorianCalendar(); calendar.add(GregorianCalendar.MONTH, -2); Date expectedDate = calendar.getTime(); assertThat(date.getMonth(), is(expectedDate.getMonth())); }
From source file:org.sonar.plugins.l10n.L10nHackyPropertiesUpdater.java
public static void main(String[] args) throws ConfigurationException, IOException { URL l10nRoot = FrenchPackPlugin.class.getResource(BundleSynchronizedMatcher.L10N_PATH); Collection<File> bundles = FileUtils.listFiles(FileUtils.toFile(l10nRoot), new String[] { "properties" }, false);// w w w . jav a 2s . c o m for (File localizedBundle : bundles) { String originalVersion = localizedBundle.getName().replaceFirst("_fr\\.", "."); System.out.println("Processing " + localizedBundle + " looking for " + originalVersion); URL originalBundle = FrenchPackPlugin.class .getResource(BundleSynchronizedMatcher.L10N_PATH + originalVersion); if (originalBundle == null) { System.out.println("\tOriginal bundle not found"); } else { System.out.println("\tOriginal bundle found, let's try to update the localized version"); Properties localizedProps = new Properties(); localizedProps.load(new FileInputStream(localizedBundle)); PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config); layout.load(new InputStreamReader(FrenchPackPlugin.class .getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + originalVersion))); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(); it.hasNext();) { String key = it.next(); Object localizedValue = localizedProps.get(key); if (localizedValue != null) { config.setProperty(key, localizedValue); } else { System.out.println("Nothing found for " + key); String currentValue = config.getString(key); config.setProperty(key, currentValue + " <== TODO"); } } layout.save(new FileWriter(localizedBundle)); System.out.println("\tFixing spaces"); fixSpacesAroundEqualsAndScrewUpEncoding(localizedBundle); System.out.println("OK: file " + localizedBundle + " contains ready-to-translate updated file."); } } }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferSensorTest.java
@Test public void shouldNotLaunchWhenShouldRunSetToFalseAndSkipNotSet() { Project project = mock(Project.class); PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty(PHPCS_SHOULD_RUN_KEY, false); when(project.getLanguage()).thenReturn(Php.PHP); when(project.getConfiguration()).thenReturn(config); PhpCodesnifferSensor sensor = new PhpCodesnifferSensor(null, null, null); assertEquals(false, sensor.shouldExecuteOnProject(project)); }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferSensorTest.java
@Test public void shouldLaunchWhenShouldRunSetToTrueAndSkipNotSet() { Project project = mock(Project.class); RulesProfile profile = mock(RulesProfile.class); PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty(PHPCS_SHOULD_RUN_KEY, true); when(project.getLanguage()).thenReturn(Php.PHP); when(project.getConfiguration()).thenReturn(config); when(project.getReuseExistingRulesConfig()).thenReturn(true); List<ActiveRule> activeRules = new ArrayList<ActiveRule>(); activeRules.add(mock(ActiveRule.class)); when(profile.getActiveRulesByRepository(PHPCS_REPOSITORY_KEY)).thenReturn(activeRules); PhpCodesnifferSensor sensor = new PhpCodesnifferSensor(null, null, profile); assertEquals(true, sensor.shouldExecuteOnProject(project)); }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferSensorTest.java
@Test public void shouldNotLaunchWhenSkipSetToTrueAndShouldRunNotSet() { Project project = mock(Project.class); PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty(PHPCS_SKIP_KEY, true); when(project.getLanguage()).thenReturn(Php.PHP); when(project.getConfiguration()).thenReturn(config); PhpCodesnifferSensor sensor = new PhpCodesnifferSensor(null, null, null); assertEquals(false, sensor.shouldExecuteOnProject(project)); }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferSensorTest.java
@Test public void shouldLaunchWhenSkipSetToFalseAndShouldRunNotSet() { Project project = mock(Project.class); RulesProfile profile = mock(RulesProfile.class); PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty(PHPCS_SKIP_KEY, false); when(project.getLanguage()).thenReturn(Php.PHP); when(project.getConfiguration()).thenReturn(config); when(project.getReuseExistingRulesConfig()).thenReturn(true); List<ActiveRule> activeRules = new ArrayList<ActiveRule>(); activeRules.add(mock(ActiveRule.class)); when(profile.getActiveRulesByRepository(PHPCS_REPOSITORY_KEY)).thenReturn(activeRules); PhpCodesnifferSensor sensor = new PhpCodesnifferSensor(null, null, profile); assertEquals(true, sensor.shouldExecuteOnProject(project)); }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferSensorTest.java
@Test public void shouldNotLaunchIgnoringShouldRunValueWhenSkipSetToTrue() { Project project = mock(Project.class); RulesProfile profile = mock(RulesProfile.class); PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty(PHPCS_SKIP_KEY, true); config.setProperty(PHPCS_SHOULD_RUN_KEY, false); when(project.getLanguage()).thenReturn(Php.PHP); when(project.getConfiguration()).thenReturn(config); when(project.getReuseExistingRulesConfig()).thenReturn(true); List<ActiveRule> activeRules = new ArrayList<ActiveRule>(); activeRules.add(mock(ActiveRule.class)); when(profile.getActiveRulesByRepository(PHPCS_REPOSITORY_KEY)).thenReturn(activeRules); PhpCodesnifferSensor sensor = new PhpCodesnifferSensor(null, null, profile); assertEquals(false, sensor.shouldExecuteOnProject(project)); }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferSensorTest.java
@Test public void shouldLaunchIgnoringShouldRunValueWhenSkipSetToFalse() { Project project = mock(Project.class); RulesProfile profile = mock(RulesProfile.class); PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty(PHPCS_SKIP_KEY, false); config.setProperty(PHPCS_SHOULD_RUN_KEY, true); when(project.getLanguage()).thenReturn(Php.PHP); when(project.getConfiguration()).thenReturn(config); when(project.getReuseExistingRulesConfig()).thenReturn(true); List<ActiveRule> activeRules = new ArrayList<ActiveRule>(); activeRules.add(mock(ActiveRule.class)); when(profile.getActiveRulesByRepository(PHPCS_REPOSITORY_KEY)).thenReturn(activeRules); PhpCodesnifferSensor sensor = new PhpCodesnifferSensor(null, null, profile); assertEquals(true, sensor.shouldExecuteOnProject(project)); }
From source file:org.sonar.plugins.php.cpd.PhpPhpCpdSensorTest.java
@Test public void testShouldNotExecuteOnProjectWithNulPom() { Project project = createProject();/* www .j a va 2 s . c om*/ project.setLanguage(Java.INSTANCE); project.setPom(null); PropertiesConfiguration conf = (PropertiesConfiguration) project.getConfiguration(); conf.setProperty("sonar.cpd.skip", "false"); testShouldRun(project, false); }
From source file:org.sonar.plugins.php.cpd.PhpPhpCpdSensorTest.java
@Test public void testShouldNotExecuteOnNonPhpProject() { Project project = createProject();/*from w w w .j a va2s. c o m*/ project.setLanguage(Java.INSTANCE); PropertiesConfiguration conf = (PropertiesConfiguration) project.getConfiguration(); conf.setProperty("sonar.cpd.skip", "false"); testShouldRun(project, false); }