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 {
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) {
@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.");
- }
- }
-
}
--- /dev/null
+/*
+ * 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.");
+ }
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
pico.addSingleton(BatchIndex.class);
pico.addSingleton(GlobalReferentialsAction.class);
pico.addSingleton(ProjectReferentialsAction.class);
+ pico.addSingleton(ProjectReferentialsLoader.class);
pico.addSingleton(UploadReportAction.class);
pico.addSingleton(BatchWs.class);
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;
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))));
}
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;
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();
}
}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
}
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)
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);
}
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;
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();
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;
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();
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;
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
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;
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
.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);
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;
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);
+++ /dev/null
-{
- "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": {}
-}
--- /dev/null
+{
+ "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": {}
+}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "timestamp": 0,
- "qprofilesByLanguage": {
- "java": {
- "key": "abcd",
- "name": "SonarQube way",
- "language": "java",
- "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
- }
- },
- "activeRules": [],
- "settingsByModule": {},
- "fileDataByModuleAndPath": {}
-}
+++ /dev/null
-{
- "timestamp": 0,
- "qprofilesByLanguage": {
- "java": {
- "key": "abcd",
- "name": "Default",
- "language": "java",
- "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
- }
- },
- "activeRules": [],
- "settingsByModule": {},
- "fileDataByModuleAndPath": {}
-}
+++ /dev/null
-{
- "timestamp": 0,
- "qprofilesByLanguage": {
- "java": {
- "key": "abcd",
- "name": "Default",
- "language": "java",
- "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
- }
- },
- "activeRules": [],
- "settingsByModule": {},
- "fileDataByModuleAndPath": {}
-}
+++ /dev/null
-{
- "timestamp": 0,
- "qprofilesByLanguage": {
- "java": {
- "key": "abcd",
- "name": "SonarQube way",
- "language": "java",
- "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
- }
- },
- "activeRules": [],
- "settingsByModule": {},
- "fileDataByModuleAndPath": {}
-}
+++ /dev/null
-{
- "timestamp": 0,
- "qprofilesByLanguage": {
- "java": {
- "key": "abcd",
- "name": "Default",
- "language": "java",
- "rulesUpdatedAt": "2014-01-14T13:00:00+0100"
- }
- },
- "activeRules": [],
- "settingsByModule": {},
- "fileDataByModuleAndPath": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}
+++ /dev/null
-{
- "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": {}
-}