summaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/java
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-09-04 10:57:46 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-09-04 10:58:30 +0200
commit72dd489edde6829eeb1bcc53be0ed6913b2fd1d2 (patch)
tree07cf5b7dfa81cf09d0870a5a5b30861019a10abb /sonar-server/src/main/java
parentd3fad486224567cbef53cb97c40f857990220a67 (diff)
downloadsonarqube-72dd489edde6829eeb1bcc53be0ed6913b2fd1d2.tar.gz
sonarqube-72dd489edde6829eeb1bcc53be0ed6913b2fd1d2.zip
SONAR-4602 Invalidate dryRun cache when changing quality profiles
Diffstat (limited to 'sonar-server/src/main/java')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/Backup.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java26
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java21
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/CleanDryRunCache.java34
6 files changed, 49 insertions, 46 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java
index 8f52f8d9955..1af960ed226 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java
@@ -30,9 +30,9 @@ import org.apache.commons.lang.CharEncoding;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.sonar.api.database.DatabaseSession;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.server.platform.PersistentSettings;
-import org.sonar.server.startup.CleanDryRunCache;
import javax.annotation.Nullable;
@@ -55,7 +55,7 @@ public class Backup {
backupables = new ArrayList<Backupable>();
}
- public Backup(DatabaseSession session, PersistentSettings persistentSettings, CleanDryRunCache cleanDryRunCache) {
+ public Backup(DatabaseSession session, PersistentSettings persistentSettings, DryRunCache dryRunCache) {
this();
this.session = session;
@@ -63,7 +63,7 @@ public class Backup {
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));
+ backupables.add(new ProfilesBackup(session, dryRunCache));
}
/**
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
index fa9e337d966..397182c7134 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
@@ -31,10 +31,20 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.measures.Metric;
import org.sonar.api.profiles.Alert;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.*;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.ActiveRuleParam;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleParam;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.jpa.dao.RulesDao;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
public class ProfilesBackup implements Backupable {
@@ -52,9 +62,11 @@ public class ProfilesBackup implements Backupable {
private Collection<RulesProfile> profiles;
private DatabaseSession session;
+ private DryRunCache dryRunCache;
- public ProfilesBackup(DatabaseSession session) {
+ public ProfilesBackup(DatabaseSession session, DryRunCache dryRunCache) {
this.session = session;
+ this.dryRunCache = dryRunCache;
}
/**
@@ -95,7 +107,7 @@ public class ProfilesBackup implements Backupable {
public void importXml(SonarConfig sonarConfig) {
if (sonarConfig.getProfiles() != null && !sonarConfig.getProfiles().isEmpty()) {
LoggerFactory.getLogger(getClass()).info("Delete profiles");
- ProfilesManager profilesManager = new ProfilesManager(session, null);
+ ProfilesManager profilesManager = new ProfilesManager(session, null, dryRunCache);
profilesManager.deleteAllProfiles();
RulesDao rulesDao = new RulesDao(session);
@@ -122,7 +134,7 @@ public class ProfilesBackup implements Backupable {
private void importAlerts(RulesProfile profile) {
if (profile.getAlerts() != null) {
- for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext(); ) {
+ for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext();) {
Alert alert = ia.next();
Metric unMarshalledMetric = alert.getMetric();
String validKey = unMarshalledMetric.getKey();
@@ -139,7 +151,7 @@ public class ProfilesBackup implements Backupable {
}
private void importActiveRules(RulesDao rulesDao, RulesProfile profile) {
- for (Iterator<ActiveRule> iar = profile.getActiveRules(true).iterator(); iar.hasNext(); ) {
+ for (Iterator<ActiveRule> iar = profile.getActiveRules(true).iterator(); iar.hasNext();) {
ActiveRule activeRule = iar.next();
Rule unMarshalledRule = activeRule.getRule();
Rule matchingRuleInDb = rulesDao.getRuleByKey(unMarshalledRule.getRepositoryKey(), unMarshalledRule.getKey());
@@ -151,7 +163,7 @@ public class ProfilesBackup implements Backupable {
activeRule.setRule(matchingRuleInDb);
activeRule.setRulesProfile(profile);
activeRule.getActiveRuleParams();
- for (Iterator<ActiveRuleParam> irp = activeRule.getActiveRuleParams().iterator(); irp.hasNext(); ) {
+ for (Iterator<ActiveRuleParam> irp = activeRule.getActiveRuleParams().iterator(); irp.hasNext();) {
ActiveRuleParam activeRuleParam = irp.next();
RuleParam unMarshalledRP = activeRuleParam.getRuleParam();
RuleParam matchingRPInDb = rulesDao.getRuleParam(matchingRuleInDb, unMarshalledRP.getKey());
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
index 2a040e860e3..11dde4538e2 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
@@ -24,30 +24,37 @@ import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.*;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.ActiveRuleChange;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleParam;
+import org.sonar.api.rules.RulePriority;
import org.sonar.api.utils.ValidationMessages;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.jpa.dao.BaseDao;
import org.sonar.jpa.dao.RulesDao;
import java.util.List;
-
public class ProfilesManager extends BaseDao {
private RulesDao rulesDao;
+ private DryRunCache dryRunCache;
- public ProfilesManager(DatabaseSession session, RulesDao rulesDao) {
+ public ProfilesManager(DatabaseSession session, RulesDao rulesDao, DryRunCache dryRunCache) {
super(session);
this.rulesDao = rulesDao;
+ this.dryRunCache = dryRunCache;
}
public void copyProfile(int profileId, String newProfileName) {
RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "id", profileId);
RulesProfile toImport = (RulesProfile) profile.clone();
toImport.setName(newProfileName);
- ProfilesBackup pb = new ProfilesBackup(getSession());
+ ProfilesBackup pb = new ProfilesBackup(getSession(), dryRunCache);
pb.importProfile(rulesDao, toImport);
getSession().commit();
+ dryRunCache.reportGlobalModification();
}
public void deleteAllProfiles() {
@@ -60,6 +67,7 @@ public class ProfilesManager extends BaseDao {
getSession().removeWithoutFlush(profile);
}
getSession().commit();
+ dryRunCache.reportGlobalModification();
}
// Managing inheritance of profiles
@@ -89,6 +97,7 @@ public class ProfilesManager extends BaseDao {
profile.setParentName(newParent == null ? null : newParent.getName());
getSession().saveWithoutFlush(profile);
getSession().commit();
+ dryRunCache.reportGlobalModification();
}
return messages;
}
@@ -116,6 +125,7 @@ public class ProfilesManager extends BaseDao {
removeActiveRule(activeRuleToRemove);
}
getSession().commit();
+ dryRunCache.reportGlobalModification();
}
/**
@@ -168,6 +178,7 @@ public class ProfilesManager extends BaseDao {
activateOrChange(child, parentActiveRule, userName);
}
getSession().commit();
+ dryRunCache.reportGlobalModification();
}
/**
@@ -181,6 +192,7 @@ public class ProfilesManager extends BaseDao {
deactivate(child, parentActiveRule.getRule(), userName);
}
getSession().commit();
+ dryRunCache.reportGlobalModification();
}
/**
@@ -216,6 +228,7 @@ public class ProfilesManager extends BaseDao {
}
getSession().commit();
+ dryRunCache.reportGlobalModification();
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java
index 8dac49cfe9b..196af403ecb 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java
@@ -25,7 +25,7 @@ import com.thoughtworks.xstream.XStream;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.configuration.Property;
-import org.sonar.core.persistence.DryRunDatabaseFactory;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.core.properties.PropertyDto;
import org.sonar.server.platform.PersistentSettings;
@@ -83,7 +83,7 @@ public class PropertiesBackup implements Backupable {
// default permissions properties should not be exported as they reference permission_templates entries in the DB
return !CoreProperties.SERVER_ID.equals(propertyKey)
&& !propertyKey.startsWith(PERMISSION_PROPERTIES_PREFIX)
- && !propertyKey.startsWith(DryRunDatabaseFactory.SONAR_DRY_RUN_CACHE_KEY_PREFIX);
+ && !DryRunCache.SONAR_DRY_RUN_CACHE_LAST_UPDATE_KEY.equals(propertyKey);
}
private boolean shouldNotBeErased(String propertyKey) {
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 65acf75027f..55f07767e23 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -37,6 +37,7 @@ import org.sonar.api.utils.TimeProfiler;
import org.sonar.api.utils.UriReader;
import org.sonar.core.component.SnapshotPerspectives;
import org.sonar.core.config.Logback;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.core.i18n.GwtI18n;
import org.sonar.core.i18n.I18nManager;
import org.sonar.core.i18n.RuleI18nManager;
@@ -258,7 +259,6 @@ public final class Platform {
coreContainer.addSingleton(ThreadLocalDatabaseSessionFactory.class);
coreContainer.addPicoAdapter(new DatabaseSessionProvider());
coreContainer.addSingleton(ServerMetadataPersister.class);
- coreContainer.addSingleton(CleanDryRunCache.class);
coreContainer.startComponents();
}
@@ -305,6 +305,7 @@ public final class Platform {
servicesContainer.addSingleton(MeasureFilterExecutor.class);
servicesContainer.addSingleton(MeasureFilterEngine.class);
servicesContainer.addSingleton(DryRunDatabaseFactory.class);
+ servicesContainer.addSingleton(DryRunCache.class);
servicesContainer.addSingleton(DefaultResourcePermissions.class);
servicesContainer.addSingleton(Periods.class);
@@ -389,6 +390,7 @@ public final class Platform {
startupContainer.addSingleton(RenameDeprecatedPropertyKeys.class);
startupContainer.addSingleton(LogServerId.class);
startupContainer.addSingleton(RegisterServletFilters.class);
+ startupContainer.addSingleton(CleanDryRunCache.class);
startupContainer.startComponents();
startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/CleanDryRunCache.java b/sonar-server/src/main/java/org/sonar/server/startup/CleanDryRunCache.java
index 42937faf196..d08ccb32e58 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/CleanDryRunCache.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/CleanDryRunCache.java
@@ -19,44 +19,20 @@
*/
package org.sonar.server.startup;
-import org.apache.commons.io.FileUtils;
-import org.sonar.core.persistence.DryRunDatabaseFactory;
-import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.server.platform.PersistentSettings;
-
-import java.io.File;
-import java.util.Map;
+import org.sonar.core.dryrun.DryRunCache;
/**
* @since 4.0
*/
public class CleanDryRunCache {
- private DefaultServerFileSystem serverFileSystem;
- private PersistentSettings settings;
-
- public CleanDryRunCache(DefaultServerFileSystem serverFileSystem, PersistentSettings settings) {
- this.serverFileSystem = serverFileSystem;
- this.settings = settings;
- }
+ private DryRunCache dryRunCache;
- private File getRootCacheLocation() {
- return new File(serverFileSystem.getTempDir(), "dryRun");
+ public CleanDryRunCache(DryRunCache dryRunCache) {
+ this.dryRunCache = dryRunCache;
}
public void start() {
- clean();
- }
-
- public void clean() {
- // Delete folder where dryRun DB are stored
- FileUtils.deleteQuietly(getRootCacheLocation());
- // Delete all lastUpdate properties to force generation of new DB
- Map<String, String> properties = settings.getProperties();
- for (String propKey : properties.keySet()) {
- if (propKey.startsWith(DryRunDatabaseFactory.SONAR_DRY_RUN_CACHE_KEY_PREFIX)) {
- settings.deleteProperty(propKey);
- }
- }
+ dryRunCache.cleanAll();
}
}