quality_profiles.remove_projects_confirm_button=Remove All
quality_profiles.copy_x_title=Copy Profile {0}
quality_profiles.copy_new_name=New name
-quality_profiles.recreate_built_in_profiles=Recreate Built-in Profiles
-quality_profiles.recreate_built_in_profiles_confirmation=Are you sure you want to recreate '{0}' profile(s) for '{1}' ?
+quality_profiles.restore_built_in_profiles=Restore Built-in Profiles
+quality_profiles.restore_built_in_profiles_confirmation=Are you sure you want to restore '{0}' profile(s) for '{1}' ?
#------------------------------------------------------------------------------
#
import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
import org.sonar.server.qualityprofile.ws.BulkRuleActivationActions;
import org.sonar.server.qualityprofile.ws.ProfilesWs;
-import org.sonar.server.qualityprofile.ws.QProfileRecreateBuiltInAction;
+import org.sonar.server.qualityprofile.ws.QProfileRestoreBuiltInAction;
import org.sonar.server.qualityprofile.ws.QProfilesWs;
import org.sonar.server.qualityprofile.ws.RuleActivationActions;
import org.sonar.server.rule.DeprecatedRulesDefinition;
pico.addSingleton(QProfileProjectLookup.class);
pico.addSingleton(QProfileRepositoryExporter.class);
pico.addSingleton(BuiltInProfiles.class);
- pico.addSingleton(QProfileRecreateBuiltInAction.class);
+ pico.addSingleton(QProfileRestoreBuiltInAction.class);
pico.addSingleton(QProfilesWs.class);
pico.addSingleton(ProfilesWs.class);
pico.addSingleton(RuleActivationActions.class);
return builtInProfiles.byLanguage(language);
}
+ /**
+ * Reset built-in profiles for the given language. Missing profiles are created and
+ * existing ones are updated
+ */
void resetLanguage(String language) {
ListMultimap<String, RulesProfile> profilesByName = loadDefinitionsGroupedByName(language);
for (Map.Entry<String, Collection<RulesProfile>> entry : profilesByName.asMap().entrySet()) {
restore(new StringReader(backup));
}
- public void resetBuiltInProfilesForLanguage(String lang) {
+ public void restoreBuiltInProfilesForLanguage(String lang) {
verifyAdminPermission();
reset.resetLanguage(lang);
}
+++ /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.qualityprofile.ws;
-
-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.api.utils.text.JsonWriter;
-import org.sonar.server.qualityprofile.QProfileResult;
-import org.sonar.server.qualityprofile.QProfileService;
-
-public class QProfileRecreateBuiltInAction implements RequestHandler {
-
- private final QProfileService service;
-
- public QProfileRecreateBuiltInAction(QProfileService service) {
- this.service = service;
- }
-
- void define(WebService.NewController controller) {
- WebService.NewAction restoreDefault = controller.createAction("recreate_built_in")
- .setDescription("Recreate Built-in Profiles")
- .setSince("4.4")
- .setPost(true)
- .setHandler(this);
- restoreDefault.createParam("language")
- .setDescription("Recreate built-in profiles for this language")
- .setExampleValue("java")
- .setRequired(true);
- }
-
- @Override
- public void handle(Request request, Response response) {
- final String language = request.mandatoryParam("language");
- service.resetBuiltInProfilesForLanguage(language);
-
- // TODO
- QProfileResult result = new QProfileResult();
-
- if (!result.infos().isEmpty() || !result.warnings().isEmpty()) {
- JsonWriter json = response.newJsonWriter();
- json.beginObject();
- if (!result.infos().isEmpty()) {
- json.name("infos").beginArray();
- for (String info : result.infos()) {
- json.value(info);
- }
- json.endArray();
- }
- if (!result.warnings().isEmpty()) {
- json.name("warnings").beginArray();
- for (String warning : result.warnings()) {
- json.value(warning);
- }
- json.endArray();
- }
- json.endObject().close();
- } else {
- response.noContent();
- }
- }
-
-}
--- /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.qualityprofile.ws;
+
+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.api.utils.text.JsonWriter;
+import org.sonar.server.qualityprofile.QProfileResult;
+import org.sonar.server.qualityprofile.QProfileService;
+
+public class QProfileRestoreBuiltInAction implements RequestHandler {
+
+ private final QProfileService service;
+
+ public QProfileRestoreBuiltInAction(QProfileService service) {
+ this.service = service;
+ }
+
+ void define(WebService.NewController controller) {
+ WebService.NewAction restoreDefault = controller.createAction("restore_built_in")
+ .setDescription("Restore built-in profiles from the definitions declared by plugins. " +
+ "Missing profiles are created, existing ones are updated.")
+ .setSince("4.4")
+ .setPost(true)
+ .setHandler(this);
+ restoreDefault.createParam("language")
+ .setDescription("Restore the built-in profiles defined for this language")
+ .setExampleValue("java")
+ .setRequired(true);
+ }
+
+ @Override
+ public void handle(Request request, Response response) {
+ String language = request.mandatoryParam("language");
+ service.restoreBuiltInProfilesForLanguage(language);
+
+ // TODO
+ QProfileResult result = new QProfileResult();
+
+ if (!result.infos().isEmpty() || !result.warnings().isEmpty()) {
+ JsonWriter json = response.newJsonWriter();
+ json.beginObject();
+ if (!result.infos().isEmpty()) {
+ json.name("infos").beginArray();
+ for (String info : result.infos()) {
+ json.value(info);
+ }
+ json.endArray();
+ }
+ if (!result.warnings().isEmpty()) {
+ json.name("warnings").beginArray();
+ for (String warning : result.warnings()) {
+ json.value(warning);
+ }
+ json.endArray();
+ }
+ json.endObject().close();
+ } else {
+ response.noContent();
+ }
+ }
+
+}
public static final String API_ENDPOINT = "api/qualityprofiles";
- private final QProfileRecreateBuiltInAction recreateBuiltInAction;
+ private final QProfileRestoreBuiltInAction resetAction;
private final RuleActivationActions ruleActivationActions;
private final BulkRuleActivationActions bulkRuleActivationActions;
- public QProfilesWs(QProfileRecreateBuiltInAction recreateBuiltInAction,
+ public QProfilesWs(QProfileRestoreBuiltInAction resetAction,
RuleActivationActions ruleActivationActions,
BulkRuleActivationActions bulkRuleActivationActions) {
- this.recreateBuiltInAction = recreateBuiltInAction;
+ this.resetAction = resetAction;
this.ruleActivationActions = ruleActivationActions;
this.bulkRuleActivationActions = bulkRuleActivationActions;
}
.setDescription("Quality Profiles")
.setSince("4.4");
- recreateBuiltInAction.define(controller);
+ resetAction.define(controller);
ruleActivationActions.define(controller);
bulkRuleActivationActions.define(controller);
redirect_to :action => 'index'
end
- # Modal window to recreate built-in profiles
- # GET /profiles/recreate_built_in_form/<profile id>
- def recreate_built_in_form
+ # Modal window to restore built-in profiles
+ # GET /profiles/restore_built_in_form/<profile id>
+ def restore_built_in_form
verify_ajax_request
require_parameters 'language'
@language = java_facade.getLanguages().find { |l| l.getKey()==params[:language].to_s }
call_backend do
@builtin_profile_names = Internal.component(Java::OrgSonarServerQualityprofile::QProfileService.java_class).builtInProfileNamesForLanguage(params[:language].to_s)
end
- render :partial => 'profiles/recreate_built_in_form'
+ render :partial => 'profiles/restore_built_in_form'
end
- # POST /profiles/recreate_built_in_form?language=<language>
- def recreate_built_in
+ # POST /profiles/restore_built_in?language=<language>
+ def restore_built_in
verify_post_request
require_parameters 'language'
call_backend do
- Internal.component(Java::OrgSonarServerQualityprofile::QProfileService.java_class).resetBuiltInProfilesForLanguage(params[:language].to_s)
+ Internal.component(Java::OrgSonarServerQualityprofile::QProfileService.java_class).restoreBuiltInProfilesForLanguage(params[:language].to_s)
#flash_result(@result)
end
redirect_to :action => 'index'
+++ /dev/null
-<form id="recreate-built-in-profiles-form" action="profiles/recreate_built_in" method="POST">
- <fieldset>
- <input type="hidden" name="language" value="<%= @language.getKey() -%>"/>
-
- <div class="modal-head">
- <h2><%= h message('quality_profiles.recreate_built_in_profiles') -%></h2>
- </div>
-
- <div class="modal-body">
- <%= h message('quality_profiles.recreate_built_in_profiles_confirmation', :params => [@builtin_profile_names.join('\', \''), @language.getName()]) -%>
- </div>
-
- <div class="modal-foot">
- <input type="submit" value="<%= h message('restore') -%>" id="recreate-built-in-profiles-submit"/>
- <a href="#" onclick="return closeModalWindow()" id="recreate-built-in-profiles-cancel"><%= h message('cancel') -%></a>
- </div>
- </fieldset>
-</form>
--- /dev/null
+<form id="restore-built-in-profiles-form" action="profiles/restore_built_in" method="POST">
+ <fieldset>
+ <input type="hidden" name="language" value="<%= @language.getKey() -%>"/>
+
+ <div class="modal-head">
+ <h2><%= h message('quality_profiles.restore_built_in_profiles') -%></h2>
+ </div>
+
+ <div class="modal-body">
+ <%= h message('quality_profiles.restore_built_in_profiles_confirmation', :params => [@builtin_profile_names.join('\', \''), @language.getName()]) -%>
+ </div>
+
+ <div class="modal-foot">
+ <input type="submit" value="<%= h message('restore') -%>" id="restore-built-in-profiles-submit"/>
+ <a href="#" onclick="return closeModalWindow()" id="restore-built-in-profiles-cancel"><%= h message('cancel') -%></a>
+ </div>
+ </fieldset>
+</form>
</ul>
<ul style="float: right" class="horizontal">
<li class="marginleft10">
- <a id="create-link-<%= language.getKey() -%>" href="<%= ApplicationController.root_context -%>/profiles/recreate_built_in_form?language=<%= u language.getKey() -%>"
- class="open-modal link-action"><%= message('quality_profiles.recreate_built_in_profiles') -%></a>
+ <a id="create-link-<%= language.getKey() -%>" href="<%= ApplicationController.root_context -%>/profiles/restore_built_in_form?language=<%= u language.getKey() -%>"
+ class="open-modal link-action"><%= message('quality_profiles.restore_built_in_profiles') -%></a>
</li>
</ul>
<% end %>
+++ /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.qualityprofile.ws;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.server.qualityprofile.QProfileResult;
-import org.sonar.server.qualityprofile.QProfileService;
-import org.sonar.server.rule.RuleService;
-import org.sonar.server.ws.WsTester;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class QProfileRecreateBuiltInActionTest {
-
- @Mock
- QProfileService profileService;
-
- WsTester tester;
-
- @Before
- public void setUp() throws Exception {
- QProfileService profileService = mock(QProfileService.class);
- RuleService ruleService = mock(RuleService.class);
- tester = new WsTester(new QProfilesWs(
- new QProfileRecreateBuiltInAction(this.profileService),
- new RuleActivationActions(profileService),
- new BulkRuleActivationActions(profileService, ruleService)));
- }
-
- @Test
- public void return_empty_result_when_no_infos_or_warnings() throws Exception {
- //when(profileService.resetBuiltInProfilesForLanguage("java")).thenReturn(new QProfileResult());
-
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
- request.execute().assertNoContent();
- }
-
- // TODO
-// @Test
-// public void show_infos() throws Exception {
-// when(profileService.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")));
-//
-// WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
-// request.execute().assertJson(getClass(), "show_infos.json");
-// }
-//
-// @Test
-// public void show_warnings() throws Exception {
-// when(profileService.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addWarnings(newArrayList("Some warning")));
-//
-// WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
-// request.execute().assertJson(getClass(), "show_warnings.json");
-// }
-//
-// @Test
-// public void show_infos_and_warnings() throws Exception {
-// when(profileService.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")).addWarnings(newArrayList("Some warning")));
-//
-// WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
-// request.execute().assertJson(getClass(), "show_infos_and_warnings.json");
-// }
-}
--- /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.qualityprofile.ws;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.server.qualityprofile.QProfileService;
+import org.sonar.server.rule.RuleService;
+import org.sonar.server.ws.WsTester;
+
+import static org.mockito.Mockito.mock;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QProfileRestoreBuiltInActionTest {
+
+ @Mock
+ QProfileService profileService;
+
+ WsTester tester;
+
+ @Before
+ public void setUp() throws Exception {
+ QProfileService profileService = mock(QProfileService.class);
+ RuleService ruleService = mock(RuleService.class);
+ tester = new WsTester(new QProfilesWs(
+ new QProfileRestoreBuiltInAction(this.profileService),
+ new RuleActivationActions(profileService),
+ new BulkRuleActivationActions(profileService, ruleService)));
+ }
+
+ @Test
+ public void return_empty_result_when_no_infos_or_warnings() throws Exception {
+ //when(profileService.resetBuiltInProfilesForLanguage("java")).thenReturn(new QProfileResult());
+
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_built_in").setParam("language", "java");
+ request.execute().assertNoContent();
+ }
+
+ // TODO
+// @Test
+// public void show_infos() throws Exception {
+// when(profileService.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")));
+//
+// WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
+// request.execute().assertJson(getClass(), "show_infos.json");
+// }
+//
+// @Test
+// public void show_warnings() throws Exception {
+// when(profileService.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addWarnings(newArrayList("Some warning")));
+//
+// WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
+// request.execute().assertJson(getClass(), "show_warnings.json");
+// }
+//
+// @Test
+// public void show_infos_and_warnings() throws Exception {
+// when(profileService.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")).addWarnings(newArrayList("Some warning")));
+//
+// WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
+// request.execute().assertJson(getClass(), "show_infos_and_warnings.json");
+// }
+}
public class QProfilesWsMediumTest {
-
@ClassRule
public static ServerTester tester = new ServerTester();
- private static final String API_BUILT_IN_METHOD = "recreate_built_in";
+ private static final String API_BUILT_IN_METHOD = "restore_built_in";
QProfilesWs ws;
DbClient db;
public void setUp() {
QProfileService profileService = mock(QProfileService.class);
RuleService ruleService = mock(RuleService.class);
- controller = new WsTester(new QProfilesWs(new QProfileRecreateBuiltInAction(
+ controller = new WsTester(new QProfilesWs(new QProfileRestoreBuiltInAction(
mock(QProfileService.class)),
new RuleActivationActions(profileService),
new BulkRuleActivationActions(profileService, ruleService)
}
@Test
- public void define_recreate_built_action() throws Exception {
- WebService.Action restoreProfiles = controller.action("recreate_built_in");
+ public void define_restore_built_action() throws Exception {
+ WebService.Action restoreProfiles = controller.action("restore_built_in");
assertThat(restoreProfiles).isNotNull();
assertThat(restoreProfiles.isPost()).isTrue();
assertThat(restoreProfiles.params()).hasSize(1);