Browse Source

SONAR-5007 rename DefaultProfileCache to BuiltInProfiles

tags/4.4-RC1
Simon Brandhof 10 years ago
parent
commit
a6ab333f10

+ 2
- 2
sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java View File

@@ -175,7 +175,7 @@ import org.sonar.server.qualitygate.ws.QGatesShowAction;
import org.sonar.server.qualitygate.ws.QGatesUnsetDefaultAction;
import org.sonar.server.qualitygate.ws.QGatesUpdateConditionAction;
import org.sonar.server.qualitygate.ws.QGatesWs;
import org.sonar.server.qualityprofile.DefaultProfilesCache;
import org.sonar.server.qualityprofile.BuiltInProfiles;
import org.sonar.server.qualityprofile.ProfilesManager;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileCopier;
@@ -427,7 +427,7 @@ class ServerComponents {
pico.addSingleton(QProfileProjectOperations.class);
pico.addSingleton(QProfileProjectLookup.class);
pico.addSingleton(QProfileRepositoryExporter.class);
pico.addSingleton(DefaultProfilesCache.class);
pico.addSingleton(BuiltInProfiles.class);
pico.addSingleton(QProfileRecreateBuiltInAction.class);
pico.addSingleton(QProfilesWs.class);
pico.addSingleton(ProfilesWs.class);

+ 53
- 0
sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInProfiles.java View File

@@ -0,0 +1,53 @@
/*
* 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 com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.sonar.api.ServerComponent;

import java.util.Collection;

/**
* Used to list default profile names.
*
* It should be removed as soon as a new API to define quality profiles is created. Currently loading all definitions
* just to get the profile names is too slow (see {@link org.sonar.api.profiles.ProfileDefinition}).
*/
public class BuiltInProfiles implements ServerComponent {

// built-in profile names grouped by language
private final Multimap<String, String> namesByLang;

public BuiltInProfiles() {
this.namesByLang = ArrayListMultimap.create();
}

Collection<String> byLanguage(String language) {
return namesByLang.get(language);
}

BuiltInProfiles put(String language, String name) {
namesByLang.put(language, name);
return this;
}

}

+ 29
- 0
sonar-server/src/main/java/org/sonar/server/qualityprofile/BulkActivationResult.java View File

@@ -0,0 +1,29 @@
/*
* 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 com.google.common.collect.Lists;

import java.util.List;

public class BulkActivationResult {

private final List<String> errors = Lists.newArrayList();
}

+ 3
- 3
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java View File

@@ -50,17 +50,17 @@ public class QProfileReset implements ServerComponent {

private final DbClient db;
private final RuleActivator activator;
private final DefaultProfilesCache builtInProfiles;
private final BuiltInProfiles builtInProfiles;
private final ProfileDefinition[] definitions;

public QProfileReset(DbClient db, RuleActivator activator, DefaultProfilesCache builtInProfiles, ProfileDefinition[] definitions) {
public QProfileReset(DbClient db, RuleActivator activator, BuiltInProfiles builtInProfiles, ProfileDefinition[] definitions) {
this.db = db;
this.activator = activator;
this.builtInProfiles = builtInProfiles;
this.definitions = definitions;
}

public QProfileReset(DbClient db, RuleActivator activator, DefaultProfilesCache builtInProfiles) {
public QProfileReset(DbClient db, RuleActivator activator, BuiltInProfiles builtInProfiles) {
this(db, activator, builtInProfiles, new ProfileDefinition[0]);
}


+ 1
- 1
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileService.java View File

@@ -99,7 +99,7 @@ public class QProfileService implements ServerComponent {

/**
* Deactivate a rule on a Quality profile. Does nothing if the rule is not activated, but
* fails (fast) if the rule or the profile does not exist.
* fails if the rule or the profile does not exist.
*/
public List<ActiveRuleChange> deactivate(ActiveRuleKey key) {
verifyAdminPermission();

+ 6
- 6
sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java View File

@@ -59,7 +59,7 @@ public class RegisterQualityProfiles implements ServerComponent {

private final PersistentSettings settings;
private final List<ProfileDefinition> definitions;
private final DefaultProfilesCache defaultProfilesCache;
private final BuiltInProfiles builtInProfiles;
private final DbClient dbClient;
private final RuleActivator ruleActivator;

@@ -67,19 +67,19 @@ public class RegisterQualityProfiles implements ServerComponent {
* To be kept when no ProfileDefinition are injected
*/
public RegisterQualityProfiles(PersistentSettings settings,
DefaultProfilesCache defaultProfilesCache,
BuiltInProfiles builtInProfiles,
DbClient dbClient,
RuleActivator ruleActivator) {
this(settings, defaultProfilesCache, dbClient, ruleActivator, Collections.<ProfileDefinition>emptyList());
this(settings, builtInProfiles, dbClient, ruleActivator, Collections.<ProfileDefinition>emptyList());
}

public RegisterQualityProfiles(PersistentSettings settings,
DefaultProfilesCache defaultProfilesCache,
BuiltInProfiles builtInProfiles,
DbClient dbClient,
RuleActivator ruleActivator,
List<ProfileDefinition> definitions) {
this.settings = settings;
this.defaultProfilesCache = defaultProfilesCache;
this.builtInProfiles = builtInProfiles;
this.dbClient = dbClient;
this.ruleActivator = ruleActivator;
this.definitions = definitions;
@@ -101,7 +101,7 @@ public class RegisterQualityProfiles implements ServerComponent {
if (shouldRegister(profileKey, session)) {
register(profileKey, entry.getValue(), session);
}
defaultProfilesCache.put(language, profileName);
builtInProfiles.put(language, profileName);
}
setDefault(language, profileDefs, session);
}

+ 55
- 0
sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInProfilesTest.java View File

@@ -0,0 +1,55 @@
/*
* 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.junit.Before;
import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;


public class BuiltInProfilesTest {

BuiltInProfiles cache;

@Before
public void setUp() throws Exception {
cache = new BuiltInProfiles();
}

@Test
public void add_profiles() throws Exception {
cache.put("java", "Default");
cache.put("java", "Sonar Way");
cache.put("js", "Default");

assertThat(cache.byLanguage("java")).containsOnly("Default", "Sonar Way");
assertThat(cache.byLanguage("js")).containsOnly("Default");
}

@Test
public void not_add_same_profile_name() throws Exception {
cache.put("java", "Default");
cache.put("java", "Default");

assertThat(cache.byLanguage("java")).containsOnly("Default");
}
}

Loading…
Cancel
Save