]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 16 Dec 2013 15:39:57 +0000 (16:39 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 16 Dec 2013 15:39:57 +0000 (16:39 +0100)
sonar-server/src/main/java/org/sonar/server/exceptions/BadRequestException.java
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/RubyQProfilesService.java [deleted file]
sonar-server/src/test/java/org/sonar/server/qualityprofile/RubyQProfilesServiceTest.java [deleted file]

index 0487470eb6f700c38b561aaf1d3664afac98d28e..ee792637e5c87891a42e0576f7d1220592c303fb 100644 (file)
@@ -101,7 +101,7 @@ public class BadRequestException extends ServerException {
 
     @CheckForNull
     public Object[] l10nParams() {
-      return l10nParams;
+      return Arrays.copyOf(l10nParams, l10nParams.length);
     }
 
     @Override
index e5d27bd2efd4978e03784d74a96e98a7443a6c9c..64d996599a6f87652eb642f0374147ddc2a8ed6c 100644 (file)
@@ -93,7 +93,6 @@ import org.sonar.server.plugins.*;
 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;
@@ -273,7 +272,6 @@ public final class Platform {
     servicesContainer.addSingleton(QProfiles.class);
     servicesContainer.addSingleton(QProfileSearch.class);
     servicesContainer.addSingleton(QProfileOperations.class);
-    servicesContainer.addSingleton(RubyQProfilesService.class);
 
     // users
     servicesContainer.addSingleton(HibernateUserFinder.class);
index c7f6af0355bc74f9868620777038b1b30bdd5ece..b790aa172cbd367e1c8b641bf3da0c69caa8ee98 100644 (file)
@@ -58,6 +58,7 @@ import static com.google.common.collect.Lists.newArrayList;
 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;
@@ -200,7 +201,7 @@ public class QProfileOperations implements ServerComponent {
     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);
     }
   }
 
@@ -209,7 +210,7 @@ public class QProfileOperations implements ServerComponent {
     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;
   }
@@ -221,14 +222,15 @@ public class QProfileOperations implements ServerComponent {
 
   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.");
     }
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/RubyQProfilesService.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/RubyQProfilesService.java
deleted file mode 100644 (file)
index 37ec46b..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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());
-  }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/RubyQProfilesServiceTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/RubyQProfilesServiceTest.java
deleted file mode 100644 (file)
index 0593eba..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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));
-  }
-}