long startup = System.currentTimeMillis();
Long lastTimestampInCache = getLastTimestampInCache(projectId);
- // TODO Temporary disable cache until cache eviction is ok
- // if (lastTimestampInCache == null || !isValid(projectId, lastTimestampInCache)) {
- lastTimestampInCache = System.nanoTime();
- cleanCache(projectId);
- createNewDatabaseForDryRun(projectId, startup, lastTimestampInCache);
- // }
+ if (lastTimestampInCache == null || !isValid(projectId, lastTimestampInCache)) {
+ lastTimestampInCache = System.nanoTime();
+ cleanCache(projectId);
+ createNewDatabaseForDryRun(projectId, startup, lastTimestampInCache);
+ }
return dbFileContent(projectId, lastTimestampInCache);
}
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
}
@Test
- @Ignore
public void should_reuse_database_without_project() throws IOException, SQLException {
setupData("should_create_database");
}
@Test
- @Ignore
public void should_reuse_database_with_project() throws IOException, SQLException {
setupData("should_create_database");
*/
package org.sonar.api.config;
+import org.sonar.api.ServerExtension;
+
import javax.annotation.Nullable;
/**
*
* @since 3.0
*/
-public abstract class GlobalPropertyChangeHandler implements SettingsChangeHandler {
+public abstract class GlobalPropertyChangeHandler implements ServerExtension {
public static final class PropertyChange {
private String key;
*/
public abstract void onChange(PropertyChange change);
- @Override
- public void onChange(SettingsChange change) {
- if (change.isGlobal()) {
- onChange(PropertyChange.create(change.key(), change.newValue()));
- }
- }
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.config;
-
-import org.sonar.api.ServerExtension;
-
-import javax.annotation.Nullable;
-
-/**
- * Observe changes of properties done from web application. It does not support :
- * <ul>
- * <li>changes done programmatically on the component org.sonar.api.config.Settings</li>
- * <li>changes done when restoring settings from XML using backup/restore feature</li>
- * </ul>
- *
- * @since 4.0
- */
-public interface SettingsChangeHandler extends ServerExtension {
-
- public static final class SettingsChange {
- private String key;
- private String newValue;
- private String componentKey;
- private String userLogin;
-
- private SettingsChange(String key, @Nullable String newValue, @Nullable String componentKey, @Nullable String userLogin) {
- this.key = key;
- this.newValue = newValue;
- this.componentKey = componentKey;
- this.userLogin = userLogin;
- }
-
- public static SettingsChange create(String key, @Nullable String newValue, @Nullable String componentKey, @Nullable String userLogin) {
- return new SettingsChange(key, newValue, componentKey, userLogin);
- }
-
- public String key() {
- return key;
- }
-
- public String newValue() {
- return newValue;
- }
-
- public String componentKey() {
- return componentKey;
- }
-
- public String userLogin() {
- return userLogin;
- }
-
- public boolean isGlobal() {
- return componentKey == null && userLogin == null;
- }
-
- @Override
- public String toString() {
- return String.format("[key=%s, newValue=%s, componentKey=%s]", key, newValue, componentKey);
- }
- }
-
- /**
- * This method gets called when a property is changed.
- */
- public void onChange(SettingsChange change);
-
-}
this.session = session;
backupables.add(new MetricsBackup(session));
- backupables.add(new PropertiesBackup(persistentSettings, cleanDryRunCache));
+ backupables.add(new PropertiesBackup(persistentSettings));
// Note that order is important, because profile can have reference to rule
backupables.add(new RulesBackup(session));
backupables.add(new ProfilesBackup(session));
import org.sonar.core.persistence.DryRunDatabaseFactory;
import org.sonar.core.properties.PropertyDto;
import org.sonar.server.platform.PersistentSettings;
-import org.sonar.server.startup.CleanDryRunCache;
import java.util.List;
import java.util.Map;
private final PersistentSettings persistentSettings;
- private final CleanDryRunCache cleanDryRunCache;
-
- public PropertiesBackup(PersistentSettings persistentSettings, CleanDryRunCache cleanDryRunCache) {
+ public PropertiesBackup(PersistentSettings persistentSettings) {
this.persistentSettings = persistentSettings;
- this.cleanDryRunCache = cleanDryRunCache;
}
public void exportXml(SonarConfig sonarConfig) {
persistentSettings.deleteProperties();
persistentSettings.saveProperties(properties);
- cleanDryRunCache.clean();
}
public void configure(XStream xStream) {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform;
-
-import org.sonar.api.config.SettingsChangeHandler;
-import org.sonar.core.resource.ResourceDao;
-
-public class DryRunCacheListener implements SettingsChangeHandler {
-
- private final PersistentSettings settings;
- private final ResourceDao resourceDao;
-
- public DryRunCacheListener(PersistentSettings settings, ResourceDao resourceDao) {
- this.settings = settings;
- this.resourceDao = resourceDao;
- }
-
- @Override
- public void onChange(SettingsChange change) {
- // TODO Temporary disable cache eviction
- // if (change.isGlobal()) {
- // settings.saveProperty(DryRunDatabaseFactory.SONAR_DRY_RUN_CACHE_LAST_UPDATE_KEY, String.valueOf(System.nanoTime()));
- // } else if (change.componentKey() != null) {
- // ResourceDto rootProject = resourceDao.getRootProjectByComponentKey(change.componentKey());
- // settings.saveProperty(DryRunDatabaseFactory.getCacheLastUpdateKey(rootProject.getId()), String.valueOf(System.nanoTime()));
- // }
- }
-}
coreContainer.addSingleton(ThreadLocalDatabaseSessionFactory.class);
coreContainer.addPicoAdapter(new DatabaseSessionProvider());
coreContainer.addSingleton(ServerMetadataPersister.class);
- coreContainer.addSingleton(DryRunCacheListener.class);
coreContainer.addSingleton(CleanDryRunCache.class);
coreContainer.startComponents();
}
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.ServerComponent;
-import org.sonar.api.config.SettingsChangeHandler;
-import org.sonar.core.resource.ResourceDao;
-import org.sonar.core.resource.ResourceDto;
-import org.sonar.core.user.UserDao;
-import org.sonar.core.user.UserDto;
+import org.sonar.api.config.GlobalPropertyChangeHandler;
import javax.annotation.Nullable;
public class SettingsChangeNotifier implements ServerComponent {
@VisibleForTesting
- SettingsChangeHandler[] changeHandlers;
- private final ResourceDao resourceDao;
- private final UserDao userDao;
+ GlobalPropertyChangeHandler[] changeHandlers;
- public SettingsChangeNotifier(ResourceDao resourceDao, UserDao userDao, SettingsChangeHandler[] changeHandlers) {
- this.resourceDao = resourceDao;
- this.userDao = userDao;
+ public SettingsChangeNotifier(GlobalPropertyChangeHandler[] changeHandlers) {
this.changeHandlers = changeHandlers;
}
- public SettingsChangeNotifier(ResourceDao resourceDao, UserDao userDao) {
- this(resourceDao, userDao, new SettingsChangeHandler[0]);
+ public SettingsChangeNotifier() {
+ this(new GlobalPropertyChangeHandler[0]);
}
- public void onPropertyChange(String key, @Nullable String value, @Nullable Long componentId, @Nullable Long userId) {
- String resourceKey = null;
- if (componentId != null) {
- ResourceDto resource = resourceDao.getResource(componentId);
- resourceKey = resource != null ? resource.getKey() : null;
- }
- String userLogin = null;
- if (userId != null) {
- UserDto user = userDao.getUser(userId);
- userLogin = user != null ? user.getLogin() : null;
- }
- SettingsChangeHandler.SettingsChange change = SettingsChangeHandler.SettingsChange.create(key, value, resourceKey, userLogin);
- for (SettingsChangeHandler changeHandler : changeHandlers) {
+ public void onGlobalPropertyChange(String key, @Nullable String value) {
+ GlobalPropertyChangeHandler.PropertyChange change = GlobalPropertyChangeHandler.PropertyChange.create(key, value);
+ for (GlobalPropertyChangeHandler changeHandler : changeHandlers) {
changeHandler.onChange(change);
}
}
return get(ProfilesManager.class);
}
- public void updateProperty(String key, @Nullable String value, @Nullable Long componentId, @Nullable Long userId) {
- if (componentId == null && userId == null) {
- get(ServerSettings.class).setProperty(key, value);
- }
- get(SettingsChangeNotifier.class).onPropertyChange(key, value, componentId, userId);
+ public void setGlobalProperty(String key, @Nullable String value) {
+ get(ServerSettings.class).setProperty(key, value);
+ get(SettingsChangeNotifier.class).onGlobalPropertyChange(key, value);
}
public Settings getSettings() {
private
def self.setGlobalProperty(key, value, resource_id, user_id)
- Api::Utils.java_facade.updateProperty(key, value, resource_id && resource_id.to_i, user_id && user_id.to_i)
+ Api::Utils.java_facade.setGlobalProperty(key, value) unless (resource_id || user_id)
end
def self.all(key, resource_id=nil, user_id=nil)
import org.apache.commons.lang.CharEncoding;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.configuration.Property;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleParam;
import org.sonar.api.rules.RulePriority;
-import org.sonar.server.startup.CleanDryRunCache;
import java.io.IOException;
import java.io.InputStream;
public class BackupTest {
- private CleanDryRunCache cleanDryRunCache;
-
- @Before
- public void prepare() {
- this.cleanDryRunCache = mock(CleanDryRunCache.class);
- }
-
@Test
public void shouldExportXml() throws Exception {
SonarConfig sonarConfig = getSonarConfig();
@Test
public void shouldReturnAValidXml() throws Exception {
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache),
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null),
new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null)));
SonarConfig sonarConfig = getSonarConfig();
sonarConfig.setMetrics(getMetrics());
public void shouldExportXmlInCdata() throws Exception {
SonarConfig sonarConfig = getSonarConfig();
sonarConfig.setProperties(getPropertiesWithXmlIlliciteCharacters());
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache)));
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
String xml = backup.getXmlFromSonarConfig(sonarConfig);
assertXmlAreSimilar(xml, "backup-with-cdata.xml");
public void shouldExportXmlWithUtf8Characters() throws Exception {
SonarConfig sonarConfig = getSonarConfig();
sonarConfig.setProperties(getPropertiesWithUtf8Characters());
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache)));
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
String xml = backup.getXmlFromSonarConfig(sonarConfig);
assertXmlAreSimilar(xml, "backup-with-utf8-char.xml");
@Test
public void shouldImportXml() {
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache),
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null),
new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null)));
String xml = getFileFromClasspath("backup-restore-valid.xml");
@Test
public void shouldImportXmlWithoutInheritanceInformation() {
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache),
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null),
new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null)));
String xml = getFileFromClasspath("backup-restore-without-inheritance.xml");
@Test
public void shouldImportXmlWithXmlIlliciteCharacters() {
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache)));
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
String xml = getFileFromClasspath("backup-with-cdata.xml");
SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml);
@Test
public void shouldImportOneDotFiveFormat() {
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache)));
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
String xml = getFileFromClasspath("shouldImportOneDotFiveFormat.xml");
SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml);
@Test
public void shouldImportXmlWithUtf8Character() {
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache)));
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
String xml = getFileFromClasspath("backup-with-utf8-char.xml");
SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml);
@Test
public void shouldNotImportMetricIds() {
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache)));
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
String xml = getFileFromClasspath("backup-with-id-for-metrics.xml");
SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml);
SonarConfig sonarConfig = getSonarConfig();
sonarConfig.setProperties(getPropertiesWithCDATA());
- Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache)));
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
String xml = backup.getXmlFromSonarConfig(sonarConfig);
assertXmlAreSimilar(xml, "backup-with-splitted-cdata.xml");
import org.sonar.api.database.configuration.Property;
import org.sonar.core.properties.PropertyDto;
import org.sonar.server.platform.PersistentSettings;
-import org.sonar.server.startup.CleanDryRunCache;
import java.util.Arrays;
import java.util.Collection;
@Before
public void setup() {
persistentSettings = mock(PersistentSettings.class);
- backup = new PropertiesBackup(persistentSettings, mock(CleanDryRunCache.class));
+ backup = new PropertiesBackup(persistentSettings);
}
@Test
import org.junit.Test;
import org.mockito.ArgumentMatcher;
-import org.sonar.api.config.SettingsChangeHandler;
-import org.sonar.core.resource.ResourceDao;
-import org.sonar.core.user.UserDao;
+import org.sonar.api.config.GlobalPropertyChangeHandler;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
public class SettingsChangeNotifierTest {
@Test
public void onGlobalPropertyChange() {
- SettingsChangeHandler handler = mock(SettingsChangeHandler.class);
- SettingsChangeNotifier notifier = new SettingsChangeNotifier(mock(ResourceDao.class), mock(UserDao.class), new SettingsChangeHandler[] {handler});
+ GlobalPropertyChangeHandler handler = mock(GlobalPropertyChangeHandler.class);
+ SettingsChangeNotifier notifier = new SettingsChangeNotifier(new GlobalPropertyChangeHandler[] {handler});
- notifier.onPropertyChange("foo", "bar", null, null);
+ notifier.onGlobalPropertyChange("foo", "bar");
- verify(handler).onChange(argThat(new ArgumentMatcher<SettingsChangeHandler.SettingsChange>() {
+ verify(handler).onChange(argThat(new ArgumentMatcher<GlobalPropertyChangeHandler.PropertyChange>() {
@Override
public boolean matches(Object o) {
- SettingsChangeHandler.SettingsChange change = (SettingsChangeHandler.SettingsChange) o;
- return change.key().equals("foo") && change.newValue().equals("bar") && change.componentKey() == null && change.userLogin() == null;
+ GlobalPropertyChangeHandler.PropertyChange change = (GlobalPropertyChangeHandler.PropertyChange) o;
+ return change.getKey().equals("foo") && change.getNewValue().equals("bar");
}
}));
}
@Test
public void no_handlers() {
- SettingsChangeNotifier notifier = new SettingsChangeNotifier(mock(ResourceDao.class), mock(UserDao.class));
+ SettingsChangeNotifier notifier = new SettingsChangeNotifier();
assertThat(notifier.changeHandlers).isEmpty();
// does not fail
- notifier.onPropertyChange("foo", "bar", null, null);
+ notifier.onGlobalPropertyChange("foo", "bar");
}
}