]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5849 Extract logic from ProjectReferentialsAction to ProjectReferentialsLoader
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Dec 2014 14:49:12 +0000 (15:49 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Dec 2014 15:20:04 +0000 (16:20 +0100)
31 files changed:
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsQuery.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsLoaderMediumTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/component/ComponentTesting.java
server/sonar-server/src/test/java/org/sonar/server/component/SnapshotTesting.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/not_returned_secured_settings_with_only_preview_permission.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/project_referentials.json [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_active_rules.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_settings.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings_inherited_from_project.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_with_sub_module.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_default_profile.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_given_profile_name.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles_even_when_project_does_not_exists.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json [deleted file]

index 847393b0ec2e48b2fb338f0d125cc84e51fece57..34a51d73aba4ce8fb59a51469668106bcc8ca7c6 100644 (file)
 
 package org.sonar.server.batch;
 
-import com.google.common.collect.Maps;
 import org.apache.commons.io.IOUtils;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.RequestHandler;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.batch.protocol.input.ProjectReferentials;
-import org.sonar.core.UtcDateUtils;
-import org.sonar.core.component.ComponentDto;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.properties.PropertiesDao;
-import org.sonar.core.properties.PropertyDto;
-import org.sonar.core.qualityprofile.db.QualityProfileDto;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.plugins.MimeTypes;
-import org.sonar.server.qualityprofile.ActiveRule;
-import org.sonar.server.qualityprofile.QProfileFactory;
-import org.sonar.server.qualityprofile.QProfileLoader;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.RuleService;
-import org.sonar.server.user.UserSession;
-
-import javax.annotation.Nullable;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.Maps.newHashMap;
 
 public class ProjectReferentialsAction implements RequestHandler {
 
@@ -62,21 +34,10 @@ public class ProjectReferentialsAction implements RequestHandler {
   private static final String PARAM_PROFILE = "profile";
   private static final String PARAM_PREVIEW = "preview";
 
-  private final DbClient dbClient;
-  private final PropertiesDao propertiesDao;
-  private final QProfileFactory qProfileFactory;
-  private final QProfileLoader qProfileLoader;
-  private final RuleService ruleService;
-  private final Languages languages;
+  private final ProjectReferentialsLoader projectReferentialsLoader;
 
-  public ProjectReferentialsAction(DbClient dbClient, PropertiesDao propertiesDao, QProfileFactory qProfileFactory, QProfileLoader qProfileLoader,
-    RuleService ruleService, Languages languages) {
-    this.dbClient = dbClient;
-    this.propertiesDao = propertiesDao;
-    this.qProfileFactory = qProfileFactory;
-    this.qProfileLoader = qProfileLoader;
-    this.ruleService = ruleService;
-    this.languages = languages;
+  public ProjectReferentialsAction(ProjectReferentialsLoader projectReferentialsLoader) {
+    this.projectReferentialsLoader = projectReferentialsLoader;
   }
 
   void define(WebService.NewController controller) {
@@ -106,162 +67,11 @@ public class ProjectReferentialsAction implements RequestHandler {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    boolean hasScanPerm = UserSession.get().hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
-    boolean preview = request.mandatoryParamAsBoolean(PARAM_PREVIEW);
-    checkPermission(preview);
-
-    DbSession session = dbClient.openSession(false);
-    try {
-      ProjectReferentials ref = new ProjectReferentials();
-
-      String projectOrModuleKey = request.mandatoryParam(PARAM_KEY);
-      String profileName = request.param(PARAM_PROFILE);
-
-      String projectKey = null;
-      ComponentDto module = dbClient.componentDao().getNullableByKey(session, projectOrModuleKey);
-      // Current project can be null when analysing a new project
-      if (module != null) {
-        ComponentDto project = dbClient.componentDao().getNullableRootProjectByKey(projectOrModuleKey, session);
-        // Can be null if the given project is a provisioned one
-        if (project != null) {
-          if (!project.key().equals(module.key())) {
-            addSettings(ref, module.getKey(), getSettingsFromParents(module.key(), hasScanPerm, session));
-          }
-          projectKey = project.key();
-          addSettingsToChildrenModules(ref, projectOrModuleKey, Maps.<String, String>newHashMap(), hasScanPerm, session);
-        } else {
-          // Add settings of the provisioned project
-          addSettings(ref, projectOrModuleKey, getPropertiesMap(propertiesDao.selectProjectProperties(projectOrModuleKey, session), hasScanPerm));
-          projectKey = projectOrModuleKey;
-        }
-      }
-
-      addProfiles(ref, projectKey, profileName, session);
-      addActiveRules(ref);
-
-      response.stream().setMediaType(MimeTypes.JSON);
-      IOUtils.write(ref.toJson(), response.stream().output());
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  private Map<String, String> getSettingsFromParents(String moduleKey, boolean hasScanPerm, DbSession session) {
-    List<ComponentDto> parents = newArrayList();
-    aggregateParentModules(moduleKey, parents, session);
-    Collections.reverse(parents);
-
-    Map<String, String> parentProperties = newHashMap();
-    for (ComponentDto parent : parents) {
-      parentProperties.putAll(getPropertiesMap(propertiesDao.selectProjectProperties(parent.key(), session), hasScanPerm));
-    }
-    return parentProperties;
-  }
-
-  private void aggregateParentModules(String component, List<ComponentDto> parents, DbSession session){
-    ComponentDto parent = dbClient.componentDao().getParentModuleByKey(component, session);
-    if (parent != null) {
-      parents.add(parent);
-      aggregateParentModules(parent.key(), parents, session);
-    }
-  }
-
-  private void addSettingsToChildrenModules(ProjectReferentials ref, String projectKey, Map<String, String> parentProperties, boolean hasScanPerm, DbSession session) {
-    Map<String, String> currentParentProperties = newHashMap();
-    currentParentProperties.putAll(parentProperties);
-    currentParentProperties.putAll(getPropertiesMap(propertiesDao.selectProjectProperties(projectKey, session), hasScanPerm));
-    addSettings(ref, projectKey, currentParentProperties);
-
-    for (ComponentDto module : dbClient.componentDao().findModulesByProject(projectKey, session)) {
-      addSettings(ref, module.key(), currentParentProperties);
-      addSettingsToChildrenModules(ref, module.key(), currentParentProperties, hasScanPerm, session);
-    }
+    ProjectReferentials ref = projectReferentialsLoader.load(ProjectReferentialsQuery.create()
+      .setModuleKey(request.mandatoryParam(PARAM_KEY))
+      .setProfileName(request.param(PARAM_PROFILE))
+      .setPreview(request.mandatoryParamAsBoolean(PARAM_PREVIEW)));
+    response.stream().setMediaType(MimeTypes.JSON);
+    IOUtils.write(ref.toJson(), response.stream().output());
   }
-
-  private void addSettings(ProjectReferentials ref, String module, Map<String, String> properties) {
-    if (!properties.isEmpty()) {
-      ref.addSettings(module, properties);
-    }
-  }
-
-  private Map<String, String> getPropertiesMap(List<PropertyDto> propertyDtos, boolean hasScanPerm) {
-    Map<String, String> properties = newHashMap();
-    for (PropertyDto propertyDto : propertyDtos) {
-      String key = propertyDto.getKey();
-      String value = propertyDto.getValue();
-      if (isPropertyAllowed(key, hasScanPerm)) {
-        properties.put(key, value);
-      }
-    }
-    return properties;
-  }
-
-  private static boolean isPropertyAllowed(String key, boolean hasScanPerm) {
-    return !key.contains(".secured") || hasScanPerm;
-  }
-
-  private void addProfiles(ProjectReferentials ref, @Nullable String projectKey, @Nullable String profileName, DbSession session) {
-    for (Language language : languages.all()) {
-      String languageKey = language.getKey();
-      QualityProfileDto qualityProfileDto = getProfile(languageKey, projectKey, profileName, session);
-      ref.addQProfile(new org.sonar.batch.protocol.input.QProfile(
-        qualityProfileDto.getKey(),
-        qualityProfileDto.getName(),
-        qualityProfileDto.getLanguage(),
-        UtcDateUtils.parseDateTime(qualityProfileDto.getRulesUpdatedAt())));
-    }
-  }
-
-  /**
-   * First try to find a quality profile matching the given name (if provided) and current language
-   * If no profile found, try to find the quality profile set on the project (if provided)
-   * If still no profile found, try to find the default profile of the language
-   *
-   * Never return null because a default profile should always be set on ech language
-   */
-  private QualityProfileDto getProfile(String languageKey, @Nullable String projectKey, @Nullable String profileName, DbSession session) {
-    QualityProfileDto qualityProfileDto = profileName != null ? qProfileFactory.getByNameAndLanguage(session, profileName, languageKey) : null;
-    if (qualityProfileDto == null && projectKey != null) {
-      qualityProfileDto = qProfileFactory.getByProjectAndLanguage(session, projectKey, languageKey);
-    }
-    qualityProfileDto = qualityProfileDto != null ? qualityProfileDto : qProfileFactory.getDefault(session, languageKey);
-    if (qualityProfileDto != null) {
-      return qualityProfileDto;
-    } else {
-      throw new IllegalStateException(String.format("No quality profile can been found on language '%s' for project '%s'", languageKey, projectKey));
-    }
-  }
-
-  private void addActiveRules(ProjectReferentials ref) {
-    for (org.sonar.batch.protocol.input.QProfile qProfile : ref.qProfiles()) {
-      for (ActiveRule activeRule : qProfileLoader.findActiveRulesByProfile(qProfile.key())) {
-        Rule rule = ruleService.getNonNullByKey(activeRule.key().ruleKey());
-        org.sonar.batch.protocol.input.ActiveRule inputActiveRule = new org.sonar.batch.protocol.input.ActiveRule(
-          activeRule.key().ruleKey().repository(),
-          activeRule.key().ruleKey().rule(),
-          rule.name(),
-          activeRule.severity(),
-          rule.internalKey(),
-          qProfile.language());
-        for (Map.Entry<String, String> entry : activeRule.params().entrySet()) {
-          inputActiveRule.addParam(entry.getKey(), entry.getValue());
-        }
-        ref.addActiveRule(inputActiveRule);
-      }
-    }
-  }
-
-  private void checkPermission(boolean preview){
-    UserSession userSession = UserSession.get();
-    boolean hasScanPerm = userSession.hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
-    boolean hasPreviewPerm = userSession.hasGlobalPermission(GlobalPermissions.DRY_RUN_EXECUTION);
-    if (!hasPreviewPerm && !hasScanPerm) {
-      throw new ForbiddenException("You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.");
-    }
-    if (!preview && !hasScanPerm) {
-      throw new ForbiddenException("You're only authorized to execute a local (dry run) SonarQube analysis without pushing the results to the SonarQube server. " +
-        "Please contact your SonarQube administrator.");
-    }
-  }
-
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsLoader.java
new file mode 100644 (file)
index 0000000..4fcbf41
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.batch;
+
+import com.google.common.collect.Maps;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+import org.sonar.batch.protocol.input.ProjectReferentials;
+import org.sonar.core.UtcDateUtils;
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.properties.PropertyDto;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.qualityprofile.ActiveRule;
+import org.sonar.server.qualityprofile.QProfileFactory;
+import org.sonar.server.qualityprofile.QProfileLoader;
+import org.sonar.server.rule.Rule;
+import org.sonar.server.rule.RuleService;
+import org.sonar.server.user.UserSession;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
+
+public class ProjectReferentialsLoader implements ServerComponent {
+
+  private final DbClient dbClient;
+  private final QProfileFactory qProfileFactory;
+  private final QProfileLoader qProfileLoader;
+  private final RuleService ruleService;
+  private final Languages languages;
+
+  public ProjectReferentialsLoader(DbClient dbClient, QProfileFactory qProfileFactory, QProfileLoader qProfileLoader, RuleService ruleService,
+                                   Languages languages) {
+    this.dbClient = dbClient;
+    this.qProfileFactory = qProfileFactory;
+    this.qProfileLoader = qProfileLoader;
+    this.ruleService = ruleService;
+    this.languages = languages;
+  }
+
+  public ProjectReferentials load(ProjectReferentialsQuery query) {
+    boolean hasScanPerm = UserSession.get().hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
+    checkPermission(query.isPreview());
+
+    DbSession session = dbClient.openSession(false);
+    try {
+      ProjectReferentials ref = new ProjectReferentials();
+      String projectKey = null;
+      ComponentDto module = dbClient.componentDao().getNullableByKey(session, query.getModuleKey());
+      // Current project/module can be null when analysing a new project
+      if (module != null) {
+        ComponentDto project = dbClient.componentDao().getNullableRootProjectByKey(query.getModuleKey(), session);
+        // Can be null if the given project is a provisioned one
+        if (project != null) {
+          if (!project.key().equals(module.key())) {
+            addSettings(ref, module.getKey(), getSettingsFromParents(module.key(), hasScanPerm, session));
+          }
+          projectKey = project.key();
+          addSettingsToChildrenModules(ref, query.getModuleKey(), Maps.<String, String>newHashMap(), hasScanPerm, session);
+        } else {
+          // Add settings of the provisioned project
+          addSettings(ref, query.getModuleKey(), getPropertiesMap(dbClient.propertiesDao().selectProjectProperties(query.getModuleKey(), session), hasScanPerm));
+          projectKey = query.getModuleKey();
+        }
+      }
+
+      addProfiles(ref, projectKey, query.getProfileName(), session);
+      addActiveRules(ref);
+      return ref;
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  private Map<String, String> getSettingsFromParents(String moduleKey, boolean hasScanPerm, DbSession session) {
+    List<ComponentDto> parents = newArrayList();
+    aggregateParentModules(moduleKey, parents, session);
+    Collections.reverse(parents);
+
+    Map<String, String> parentProperties = newHashMap();
+    for (ComponentDto parent : parents) {
+      parentProperties.putAll(getPropertiesMap(dbClient.propertiesDao().selectProjectProperties(parent.key(), session), hasScanPerm));
+    }
+    return parentProperties;
+  }
+
+  private void aggregateParentModules(String component, List<ComponentDto> parents, DbSession session) {
+    ComponentDto parent = dbClient.componentDao().getParentModuleByKey(component, session);
+    if (parent != null) {
+      parents.add(parent);
+      aggregateParentModules(parent.key(), parents, session);
+    }
+  }
+
+  private void addSettingsToChildrenModules(ProjectReferentials ref, String projectKey, Map<String, String> parentProperties, boolean hasScanPerm, DbSession session) {
+    Map<String, String> currentParentProperties = newHashMap();
+    currentParentProperties.putAll(parentProperties);
+    currentParentProperties.putAll(getPropertiesMap(dbClient.propertiesDao().selectProjectProperties(projectKey, session), hasScanPerm));
+    addSettings(ref, projectKey, currentParentProperties);
+
+    for (ComponentDto module : dbClient.componentDao().findModulesByProject(projectKey, session)) {
+      addSettings(ref, module.key(), currentParentProperties);
+      addSettingsToChildrenModules(ref, module.key(), currentParentProperties, hasScanPerm, session);
+    }
+  }
+
+  private void addSettings(ProjectReferentials ref, String module, Map<String, String> properties) {
+    if (!properties.isEmpty()) {
+      ref.addSettings(module, properties);
+    }
+  }
+
+  private Map<String, String> getPropertiesMap(List<PropertyDto> propertyDtos, boolean hasScanPerm) {
+    Map<String, String> properties = newHashMap();
+    for (PropertyDto propertyDto : propertyDtos) {
+      String key = propertyDto.getKey();
+      String value = propertyDto.getValue();
+      if (isPropertyAllowed(key, hasScanPerm)) {
+        properties.put(key, value);
+      }
+    }
+    return properties;
+  }
+
+  private static boolean isPropertyAllowed(String key, boolean hasScanPerm) {
+    return !key.contains(".secured") || hasScanPerm;
+  }
+
+  private void addProfiles(ProjectReferentials ref, @Nullable String projectKey, @Nullable String profileName, DbSession session) {
+    for (Language language : languages.all()) {
+      String languageKey = language.getKey();
+      QualityProfileDto qualityProfileDto = getProfile(languageKey, projectKey, profileName, session);
+      ref.addQProfile(new org.sonar.batch.protocol.input.QProfile(
+        qualityProfileDto.getKey(),
+        qualityProfileDto.getName(),
+        qualityProfileDto.getLanguage(),
+        UtcDateUtils.parseDateTime(qualityProfileDto.getRulesUpdatedAt())));
+    }
+  }
+
+  /**
+   * First try to find a quality profile matching the given name (if provided) and current language
+   * If no profile found, try to find the quality profile set on the project (if provided)
+   * If still no profile found, try to find the default profile of the language
+   * <p/>
+   * Never return null because a default profile should always be set on ech language
+   */
+  private QualityProfileDto getProfile(String languageKey, @Nullable String projectKey, @Nullable String profileName, DbSession session) {
+    QualityProfileDto qualityProfileDto = profileName != null ? qProfileFactory.getByNameAndLanguage(session, profileName, languageKey) : null;
+    if (qualityProfileDto == null && projectKey != null) {
+      qualityProfileDto = qProfileFactory.getByProjectAndLanguage(session, projectKey, languageKey);
+    }
+    qualityProfileDto = qualityProfileDto != null ? qualityProfileDto : qProfileFactory.getDefault(session, languageKey);
+    if (qualityProfileDto != null) {
+      return qualityProfileDto;
+    } else {
+      throw new IllegalStateException(String.format("No quality profile can been found on language '%s' for project '%s'", languageKey, projectKey));
+    }
+  }
+
+  private void addActiveRules(ProjectReferentials ref) {
+    for (org.sonar.batch.protocol.input.QProfile qProfile : ref.qProfiles()) {
+      for (ActiveRule activeRule : qProfileLoader.findActiveRulesByProfile(qProfile.key())) {
+        Rule rule = ruleService.getNonNullByKey(activeRule.key().ruleKey());
+        org.sonar.batch.protocol.input.ActiveRule inputActiveRule = new org.sonar.batch.protocol.input.ActiveRule(
+          activeRule.key().ruleKey().repository(),
+          activeRule.key().ruleKey().rule(),
+          rule.name(),
+          activeRule.severity(),
+          rule.internalKey(),
+          qProfile.language());
+        for (Map.Entry<String, String> entry : activeRule.params().entrySet()) {
+          inputActiveRule.addParam(entry.getKey(), entry.getValue());
+        }
+        ref.addActiveRule(inputActiveRule);
+      }
+    }
+  }
+
+  private void checkPermission(boolean preview) {
+    UserSession userSession = UserSession.get();
+    boolean hasScanPerm = userSession.hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
+    boolean hasPreviewPerm = userSession.hasGlobalPermission(GlobalPermissions.DRY_RUN_EXECUTION);
+    if (!hasPreviewPerm && !hasScanPerm) {
+      throw new ForbiddenException("You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.");
+    }
+    if (!preview && !hasScanPerm) {
+      throw new ForbiddenException("You're only authorized to execute a local (dry run) SonarQube analysis without pushing the results to the SonarQube server. " +
+        "Please contact your SonarQube administrator.");
+    }
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsQuery.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsQuery.java
new file mode 100644 (file)
index 0000000..301e2b0
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.batch;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class ProjectReferentialsQuery {
+
+  private String projectOrModuleKey;
+  private String profileName;
+  private boolean preview;
+
+  private ProjectReferentialsQuery() {
+    // No direct call
+  }
+
+  public boolean isPreview() {
+    return preview;
+  }
+
+  public ProjectReferentialsQuery setPreview(boolean preview) {
+    this.preview = preview;
+    return this;
+  }
+
+  @CheckForNull
+  public String getProfileName() {
+    return profileName;
+  }
+
+  public ProjectReferentialsQuery setProfileName(@Nullable String profileName) {
+    this.profileName = profileName;
+    return this;
+  }
+
+  public String getModuleKey() {
+    return projectOrModuleKey;
+  }
+
+  public ProjectReferentialsQuery setModuleKey(String projectOrModuleKey) {
+    this.projectOrModuleKey = projectOrModuleKey;
+    return this;
+  }
+
+  public static ProjectReferentialsQuery create(){
+    return new ProjectReferentialsQuery();
+  }
+}
index b1f54a0cced7ea4094c5f4ea218c8fb171396b96..add819b8be00b50a0986276c4fec541e00157a4d 100644 (file)
@@ -342,6 +342,7 @@ class ServerComponents {
     pico.addSingleton(BatchIndex.class);
     pico.addSingleton(GlobalReferentialsAction.class);
     pico.addSingleton(ProjectReferentialsAction.class);
+    pico.addSingleton(ProjectReferentialsLoader.class);
     pico.addSingleton(UploadReportAction.class);
     pico.addSingleton(BatchWs.class);
 
index bf762d18a7aa9871b4c45ac283233fd734ad6d82..48add35421494ec0fb2f768f4ba5b0264c5fe96a 100644 (file)
@@ -28,14 +28,10 @@ import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.resources.Languages;
 import org.sonar.core.properties.PropertiesDao;
 import org.sonar.server.computation.AnalysisReportQueue;
 import org.sonar.server.computation.AnalysisReportTaskLauncher;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.qualityprofile.QProfileFactory;
-import org.sonar.server.qualityprofile.QProfileLoader;
-import org.sonar.server.rule.RuleService;
 import org.sonar.server.ws.WsTester;
 
 import java.io.File;
@@ -63,8 +59,7 @@ public class BatchWsTest {
   public void before() throws IOException {
     tester = new WsTester(new BatchWs(batchIndex,
       new GlobalReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class)),
-      new ProjectReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class), mock(QProfileFactory.class), mock(QProfileLoader.class), mock(RuleService.class),
-        mock(Languages.class)),
+      new ProjectReferentialsAction(mock(ProjectReferentialsLoader.class)),
       new UploadReportAction(mock(AnalysisReportQueue.class), mock(AnalysisReportTaskLauncher.class))));
   }
 
index 0f6972c1ab6053f5c602e17a9cd1aa33dcab60e1..d9114192c76adc14132153f24f9cd334c032027a 100644 (file)
 
 package org.sonar.server.batch;
 
-import com.google.common.collect.ImmutableMap;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.Severity;
-import org.sonar.core.component.ComponentDto;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.properties.PropertiesDao;
-import org.sonar.core.properties.PropertyDto;
-import org.sonar.core.qualityprofile.db.ActiveRuleKey;
-import org.sonar.core.qualityprofile.db.QualityProfileDto;
-import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.qualityprofile.ActiveRule;
-import org.sonar.server.qualityprofile.QProfileFactory;
-import org.sonar.server.qualityprofile.QProfileLoader;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.RuleService;
-import org.sonar.server.user.MockUserSession;
+import org.sonar.batch.protocol.input.ProjectReferentials;
 import org.sonar.server.ws.WsTester;
 
-import java.util.Collections;
-
-import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -60,416 +37,35 @@ import static org.mockito.Mockito.when;
 public class ProjectReferentialsActionTest {
 
   @Mock
-  DbSession session;
-
-  @Mock
-  ComponentDao componentDao;
-
-  @Mock
-  PropertiesDao propertiesDao;
-
-  @Mock
-  QProfileFactory qProfileFactory;
-
-  @Mock
-  QProfileLoader qProfileLoader;
-
-  @Mock
-  RuleService ruleService;
-
-  @Mock
-  Languages languages;
-
-  @Mock
-  Language language;
+  ProjectReferentialsLoader projectReferentialsLoader;
 
   WsTester tester;
 
-  ComponentDto project;
-  ComponentDto module;
-  ComponentDto subModule;
-
   @Before
   public void setUp() throws Exception {
-    DbClient dbClient = mock(DbClient.class);
-    when(dbClient.openSession(false)).thenReturn(session);
-    when(dbClient.componentDao()).thenReturn(componentDao);
-
-    project = new ComponentDto().setKey("org.codehaus.sonar:sonar").setQualifier(Qualifiers.PROJECT);
-    module = new ComponentDto().setKey("org.codehaus.sonar:sonar-server").setQualifier(Qualifiers.MODULE);
-    subModule = new ComponentDto().setKey("org.codehaus.sonar:sonar-server-dao").setQualifier(Qualifiers.MODULE);
-
-    when(componentDao.getNullableByKey(session, project.key())).thenReturn(project);
-    when(componentDao.getNullableByKey(session, module.key())).thenReturn(module);
-    when(componentDao.getNullableByKey(session, subModule.key())).thenReturn(subModule);
-
-    when(language.getKey()).thenReturn("java");
-    when(languages.all()).thenReturn(new Language[] {language});
-
-    when(qProfileFactory.getDefault(session, "java")).thenReturn(
-      QualityProfileDto.createFor("abcd").setName("Default").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200")
-      );
-
     tester = new WsTester(new BatchWs(mock(BatchIndex.class), mock(GlobalReferentialsAction.class),
-      new ProjectReferentialsAction(dbClient, propertiesDao, qProfileFactory, qProfileLoader, ruleService, languages), mock(UploadReportAction.class)));
-  }
-
-  @Test
-  public void return_project_settings() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    // Project without modules
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(project);
-    when(componentDao.findModulesByProject(project.key(), session)).thenReturn(Collections.<ComponentDto>emptyList());
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-    request.execute().assertJson(getClass(), "return_project_settings.json");
-  }
-
-  @Test
-  public void not_returned_secured_settings_with_only_preview_permission() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.DRY_RUN_EXECUTION);
-
-    // Project without modules
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(project);
-    when(componentDao.findModulesByProject(project.key(), session)).thenReturn(Collections.<ComponentDto>emptyList());
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key()).setParam("preview", "true");
-    request.execute().assertJson(getClass(), "not_returned_secured_settings_with_only_preview_permission.json");
-  }
-
-  @Test
-  public void return_project_with_module_settings() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(project);
-    when(componentDao.findModulesByProject(project.key(), session)).thenReturn(newArrayList(module));
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER"),
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-    request.execute().assertJson(getClass(), "return_project_with_module_settings.json");
-  }
-
-  @Test
-  public void return_project_with_module_settings_inherited_from_project() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(project);
-    when(componentDao.findModulesByProject(project.key(), session)).thenReturn(newArrayList(module));
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-    // No property on module -> should have the same than project
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-    request.execute().assertJson(getClass(), "return_project_with_module_settings_inherited_from_project.json");
-  }
-
-  @Test
-  public void return_project_with_module_with_sub_module() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(project);
-    when(componentDao.findModulesByProject(project.key(), session)).thenReturn(newArrayList(module));
-    when(componentDao.findModulesByProject(module.key(), session)).thenReturn(newArrayList(subModule));
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER"),
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-
-    when(propertiesDao.selectProjectProperties(subModule.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER-DAO")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-    request.execute().assertJson(getClass(), "return_project_with_module_with_sub_module.json");
-  }
-
-  @Test
-  public void return_project_with_two_modules() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    ComponentDto module2 = new ComponentDto().setKey("org.codehaus.sonar:sonar-application").setQualifier(Qualifiers.MODULE);
-
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(project);
-    when(componentDao.findModulesByProject(project.key(), session)).thenReturn(newArrayList(module, module2));
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER"),
-      // This property should not be found on the other module
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-
-    when(propertiesDao.selectProjectProperties(module2.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-APPLICATION")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-    request.execute().assertJson(getClass(), "return_project_with_two_modules.json");
-  }
-
-  @Test
-  public void return_provisioned_project_settings() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    // No root project will be found on provisioned project
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(null);
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-    request.execute().assertJson(getClass(), "return_project_settings.json");
-  }
-
-  @Test
-  public void return_provisioned_project_profile() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    // No root project will be found on provisioned project
-    when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(null);
-
-    when(qProfileFactory.getByProjectAndLanguage(session, project.key(), "java")).thenReturn(
-      QualityProfileDto.createFor("abcd").setName("SonarQube way").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200")
-      );
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-    request.execute().assertJson(getClass(), "return_provisioned_project_profile.json");
-  }
-
-  @Test
-  public void return_sub_module_settings() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    when(componentDao.getNullableRootProjectByKey(subModule.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(module.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
-
-    when(propertiesDao.selectProjectProperties(subModule.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john"),
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings.json");
-  }
-
-  @Test
-  public void return_sub_module_settings_including_settings_from_parent_modules() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    when(componentDao.getNullableRootProjectByKey(subModule.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(module.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR")
-      ));
-
-    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    when(propertiesDao.selectProjectProperties(subModule.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings_including_settings_from_parent_modules.json");
-  }
-
-  @Test
-  public void return_sub_module_settings_only_inherited_from_project() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    when(componentDao.getNullableRootProjectByKey(subModule.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(module.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john"),
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-    // No settings on module or sub module -> All setting should come from the project
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings_inherited_from_project.json");
-  }
-
-  @Test
-  public void return_sub_module_settings_inherited_from_project_and_module() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    when(componentDao.getNullableRootProjectByKey(subModule.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(module.key(), session)).thenReturn(project);
-    when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
-
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john"),
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-
-    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER")
-      ));
-
-    // No settings on sub module -> All setting should come from the project and the module
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings_inherited_from_project_and_module.json");
-  }
-
-  @Test
-  public void return_quality_profiles() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-    String projectKey = "org.codehaus.sonar:sonar";
-
-    when(qProfileFactory.getByProjectAndLanguage(session, projectKey, "java")).thenReturn(
-      QualityProfileDto.createFor("abcd").setName("SonarQube way").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200")
-      );
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", projectKey);
-    request.execute().assertJson(getClass(), "return_quality_profiles.json");
-  }
-
-  @Test
-  public void fail_when_quality_profile_for_a_language() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", "org.codehaus.sonar:sonar");
-
-    try {
-      request.execute();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("No quality profile can been found on language 'java' for project 'org.codehaus.sonar:sonar'");
-    }
+      new ProjectReferentialsAction(projectReferentialsLoader), mock(UploadReportAction.class)));
   }
 
   @Test
-  public void return_quality_profile_from_default_profile() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+  public void project_referentials() throws Exception {
     String projectKey = "org.codehaus.sonar:sonar";
 
-    when(qProfileFactory.getDefault(session, "java")).thenReturn(
-      QualityProfileDto.createFor("abcd").setName("Default").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200")
-      );
+    ProjectReferentials projectReferentials = mock(ProjectReferentials.class);
+    when(projectReferentials.toJson()).thenReturn("{\"settingsByModule\": {}}");
 
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", projectKey);
-    request.execute().assertJson(getClass(), "return_quality_profile_from_default_profile.json");
-  }
-
-  @Test
-  public void return_quality_profile_from_given_profile_name() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-    String projectKey = "org.codehaus.sonar:sonar";
-
-    when(qProfileFactory.getByNameAndLanguage(session, "Default", "java")).thenReturn(
-      QualityProfileDto.createFor("abcd").setName("Default").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200")
-      );
+    ArgumentCaptor<ProjectReferentialsQuery> queryArgumentCaptor = ArgumentCaptor.forClass(ProjectReferentialsQuery.class);
+    when(projectReferentialsLoader.load(queryArgumentCaptor.capture())).thenReturn(projectReferentials);
 
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", projectKey).setParam("profile", "Default");
-    request.execute().assertJson(getClass(), "return_quality_profile_from_given_profile_name.json");
-  }
-
-  @Test
-  public void return_quality_profiles_even_when_project_does_not_exists() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-    String projectKey = "org.codehaus.sonar:sonar";
-    when(componentDao.getNullableByKey(session, projectKey)).thenReturn(null);
-
-    when(qProfileFactory.getDefault(session, "java")).thenReturn(
-      QualityProfileDto.createFor("abcd").setName("Default").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200")
-      );
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", projectKey);
-    request.execute().assertJson(getClass(), "return_quality_profiles_even_when_project_does_not_exists.json");
-  }
-
-  @Test
-  public void return_active_rules() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-    String projectKey = "org.codehaus.sonar:sonar";
-
-    when(qProfileFactory.getByProjectAndLanguage(session, projectKey, "java")).thenReturn(
-      QualityProfileDto.createFor("abcd").setName("Default").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200")
-      );
-
-    RuleKey ruleKey = RuleKey.of("squid", "AvoidCycle");
-    ActiveRule activeRule = mock(ActiveRule.class);
-    when(activeRule.key()).thenReturn(ActiveRuleKey.of("abcd", ruleKey));
-    when(activeRule.severity()).thenReturn(Severity.MINOR);
-    when(activeRule.params()).thenReturn(ImmutableMap.of("max", "2"));
-    when(qProfileLoader.findActiveRulesByProfile("abcd")).thenReturn(newArrayList(activeRule));
-
-    Rule rule = mock(Rule.class);
-    when(rule.name()).thenReturn("Avoid Cycle");
-    when(rule.internalKey()).thenReturn("squid-1");
-    when(ruleService.getNonNullByKey(ruleKey)).thenReturn(rule);
-
-    WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", projectKey);
-    request.execute().assertJson(getClass(), "return_active_rules.json");
-  }
-
-  @Test
-  public void fail_if_no_permission() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions();
-
-    try {
-      WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key());
-      request.execute();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.");
-    }
-  }
-
-  @Test
-  public void fail_when_not_preview_and_only_dry_run_permission() throws Exception {
-    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.DRY_RUN_EXECUTION);
+    WsTester.TestRequest request = tester.newGetRequest("batch", "project")
+      .setParam("key", projectKey)
+      .setParam("profile", "Default")
+      .setParam("preview", "false");
+    request.execute().assertJson("{\"settingsByModule\": {}}");
 
-    try {
-      WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key()).setParam("preview", "false");
-      request.execute();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage(
-        "You're only authorized to execute a local (dry run) SonarQube analysis without pushing the results to the SonarQube server. " +
-          "Please contact your SonarQube administrator.");
-    }
+    assertThat(queryArgumentCaptor.getValue().getModuleKey()).isEqualTo(projectKey);
+    assertThat(queryArgumentCaptor.getValue().getProfileName()).isEqualTo("Default");
+    assertThat(queryArgumentCaptor.getValue().isPreview()).isFalse();
   }
 
 }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsLoaderMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsLoaderMediumTest.java
new file mode 100644 (file)
index 0000000..3eae77a
--- /dev/null
@@ -0,0 +1,701 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.batch;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.Severity;
+import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.batch.protocol.input.ProjectReferentials;
+import org.sonar.batch.protocol.input.QProfile;
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.SnapshotDto;
+import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.properties.PropertyDto;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
+import org.sonar.core.rule.RuleDto;
+import org.sonar.core.rule.RuleParamDto;
+import org.sonar.server.component.ComponentTesting;
+import org.sonar.server.component.SnapshotTesting;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.qualityprofile.QProfileName;
+import org.sonar.server.qualityprofile.QProfileTesting;
+import org.sonar.server.qualityprofile.RuleActivation;
+import org.sonar.server.qualityprofile.RuleActivator;
+import org.sonar.server.rule.RuleTesting;
+import org.sonar.server.tester.ServerTester;
+import org.sonar.server.user.MockUserSession;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+public class ProjectReferentialsLoaderMediumTest {
+
+  @ClassRule
+  public static ServerTester tester = new ServerTester().addXoo();
+
+  DbSession dbSession;
+
+  ProjectReferentialsLoader loader;
+
+  @Before
+  public void before() {
+    tester.clearDbAndIndexes();
+    dbSession = tester.get(DbClient.class).openSession(false);
+    loader = tester.get(ProjectReferentialsLoader.class);
+  }
+
+  @After
+  public void after() {
+    dbSession.close();
+  }
+
+  @Test
+  public void return_project_settings() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()),
+      dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()),
+      dbSession);
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    Map<String, String> projectSettings = ref.settings(project.key());
+    assertThat(projectSettings).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john"
+    ));
+  }
+
+  @Test
+  public void not_returned_secured_settings_with_only_preview_permission() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.DRY_RUN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()),
+      dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()),
+      dbSession);
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()).setPreview(true));
+    Map<String, String> projectSettings = ref.settings(project.key());
+    assertThat(projectSettings).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR"
+    ));
+  }
+
+  @Test
+  public void return_project_with_module_settings() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()), dbSession);
+
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+
+    // Module properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    assertThat(ref.settings(project.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john"
+    ));
+    assertThat(ref.settings(module.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR-SERVER",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+  }
+
+  @Test
+  public void return_project_with_module_settings_inherited_from_project() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()), dbSession);
+
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+
+    // No property on module -> should have the same as project
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    assertThat(ref.settings(project.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john"
+    ));
+    assertThat(ref.settings(module.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john"
+    ));
+  }
+
+  @Test
+  public void return_project_with_module_with_sub_module() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()), dbSession);
+
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
+
+    // Module properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module.getId()), dbSession);
+
+    ComponentDto subModule = ComponentTesting.newModuleDto(module);
+    tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+
+    // Sub module properties
+    tester.get(DbClient.class).propertiesDao().setProperty(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER-DAO").setResourceId(subModule.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    assertThat(ref.settings(project.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john"
+    ));
+    assertThat(ref.settings(module.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR-SERVER",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+    assertThat(ref.settings(subModule.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR-SERVER-DAO",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+  }
+
+  @Test
+  public void return_project_with_two_modules() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()), dbSession);
+
+    ComponentDto module1 = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module1);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module1, project, projectSnapshot));
+
+    // Module 1 properties
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module1.getId()), dbSession);
+    // This property should not be found on the other module
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module1.getId()), dbSession);
+
+    ComponentDto module2 = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module2);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module2, project, projectSnapshot));
+
+    // Module 2 property
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-APPLICATION").setResourceId(module2.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    assertThat(ref.settings(project.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john"
+    ));
+    assertThat(ref.settings(module1.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR-SERVER",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+    assertThat(ref.settings(module2.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR-APPLICATION",
+      "sonar.jira.login.secured", "john"
+    ));
+  }
+
+  @Test
+  public void return_provisioned_project_settings() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    // No snapshot attached on the project -> provisioned project
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    assertThat(ref.settings(project.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john"
+    ));
+  }
+
+  @Test
+  public void return_sub_module_settings() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+    // No project properties
+
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
+    // No module properties
+
+    ComponentDto subModule = ComponentTesting.newModuleDto(module);
+    tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+
+    // Sub module properties
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(subModule.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(subModule.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(subModule.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(subModule.key()));
+    assertThat(ref.settings(project.key())).isEmpty();
+    assertThat(ref.settings(module.key())).isEmpty();
+    assertThat(ref.settings(subModule.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+  }
+
+  @Test
+  public void return_sub_module_settings_including_settings_from_parent_modules() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+
+    // Project property
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()), dbSession);
+
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
+
+    // Module property
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(module.getId()), dbSession);
+
+    ComponentDto subModule = ComponentTesting.newModuleDto(module);
+    tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+
+    // Sub module properties
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(subModule.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(subModule.key()));
+    assertThat(ref.settings(project.key())).isEmpty();
+    assertThat(ref.settings(module.key())).isEmpty();
+    assertThat(ref.settings(subModule.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+  }
+
+  @Test
+  public void return_sub_module_settings_only_inherited_from_project() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(project.getId()), dbSession);
+
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
+    // No module property
+
+    ComponentDto subModule = ComponentTesting.newModuleDto(module);
+    tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+    // No sub module property
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(subModule.key()));
+    assertThat(ref.settings(project.key())).isEmpty();
+    assertThat(ref.settings(module.key())).isEmpty();
+    assertThat(ref.settings(subModule.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+  }
+
+  @Test
+  public void return_sub_module_settings_inherited_from_project_and_module() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, projectSnapshot);
+    addDefaultProfile();
+
+    // Project properties
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()), dbSession);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(project.getId()), dbSession);
+
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    tester.get(DbClient.class).componentDao().insert(dbSession, module);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
+
+    // Module property
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()), dbSession);
+
+    ComponentDto subModule = ComponentTesting.newModuleDto(module);
+    tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+    // No sub module property
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(subModule.key()));
+    assertThat(ref.settings(project.key())).isEmpty();
+    assertThat(ref.settings(module.key())).isEmpty();
+    assertThat(ref.settings(subModule.key())).isEqualTo(ImmutableMap.of(
+      "sonar.jira.project.key", "SONAR-SERVER",
+      "sonar.jira.login.secured", "john",
+      "sonar.coverage.exclusions", "**/*.java"
+    ));
+  }
+
+  @Test
+  public void return_quality_profile_from_project_profile() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+    Date ruleUpdatedAt = DateUtils.parseDateTime("2014-01-14T13:00:00+0100");
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
+
+    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(DateUtils.formatDateTime(ruleUpdatedAt));
+    tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way").setResourceId(project.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    List<QProfile> profiles = newArrayList(ref.qProfiles());
+    assertThat(profiles).hasSize(1);
+    assertThat(profiles.get(0).key()).isEqualTo("abcd");
+    assertThat(profiles.get(0).name()).isEqualTo("SonarQube way");
+    assertThat(profiles.get(0).language()).isEqualTo("xoo");
+    assertThat(profiles.get(0).rulesUpdatedAt()).isEqualTo(ruleUpdatedAt);
+  }
+
+  @Test
+  public void return_quality_profile_from_default_profile() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+    Date ruleUpdatedAt = DateUtils.parseDateTime("2014-01-14T13:00:00+0100");
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
+
+    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(DateUtils.formatDateTime(ruleUpdatedAt));
+    tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way"), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    List<QProfile> profiles = newArrayList(ref.qProfiles());
+    assertThat(profiles).hasSize(1);
+    assertThat(profiles.get(0).key()).isEqualTo("abcd");
+    assertThat(profiles.get(0).name()).isEqualTo("SonarQube way");
+    assertThat(profiles.get(0).language()).isEqualTo("xoo");
+    assertThat(profiles.get(0).rulesUpdatedAt()).isEqualTo(ruleUpdatedAt);
+  }
+
+  @Test
+  public void return_quality_profile_from_given_profile_name() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+    Date ruleUpdatedAt = DateUtils.parseDateTime("2014-01-14T13:00:00+0100");
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
+
+    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(DateUtils.formatDateTime(ruleUpdatedAt));
+    tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way"), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()).setProfileName("SonarQube way"));
+    List<QProfile> profiles = newArrayList(ref.qProfiles());
+    assertThat(profiles).hasSize(1);
+    assertThat(profiles.get(0).key()).isEqualTo("abcd");
+    assertThat(profiles.get(0).name()).isEqualTo("SonarQube way");
+    assertThat(profiles.get(0).language()).isEqualTo("xoo");
+    assertThat(profiles.get(0).rulesUpdatedAt()).isEqualTo(ruleUpdatedAt);
+  }
+
+  @Test
+  public void return_quality_profiles_even_when_project_does_not_exists() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+    Date ruleUpdatedAt = DateUtils.parseDateTime("2014-01-14T13:00:00+0100");
+
+    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(DateUtils.formatDateTime(ruleUpdatedAt));
+    tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way"), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey("project"));
+    List<QProfile> profiles = newArrayList(ref.qProfiles());
+    assertThat(profiles).hasSize(1);
+    assertThat(profiles.get(0).key()).isEqualTo("abcd");
+    assertThat(profiles.get(0).name()).isEqualTo("SonarQube way");
+    assertThat(profiles.get(0).language()).isEqualTo("xoo");
+    assertThat(profiles.get(0).rulesUpdatedAt()).isEqualTo(ruleUpdatedAt);
+  }
+
+
+  @Test
+  public void return_provisioned_project_profile() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+    Date ruleUpdatedAt = DateUtils.parseDateTime("2014-01-14T13:00:00+0100");
+
+    // No snapshot attached on the project -> provisioned project
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+
+    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(DateUtils.formatDateTime(ruleUpdatedAt));
+    tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way").setResourceId(project.getId()), dbSession);
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    List<QProfile> profiles = newArrayList(ref.qProfiles());
+    assertThat(profiles).hasSize(1);
+    assertThat(profiles.get(0).key()).isEqualTo("abcd");
+    assertThat(profiles.get(0).name()).isEqualTo("SonarQube way");
+    assertThat(profiles.get(0).language()).isEqualTo("xoo");
+    assertThat(profiles.get(0).rulesUpdatedAt()).isEqualTo(ruleUpdatedAt);
+  }
+
+  @Test
+  public void fail_when_no_quality_profile_for_a_language() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto().setKey("org.codehaus.sonar:sonar");
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    dbSession.commit();
+
+    try {
+      loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("No quality profile can been found on language 'xoo' for project 'org.codehaus.sonar:sonar'");
+    }
+  }
+
+  @Test
+  public void return_active_rules() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+    Date ruleUpdatedAt = DateUtils.parseDateTime("2014-01-14T13:00:00+0100");
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForProject(project));
+
+    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(DateUtils.formatDateTime(ruleUpdatedAt));
+    tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way"), dbSession);
+
+    RuleKey ruleKey = RuleKey.of("squid", "AvoidCycle");
+    RuleDto rule = RuleTesting.newDto(ruleKey).setName("Avoid Cycle").setConfigKey("squid-1").setLanguage(ServerTester.Xoo.KEY);
+    tester.get(DbClient.class).ruleDao().insert(dbSession, rule);
+    tester.get(DbClient.class).ruleDao().addRuleParam(dbSession, rule, RuleParamDto.createFor(rule)
+      .setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
+
+    RuleActivation activation = new RuleActivation(ruleKey);
+    activation.setSeverity(Severity.MINOR);
+    activation.setParameter("max", "2");
+    tester.get(RuleActivator.class).activate(dbSession, activation, profileDto.getKey());
+
+    dbSession.commit();
+
+    ProjectReferentials ref = loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+    List<ActiveRule> activeRules = newArrayList(ref.activeRules());
+    assertThat(activeRules).hasSize(1);
+    assertThat(activeRules.get(0).repositoryKey()).isEqualTo("squid");
+    assertThat(activeRules.get(0).ruleKey()).isEqualTo("AvoidCycle");
+    assertThat(activeRules.get(0).name()).isEqualTo("Avoid Cycle");
+    assertThat(activeRules.get(0).language()).isEqualTo("xoo");
+    assertThat(activeRules.get(0).severity()).isEqualTo("MINOR");
+    assertThat(activeRules.get(0).internalKey()).isEqualTo("squid-1");
+    assertThat(activeRules.get(0).language()).isEqualTo("xoo");
+    assertThat(activeRules.get(0).params()).isEqualTo(ImmutableMap.of("max", "2"));
+  }
+
+  @Test
+  public void fail_if_no_permission() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions();
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    dbSession.commit();
+
+    try {
+      loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()));
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.");
+    }
+  }
+
+  @Test
+  public void fail_when_not_preview_and_only_dry_run_permission() throws Exception {
+    MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.DRY_RUN_EXECUTION);
+
+    ComponentDto project = ComponentTesting.newProjectDto();
+    tester.get(DbClient.class).componentDao().insert(dbSession, project);
+    dbSession.commit();
+
+    try {
+      loader.load(ProjectReferentialsQuery.create().setModuleKey(project.key()).setPreview(false));
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage(
+        "You're only authorized to execute a local (dry run) SonarQube analysis without pushing the results to the SonarQube server. " +
+          "Please contact your SonarQube administrator.");
+    }
+  }
+
+  private void addDefaultProfile() {
+    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(DateUtils.formatDateTime(new Date()));
+    tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto);
+    tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.profile.xoo").setValue("SonarQube way"), dbSession);
+  }
+
+}
index 4f1da87acaf167c747481e7401b6829c0b1048e1..cdc017e5aadb54fa7d0bce5bccb91cf916f8ae8a 100644 (file)
@@ -62,14 +62,15 @@ public class ComponentTesting {
   }
 
   public static ComponentDto newModuleDto(ComponentDto subProjectOrProject) {
+    String uuid = Uuids.create();
     return new ComponentDto()
       .setUuid(Uuids.create())
       .setProjectUuid(subProjectOrProject.projectUuid())
       .setModuleUuid(subProjectOrProject.uuid())
       .setModuleUuidPath(subProjectOrProject.moduleUuidPath() == null ? subProjectOrProject.uuid() : subProjectOrProject.moduleUuidPath() + "." + subProjectOrProject.uuid())
-      .setKey("module")
-      .setName("Module")
-      .setLongName("Module")
+      .setKey("KEY_" + uuid)
+      .setName("NAME_" + uuid)
+      .setLongName("LONG_NAME_" + uuid)
       .setParentProjectId(subProjectOrProject.getId())
       .setScope(Scopes.PROJECT)
       .setQualifier(Qualifiers.MODULE)
index eb27722379abc62e9c6378bc8c54e2aab3c1fa9f..8785d3db8b802928effd3b5a2b51e498968b228d 100644 (file)
@@ -27,12 +27,18 @@ import org.sonar.core.component.SnapshotDto;
 public class SnapshotTesting {
 
   /**
-   * When project is null, that means that the component is a project
+   * Can be used for modules and files
    */
-  public static SnapshotDto createForComponent(ComponentDto component, ComponentDto project) {
+  public static SnapshotDto createForComponent(ComponentDto component, ComponentDto parentProject, SnapshotDto parentSnapshot) {
+    Long parentRootId = parentSnapshot.getRootId();
     return new SnapshotDto()
       .setResourceId(component.getId())
-      .setRootProjectId(project.getId())
+      .setRootProjectId(parentSnapshot.getRootProjectId())
+      .setRootId(parentRootId != null ? parentRootId : parentSnapshot.getId())
+      .setStatus(SnapshotDto.STATUS_PROCESSED)
+      .setQualifier(component.qualifier())
+      .setScope(component.scope())
+      .setParentId(parentSnapshot.getId())
       .setLast(true);
   }
 
index 345c68639f7f8fe3f238a28b534f523563107a26..b741d9638dc2c552fbca4e0383432f27ee160b97 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.api.issue.Issue;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.SnapshotDto;
 import org.sonar.core.issue.db.IssueDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
@@ -84,11 +85,12 @@ public class IssueBulkChangeServiceMediumTest {
 
     project = ComponentTesting.newProjectDto().setKey("MyProject");
     tester.get(ComponentDao.class).insert(session, project);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForProject(project));
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(SnapshotDao.class).insert(session, projectSnapshot);
 
     file = ComponentTesting.newFileDto(project).setKey("MyComponent");
     tester.get(ComponentDao.class).insert(session, file);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project));
+    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
 
     // project can be seen by anyone
     session.commit();
index 1b1fa83bcdff8a0a48f747dcf490d1cf99e61a92..1d017d3ea1f51bd51e5b7ad7826caf877dc47e5f 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.SnapshotDto;
 import org.sonar.core.issue.db.IssueDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
@@ -81,11 +82,12 @@ public class IssueCommentServiceMediumTest {
 
     project = ComponentTesting.newProjectDto();
     tester.get(ComponentDao.class).insert(session, project);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForProject(project));
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(SnapshotDao.class).insert(session, projectSnapshot);
 
     file = ComponentTesting.newFileDto(project);
     tester.get(ComponentDao.class).insert(session, file);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project));
+    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
 
     // project can be seen by anyone
     session.commit();
index 47668c6c9638184b80062c08e77a282e18a3c050..02d11147bff6153142b054cd17d65ccea0dcacae 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.rule.Severity;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.SnapshotDto;
 import org.sonar.core.issue.db.ActionPlanDto;
 import org.sonar.core.issue.db.IssueDto;
 import org.sonar.core.issue.workflow.Transition;
@@ -94,11 +95,12 @@ public class IssueServiceMediumTest {
 
     project = ComponentTesting.newProjectDto();
     tester.get(ComponentDao.class).insert(session, project);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForProject(project));
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    tester.get(SnapshotDao.class).insert(session, projectSnapshot);
 
     file = ComponentTesting.newFileDto(project);
     tester.get(ComponentDao.class).insert(session, file);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project));
+    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
 
 
     // workaround for the test to have sufficient privileges
index 5ea03bc325f1680265c2dd392f168d00e7ee6295..93a9d675744c5b401066d844daa4bbe642033e10 100644 (file)
@@ -32,11 +32,8 @@ import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.KeyValueFormat;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
-import org.sonar.core.issue.db.ActionPlanDao;
-import org.sonar.core.issue.db.ActionPlanDto;
-import org.sonar.core.issue.db.IssueChangeDao;
-import org.sonar.core.issue.db.IssueChangeDto;
-import org.sonar.core.issue.db.IssueDto;
+import org.sonar.core.component.SnapshotDto;
+import org.sonar.core.issue.db.*;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.rule.RuleDto;
@@ -421,7 +418,8 @@ public class SearchActionMediumTest {
   public void components_contains_sub_projects() throws Exception {
     ComponentDto project = ComponentTesting.newProjectDto().setKey("ProjectHavingModule");
     db.componentDao().insert(session, project);
-    db.snapshotDao().insert(session, SnapshotTesting.createForProject(project));
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    db.snapshotDao().insert(session, projectSnapshot);
     session.commit();
 
     // project can be seen by anyone
@@ -431,11 +429,11 @@ public class SearchActionMediumTest {
       .setScope("PRJ")
       .setParentProjectId(project.getId());
     db.componentDao().insert(session, module);
-    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, project));
+    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, project, projectSnapshot));
 
     ComponentDto file = ComponentTesting.newFileDto(module).setKey("FileLinkedToModule");
     db.componentDao().insert(session, file);
-    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project));
+    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
 
     IssueDto issue = IssueTesting.newDto(rule, file, project);
     db.issueDao().insert(session, issue);
index 755fc4bbb75e50c3f08521639646dd1832a4d2e6..b1d3a66077ddd02e07ae063957a7ae0d54f84d25 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Test;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
+import org.sonar.core.component.SnapshotDto;
 import org.sonar.core.issue.db.IssueDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
@@ -75,11 +76,12 @@ public class BackendCleanupMediumTest {
 
     project = ComponentTesting.newProjectDto().setKey("MyProject");
     tester.get(ComponentDao.class).insert(session, project);
-    db.snapshotDao().insert(session, SnapshotTesting.createForProject(project));
+    SnapshotDto projectSnapshot = SnapshotTesting.createForProject(project);
+    db.snapshotDao().insert(session, projectSnapshot);
 
     file = ComponentTesting.newFileDto(project).setKey("MyComponent");
     tester.get(ComponentDao.class).insert(session, file);
-    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project));
+    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
     session.commit();
     // project can be seen by anyone
     MockUserSession.set().setLogin("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/not_returned_secured_settings_with_only_preview_permission.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/not_returned_secured_settings_with_only_preview_permission.json
deleted file mode 100644 (file)
index 1704720..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar": {
-      "sonar.jira.project.key": "SONAR"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/project_referentials.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/project_referentials.json
new file mode 100644 (file)
index 0000000..ff04061
--- /dev/null
@@ -0,0 +1,31 @@
+{
+  "timestamp": 0,
+  "qprofilesByLanguage": {
+    "java": {
+      "key": "abcd",
+      "name": "Default",
+      "language": "java",
+      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
+    }
+  },
+  "activeRules": [
+    {
+      "repositoryKey": "squid",
+      "ruleKey": "AvoidCycle",
+      "name": "Avoid Cycle",
+      "severity": "MINOR",
+      "internalKey": "squid-1",
+      "language": "java",
+      "params": {
+        "max" : "2"
+      }
+    }
+  ],
+  "settingsByModule": {
+    "org.codehaus.sonar:sonar": {
+      "sonar.jira.project.key": "SONAR",
+      "sonar.jira.login.secured": "john"
+    }
+  },
+  "fileDataByModuleAndPath": {}
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_active_rules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_active_rules.json
deleted file mode 100644 (file)
index 03e475b..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [
-    {
-      "repositoryKey": "squid",
-      "ruleKey": "AvoidCycle",
-      "name": "Avoid Cycle",
-      "severity": "MINOR",
-      "internalKey": "squid-1",
-      "language": "java",
-      "params": {
-        "max" : "2"
-      }
-    }
-  ],
-  "settingsByModule": {},
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_settings.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_settings.json
deleted file mode 100644 (file)
index c7ac51a..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings.json
deleted file mode 100644 (file)
index 7aaec4b..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john"
-    },
-    "org.codehaus.sonar:sonar-server": {
-      "sonar.jira.project.key": "SONAR-SERVER",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings_inherited_from_project.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings_inherited_from_project.json
deleted file mode 100644 (file)
index 65da301..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john"
-    },
-    "org.codehaus.sonar:sonar-server": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_with_sub_module.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_with_sub_module.json
deleted file mode 100644 (file)
index ccaaedd..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john"
-    },
-    "org.codehaus.sonar:sonar-server": {
-      "sonar.jira.project.key": "SONAR-SERVER",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    },
-    "org.codehaus.sonar:sonar-server-dao": {
-      "sonar.jira.project.key": "SONAR-SERVER-DAO",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json
deleted file mode 100644 (file)
index 85b6e16..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john"
-    },
-    "org.codehaus.sonar:sonar-server": {
-      "sonar.jira.project.key": "SONAR-SERVER",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    },
-    "org.codehaus.sonar:sonar-application": {
-      "sonar.jira.project.key": "SONAR-APPLICATION",
-      "sonar.jira.login.secured": "john"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json
deleted file mode 100644 (file)
index 5e43528..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "SonarQube way",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {},
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_default_profile.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_default_profile.json
deleted file mode 100644 (file)
index ef28667..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {},
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_given_profile_name.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_given_profile_name.json
deleted file mode 100644 (file)
index ef28667..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {},
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json
deleted file mode 100644 (file)
index 5e43528..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "SonarQube way",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {},
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles_even_when_project_does_not_exists.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles_even_when_project_does_not_exists.json
deleted file mode 100644 (file)
index ef28667..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {},
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings.json
deleted file mode 100644 (file)
index a43f52b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar-server-dao": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json
deleted file mode 100644 (file)
index a43f52b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar-server-dao": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project.json
deleted file mode 100644 (file)
index a43f52b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar-server-dao": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json
deleted file mode 100644 (file)
index 93ed2b5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar-server-dao": {
-      "sonar.jira.project.key": "SONAR-SERVER",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  },
-  "fileDataByModuleAndPath": {}
-}