aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-07 22:23:16 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-08 16:16:55 +0200
commit6887183ae36fa1f6af8ef1001b760d57a21e2359 (patch)
tree8b687eae736367c96657afcbb4e5fb4fe1de183d /sonar-server/src
parente4917a95b2ad84510f436aedc83643c34fd8b77f (diff)
downloadsonarqube-6887183ae36fa1f6af8ef1001b760d57a21e2359.tar.gz
sonarqube-6887183ae36fa1f6af8ef1001b760d57a21e2359.zip
Remove unused QProfileOperations
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java90
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java7
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java8
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java3
5 files changed, 8 insertions, 102 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index 3ecbb8bb0dc..d711892df8d 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -182,7 +182,6 @@ import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileLoader;
import org.sonar.server.qualityprofile.QProfileLookup;
-import org.sonar.server.qualityprofile.QProfileOperations;
import org.sonar.server.qualityprofile.QProfileProjectLookup;
import org.sonar.server.qualityprofile.QProfileProjectOperations;
import org.sonar.server.qualityprofile.QProfileRepositoryExporter;
@@ -422,7 +421,6 @@ class ServerComponents {
pico.addSingleton(AnnotationProfileParser.class);
pico.addSingleton(QProfiles.class);
pico.addSingleton(QProfileLookup.class);
- pico.addSingleton(QProfileOperations.class);
pico.addSingleton(QProfileProjectOperations.class);
pico.addSingleton(QProfileProjectLookup.class);
pico.addSingleton(QProfileRepositoryExporter.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
deleted file mode 100644
index 872a14474ac..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.qualityprofile;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.preview.PreviewCache;
-import org.sonar.core.qualityprofile.db.QualityProfileDto;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.UserSession;
-
-import java.util.Map;
-
-public class QProfileOperations implements ServerComponent {
-
- public static final String PROFILE_PROPERTY_PREFIX = "sonar.profile.";
-
- private final DbClient db;
- private final QProfileRepositoryExporter exporter;
- private final PreviewCache dryRunCache;
-
- public QProfileOperations(DbClient db,
- QProfileRepositoryExporter exporter, PreviewCache dryRunCache) {
- this.db = db;
- this.exporter = exporter;
- this.dryRunCache = dryRunCache;
- }
-
- public QProfileResult newProfile(String name, String language, Map<String, String> xmlProfilesByPlugin, UserSession userSession) {
- DbSession session = db.openSession(false);
- try {
- QProfile profile = newProfile(name, language, true, userSession, session);
-
- QProfileResult result = new QProfileResult();
- result.setProfile(profile);
-
- for (Map.Entry<String, String> entry : xmlProfilesByPlugin.entrySet()) {
- result.add(exporter.importXml(profile, entry.getKey(), entry.getValue(), session));
- }
- dryRunCache.reportGlobalModification(session);
- session.commit();
- return result;
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- private QProfile newProfile(String name, String language, boolean failIfAlreadyExists, UserSession userSession, DbSession session) {
- checkPermission(userSession);
- if (failIfAlreadyExists) {
- checkNotAlreadyExists(name, language, session);
- }
- QualityProfileDto dto = new QualityProfileDto().setName(name).setLanguage(language);
- db.qualityProfileDao().insert(session, dto);
- return QProfile.from(dto);
- }
-
- private void checkPermission(UserSession userSession) {
- userSession.checkLoggedIn();
- userSession.checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
- }
-
- private void checkNotAlreadyExists(String name, String language, DbSession session) {
- if (db.qualityProfileDao().getByNameAndLanguage(name, language, session) != null) {
- throw new BadRequestException("quality_profiles.profile_x_already_exists", name);
- }
- }
-
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java
index 2f71fa67051..b61a4d9224c 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java
@@ -39,6 +39,7 @@ import java.util.Map;
public class QProfileProjectLookup implements ServerComponent {
+ public static final String PROFILE_PROPERTY_PREFIX = "sonar.profile.";
private final DbClient db;
public QProfileProjectLookup(DbClient db) {
@@ -52,7 +53,7 @@ public class QProfileProjectLookup implements ServerComponent {
QProfileValidations.checkProfileIsNotNull(qualityProfile);
Map<String, Component> componentsByKeys = Maps.newHashMap();
for (Component component : db.qualityProfileDao().selectProjects(
- qualityProfile.getName(), QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), session
+ qualityProfile.getName(), PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), session
)) {
componentsByKeys.put(component.key(), component);
}
@@ -73,12 +74,12 @@ public class QProfileProjectLookup implements ServerComponent {
}
public int countProjects(QProfile profile) {
- return db.qualityProfileDao().countProjects(profile.name(), QProfileOperations.PROFILE_PROPERTY_PREFIX + profile.language());
+ return db.qualityProfileDao().countProjects(profile.name(), PROFILE_PROPERTY_PREFIX + profile.language());
}
@CheckForNull
public QProfile findProfileByProjectAndLanguage(long projectId, String language) {
- QualityProfileDto dto = db.qualityProfileDao().getByProjectAndLanguage(projectId, language, QProfileOperations.PROFILE_PROPERTY_PREFIX + language);
+ QualityProfileDto dto = db.qualityProfileDao().getByProjectAndLanguage(projectId, language, PROFILE_PROPERTY_PREFIX + language);
if (dto != null) {
return QProfile.from(dto);
}
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
index 70cc10e4016..f1e694297ca 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
@@ -48,7 +48,7 @@ public class QProfileProjectOperations implements ServerComponent {
QualityProfileDto qualityProfile = findNotNull(profileId, session);
db.propertiesDao().setProperty(new PropertyDto().setKey(
- QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage()).setValue(qualityProfile.getName()).setResourceId(project.getId()), session);
+ QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage()).setValue(qualityProfile.getName()).setResourceId(project.getId()), session);
session.commit();
} finally {
MyBatis.closeQuietly(session);
@@ -62,7 +62,7 @@ public class QProfileProjectOperations implements ServerComponent {
ComponentDto project = (ComponentDto) findProjectNotNull(projectId, session);
QualityProfileDto qualityProfile = findNotNull(profileId, session);
- db.propertiesDao().deleteProjectProperty(QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), project.getId(), session);
+ db.propertiesDao().deleteProjectProperty(QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), project.getId(), session);
session.commit();
} finally {
MyBatis.closeQuietly(session);
@@ -75,7 +75,7 @@ public class QProfileProjectOperations implements ServerComponent {
try {
ComponentDto project = (ComponentDto) findProjectNotNull(projectId, session);
- db.propertiesDao().deleteProjectProperty(QProfileOperations.PROFILE_PROPERTY_PREFIX + language, project.getId(), session);
+ db.propertiesDao().deleteProjectProperty(QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + language, project.getId(), session);
session.commit();
} finally {
MyBatis.closeQuietly(session);
@@ -87,7 +87,7 @@ public class QProfileProjectOperations implements ServerComponent {
DbSession session = db.openSession(false);
try {
QualityProfileDto qualityProfile = findNotNull(profileId, session);
- db.propertiesDao().deleteProjectProperties(QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), qualityProfile.getName(), session);
+ db.propertiesDao().deleteProjectProperties(QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), qualityProfile.getName(), session);
session.commit();
} finally {
MyBatis.closeQuietly(session);
diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java
index 40719dc03c3..59ecedf9321 100644
--- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java
@@ -43,9 +43,6 @@ public class QProfilesTest {
@Mock
QProfileLookup profileLookup;
- @Mock
- QProfileOperations profileOperations;
-
QProfiles qProfiles;
@Before