@CheckForNull
public Object[] l10nParams() {
- return l10nParams;
+ return Arrays.copyOf(l10nParams, l10nParams.length);
}
@Override
import org.sonar.server.qualityprofile.QProfileOperations;
import org.sonar.server.qualityprofile.QProfileSearch;
import org.sonar.server.qualityprofile.QProfiles;
-import org.sonar.server.qualityprofile.RubyQProfilesService;
import org.sonar.server.rule.RubyRuleService;
import org.sonar.server.rule.RuleRegistry;
import org.sonar.server.rules.ProfilesConsole;
servicesContainer.addSingleton(QProfiles.class);
servicesContainer.addSingleton(QProfileSearch.class);
servicesContainer.addSingleton(QProfileOperations.class);
- servicesContainer.addSingleton(RubyQProfilesService.class);
// users
servicesContainer.addSingleton(HibernateUserFinder.class);
public class QProfileOperations implements ServerComponent {
private static final String PROPERTY_PREFIX = "sonar.profile.";
+ private static final String QUALITY_PROFILES_ALREADY_EXISTS = "quality_profiles.already_exists";
private final MyBatis myBatis;
private final QualityProfileDao dao;
validateName(name);
Validation.checkMandatoryParameter(language, "language");
if (find(name, language) != null) {
- throw BadRequestException.ofL10n("quality_profiles.already_exists");
+ throw BadRequestException.ofL10n(QUALITY_PROFILES_ALREADY_EXISTS);
}
}
validateName(newName);
QualityProfileDto profileDto = findNeverNull(profileId);
if (!profileDto.getName().equals(newName) && find(newName, profileDto.getLanguage()) != null) {
- throw BadRequestException.ofL10n("quality_profiles.already_exists");
+ throw BadRequestException.ofL10n(QUALITY_PROFILES_ALREADY_EXISTS);
}
return profileDto;
}
private QualityProfileDto findNeverNull(Integer id) {
QualityProfileDto qualityProfile = find(id);
- if (qualityProfile == null) {
- throw new NotFoundException("This quality profile does not exists.");
- }
- return qualityProfile;
+ return checkNotNull((qualityProfile));
}
private QualityProfileDto findNeverNull(String name, String language) {
QualityProfileDto qualityProfile = find(name, language);
+ return checkNotNull(qualityProfile);
+ }
+
+ private QualityProfileDto checkNotNull(QualityProfileDto qualityProfile) {
if (qualityProfile == null) {
throw new NotFoundException("This quality profile does not exists.");
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.qualityprofile;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.server.util.Validation;
-
-import java.util.List;
-import java.util.Map;
-
-public class RubyQProfilesService implements ServerComponent {
-
- private final QProfiles qProfiles;
-
- public RubyQProfilesService(QProfiles qProfiles) {
- this.qProfiles = qProfiles;
- }
-
- public List<QProfile> searchProfiles() {
- return qProfiles.searchProfiles();
- }
-
- public void newProfile(Map<String, Object> params) {
- String name = (String) params.get("name");
- String language = (String) params.get("language");
-// RubyUtils.toStrings()
-
- Validation.checkMandatoryParameter(name, "name");
- Validation.checkMandatoryParameter(language, "language");
-// qProfiles.newProfile(name, language, UserSession.get());
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.qualityprofile;
-
-import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RubyQProfilesServiceTest {
-
- @Mock
- QProfiles qProfiles;
-
- RubyQProfilesService service;
-
- @Before
- public void setUp() throws Exception {
- service = new RubyQProfilesService(qProfiles);
- }
-
- @Test
- public void search_profiles() throws Exception {
- when(qProfiles.searchProfiles()).thenReturn(newArrayList(
- new QProfile().setId(1).setName("Sonar Way with Findbugs").setLanguage("java").setParent("Sonar Way").setVersion(1).setUsed(false)
- ));
-
- assertThat(service.searchProfiles()).hasSize(1);
- }
-
- @Test
- public void new_profile() throws Exception {
- service.newProfile(ImmutableMap.<String, Object>of(
- "name", "Default",
- "language", "java")
- );
-// verify(qProfiles).newProfile(eq("Default"), eq("java"), any(UserSession.class));
- }
-}