aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-03-19 16:17:57 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-03-19 16:17:57 +0100
commit35706997d4a2c15b0e2c237504bfa49ccb021998 (patch)
tree90b3cbd0025a7f7ec4912fa0891dbbdc5f753f5f
parentf355b2c64238de582c9d9df0de63da71947a8de7 (diff)
parent7127ab95012034fc643b743c11c466acd60391f4 (diff)
downloadsonarqube-35706997d4a2c15b0e2c237504bfa49ccb021998.tar.gz
sonarqube-35706997d4a2c15b0e2c237504bfa49ccb021998.zip
Merge remote-tracking branch 'origin/master'
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java11
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml17
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml12
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java23
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java16
6 files changed, 65 insertions, 16 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
index a6f736eea56..0917fa776b2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
@@ -72,6 +72,8 @@ public final class DefaultResourcePersister implements ResourcePersister {
// assume that the parent project has already been saved
parentSnapshot = snapshotsByResource.get(project.getParent());
model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
+ } else {
+ model.setRootId(null);
}
model = session.save(model);
project.setId(model.getId());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
index a8b7e4d986b..c85ca8a895f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
@@ -137,4 +137,15 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
checkTablesWithExcludedColumns("shouldUpdateExistingResource", new String[]{"build_date"}, "projects", "snapshots");
}
+ // SONAR-1700
+ @Test
+ public void shouldRemoveRootIndexIfResourceIsProject() {
+ setupData("shouldRemoveRootIndexIfResourceIsProject");
+
+ ResourcePersister persister = new DefaultResourcePersister(getSession());
+ persister.saveProject(singleProject, null);
+
+ checkTablesWithExcludedColumns("shouldRemoveRootIndexIfResourceIsProject", new String[]{"build_date"}, "projects", "snapshots");
+ }
+
}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml
new file mode 100644
index 00000000000..147b3c37abf
--- /dev/null
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml
@@ -0,0 +1,17 @@
+<dataset>
+
+ <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
+ name="Foo" long_name="Foo" description="some description"
+ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" profile_id="[null]"/>
+
+ <!-- old snapshot -->
+ <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" build_date="2010-12-23 00:00:00.00" version="[null]" path=""
+ status="U" islast="false" depth="0" />
+
+ <!-- new snapshot -->
+ <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3002" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path=""
+ status="U" islast="false" depth="0" />
+
+</dataset> \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml
new file mode 100644
index 00000000000..56b2ab204d2
--- /dev/null
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml
@@ -0,0 +1,12 @@
+<dataset>
+
+ <!-- This project has a root_id which should be set to NULL (SONAR-1700) -->
+ <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="12345"
+ name="name" long_name="long name" description="description"
+ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" profile_id="[null]"/>
+
+ <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" build_date="2010-12-23 00:00:00.00" version="[null]" path=""
+ status="U" islast="false" depth="0" />
+
+</dataset> \ No newline at end of file
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java
index 3d63834ca61..f597ee3214b 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java
@@ -52,12 +52,12 @@ public final class ActivateDefaultProfiles {
RulesProfile profileToActivate = null;
boolean oneProfileIsActivated = false;
if (profiles.isEmpty()) {
- profileToActivate = new RulesProfile("Default " + language.getName(), language.getKey(), true, false);
-
+ profileToActivate = RulesProfile.create("Default " + language.getName(), language.getKey());
+ profileToActivate.setDefaultProfile(true);
+ profileToActivate.setProvided(false);
} else if (profiles.size() == 1) {
profileToActivate = profiles.get(0);
-
- } else {
+ } else if (!activeProfileFoundInDB(profiles)) {
Iterator<RulesProfile> iterator = profiles.iterator();
while (iterator.hasNext() && !oneProfileIsActivated) {
RulesProfile profile = iterator.next();
@@ -66,10 +66,8 @@ public final class ActivateDefaultProfiles {
profileToActivate = profile;
}
}
- if (!oneProfileIsActivated) {
- if (profileToActivate == null) {
- profileToActivate = profiles.get(0);
- }
+ if (!oneProfileIsActivated && profileToActivate == null) {
+ profileToActivate = profiles.get(0);
}
}
if (!oneProfileIsActivated && profileToActivate != null) {
@@ -77,4 +75,13 @@ public final class ActivateDefaultProfiles {
session.saveWithoutFlush(profileToActivate);
}
}
+
+ private boolean activeProfileFoundInDB(List<RulesProfile> profiles) {
+ for (RulesProfile rulesProfile : profiles) {
+ if (rulesProfile.getDefaultProfile()) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
index 89aeded16e8..7ed797f2ead 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
@@ -108,7 +108,7 @@ public final class RegisterProvidedProfiles {
void saveProvidedProfiles(List<RulesProfile> profiles, DatabaseSession session) {
for (RulesProfile profile : profiles) {
TimeProfiler profiler = new TimeProfiler().start("Save profile " + profile);
- RulesProfile persistedProfile = findOrCreate(profile.getName(), profile.getLanguage(), session);
+ RulesProfile persistedProfile = findOrCreate(profile, session);
for (ActiveRule activeRule : profile.getActiveRules()) {
Rule rule = getPersistedRule(activeRule);
@@ -140,14 +140,14 @@ public final class RegisterProvidedProfiles {
return rule;
}
- private RulesProfile findOrCreate(String name, String language, DatabaseSession session) {
- RulesProfile profile = session.getSingleResult(RulesProfile.class, "name", name, "language", language);
- if (profile == null) {
- profile = RulesProfile.create(name, language);
- profile.setProvided(true);
- profile.setDefaultProfile(false);
+ private RulesProfile findOrCreate(RulesProfile profile, DatabaseSession session) {
+ RulesProfile persistedProfile = session.getSingleResult(RulesProfile.class, "name", profile.getName(), "language", profile.getLanguage());
+ if (persistedProfile == null) {
+ persistedProfile = RulesProfile.create(profile.getName(), profile.getLanguage());
+ persistedProfile.setDefaultProfile(profile.getDefaultProfile());
+ persistedProfile.setProvided(true);
}
- return profile;
+ return persistedProfile;
}
}